private void OnEntityAdd(IMyEntity e)
        {
            MyEntity entity = e as MyEntity;

            EntityDescription description = new EntityDescription()
            {
                EntityId   = entity.EntityId,
                Name       = entity.DisplayNameText,
                ObjectType = entity.GetType().Name,
                TypeId     = ((entity.DefinitionId.HasValue) ? entity.DefinitionId.Value.TypeId.ToString() : string.Empty),
                SubtypeId  = ((entity.DefinitionId.HasValue) ? entity.DefinitionId.Value.SubtypeId.ToString() : string.Empty),
                Created    = Tools.DateTime
            };

            SQLQueryData.WriteToDatabase(description);

            if (conf.LogGrids)
            {
                if (entity is MyCubeGrid)
                {
                    gridManager.AddGrid(entity as MyCubeGrid);
                }

                if (conf.LogInventory && !RegisteredInventories.ContainsKey(entity.EntityId))
                {
                    RegisteredInventories.Add(entity.EntityId, new InventoryComponent(entity));
                }
            }
        }
        private void OnEntityRemove(IMyEntity e)
        {
            if (!((MySession)MyAPIGateway.Session).Ready)
            {
                return;
            }
            MyEntity entity = e as MyEntity;

            EntityDescription description = new EntityDescription()
            {
                EntityId   = entity.EntityId,
                Name       = entity.DisplayNameText,
                ObjectType = entity.GetType().Name,
                TypeId     = ((entity.DefinitionId.HasValue) ? entity.DefinitionId.Value.TypeId.ToString() : string.Empty),
                SubtypeId  = ((entity.DefinitionId.HasValue) ? entity.DefinitionId.Value.SubtypeId.ToString() : string.Empty),
                Removed    = Tools.DateTime
            };

            SQLQueryData.WriteToDatabase(description);
            if (conf.LogGrids)
            {
                if (entity is MyCubeGrid)
                {
                    gridManager.RemoveGrid(entity as MyCubeGrid);
                }

                if (conf.LogInventory && RegisteredInventories.ContainsKey(entity.EntityId))
                {
                    RegisteredInventories[entity.EntityId].Close();
                    RegisteredInventories.Remove(entity.EntityId);
                }
            }
        }
        public void AddGrid(MyCubeGrid grid)
        {
            grid.OnNameChanged += OnGridNameChange;
            grid.OnGridSplit   += OnGridSplit;
            //grid.OnStaticChanged += OnStaticStateChanged;

            grid.OnBlockAdded   += OnBlockAdded;
            grid.OnBlockRemoved += OnBlockRemoved;

            grid.OnBlockIntegrityChanged += OnBlockIntegrityChanged;
            //grid.OnBlockOwnershipChanged += OnOwnershipChanged;

            SQLQueryData.WriteToDatabase(new GridDescription()
            {
                GridId  = grid.EntityId,
                Type    = grid.GridSizeEnum.ToString(),
                Created = Tools.DateTime
            });

            SQLQueryData.WriteToDatabase(new GridNameDescription()
            {
                GridId    = grid.EntityId,
                Name      = grid.DisplayName,
                Timestamp = Tools.DateTime
            });

            AddGridBlocks(grid);
        }
        private void OnFactionCreated(long id)
        {
            IMyFaction faction = MyAPIGateway.Session.Factions.TryGetFactionById(id);

            if (faction != null)
            {
                ActivityCollector.Log.Info($"New Faction Created: {faction.Tag} | {faction.Name}");

                SQLQueryData.WriteToDatabase(new FactionActivityDescription()
                {
                    FromFactionId = id,
                    ToFactionId   = id,
                    PlayerId      = faction.FounderId,
                    SenderId      = faction.FounderId,
                    Action        = "CreateFaction",
                    Timestamp     = Tools.DateTime
                });

                SQLQueryData.WriteToDatabase(new FactionNameDescription()
                {
                    FactionId   = id,
                    Tag         = faction.Tag,
                    Name        = faction.Name,
                    Description = faction.Description,
                    Timestamp   = Tools.DateTime
                });
            }
        }
        private void OnPlayersChanged(bool connected, MyPlayer.PlayerId pid)
        {
            MyIdentity identity = session.Players.TryGetPlayerIdentity(pid);

            ActivityCollector.Log.Info($"{identity.DisplayName} has {((connected) ? "Connected" : "Disconnected")}");
            if (connected)
            {
                MyPlayer p;
                session.Players.TryGetPlayerById(pid, out p);
                p.Controller.ControlledEntityChanged += OnControlledEntityChanged;

                SQLQueryData.WriteToDatabase(new UserDescription()
                {
                    SteamId   = pid.SteamId,
                    PlayerId  = identity.IdentityId,
                    Name      = identity.DisplayName,
                    Connected = Tools.DateTime,
                    State     = LoginState.Active
                });
            }
            else
            {
                SQLQueryData.WriteToDatabase(new UserDescription()
                {
                    SteamId      = pid.SteamId,
                    PlayerId     = identity.IdentityId,
                    Name         = identity.DisplayName,
                    Disconnected = Tools.DateTime,
                    State        = LoginState.Disconnected
                });
            }
        }
 private void OnGridNameChange(MyCubeGrid grid)
 {
     SQLQueryData.WriteToDatabase(new GridNameDescription()
     {
         GridId    = grid.EntityId,
         Name      = grid.DisplayName,
         Timestamp = Tools.DateTime
     });
 }
 private void OnGridSplit(MyCubeGrid parent, MyCubeGrid child)
 {
     SQLQueryData.WriteToDatabase(new GridDescription()
     {
         GridId          = child.EntityId,
         ParentId        = parent.EntityId,
         SplitWithParent = Tools.DateTime
     });
 }
        public void Run()
        {
            if (interval == ActivityCollector.Config.Data.EntityMovementInterval)
            {
                interval = 0;

                foreach (MyEntity ent in entities)
                {
                    try
                    {
                        MovementDescription last = entitiesMovement[ent.EntityId];
                        bool writeToDB           = false;

                        if (ent.Physics != null)
                        {
                            MovementDescription current = new MovementDescription()
                            {
                                EntityId            = ent.EntityId,
                                Position            = ent.PositionComp.GetPosition(),
                                LinearAcceleration  = Tools.Round(ent.Physics.LinearAcceleration),
                                LinearVelocity      = ent.Physics.LinearVelocity,
                                AngularAcceleration = ent.Physics.AngularAcceleration,
                                AngularVelocity     = ent.Physics.AngularVelocity,
                                ForwardVector       = ent.PositionComp.WorldMatrix.Forward
                            };

                            if (last == null)
                            {
                                writeToDB = true;
                            }
                            else
                            {
                                current.LinearRateOfChange = current.LinearAcceleration - last.LinearAcceleration;

                                if (Tools.Round(current.LinearRateOfChange) != Vector3.Zero /*current.LinearAcceleration != last.LinearAcceleration || current.AngularAcceleration != last.AngularAcceleration */)
                                {
                                    writeToDB = true;
                                }
                            }

                            if (writeToDB)
                            {
                                SQLQueryData.WriteToDatabase(current);
                                entitiesMovement[ent.EntityId] = current;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        ActivityCollector.Log.Error(e.ToString());
                    }
                }
            }

            interval++;
        }
 private void OnBlockOwnershipChanged(MyTerminalBlock block)
 {
     SQLQueryData.WriteToDatabase(new BlockOwnershipDescription()
     {
         GridId        = block.CubeGrid.EntityId,
         BlockEntityId = block.EntityId,
         Owner         = block.OwnerId,
         Timestamp     = Tools.DateTime
     });
 }
 private void OnFactionStateChanged(MyFactionStateChange action, long fromFaction, long toFaction, long playerId, long senderId)
 {
     SQLQueryData.WriteToDatabase(new FactionActivityDescription()
     {
         Action        = action.ToString(),
         FromFactionId = fromFaction,
         ToFactionId   = toFaction,
         PlayerId      = playerId,
         SenderId      = senderId,
         Timestamp     = Tools.DateTime
     });
 }
Example #11
0
        public void SessionReady()
        {
            MyAPIGateway.Session.OnSessionReady -= SessionReady;

            ActivityCollector.Log.Info($"Writing Definititions");

            foreach (MyComponentDefinition c in MyDefinitionManager.Static.GetDefinitionsOfType <MyComponentDefinition>())
            {
                SQLQueryData.WriteToDatabase(new BlockComponentDefinitionDescription()
                {
                    TypeId         = c.Id.TypeId.ToString(),
                    SubtypeId      = c.Id.SubtypeId.ToString(),
                    Name           = c.DisplayNameText,
                    Mass           = c.Mass,
                    Volume         = c.Volume,
                    MaxIntegrity   = c.MaxIntegrity,
                    MaxStackAmount = (float)c.MaxStackAmount,
                    Health         = c.Health,
                    Description    = c.DescriptionText,
                });
            }

            foreach (MyCubeBlockDefinition cube in MyDefinitionManager.Static.GetDefinitionsOfType <MyCubeBlockDefinition>())
            {
                SQLQueryData.WriteToDatabase(new BlockDefinitionDescription()
                {
                    TypeId                  = cube.Id.TypeId.ToString(),
                    SubTypeId               = cube.Id.SubtypeId.ToString(),
                    Name                    = cube.DisplayNameText,
                    CubeSize                = cube.CubeSize.ToString(),
                    MaxIntegrity            = cube.MaxIntegrity,
                    CriticalIntegrityRatio  = cube.CriticalIntegrityRatio,
                    GeneralDamageMultiplier = cube.GeneralDamageMultiplier,
                    DisassembleRatio        = cube.DisassembleRatio,
                    DeformationRatio        = cube.DeformationRatio,
                    UsesDeformation         = cube.UsesDeformation,
                    Mass                    = cube.Mass,
                    PCU          = cube.PCU,
                    IsAirTight   = (cube.IsAirTight.HasValue ? cube.IsAirTight.Value : false),
                    SizeX        = cube.Size.X,
                    SizeY        = cube.Size.Y,
                    SizeZ        = cube.Size.Z,
                    ModelOffestX = cube.ModelOffset.X,
                    ModelOffestY = cube.ModelOffset.Y,
                    ModelOffestZ = cube.ModelOffset.Z,
                    Components   = cube.Components,
                    Description  = cube.DescriptionText
                });
            }
        }
        public void LogData()
        {
            InventoryDescription description = new InventoryDescription();

            foreach (InventoryItem item in ItemDeltas)
            {
                if (item.Added > 0)
                {
                    description.Add(EntityId, BlockId, item.Index, item.InventoryType, InvAction.Add, item.Added, item.TypeId.ToString(), item.SubtypeId.ToString());
                }

                if (item.Removed > 0)
                {
                    description.Add(EntityId, BlockId, item.Index, item.InventoryType, InvAction.Remove, item.Removed, item.TypeId.ToString(), item.SubtypeId.ToString());
                }
            }

            SQLQueryData.WriteToDatabase(description);
            ItemDeltas.Clear();
        }
Example #13
0
        private void OnBlockRemoved(MySlimBlock slim)
        {
            slim.CubeGridChanged -= OnBlockCubeGridChanged;
            if (slim.FatBlock != null && slim.FatBlock is MyTerminalBlock)
            {
                if (RegisteredBlockInventories.ContainsKey(slim.FatBlock.EntityId))
                {
                    RegisteredBlockInventories[slim.FatBlock.EntityId].Close();
                    RegisteredBlockInventories.Remove(slim.FatBlock.EntityId);
                }
            }

            SQLQueryData.WriteToDatabase(new BlockDescription()
            {
                GridId  = slim.CubeGrid.EntityId,
                X       = slim.Position.X,
                Y       = slim.Position.Y,
                Z       = slim.Position.Z,
                Removed = Tools.DateTime
            });
        }
Example #14
0
        private void OnBlockAdded(MySlimBlock slim)
        {
            long blockEntityId = 0;

            slim.CubeGridChanged += OnBlockCubeGridChanged;

            if (!LastBlockIntegrity.ContainsKey(slim.UniqueId))
            {
                LastBlockIntegrity.Add(slim.UniqueId, slim.Integrity);
            }

            if (slim.FatBlock != null && slim.FatBlock is MyTerminalBlock)
            {
                MyTerminalBlock tb = slim.FatBlock as MyTerminalBlock;

                if (!RegisteredBlockInventories.ContainsKey(tb.EntityId))
                {
                    RegisteredBlockInventories.Add(tb.EntityId, new InventoryComponent(tb));
                }

                tb.OwnershipChanged += OnBlockOwnershipChanged;
                blockEntityId        = tb.EntityId;

                OnBlockOwnershipChanged(tb);
            }

            SQLQueryData.WriteToDatabase(new BlockDescription()
            {
                BlockEntityId = blockEntityId,
                GridId        = slim.CubeGrid.EntityId,
                BuiltBy       = slim.BuiltBy,
                TypeId        = slim.BlockDefinition.Id.TypeId.ToString(),
                SubTypeId     = slim.BlockDefinition.Id.SubtypeId.ToString(),
                X             = slim.Position.X,
                Y             = slim.Position.Y,
                Z             = slim.Position.Z,
                Created       = Tools.DateTime
            });
        }
        public InventoryComponent(MyEntity entity)
        {
            Entity = entity;

            if (entity.HasInventory)
            {
                Entity.OnClose += OnClose;

                InventoryDescription description = new InventoryDescription();

                if (Output != null)
                {
                    Output.BeforeContentsChanged += OnBeforeOutputChange;
                    Output.ContentsChanged       += OnOutputChange;

                    if (!(entity is MyCharacter))
                    {
                        foreach (var item in Output.GetItems())
                        {
                            description.Add(EntityId, BlockId, item.ItemId, InvType.Output, InvAction.Current, item.Amount, item.Content.TypeId.ToString(), item.Content.SubtypeId.ToString());
                        }
                    }
                }

                if (Input != null)
                {
                    Input.BeforeContentsChanged += OnBeforeInputChange;
                    Input.ContentsChanged       += OnInputChange;

                    foreach (var item in Input.GetItems())
                    {
                        description.Add(EntityId, BlockId, item.ItemId, InvType.Input, InvAction.Current, item.Amount, item.Content.TypeId.ToString(), item.Content.SubtypeId.ToString());
                    }
                }

                SQLQueryData.WriteToDatabase(description);
            }
        }
Example #16
0
        private void OnBlockCubeGridChanged(MySlimBlock slim, MyCubeGrid grid)
        {
            SQLQueryData.WriteToDatabase(new BlockDescription()
            {
                GridId  = grid.EntityId,
                X       = slim.Position.X,
                Y       = slim.Position.Y,
                Z       = slim.Position.Z,
                Removed = Tools.DateTime
            });

            SQLQueryData.WriteToDatabase(new BlockDescription()
            {
                GridId    = slim.CubeGrid.EntityId,
                BuiltBy   = slim.BuiltBy,
                TypeId    = slim.BlockDefinition.Id.TypeId.ToString(),
                SubTypeId = slim.BlockDefinition.Id.SubtypeId.ToString(),
                X         = slim.Position.X,
                Y         = slim.Position.Y,
                Z         = slim.Position.Z,
                Created   = Tools.DateTime
            });
        }
Example #17
0
        public void RemoveGrid(MyCubeGrid grid)
        {
            grid.OnNameChanged -= OnGridNameChange;
            grid.OnGridSplit   -= OnGridSplit;
            //grid.OnStaticChanged -= OnStaticStateChanged;

            grid.OnBlockAdded   -= OnBlockAdded;
            grid.OnBlockRemoved -= OnBlockRemoved;

            //grid.OnBlockIntegrityChanged -= OnBlockIntegrityChanged;
            //grid.OnBlockOwnershipChanged -= OnOwnershipChanged;

            SQLQueryData.WriteToDatabase(new GridDescription()
            {
                GridId  = grid.EntityId,
                Removed = Tools.DateTime
            });

            foreach (MySlimBlock block in grid.GetBlocks())
            {
                OnBlockRemoved(block);
            }
        }
Example #18
0
        private void OnBlockIntegrityChanged(MySlimBlock slim)
        {
            if (!LastBlockIntegrity.ContainsKey(slim.UniqueId))
            {
                LastBlockIntegrity.Add(slim.UniqueId, slim.Integrity);
            }

            float integrityDelta = LastBlockIntegrity[slim.UniqueId] - slim.Integrity;

            if (integrityDelta < 0)
            {
                SQLQueryData.WriteToDatabase(new CombatDescription()
                {
                    VictimGridBlockId = Tools.GetBlockId(slim.Position),
                    VictimGridId      = slim.CubeGrid.EntityId,
                    Type      = "Repair",
                    Damage    = integrityDelta,
                    Integrity = slim.Integrity,
                    Timestamp = Tools.DateTime
                });
            }

            LastBlockIntegrity[slim.UniqueId] = slim.Integrity;
        }
Example #19
0
        private void CombatDamageHandler(object target, MyDamageInformation info)
        {
            if (info.Amount == 0)
            {
                return;
            }

            CombatDescription log = new CombatDescription
            {
                Damage    = info.Amount,
                Type      = info.Type.String,
                Timestamp = Tools.DateTime
            };

            if (target is IMySlimBlock)
            {
                IMySlimBlock slim = target as IMySlimBlock;
                log.Integrity         = slim.Integrity;
                log.VictimGridId      = slim.CubeGrid.EntityId;
                log.VictimGridBlockId = Tools.GetBlockId(slim.Position);
            }
            else if (target is IMyCharacter)
            {
                IMyCharacter character = target as IMyCharacter;

                // characters keep getting hit after death we dont want to log that
                if (character.Name == AlreadyLogged)
                {
                    return;
                }

                if (character.Integrity <= 0)
                {
                    character.Name = AlreadyLogged;
                }
                log.VictimEntityId = character.EntityId;
                log.Integrity      = character.Integrity;
            }
            else if (target is IMyFloatingObject)
            {
                IMyFloatingObject obj = (target as IMyFloatingObject);
                log.VictimEntityId = obj.EntityId;
                log.Integrity      = obj.Integrity;
            }
            else
            {
                ActivityCollector.Log.Error($"Unrecognised Victim {target.GetType()}");
            }


            IMyEntity entity = MyAPIGateway.Entities.GetEntityById(info.AttackerId);

            if (entity == null)
            {
            }
            else if (entity is IMyCubeBlock)
            {
                IMyCubeBlock cube = entity as IMyCubeBlock;

                log.AttackerGridId   = cube.CubeGrid.EntityId;
                log.AttackerEntityId = cube.EntityId;
            }
            else if (entity is IMyCharacter)
            {
                try
                {
                    IMyCharacter character = entity as IMyCharacter;

                    if (character.Name != null) // hacks continued
                    {
                        long missileId = -1;
                        long.TryParse(entity.Name, out missileId);
                        if (missileId != -1)
                        {
                            IMyEntity missileEntity = MyAPIGateway.Entities.GetEntityById(missileId);

                            if (missileEntity != null)
                            {
                                if (missileEntity is IMyCubeGrid)
                                {
                                    IMyCubeGrid grid = missileEntity as IMyCubeGrid;

                                    log.AttackerGridId = grid.EntityId;
                                }
                                else
                                {
                                    IMyCubeBlock cube = missileEntity as IMyCubeBlock;

                                    log.AttackerGridId      = cube.CubeGrid.EntityId;
                                    log.AttackerGridBlockId = Tools.GetBlockId(cube.Position);
                                }
                            }
                            else
                            {
                                ActivityCollector.Log.Error($"missiles parent grid was not found!");
                            }
                        }
                        else
                        {
                            ActivityCollector.Log.Error($"Entity of type {entity.GetType()} failed to parse id {entity.Name}");
                        }
                    }
                    else
                    {
                        log.AttackerEntityId = character.EntityId;
                    }
                }
                catch (Exception e)
                {
                    ActivityCollector.Log.Error(e);
                }
            }
            else if (entity is IMyGunBaseUser) // player tools
            {
                IMyGunBaseUser gun = entity as IMyGunBaseUser;

                log.AttackerEntityId = gun.Weapon.EntityId;
            }
            else if (entity is IMyEngineerToolBase)
            {
                IMyEngineerToolBase toolbase = entity as IMyEngineerToolBase;

                log.AttackerEntityId = toolbase.EntityId;
            }
            else if (entity is IMySlimBlock)
            {
                IMySlimBlock slim = entity as IMySlimBlock;

                log.AttackerGridId = slim.CubeGrid.EntityId;

                if (slim.FatBlock != null)
                {
                    log.AttackerEntityId = slim.FatBlock.EntityId;
                }
                else
                {
                }
            }
            else if (entity is IMyCubeGrid)
            {
                IMyCubeGrid grid = entity as IMyCubeGrid;

                log.AttackerGridId = grid.EntityId;
            }
            else if (entity is MyVoxelBase)
            {
                MyVoxelBase voxel = entity as MyVoxelBase;
                log.AttackerEntityId = entity.EntityId;
            }
            else if (entity.GetType().Name == "MyMissile")
            {
                long missileId = -1;
                long.TryParse(entity.Name, out missileId);
                if (missileId != -1)
                {
                    IMyEntity missileEntity = MyAPIGateway.Entities.GetEntityById(missileId);

                    if (missileEntity != null)
                    {
                        if (missileEntity is IMyCubeGrid)
                        {
                            IMyCubeGrid grid = missileEntity as IMyCubeGrid;
                            log.AttackerGridId = grid.EntityId;
                        }
                        else
                        {
                            IMyCubeBlock cube = missileEntity as IMyCubeBlock;
                            log.AttackerGridId   = cube.CubeGrid.EntityId;
                            log.AttackerEntityId = cube.EntityId;
                        }
                    }
                    else
                    {
                        ActivityCollector.Log.Error($"Missles parent grid was not found!");
                    }
                }
                else
                {
                    ActivityCollector.Log.Error($"Entity of type {entity.GetType()} failed to parse id {entity.Name}");
                }
            }
            else
            {
                ActivityCollector.Log.Error($"Unknown attacker entity of type: {entity.GetType()}");
            }

            SQLQueryData.WriteToDatabase(log);
        }
        public void OnControlledEntityChanged(IMyControllableEntity oldEntity, IMyControllableEntity newEntity)
        {
            if (newEntity == null)
            {
                long entityId;
                if (oldEntity.Entity is MyCharacter)
                {
                    entityId = oldEntity.Entity.EntityId;
                }
                else if (oldEntity.Entity is IMyShipController)
                {
                    entityId = (oldEntity.Entity as IMyShipController).LastPilot.EntityId;
                }
                else
                {
                    ActivityCollector.Log.Warn($"Unrecognized controlled object on player control release {oldEntity.Entity.GetType()}");
                    return;
                }

                SQLQueryData.WriteToDatabase(new UserSpawnDescription()
                {
                    CharacterId = entityId,
                    EndTime     = Tools.DateTime
                });
            }
            else if (oldEntity == null)
            {
                if (newEntity.Entity is MyCharacter)
                {
                    SQLQueryData.WriteToDatabase(new UserSpawnDescription()
                    {
                        PlayerId    = Tools.GetPlayerIdentityId(newEntity.Entity as MyCharacter),
                        CharacterId = newEntity.Entity.EntityId,
                        SteamId     = Tools.GetPlayerSteamId(newEntity.Entity as MyCharacter),
                        StartTime   = Tools.DateTime
                    });
                }
                else if (newEntity.Entity is MyShipController)
                {
                    IMyCharacter character = (newEntity.Entity as IMyShipController).LastPilot;
                    SQLQueryData.WriteToDatabase(new UserSpawnDescription()
                    {
                        PlayerId    = Tools.GetPlayerIdentityId(character),
                        CharacterId = character.EntityId,
                        SteamId     = Tools.GetPlayerSteamId(character),
                        StartTime   = Tools.DateTime
                    });
                }
            }
            else if (newEntity.Entity is MyCharacter && oldEntity.Entity is IMyShipController)
            {
                SQLQueryData.WriteToDatabase(new UserPilotControlChangedDescription()
                {
                    PlayerId = Tools.GetPlayerIdentityId(newEntity.Entity as MyCharacter),
                    GridId   = (oldEntity.Entity as IMyShipController).CubeGrid.EntityId,
                    EndTime  = Tools.DateTime
                });
            }
            else if (oldEntity.Entity is MyCharacter && newEntity.Entity is IMyShipController)
            {
                SQLQueryData.WriteToDatabase(new UserPilotControlChangedDescription()
                {
                    PlayerId  = Tools.GetPlayerIdentityId(oldEntity.Entity as MyCharacter),
                    GridId    = (newEntity.Entity as IMyShipController).CubeGrid.EntityId,
                    StartTime = Tools.DateTime
                });
            }
        }