Example #1
0
        internal void SendCompBaseData(CoreComponent comp)
        {
            if (IsServer)
            {
                const PacketType type = PacketType.CompBase;
                comp.Data.Repo.Base.UpdateCompBasePacketInfo(comp, true);

                PacketInfo     oldInfo;
                CompBasePacket iPacket;
                if (PrunedPacketsToClient.TryGetValue(comp.Data.Repo.Base, out oldInfo))
                {
                    iPacket          = (CompBasePacket)oldInfo.Packet;
                    iPacket.EntityId = comp.MyCube.EntityId;
                    iPacket.Data     = comp.Data.Repo.Base;
                }
                else
                {
                    iPacket          = PacketCompBasePool.Get();
                    iPacket.MId      = ++comp.MIds[(int)type];
                    iPacket.EntityId = comp.MyCube.EntityId;
                    iPacket.SenderId = MultiplayerId;
                    iPacket.PType    = type;
                    iPacket.Data     = comp.Data.Repo.Base;
                }

                PrunedPacketsToClient[comp.Data.Repo.Base] = new PacketInfo {
                    Entity = comp.MyCube,
                    Packet = iPacket,
                };
            }
            else
            {
                Log.Line($"SendCompData should never be called on Client");
            }
        }
Example #2
0
 internal void SendTrackReticleUpdate(CoreComponent comp, bool track)
 {
     if (IsClient)
     {
         uint[] mIds;
         if (PlayerMIds.TryGetValue(MultiplayerId, out mIds))
         {
             PacketsToServer.Add(new BoolUpdatePacket
             {
                 MId      = ++mIds[(int)PacketType.ReticleUpdate],
                 EntityId = comp.MyCube.EntityId,
                 SenderId = MultiplayerId,
                 PType    = PacketType.ReticleUpdate,
                 Data     = track
             });
         }
         else
         {
             Log.Line($"SendTrackReticleUpdate no player MIds found");
         }
     }
     else if (HandlesInput)
     {
         comp.Data.Repo.Base.State.TrackingReticle = track;
         SendCompBaseData(comp);
     }
 }
Example #3
0
        /// <summary>
        /// Returns all the properties in the given component
        /// </summary>
        /// <param name="comp"></param>
        public static PropertyInfo[] GetProperties(CoreComponent comp)
        {
            List <PropertyInfo> returnProps = new List <PropertyInfo>();

            System.Reflection.PropertyInfo[] properties = comp.GetType().GetProperties();
            foreach (PropertyInfo prop in properties)
            {
                bool ignoreProp = false;
                var  attributes = prop.GetCustomAttributes(true);
                foreach (Attribute at in attributes)
                {
                    if (at is IgnoreInSaveAttribute)
                    {
                        ignoreProp = true;
                        break;
                    }
                }
                if (!ignoreProp)
                {
                    returnProps.Add(prop);
                }
                else
                {
                    continue;
                }
            }

            return(returnProps.ToArray());
        }
Example #4
0
        /// <summary>
        /// Returns all the fields in the given component
        /// </summary>
        /// <param name="comp"></param>
        public static FieldInfo[] GetFields(CoreComponent comp)
        {
            List <FieldInfo> returnFields = new List <FieldInfo>();

            System.Reflection.FieldInfo[] fields = comp.GetType().GetFields();
            foreach (System.Reflection.FieldInfo field in fields)
            {
                bool ignoreField = false;
                var  attributes  = field.GetCustomAttributes(true);
                foreach (Attribute at in attributes)
                {
                    if (at is IgnoreInSaveAttribute)
                    {
                        ignoreField = true;
                        break;
                    }
                }
                if (!ignoreField)
                {
                    returnFields.Add(field);
                }
                else
                {
                    continue;
                }
            }

            return(returnFields.ToArray());
        }
