예제 #1
0
        protected static void Promote(ulong playerId, bool promote)
        {
            if (!MyEventContext.Current.IsLocallyInvoked && !MyMultiplayer.Static.IsAdmin(MyEventContext.Current.Sender.Value))
            {
                MyEventContext.ValidationFailed();
                return;
            }

            if (promote)
            {
                MySession.Static.PromotedUsers.Add(playerId);
            }
            else
            {
                MySession.Static.PromotedUsers.Remove(playerId);
            }


            if (Sync.IsServer)
            {
                MyPlayer player;
                MySession.Static.Players.TryGetPlayerById(new MyPlayer.PlayerId(playerId, 0), out player);
                if (player != null && player.Character != null)
                {
                    player.Character.IsPromoted = promote;
                }
                MyMultiplayer.RaiseStaticEvent(x => ShowPromoteMessage, promote, new EndpointId(playerId));
            }
            Refresh();
        }
        private static void SpawnIntoContainer_Implementation(long amount, SerializableDefinitionId item, long entityId, long playerId)
        {
            if (!MyEventContext.Current.IsLocallyInvoked && !MySession.Static.HasPlayerCreativeRights(MyEventContext.Current.Sender.Value))
            {
                MyEventContext.ValidationFailed();
                return;
            }

            MyEntity entity;

            if (!MyEntities.TryGetEntityById(entityId, out entity))
            {
                return;
            }

            if (!entity.HasInventory || !((MyTerminalBlock)entity).HasPlayerAccess(playerId))
            {
                return;
            }

            MyInventory inventory = entity.GetInventory();

            if (!inventory.CheckConstraint(item))
            {
                return;
            }

            MyFixedPoint itemAmt = (MyFixedPoint)Math.Min(amount, (decimal)inventory.ComputeAmountThatFits(item));

            inventory.AddItems(itemAmt, (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(item));
        }
예제 #3
0
        private void SwitchNet(int junction, int target)
        {
            if (_bendy?.Nodes == null)
            {
                MyEventContext.ValidationFailed();
                return;
            }
            if (junction >= _bendy.Nodes.Length)
            {
                MyEventContext.ValidationFailed();
                return;
            }
            if (target >= _bendy.Nodes.Length)
            {
                MyEventContext.ValidationFailed();
                return;
            }
            var junctionNode = _bendy.Nodes[junction];
            var targetNode   = _bendy.Nodes[target];
            var edge         = junctionNode.ConnectionTo(targetNode);

            if (edge == null)
            {
                MyEventContext.ValidationFailed();
                return;
            }
            SwitchableNodeData.GetOrCreate(junctionNode).SideOrCreateFor(targetNode).SwitchToInternal(edge);
        }
예제 #4
0
 public static void Action(string action, [Nullable] string data)
 {
     if (MySession.Static.GetUserPromoteLevel(MyEventContext.Current.Sender.Value) < MyPromoteLevel.Admin)
     {
         MyEventContext.ValidationFailed();
     }
     else
     {
         MySandboxGame.Log.WriteLineAndConsole("Executing /se action command: " + action);
         if (action != null)
         {
             try
             {
                 Plugin.Static.DataHandler.Execute(action, JToken.Parse(data ?? "{}"),
                                                   new Data.Data
                 {
                     Type   = EventType.TwitchExtension,
                     Amount = 1
                 });
             }
             catch (Exception e)
             {
                 Utils.SendChat(e.Message);
                 Plugin.Static.Logger.WriteLine(e);
             }
         }
     }
 }
 void UpdateProgram(byte[] program)
 {
     if (!MySession.Static.IsUserScripter(MyEventContext.Current.Sender.Value))
     {
         MyEventContext.ValidationFailed();
         return;
     }
     UpdateProgram(StringCompressor.DecompressString(program));
 }
 static void UploadSettingsToServer(MyTrashRemovalSettings newSettings)
 {
     if (!MyEventContext.Current.IsLocallyInvoked && !MySession.Static.HasPlayerAdminRights(MyEventContext.Current.Sender.Value))
     {
         MyEventContext.ValidationFailed();
         return;
     }
     MyTrashRemoval.PreviewSettings = newSettings;
 }
 void OnClosedRequest()
 {
     if (!MySession.Static.CreativeMode && !MyEventContext.Current.IsLocallyInvoked && !MySession.Static.HasPlayerCreativeRights(MyEventContext.Current.Sender.Value))
     {
         MyEventContext.ValidationFailed();
         return;
     }
     Close();
 }
예제 #8
0
        static void RemoveTrash_Implementation(MyTrashRemovalSettings settings, MyTrashRemovalOperation operation)
        {
            if (!MyEventContext.Current.IsLocallyInvoked && !MySession.Static.HasPlayerAdminRights(MyEventContext.Current.Sender.Value))
            {
                MyEventContext.ValidationFailed();
                return;
            }

            MyTrashRemoval.Apply(settings, operation);
        }
예제 #9
0
 private static void RequestSpawnCreative_Implementation(MyObjectBuilder_FloatingObject obj)
 {
     if (MySession.Static.CreativeMode || MyEventContext.Current.IsLocallyInvoked || MySession.Static.HasPlayerAdminRights(MyEventContext.Current.Sender.Value))
     {
         MyEntities.CreateFromObjectBuilderAndAdd(obj);
     }
     else
     {
         MyEventContext.ValidationFailed();
     }
 }
예제 #10
0
 public static void Clear()
 {
     if (MySession.Static.GetUserPromoteLevel(MyEventContext.Current.Sender.Value) < MyPromoteLevel.Admin)
     {
         MyEventContext.ValidationFailed();
     }
     else
     {
         ActionNotification.Clear();
     }
 }
예제 #11
0
        static void RemoveEntity_Implementation(long entityId, MyTrashRemovalOperation operation)
        {
            if (!MyEventContext.Current.IsLocallyInvoked && !MySession.Static.HasPlayerAdminRights(MyEventContext.Current.Sender.Value))
            {
                MyEventContext.ValidationFailed();
                return;
            }

            MyEntity entity;

            if (MyEntities.TryGetEntityById(entityId, out entity))
            {
                MyTrashRemoval.ApplyOperation(entity, operation);
            }
        }
예제 #12
0
 private static void OnTeleport(ulong userId, Vector3D location)
 {
     if ((Sync.IsValidEventOnServer && !MyEventContext.Current.IsLocallyInvoked) && !MySession.Static.IsUserSpaceMaster(MyEventContext.Current.Sender.Value))
     {
         (Static as MyMultiplayerServerBase).ValidationFailed(MyEventContext.Current.Sender.Value, true, null, true);
         MyEventContext.ValidationFailed();
     }
     else
     {
         MyPlayer playerById = Sync.Players.GetPlayerById(new MyPlayer.PlayerId(userId));
         if (playerById.Controller.ControlledEntity != null)
         {
             playerById.Controller.ControlledEntity.Entity.GetTopMostParent(null).PositionComp.SetPosition(location, null, false, true);
         }
     }
 }
 static void RemoveFloating_Impelentation()
 {
     if (!MyEventContext.Current.IsLocallyInvoked && !MySession.Static.HasPlayerAdminRights(MyEventContext.Current.Sender.Value))
     {
         MyEventContext.ValidationFailed();
         return;
     }
     foreach (var entity in MyEntities.GetEntities())
     {
         MyFloatingObject floating = entity as MyFloatingObject;
         if (floating != null)
         {
             floating.SendCloseRequest();
         }
     }
 }
예제 #14
0
        static void ReplicateEverything_Implementation()
        {
            if (MyEventContext.Current.IsLocallyInvoked)
            {
                return;
            }

            if (!MySession.Static.HasPlayerAdminRights(MyEventContext.Current.Sender.Value))
            {
                MyEventContext.ValidationFailed();
                return;
            }

            var server = (MyReplicationServer)MyMultiplayer.Static.ReplicationLayer;

            server.ForceEverything(MyEventContext.Current.Sender);
        }
        protected static void Promote(ulong playerId, bool promote)
        {
            if (!MyEventContext.Current.IsLocallyInvoked && !MySession.Static.IsUserAdmin(MyEventContext.Current.Sender.Value))
            {
                MyEventContext.ValidationFailed();
                return;
            }

            MyPromoteLevel targetUserLevel = MySession.Static.GetUserPromoteLevel(playerId);

            if (promote)
            {
                targetUserLevel++;
                if (!MySession.Static.EnableScripterRole && targetUserLevel == MyPromoteLevel.Scripter)
                {
                    targetUserLevel++;
                }
                MySession.Static.PromotedUsers[playerId] = targetUserLevel;
            }
            else
            {
                targetUserLevel--;
                if (!MySession.Static.EnableScripterRole && targetUserLevel == MyPromoteLevel.Scripter)
                {
                    targetUserLevel--;
                }
                if (targetUserLevel > MyPromoteLevel.None)
                {
                    MySession.Static.PromotedUsers[playerId] = targetUserLevel;
                }
                else
                {
                    MySession.Static.PromotedUsers.Remove(playerId);
                }
            }

            if (Sync.IsServer)
            {
                MyMultiplayer.RaiseStaticEvent(x => ShowPromoteMessage, targetUserLevel, promote, new EndpointId(playerId));
            }
            Refresh();
        }
        static void CycleRequest_Implementation(MyEntityCyclingOrder order, bool reset, bool findLarger, float metricValue, long currentEntityId, CyclingOptions options)
        {
            if (!MyEventContext.Current.IsLocallyInvoked && !MySession.Static.HasPlayerAdminRights(MyEventContext.Current.Sender.Value))
            {
                MyEventContext.ValidationFailed();
                return;
            }

            if (reset)
            {
                metricValue     = float.MinValue;
                currentEntityId = 0;
                findLarger      = false;
            }

            MyEntityCycling.FindNext(order, ref metricValue, ref currentEntityId, findLarger, options);

            var      e   = MyEntities.GetEntityByIdOrDefault(currentEntityId);
            Vector3D pos = e != null ? e.WorldMatrix.Translation : Vector3D.Zero;

            if (MyEventContext.Current.IsLocallyInvoked)
            {
                Cycle_Implementation(metricValue, currentEntityId, pos);
            }
            else
            {
                var proxy = e as IMyEventProxy;
                if (proxy != null)
                {
                    if (proxy is MyCubeGrid && (proxy as MyCubeGrid).Physics == null)
                    {
                        //don't send grids without physics
                    }
                    else
                    {
                        MyMultiplayer.ReplicateImmediatelly(proxy, MyEventContext.Current.Sender);
                    }
                }
                MyMultiplayer.RaiseStaticEvent(x => Cycle_Implementation, metricValue, currentEntityId, pos, MyEventContext.Current.Sender);
            }
        }
예제 #17
0
        static void OnVoxelClosedRequest(long entityId)
        {
            if (!MyEventContext.Current.IsLocallyInvoked && !MySession.Static.HasPlayerCreativeRights(MyEventContext.Current.Sender.Value))
            {
                MyEventContext.ValidationFailed();
                return;
            }
            MyEntity entity;

            MyEntities.TryGetEntityById(entityId, out entity);
            if (entity == null)
            {
                return;
            }

            // Test right to closing entity (e.g. is creative mode?)
            if (!entity.MarkedForClose)
            {
                entity.Close(); // close only on server, server uses replication to propagate it to clients
            }
        }
        private static void PlaceEdge(EdgePlacerConfig cfg, Vector3D[] segments)
        {
            MyEntity holderEntity;

            MyEntities.TryGetEntityById(cfg.EntityPlacing, out holderEntity);
            var holderPlayer = holderEntity != null?MyAPIGateway.Players.GetPlayerControllingEntity(holderEntity) : null;

            var def = DefinitionFor(cfg.Placed);

            if (def == null)
            {
                MyEventContext.ValidationFailed();
                return;
            }

            #region Validation

            if (!MyEventContext.Current.IsLocallyInvoked)
            {
                if (holderEntity == null || holderPlayer == null ||
                    MyEventContext.Current.Sender.Value != holderPlayer.SteamUserId)
                {
                    MyEventContext.ValidationFailed();
                    return;
                }

                if (MyAreaPermissionSystem.Static != null)
                {
                    foreach (var pos in segments)
                    {
                        if (MyAreaPermissionSystem.Static.HasPermission(holderPlayer.IdentityId, pos,
                                                                        MyPermissionsConstants.Build))
                        {
                            continue;
                        }
                        holderPlayer.ShowNotification("You cannot build here", 2000, null, new Vector4(1, 0, 0, 1));
                        MyEventContext.ValidationFailed();
                        return;
                    }
                }

                var validPlacedType = false;
                foreach (var item in holderEntity.GetInventory(MyCharacterConstants.MainInventory).Items)
                {
                    if (item == null)
                    {
                        continue;
                    }
                    var itemDef =
                        MyDefinitionManager.Get <MyInventoryItemDefinition>(item.DefinitionId) as MyHandItemDefinition;
                    if (itemDef == null)
                    {
                        continue;
                    }
                    foreach (var behaviorDef in itemDef.Behaviors)
                    {
                        var placeDef = behaviorDef as EdgePlacerBehaviorDefinition;
                        if (placeDef == null || placeDef.Placed != cfg.Placed)
                        {
                            continue;
                        }
                        validPlacedType = true;
                        break;
                    }

                    if (validPlacedType)
                    {
                        break;
                    }
                }

                if (!validPlacedType)
                {
                    MyEventContext.ValidationFailed();
                    MySession.Static.Log.Warning(
                        $"{holderPlayer} tried to place {cfg.Placed}, but has no item that can place it");
                    return;
                }

                var layer     = MySession.Static.Components.Get <BendyController>().GetOrCreateLayer(def.Layer);
                var annotated = AnnotateNodes(layer, segments);
                var tmp       = new List <string>();
                if (!ValidatePath(def, layer, annotated, tmp))
                {
                    holderPlayer.ShowNotification(string.Join("\n", tmp));
                    MyEventContext.ValidationFailed();
                    return;
                }
            }

            #endregion


            var graph = MySession.Static.Components.Get <BendyController>().GetOrCreateLayer(def.Layer);

            for (var i = 1; i < segments.Length; i++)
            {
                var nextNode = graph.GetOrCreateNode(segments[i - 1]);
                var prevNode = graph.GetOrCreateNode(segments[i]);

                if (graph.GetEdge(prevNode, nextNode) != null)
                {
                    continue;
                }

                var obContainer = new MyObjectBuilder_ComponentContainer();
                var worldMatrix = MatrixD.CreateWorld((prevNode.Position + nextNode.Position) / 2,
                                                      Vector3D.Normalize(nextNode.Position - prevNode.Position),
                                                      Vector3D.Normalize(nextNode.Up + prevNode.Up));
                var worldMatrixInv = MatrixD.Invert(worldMatrix);
                ((ICollection <MyObjectBuilder_EntityComponent>)obContainer.Components).Add(
                    new MyObjectBuilder_BendyComponent()
                {
                    Overrides = new[]
                    {
                        new MyObjectBuilder_BendyComponent.NodePose
                        {
                            Index    = 0,
                            Position = (Vector3)Vector3D.Transform(prevNode.Position, worldMatrixInv),
                            Up       = (Vector3)Vector3D.Transform(prevNode.Up, worldMatrixInv)
                        },
                        new MyObjectBuilder_BendyComponent.NodePose
                        {
                            Index    = 1,
                            Position = (Vector3)Vector3D.Transform(nextNode.Position, worldMatrixInv),
                            Up       = (Vector3)Vector3D.Transform(nextNode.Up, worldMatrixInv)
                        }
                    }
                });
                var entOb = new MyObjectBuilder_EntityBase()
                {
                    EntityDefinitionId     = (MyDefinitionId)cfg.Placed,
                    PersistentFlags        = MyPersistentEntityFlags2.InScene,
                    PositionAndOrientation = new MyPositionAndOrientation(worldMatrix),
                    SubtypeName            = cfg.Placed.SubtypeId,
                    ComponentContainer     = obContainer
                };
                var entity = MyAPIGateway.Entities.CreateFromObjectBuilderAndAdd(entOb);
                if (holderPlayer != null && holderPlayer.IsCreative())
                {
                    entity.Components.Get <ConstructableComponent>()?.InstallFromCreative();
                    ConstructableComponentDefinition.CcComponent test;
                    int test2;
                    entity.Components.Get <ConstructableComponent>()
                    ?.IncreaseIntegrity(1e9f, out test, out test2);
                }

                entity.Components.Get <BendyPhysicsComponent>()?.DestroyEnvItems();

                EntityAdded?.Invoke(holderEntity, holderPlayer, entity);
            }
        }
        private static void RemoveEdge(long removerEntityId, long entityIdToRemove)
        {
            MyEntity holderEntity;

            MyEntities.TryGetEntityById(removerEntityId, out holderEntity);
            var holderPlayer = holderEntity != null
                ? MyAPIGateway.Players.GetPlayerControllingEntity(holderEntity)
                : null;

            MyEntity removeEntity = null;

            MyEntities.TryGetEntityById(entityIdToRemove, out removeEntity);

            if (removeEntity == null)
            {
                MyEventContext.ValidationFailed();
                return;
            }

            #region Validation

            if (!MyEventContext.Current.IsLocallyInvoked)
            {
                if (holderEntity == null || holderPlayer == null ||
                    MyEventContext.Current.Sender.Value != holderPlayer.SteamUserId)
                {
                    MyEventContext.ValidationFailed();
                    return;
                }

                if (MyAreaPermissionSystem.Static != null && !MyAreaPermissionSystem.Static.HasPermission(
                        holderPlayer.IdentityId, removeEntity.GetPosition(), MyPermissionsConstants.QuickDeconstruct))
                {
                    holderPlayer.ShowNotification("You cannot quick deconstruct here", 2000, null,
                                                  new Vector4(1, 0, 0, 1));
                    return;
                }

                string err;
                if (!ValidateQuickRemove(holderPlayer, removeEntity, out err))
                {
                    MyEventContext.ValidationFailed();
                    if (!string.IsNullOrEmpty(err))
                    {
                        holderPlayer.ShowNotification(err, 2000, null, new Vector4(1, 0, 0, 1));
                    }
                    return;
                }
            }

            #endregion

            var block = removeEntity?.Get <MyBlockComponent>();
            if (block != null)
            {
                block.GridData.RemoveBlock(block.Block);
            }
            else
            {
                removeEntity.Close();
            }

            EntityRemoved?.Invoke(holderEntity, holderPlayer, removeEntity);
        }