示例#1
0
        static void OnChangeSlotItemRequest(int playerSerialId, int index, DefinitionIdBlit defId)
        {
            ulong senderId = GetSenderIdSafe();
            var   playerId = new PlayerId(senderId, playerSerialId);

            if (!MySession.Static.Toolbars.ContainsToolbar(playerId))
            {
                return;
            }

            MyDefinitionBase def;

            MyDefinitionManager.Static.TryGetDefinition(defId, out def);
            if (def == null)
            {
                return;
            }

            var ob      = MyToolbarItemFactory.ObjectBuilderFromDefinition(def);
            var tItem   = MyToolbarItemFactory.CreateToolbarItem(ob);
            var toolbar = MySession.Static.Toolbars.TryGetPlayerToolbar(playerId);

            if (toolbar == null)
            {
                return;
            }
            toolbar.SetItemAtIndex(index, tItem);
        }
示例#2
0
        public static void RequestChangeSlotItem(PlayerId pid, int index, MyDefinitionId defId)
        {
            DefinitionIdBlit defIdBlit = new DefinitionIdBlit();

            defIdBlit = defId;
            MyMultiplayer.RaiseStaticEvent(s => MyToolBarCollection.OnChangeSlotItemRequest, pid.SerialId, index, defIdBlit);
        }
示例#3
0
        /// <summary>
        /// Decides if a block about to be spawned is permitted by the player
        /// </summary>
        /// <param name="definition"></param>
        /// <returns></returns>
        private static bool Prefix(DefinitionIdBlit definition)
        {
            if (!BlockLimiterConfig.Instance.EnableLimits)
            {
                return(true);
            }

            var block = MyDefinitionManager.Static.GetCubeBlockDefinition(definition);

            if (block == null)
            {
                return(true);
            }


            var remoteUserId = MyEventContext.Current.Sender.Value;
            var player       = MySession.Static.Players.TryGetPlayerBySteamId(remoteUserId);
            var playerId     = player.Identity.IdentityId;

            if (Block.IsWithinLimits(block, playerId, null, out var limitName) && !Grid.CountViolation(block, playerId))
            {
                return(true);
            }


            var p = player.DisplayName;

            Log.Info($"Blocked {p} from placing {block}");

            //ModCommunication.SendMessageTo(new NotificationMessage($"You've reach your limit for {b}",5000,MyFontEnum.Red),remoteUserId );
            var msg = Utilities.GetMessage(BlockLimiterConfig.Instance.DenyMessage, new List <string> {
                block.ToString().Substring(16)
            }, limitName);

            if (remoteUserId != 0 && MySession.Static.Players.IsPlayerOnline(playerId))
            {
                BlockLimiter.Instance.Torch.CurrentSession.Managers.GetManager <ChatManagerServer>()?
                .SendMessageAsOther(BlockLimiterConfig.Instance.ServerName, msg, Color.Red, remoteUserId);
            }

            Utilities.SendFailSound(remoteUserId);
            Utilities.ValidationFailed();

            return(false);
        }
        static void OnChangeSlotItemRequest(int playerSerialId, int index, DefinitionIdBlit defId)
		{
            ulong senderId = GetSenderIdSafe();
            var playerId = new PlayerId(senderId, playerSerialId);
			if (!MySession.Static.Toolbars.ContainsToolbar(playerId))
				return;

			MyDefinitionBase def;
			MyDefinitionManager.Static.TryGetDefinition(defId, out def);
			if (def == null)
				return;

			var ob = MyToolbarItemFactory.ObjectBuilderFromDefinition(def);
			var tItem = MyToolbarItemFactory.CreateToolbarItem(ob);
			var toolbar = MySession.Static.Toolbars.TryGetPlayerToolbar(playerId);
			if (toolbar == null)
				return;
			toolbar.SetItemAtIndex(index, tItem);
		}