Example #5
0
 internal void SendOverRidesClientComp(CoreComponent comp, string settings, int value)
 {
     if (IsClient)
     {
         uint[] mIds;
         if (PlayerMIds.TryGetValue(MultiplayerId, out mIds))
         {
             PacketsToServer.Add(new OverRidesPacket
             {
                 MId      = ++mIds[(int)PacketType.OverRidesUpdate],
                 PType    = PacketType.OverRidesUpdate,
                 EntityId = comp.MyCube.EntityId,
                 SenderId = MultiplayerId,
                 Setting  = settings,
                 Value    = value,
             });
         }
         else
         {
             Log.Line($"SendOverRidesClientComp no player MIds found");
         }
     }
     else
     {
         Log.Line($"SendOverRidesClientComp should only be called on clients");
     }
 }
        public void SetProxy_UnknownResult(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] CoreComponent sut,
            string host,
            int port)
        {
            // ARRANGE
            var proxy = new JObject(
                new JProperty("type", 1),
                new JProperty("http", new JObject(
                                  new JProperty("host", host),
                                  new JProperty("port", port))));

            httpClientMock.SetupApiCall(sut, CallType.Other, "setproxy",
                                        new Parameters
            {
                { "proxy", proxy }
            }, DataType.Other)
            .Returns("FAILED")
            .Verifiable();

            // ACT
            Action act = () => sut.SetProxy(host, port);

            // ASSERT
            act.ShouldThrow <ZapException>().WithMessage(Resources.UnknownSetProxyResult);
            httpClientMock.Verify();
        }
        /// <summary>
        /// Initialize Camera config string
        /// </summary>
        private void InitializeCameraDevice()
        {
            CoreComponent component     = null;
            string        cameraDevices = "";

            //get camera friendly names from
            try
            {
                component     = new CoreComponent();
                cameraDevices = component.GetCameraDevice();
            }
            catch (Exception ex)
            {
                Log.LogError("Cannot get Camera devices: " + ex.ToString());
            }
            finally
            {
                if (component != null)
                {
                    component.Dispose();
                    component = null;
                }
            }
            CameraConfig.Text = cameraDevices;
        }
        public void SetProxy(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] CoreComponent sut,
            string host,
            int port)
        {
            // ARRANGE
            var proxy = new JObject(
                new JProperty("type", 1),
                new JProperty("http", new JObject(
                                  new JProperty("host", host),
                                  new JProperty("port", port))));

            httpClientMock.SetupApiCall(sut, CallType.Other, "setproxy",
                                        new Parameters
            {
                { "proxy", proxy }
            }, DataType.Other)
            .Returns("OK")
            .Verifiable();

            // ACT
            sut.SetProxy(host, port);

            // ASSERT
            httpClientMock.Verify();
        }
            internal void ServerUpdate(CoreComponent comp)
            {
                long aTermId;

                if (!ServerTerminalMaps.TryGetValue(comp, out aTermId))
                {
                    ServerTerminalMaps[comp] = comp.MyCube.EntityId;
                    //if (!Session.LocalVersion) Log.Line($"ServerUpdate added Id");
                }
                else
                {
                    var cube = MyEntities.GetEntityByIdOrDefault(aTermId) as MyCubeBlock;
                    if (cube != null && cube.CubeGrid.EntityId != comp.Ai.MyGrid.EntityId)
                    {
                        ServerTerminalMaps[comp] = 0;
                        //if (!Session.LocalVersion) Log.Line($"ServerUpdate reset Id");
                    }
                }

                comp.Ai.Data.Repo.ActiveTerminal = comp.MyCube.EntityId;

                if (comp.IsAsleep)
                {
                    comp.WakeupComp();
                }

                if (Session.MpActive)
                {
                    Session.SendAiData(comp.Ai);
                }
            }
        public void GetMessagesHar(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] CoreComponent sut,
            string baseUrl,
            int start,
            int count,
            Har messages)
        {
            // ARRANGE
            httpClientMock.SetupApiCall(sut, CallType.Other, "messagesHar",
                                        new Parameters
            {
                { "baseurl", baseUrl },
                { "start", start },
                { "count", count }
            }, DataType.Other)
            .Returns(Har.Serialize(messages))
            .Verifiable();

            // ACT
            var result = sut.GetMessagesHar(baseUrl, start, count);

            // ASSERT
            result.ShouldBeEquivalentTo(messages);
            httpClientMock.Verify();
        }