示例#5
0
        /// <summary>
        /// Decides if a block about to be spawned is permitted by the player
        /// </summary>
        /// <param name="definition"></param>
        /// <returns></returns>
        private static bool Prefix(DefinitionIdBlit definition)
        {
            if (!BlockLimiterConfig.Instance.EnableLimits)
            {
                return(true);
            }

            var block = MyDefinitionManager.Static.GetCubeBlockDefinition(definition);

            if (block == null)
            {
                return(true);
            }

            var remoteUserId = MyEventContext.Current.Sender.Value;
            var player       = MySession.Static.Players.TryGetPlayerBySteamId(remoteUserId);
            var playerId     = player.Identity.IdentityId;

            if (Block.IsWithinLimits(block, playerId, null))
            {
                return(true);
            }


            var b = block.BlockPairName;
            var p = player.DisplayName;

            if (BlockLimiterConfig.Instance.EnableLog)
            {
                BlockLimiter.Instance.Log.Info($"Blocked {p} from placing a {b}");
            }

            //ModCommunication.SendMessageTo(new NotificationMessage($"You've reach your limit for {b}",5000,MyFontEnum.Red),remoteUserId );
            var msg = BlockLimiterConfig.Instance.DenyMessage.Replace("{BN}", $"{b}");

            MyVisualScriptLogicProvider.SendChatMessage($"{msg}", BlockLimiterConfig.Instance.ServerName, playerId, MyFontEnum.Red);

            Utilities.SendFailSound(remoteUserId);
            Utilities.ValidationFailed();

            return(false);
        }
示例#6
0
        public override bool Handle(ulong remoteUserId, CallSite site, BitStream stream, object obj)
        {
            if (!PluginSettings.Instance.ProtectionZonesEnabled)
            {
                return(false);
            }

            Author           author      = new Author();
            DefinitionIdBlit blit        = new DefinitionIdBlit();
            BuildData        data        = new BuildData();
            bool             instant     = false;
            bool             forceStatic = false;
            uint             hsf         = 0;

            base.Serialize(site.MethodInfo, stream, ref author, ref blit, ref data, ref instant, ref forceStatic, ref hsf);

            bool found = false;

            foreach (var item in PluginSettings.Instance.ProtectionItems)
            {
                if (!item.Enabled || !item.StopBuild)
                {
                    continue;
                }

                MyCubeGrid grid;
                if (!MyEntities.TryGetEntityById(item.EntityId, out grid))
                {
                    continue;
                }

                var sphere = new BoundingSphereD(grid.Center(), item.Radius);

                if (sphere.Contains(data.Position) == ContainmentType.Disjoint)
                {
                    continue;
                }

                if (item.AdminExempt && PlayerManager.Instance.IsUserAdmin(remoteUserId))
                {
                    continue;
                }

                found = true;
                break;
            }

            if (!found)
            {
                return(false);
            }

            NoGrief.Log.Info($"Intercepted grid spawn request from {PlayerMap.Instance.GetFastPlayerNameFromSteamId(remoteUserId)}");
            Communication.SendPrivateInformation(remoteUserId, "You cannot build blocks in this protected area!");

            //send the fail message to make the client play the paste fail sound
            //just because we can
            var inf = typeof(MyCubeBuilder).GetMethod("SpawnGridReply", BindingFlags.NonPublic | BindingFlags.Static);

            ServerNetworkManager.Instance.RaiseStaticEvent(inf, remoteUserId, false);

            return(true);
        }
 public static void RequestChangeSlotItem(PlayerId pid, int index, MyDefinitionId defId)
 {
     DefinitionIdBlit defIdBlit = new DefinitionIdBlit();
     defIdBlit = defId;
     MyMultiplayer.RaiseStaticEvent(s => MyToolBarCollection.OnChangeSlotItemRequest, pid.SerialId, index, defIdBlit);
 }
 private static void AddRopeRequest_Implementation(long entityId1, long entityId2, DefinitionIdBlit ropeDefinitionId)
 {
     var definition = (MyRopeDefinition)MyDefinitionManager.Static.GetDefinition(ropeDefinitionId);
     if (CanConnectHooks(entityId1, entityId2, definition))
         AddRopeData(entityId1, entityId2, definition, 0);
 }