Example #11
0
    //Connect components to eachother - called in audio engine
    public void createConnection(CoreComponent input, CoreComponent output, CoreSocketCasing inputSocket, CoreSocketCasing outputSocket)
    {
        if (inputSocket is AudioInputSocketCasing && outputSocket is AudioOutputSocketCasing)
        {
            AudioSocketComponent inSocComp  = audioInputs[inputSocket.getSocketNum()];
            AudioSocketComponent outSocComp = output.io.audioOutputs[outputSocket.getSocketNum()];

            inSocComp.connect(outSocComp);
            inSocComp.setSocketNum(inputSocket.getSocketNum());

            outSocComp.connect(inSocComp);
            outSocComp.setSocketNum(outputSocket.getSocketNum());
        }
        else if (inputSocket is DataInputSocketCasing && outputSocket is DataOutputSocketCasing)
        {
            DataSocketComponent inSocComp  = dataInputs[inputSocket.getSocketNum()];
            DataSocketComponent outSocComp = output.io.dataOutputs[outputSocket.getSocketNum()];

            DataSocketCasing dataInputSocket  = inputSocket as DataSocketCasing;
            DataSocketCasing dataOutputSocket = outputSocket as DataSocketCasing;

            inSocComp.connect(outSocComp);
            inSocComp.setSocketNum(dataInputSocket.getSocketNum());
            inSocComp.setControlNum(dataInputSocket.getControlNum());

            outSocComp.connect(inSocComp);
            outSocComp.setSocketNum(dataOutputSocket.getSocketNum());
            outSocComp.setControlNum(dataOutputSocket.getControlNum());
        }
    }
Example #12
0
        private bool ServerOverRidesUpdate(PacketObj data)
        {
            var packet          = data.Packet;
            var overRidesPacket = (OverRidesPacket)packet;
            var ent             = MyEntities.GetEntityByIdOrDefault(packet.EntityId, null, true);
            var comp            = ent?.Components.Get <CoreComponent>();

            if (comp?.Ai == null || comp.Platform.State != CorePlatform.PlatformState.Ready)
            {
                return(Error(data, Msg("Comp", comp != null), Msg("Ai", comp?.Ai != null), Msg("Ai", comp?.Platform.State == CorePlatform.PlatformState.Ready)));
            }

            uint[] mIds;
            if (PlayerMIds.TryGetValue(packet.SenderId, out mIds) && mIds[(int)packet.PType] < packet.MId)
            {
                mIds[(int)packet.PType] = packet.MId;

                CoreComponent.RequestSetValue(comp, overRidesPacket.Setting, overRidesPacket.Value, SteamToPlayer[overRidesPacket.SenderId]);
                data.Report.PacketValid = true;
            }
            else
            {
                Log.Line($"ServerOverRidesUpdate: MidsHasSenderId:{PlayerMIds.ContainsKey(packet.SenderId)} - midsNull:{mIds == null} - senderId:{packet.SenderId}");
            }

            return(true);
        }
Example #13
0
    //Connect two components sockets together -- Receiving Socket --> Sending Socket
    public void createConnection(CoreSocketCasing socket1, CoreSocketCasing socket2)
    {
        //Interprets the correct way around - input->output
        CoreComponent    input = null, output = null;
        CoreSocketCasing inSoc = null, outSoc = null;

        if (socket1 is AudioInputSocketCasing || socket1 is DataInputSocketCasing)
        {
            input  = socket1.GetComponentInParent <CoreCasing>().getComponent();
            output = socket2.GetComponentInParent <CoreCasing>().getComponent();

            inSoc  = socket1;
            outSoc = socket2;
        }
        else if (socket1 is AudioOutputSocketCasing || socket1 is DataOutputSocketCasing)
        {
            input  = socket2.GetComponentInParent <CoreCasing>().getComponent();
            output = socket1.GetComponentInParent <CoreCasing>().getComponent();

            inSoc  = socket2;
            outSoc = socket1;
        }
        else
        {
            return;
        }

        input.io.createConnection(input, output, inSoc, outSoc);

        socket1.drawCable(socket2);

        print("Connection made");
    }
            internal void HandleInputUpdate(CoreComponent comp)
            {
                if (Active && (Comp != comp || OriginalAiVersion != comp.Ai.Version))
                {
                    Clean();
                }

                Session.LastTerminal = (IMyTerminalBlock)comp.MyCube;

                Comp = comp;

                OriginalAiVersion = comp.Ai.Version;

                if (comp.IsAsleep)
                {
                    comp.WakeupComp();
                }

                if (Session.IsClient && !Active)
                {
                    Session.SendActiveTerminal(comp);
                }
                else if (Session.IsServer)
                {
                    ServerUpdate(Comp);
                }

                Active = true;
            }
Example #15
0
    void Start()
    {
        //Go up parents until an audio component is found
        CoreCasing casing = null;
        GameObject level  = this.gameObject;

        component = null;
        while (casing == null)
        {
            if (level.transform.parent != null)
            {
                level = level.transform.parent.gameObject;
            }
            else
            {
                break;
            }
            casing = level.GetComponent <CoreCasing>();
        }
        if (casing != null)
        {
            component = casing.getComponent();
        }

        //Run the child's intitialisation
        initialise();
    }
            internal void Clean(bool purge = false)
            {
                if (Session.MpActive && Session.HandlesInput && Comp != null && !purge)
                {
                    uint[] mIds;
                    if (Session.PlayerMIds.TryGetValue(Session.MultiplayerId, out mIds))
                    {
                        Session.PacketsToServer.Add(new TerminalMonitorPacket
                        {
                            SenderId = Session.MultiplayerId,
                            PType    = PacketType.TerminalMonitor,
                            EntityId = Comp.MyCube.EntityId,
                            State    = TerminalMonitorPacket.Change.Clean,
                            MId      = ++mIds[(int)PacketType.TerminalMonitor],
                        });
                    }
                }

                if (!purge && Session.IsServer)
                {
                    ServerClean(Comp);
                }

                Comp = null;
                OriginalAiVersion = -1;
                Active            = false;
            }
        public void GetAlert(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] CoreComponent sut,
            int id,
            Alert alert)
        {
            // ARRANGE
            var json = new JObject(
                new JProperty("alert", JObject.FromObject(alert)));

            httpClientMock.SetupApiCall(sut, CallType.View, "alert",
                                        new Parameters
            {
                { "id", id }
            })
            .Returns(json.ToString())
            .Verifiable();

            // ACT
            var result = sut.GetAlert(id);

            // ASSERT
            result.ShouldBeEquivalentTo(alert);
            httpClientMock.Verify();
        }
        public void UpdateCompBasePacketInfo(CoreComponent comp, bool clean = false)
        {
            ++Revision;
            ++State.Revision;
            Session.PacketInfo info;
            if (clean && comp.Session.PrunedPacketsToClient.TryGetValue(comp.Data.Repo.Base.State, out info))
            {
                comp.Session.PrunedPacketsToClient.Remove(comp.Data.Repo.Base.State);
                comp.Session.PacketStatePool.Return((CompStatePacket)info.Packet);
            }

            for (int i = 0; i < Targets.Length; i++)
            {
                var t  = Targets[i];
                var wr = Reloads[i];

                if (clean)
                {
                    if (comp.Session.PrunedPacketsToClient.TryGetValue(t, out info))
                    {
                        comp.Session.PrunedPacketsToClient.Remove(t);
                        comp.Session.PacketTargetPool.Return((TargetPacket)info.Packet);
                    }
                    if (comp.Session.PrunedPacketsToClient.TryGetValue(wr, out info))
                    {
                        comp.Session.PrunedPacketsToClient.Remove(wr);
                        comp.Session.PacketReloadPool.Return((WeaponReloadPacket)info.Packet);
                    }
                }
                ++wr.Revision;
                ++t.Revision;
                t.WeaponRandom.ReInitRandom();
            }
        }