示例#9
0
        static void RequestGridSpawn(long builderEntityId, DefinitionIdBlit definition, BuildData position, bool instantBuild, bool forceStatic, uint colorMaskHsv)
        {
            Debug.Assert(BuildComponent != null, "The build component was not set in cube builder!");

            MyEntity builder = null;
            bool isAdmin = (MyEventContext.Current.IsLocallyInvoked || MySession.Static.HasPlayerAdminRights(MyEventContext.Current.Sender.Value) || MySession.Static.IsAdminModeEnabled(Sync.MyId));
            MyEntities.TryGetEntityById(builderEntityId, out builder);

            var blockDefinition = MyDefinitionManager.Static.GetCubeBlockDefinition(definition);
            MatrixD worldMatrix = MatrixD.CreateWorld(position.Position, position.Forward, position.Up);

            float gridSize = MyDefinitionManager.Static.GetCubeSize(blockDefinition.CubeSize);
            BoundingBoxD localAABB = new BoundingBoxD(-blockDefinition.Size * gridSize * 0.5f, blockDefinition.Size * gridSize * 0.5f);

            MyGridPlacementSettings settings = CubeBuilderDefinition.BuildingSettings.GetGridPlacementSettings(blockDefinition.CubeSize);
            VoxelPlacementSettings voxelPlacementDef = new VoxelPlacementSettings() { PlacementMode = VoxelPlacementMode.OutsideVoxel };
            settings.VoxelPlacement = voxelPlacementDef;

            bool isStatic = forceStatic || MyCubeGrid.IsAabbInsideVoxel(worldMatrix, localAABB, settings) || Static.m_stationPlacement;

            BuildComponent.GetGridSpawnMaterials(blockDefinition, worldMatrix, isStatic);
            bool hasBuildMat = (isAdmin && instantBuild) || MyCubeBuilder.BuildComponent.HasBuildingMaterials(builder);

            bool canSpawn = true;
            // Try spawning "fake" grid in that place, if fail it means something already there.
            // TODO: broken for armor blocks. Rendering instance stays on the screen after creating temp grid
            //if (isStatic)
            //{
            //    canSpawn = GridPlacementTest(builder, blockDefinition, worldMatrix);
            //}
            canSpawn = hasBuildMat & canSpawn; // It is not possible to create something in already occupied place, even if admin.

            ulong senderId =  MyEventContext.Current.Sender.Value;

            MyMultiplayer.RaiseStaticEvent(s => SpawnGridReply, canSpawn, new EndpointId(senderId));

            if (!canSpawn) return;

            MyCubeGrid grid = null;
            SpawnFlags flags = SpawnFlags.Default;
            if (isAdmin && instantBuild)
            {
                flags |= SpawnFlags.SpawnAsMaster;
            }

            Vector3 color = ColorExtensions.UnpackHSVFromUint(colorMaskHsv);

            if (isStatic)
            {
                grid = SpawnStaticGrid(blockDefinition, builder, worldMatrix, color, flags);
            }
            else
                grid = SpawnDynamicGrid(blockDefinition, builder, worldMatrix, color, spawnFlags: flags);

            

            if (grid != null)
            {
                if(grid.IsStatic && grid.GridSizeEnum != MyCubeSize.Small)
                {
                    bool result = MyCoordinateSystem.Static.IsLocalCoordSysExist(ref worldMatrix, grid.GridSize);
                    if (result)
                    {
                        MyCoordinateSystem.Static.RegisterCubeGrid(grid);
                    }
                    else
                    {
                        MyCoordinateSystem.Static.CreateCoordSys(grid, CubeBuilderDefinition.BuildingSettings.StaticGridAlignToCenter, true);
                    }
                }

                AfterGridBuild(builder, grid, instantBuild);
            }
        }
示例#10
0
        static void RequestGridSpawn(long builderEntityId, DefinitionIdBlit definition,BuildData position, bool isStatic, bool instantBuild)
        {
            Debug.Assert(BuildComponent != null, "The build component was not set in cube builder!");

            MyEntity builder = null;
            bool isAdmin = (MyEventContext.Current.IsLocallyInvoked || MySession.Static.HasPlayerAdminRights(MyEventContext.Current.Sender.Value));
            if ((instantBuild && isAdmin) == false)
            {
                MyEntities.TryGetEntityById(builderEntityId, out builder);
            }

            var blockDefinition = Definitions.MyDefinitionManager.Static.GetCubeBlockDefinition(definition);
            MatrixD worldMatrix = MatrixD.CreateWorld(position.Position, position.Forward, position.Up);

            BuildComponent.GetGridSpawnMaterials(blockDefinition, worldMatrix, isStatic);
            bool hasBuildMat = MyCubeBuilder.BuildComponent.HasBuildingMaterials(builder);
            hasBuildMat |= isAdmin;

            bool canSpawn = true;
            // Try spawning "fake" grid in that place, if fail it means something already there.
            if (isStatic)
            {
                canSpawn = GridPlacementTest(builder, blockDefinition, worldMatrix);
            }
            canSpawn = hasBuildMat & canSpawn; // It is not possible to create something in already occupied place, even if admin.

            ulong senderId =  MyEventContext.Current.Sender.Value;

            MyMultiplayer.RaiseStaticEvent(s => SpawnGridReply, canSpawn, new EndpointId(senderId));

            if (!canSpawn) return;

            SpawnGrid(blockDefinition, worldMatrix, builder, isStatic);
        }