Example #19
0
 public ZapClient(string host, int port, Protocols protocol = Protocols.http)
 {
     Protocol          = protocol;
     Host              = host;
     Port              = port;
     Acsrf             = new AcsrfComponent(this);
     AjaxSpider        = new AjaxSpiderComponent(this);
     Ascan             = new AscanComponent(this);
     Authentication    = new AuthenticationComponent(this);
     Authorization     = new AuthorizationComponent(this);
     Autoupdate        = new AutoupdateComponent(this);
     Break             = new BreakComponent(this);
     Context           = new ContextComponent(this);
     Core              = new CoreComponent(this);
     ForcedUser        = new ForcedUserComponent(this);
     HttpSessions      = new HttpSessionsComponent(this);
     Params            = new ParamsComponent(this);
     Pscan             = new PscanComponent(this);
     Reveal            = new RevealComponent(this);
     Script            = new ScriptComponent(this);
     Search            = new SearchComponent(this);
     Selenium          = new SeleniumComponent(this);
     SessionManagement = new SessionManagementComponent(this);
     Spider            = new SpiderComponent(this);
     Users             = new UsersComponent(this);
 }
        public void SendRequest(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] CoreComponent sut,
            string httpRequest,
            bool followRedirects,
            IEnumerable <Message> messages)
        {
            // ARRANGE
            var json = new JObject(
                new JProperty("sendRequest", JArray.FromObject(messages)));

            httpClientMock.SetupApiCall(sut, CallType.Action, "sendRequest",
                                        new Parameters
            {
                { "request", httpRequest },
                { "followRedirects", followRedirects }
            })
            .Returns(json.ToString())
            .Verifiable();

            // ACT
            var result = sut.SendRequest(httpRequest, followRedirects);

            // ASSERT
            result.ShouldBeEquivalentTo(messages);
            httpClientMock.Verify();
        }
        public void GetAlerts(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] CoreComponent sut,
            string baseUrl,
            int start,
            int count,
            IEnumerable <Alert> alerts)
        {
            // ARRANGE
            var json = new JObject(
                new JProperty("alerts", JArray.FromObject(alerts)));

            httpClientMock.SetupApiCall(sut, CallType.View, "alerts",
                                        new Parameters
            {
                { "baseurl", baseUrl },
                { "start", start },
                { "count", count }
            })
            .Returns(json.ToString())
            .Verifiable();

            // ACT
            var result = sut.GetAlerts(baseUrl, start, count);

            // ASSERT
            result.ShouldBeEquivalentTo(alerts);
            httpClientMock.Verify();
        }
        public void GetNumberOfMessages(
            [Frozen] Mock <IHttpClient> httpClientMock,
            [Greedy] CoreComponent sut,
            string baseUrl,
            int numberOfMessages)
        {
            // ARRANGE
            var json = new JObject(
                new JProperty("numberOfMessages", numberOfMessages));

            httpClientMock.SetupApiCall(sut, CallType.View, "numberOfMessages",
                                        new Parameters
            {
                { "baseurl", baseUrl }
            })
            .Returns(json.ToString())
            .Verifiable();

            // ACT
            var result = sut.GetNumberOfMessages(baseUrl);

            // ASSERT
            result.Should().Be(numberOfMessages);
            httpClientMock.Verify();
        }
        internal PlatformState Init(CoreComponent comp)
        {
            if (comp.MyCube.MarkedForClose)
            {
                return(PlatformCrash(comp, true, false, $"Your block subTypeId ({comp.MyCube.BlockDefinition.Id.SubtypeId.String}) markedForClose, init platform invalid, I am crashing now Dave."));
            }

            if (!comp.MyCube.IsFunctional)
            {
                State = PlatformState.Delay;
                return(State);
            }

            //Get or init Ai
            var newAi = false;

            if (!Comp.Session.GridTargetingAIs.TryGetValue(Comp.MyCube.CubeGrid, out Comp.Ai))
            {
                newAi   = true;
                Comp.Ai = Comp.Session.GridAiPool.Get();
                Comp.Ai.Init(Comp.MyCube.CubeGrid, Comp.Session);
                Comp.Session.GridTargetingAIs.TryAdd(Comp.MyCube.CubeGrid, Comp.Ai);
            }

            var blockDef = Comp.MyCube.BlockDefinition.Id.SubtypeId;

            if (!Comp.Ai.WeaponCounter.ContainsKey(blockDef))
            {
                Comp.Ai.WeaponCounter[blockDef] = Comp.Session.WeaponCountPool.Get();
            }

            var wCounter = comp.Ai.WeaponCounter[blockDef];

            wCounter.Max = Structure.GridWeaponCap;

            if (newAi)
            {
                Comp.SubGridInit();
                if (Comp.Ai.MarkedForClose)
                {
                    Log.Line($"PlatFormInit and AI MarkedForClose: CubeMarked:{Comp.MyCube.MarkedForClose}");
                }
            }

            if (wCounter.Max == 0 || Comp.Ai.Construct.GetWeaponCount(blockDef) + 1 <= wCounter.Max)
            {
                wCounter.Current++;
                GridAi.Constructs.UpdateWeaponCounters(Comp.Ai);
                State = PlatformState.Valid;
            }
            else
            {
                return(PlatformCrash(comp, true, false, $"{blockDef.String} over block limits: {wCounter.Current}."));
            }

            Parts.Entity = comp.Entity as MyEntity;

            return(GetParts(comp));
        }
        public void ComponentName(
            [Greedy] CoreComponent sut)
        {
            // ACT
            var result = sut.ComponentName;

            // ASSERT
            result.Should().Be("core");
        }
Example #25
0
        public static ICoreComponent CreateCoreComponent(IGraphUiContainer uiContainer, bool enableGeometricPreview)
        {
            if (null != CoreComponent.Instance)
            {
                throw new InvalidOperationException("'ClassFactory.CreateCoreComponent' called twice!");
            }

            return(CoreComponent.CreateSingleton(uiContainer, enableGeometricPreview));
        }
        internal void ResetParts(CoreComponent comp)
        {
            Parts.Clean(comp.Entity as MyEntity);
            Parts.CheckSubparts();

            ResetTurret(comp);

            comp.Status = Started;
        }
Example #27
0
        public CorePart(string name, int width, int height, RotateChar[] structure, CoreComponent cc, StabilityComponent sc, Direction facing = Direction.N)
            : base(name, width, height, structure, facing)
        {
            CoreComponent      = cc;
            StabilityComponent = sc;

            Components.Add(cc);
            Components.Add(sc);
        }
        public void SetSelectedMenuEntry(CoreComponent option)
        {
            if (option == null)
            {
                throw new InvalidOperationException("Attempting to set selected menu entry to null");
            }

            selectedMenuEntry = option;
            selectedMenuEntry.SetMenuHighlight(true);
        }
        public void SetSelectedEntry(CoreComponent coreComp)
        {
            if (coreComp == null)
            {
                throw new InvalidOperationException("Attempting to set selected entry to null");
            }

            selectedEntry = coreComp;
            selectedEntry.SetHighlight(true);
        }
Example #30
0
        internal static void RequestControlMode(IMyTerminalBlock block, long newValue)
        {
            var comp = block?.Components?.Get <CoreComponent>();

            if (comp == null || comp.Platform.State != CorePlatform.PlatformState.Ready)
            {
                return;
            }

            CoreComponent.RequestSetValue(comp, "ControlModes", (int)newValue, comp.Session.PlayerId);
        }