Exemplo n.º 1
0
 protected void ChangeUpdateOrder(MyUpdateOrder value)
 {
     if (value != UpdateOrder)
     {
         MyAPIGateway.Utilities.InvokeOnGameThread(() => SetUpdateOrder(value));
     }
 }
Exemplo n.º 2
0
 public void RegisterComponent(MySessionComponentBase component, MyUpdateOrder updateOrder, int priority)
 {
     // TODO: Better handling of component overrides
     //if(m_sessionComponents.ContainsKey(component.ComponentType))
     m_sessionComponents[component.ComponentType] = component;
     component.Session = this;
     AddComponentForUpdate(updateOrder, component);
 }
Exemplo n.º 3
0
        public void RegisterComponent(MySessionComponentBase component, MyUpdateOrder updateOrder, int priority)
        {
            m_sessionComponents.Add(component.ComponentType, component);

            AddComponentForUpdate(updateOrder, MyUpdateOrder.BeforeSimulation, component);
            AddComponentForUpdate(updateOrder, MyUpdateOrder.Simulation, component);
            AddComponentForUpdate(updateOrder, MyUpdateOrder.AfterSimulation, component);
            AddComponentForUpdate(updateOrder, MyUpdateOrder.NoUpdate, component);
        }
        public MySessionComponentBase()
        {
            var type = GetType();
            var attr = (MySessionComponentDescriptor)Attribute.GetCustomAttribute(type, typeof(MySessionComponentDescriptor), false);

            DebugName = type.Name;
            Priority = attr.Priority;
            UpdateOrder = attr.UpdateOrder;
            ObjectBuilderType = attr.ObjectBuilderType;

            if (ObjectBuilderType != MyObjectBuilderType.Invalid)
                MySessionComponentMapping.Map(GetType(), ObjectBuilderType);
        }
Exemplo n.º 5
0
        private void AddComponentForUpdate(MyUpdateOrder updateOrder, MyUpdateOrder insertIfOrder, MySessionComponentBase component)
        {
            if ((updateOrder & insertIfOrder) != insertIfOrder)
            {
                return;
            }
            SortedSet <MySessionComponentBase> componentList = null;

            if (!m_sessionComponentsForUpdate.TryGetValue((int)insertIfOrder, out componentList))
            {
                m_sessionComponentsForUpdate.Add((int)insertIfOrder, componentList = new SortedSet <MySessionComponentBase>(SessionComparer));
            }

            componentList.Add(component);
        }
Exemplo n.º 6
0
        public MySessionComponentBase()
        {
            var type = GetType();
            var attr = (MySessionComponentDescriptor)Attribute.GetCustomAttribute(type, typeof(MySessionComponentDescriptor), false);

            DebugName         = type.Name;
            Priority          = attr.Priority;
            UpdateOrder       = attr.UpdateOrder;
            ObjectBuilderType = attr.ObjectBuilderType;

            if (ObjectBuilderType != MyObjectBuilderType.Invalid)
            {
                MySessionComponentMapping.Map(GetType(), ObjectBuilderType);
            }
        }
        public MySessionComponentDescriptor(MyUpdateOrder updateOrder, int priority, Type obType)
        {
            UpdateOrder = updateOrder;
            Priority = priority;
            ObjectBuilderType = obType;

            if (obType != null)
            {
                Debug.Assert(typeof(MyObjectBuilder_SessionComponent).IsAssignableFrom(obType), obType.FullName);

                if (!typeof(MyObjectBuilder_SessionComponent).IsAssignableFrom(obType))
                {
                    ObjectBuilderType = MyObjectBuilderType.Invalid;
                }
            }
        }
Exemplo n.º 8
0
        public MySessionComponentDescriptor(MyUpdateOrder updateOrder, int priority, Type obType, Type registrationType = null)
        {
            UpdateOrder       = updateOrder;
            Priority          = priority;
            ObjectBuilderType = obType;

            if (obType != null)
            {
                Debug.Assert(typeof(MyObjectBuilder_SessionComponent).IsAssignableFrom(obType), obType.FullName);

                if (!typeof(MyObjectBuilder_SessionComponent).IsAssignableFrom(obType))
                {
                    ObjectBuilderType = MyObjectBuilderType.Invalid;
                }
            }

            ComponentType = registrationType;
        }
Exemplo n.º 9
0
        public void AddComponentForUpdate(MyUpdateOrder updateOrder, MySessionComponentBase component)
        {
            for (int i = 0; i <= 2; ++i)
            {
                if (((int)updateOrder & (1 << i)) == 0)
                {
                    continue;
                }

                SortedSet <MySessionComponentBase> componentList = null;

                if (!m_sessionComponentsForUpdate.TryGetValue(1 << i, out componentList))
                {
                    m_sessionComponentsForUpdate.Add(1 << i, componentList = new SortedSet <MySessionComponentBase>(SessionComparer));
                }

                componentList.Add(component);
            }
        }
Exemplo n.º 10
0
 public void SetComponentUpdateOrder(MySessionComponentBase component, MyUpdateOrder order)
 {
     for (int i = 0; i <= 2; ++i)
     {
         SortedSet <MySessionComponentBase> componentList = null;
         if ((order & (MyUpdateOrder)(1 << i)) != 0)
         {
             if (!m_sessionComponentsForUpdate.TryGetValue(1 << i, out componentList))
             {
                 componentList = new SortedSet <MySessionComponentBase>();
                 m_sessionComponentsForUpdate.Add(i, componentList);
             }
             componentList.Add(component);
         }
         else
         {
             if (m_sessionComponentsForUpdate.TryGetValue(1 << i, out componentList))
             {
                 componentList.Remove(component);
             }
         }
     }
 }
 public MySessionComponentDescriptor(MyUpdateOrder updateOrder, int priority, Type type)
 {
     UpdateOrder = updateOrder;
     Priority = priority;
     ObjectBuilderType = type;
 }
 public MySessionComponentDescriptor(MyUpdateOrder updateOrder, int priority)
     : this(updateOrder, priority, null)
 {
 }
 public MySessionComponentDescriptor(MyUpdateOrder updateOrder)
     : this(updateOrder, 1000)
 {
 }
Exemplo n.º 14
0
 public void SetUpdateOrder(MyUpdateOrder order)
 {
     Session.SetComponentUpdateOrder(this, order);
     UpdateOrder = order;
 }
Exemplo n.º 15
0
        public override bool Initialize(out MyUpdateOrder order)
        {
            order = MyUpdateOrder.NoUpdate;
            if (NetworkHandlerSystem.IsClient)
            {
                if (MyAPIGateway.Session.Player == null)
                {
                    return(false);
                }
            }
            /* Handle Server side */
            if (NetworkHandlerSystem.IsServer)
            {
                /* LOAD World Settings */
                try
                {
                    using (var sw = MyAPIGateway.Utilities.ReadFileInWorldStorage(Settings.configFile, typeof(Core)))
                        settings.Load(MyAPIGateway.Utilities.SerializeFromXML <SettingsFile>(sw.ReadToEnd()));
                }
                catch (Exception e)
                {
                    if (e.HResult == -2147024894)  // Unable to find the specified file.
                    {
                        settings = settings.CreateDefaults();
                    }
                    else
                    {
                        MyLog.Default.WriteLine($"Possible Old Settings: {e.Message}");
                        MyLog.Default.WriteLine($"Possible Old SettingsStack: {e.StackTrace}");
                        MyLog.Default.Flush();

                        SettingsFile possibleOldSettings = new SettingsFile();
                        try
                        {
                            using (var sw = MyAPIGateway.Utilities.ReadFileInWorldStorage(Settings.configFile, typeof(Core)))
                                possibleOldSettings = (SettingsFile)MyAPIGateway.Utilities.SerializeFromXML <Settings>(sw.ReadToEnd());

                            using (var sw = MyAPIGateway.Utilities.WriteFileInWorldStorage("config.xml.old", typeof(Core)))
                                sw.Write(MyAPIGateway.Utilities.SerializeToXML(possibleOldSettings));
                            /* Create Defaults then Load and Save Old Settings file */
                            settings = settings.CreateDefaults();
                            settings.Load(possibleOldSettings);
                            MyLog.Default.WriteLine("Successfully Loaded Old World Settings:");
                        }
                        catch (Exception e1)
                        {
                            MyLog.Default.WriteLine($"ERROR Get World Settings: {e1.Message}");
                            MyLog.Default.WriteLine($"ERROR Get World SettingsStack: {e1.StackTrace}");
                            MyLog.Default.Flush();
                            settings = settings.CreateDefaults();
                        }
                    }
                }

                /* Save after loading to add new default settings just incase we added more */
                settings.SaveSettings(true);

                try
                {
                    var cfg = MyAPIGateway.Utilities.ConfigDedicated;
                    cfg.Load();
                    ulong steamId;
                    foreach (string id in cfg.Administrators)
                    {
                        if (ulong.TryParse(id, out steamId))
                        {
                            unlockAllPlayers.Add(steamId, true);
                            MyLog.Default.WriteLine($"Admin Found {steamId}");
                        }
                    }
                    if (unlockAllPlayers.Count() == 0)
                    {
                        MyLog.Default.WriteLine($"No Admins");
                    }
                }
                catch (Exception e)
                {
                    MyLog.Default.WriteLine($"Failed to load Server cfg file: {e.Message}");
                    MyLog.Default.Flush();
                }
                if (settings.AlwaysUnlocked == null)
                {
                    settings.AlwaysUnlocked = new HashSet <SerializableDefinitionId>();
                }
                MyAPIGateway.Session.DamageSystem.RegisterDestroyHandler(0, DestroyHandler);
                MyVisualScriptLogicProvider.PlayerResearchClearAll();
                PrepareCache();
            }
            /* Setup Client and Server wide communication*/
            try
            {
                PlayerInit             = nhs.Create <long>(null, PlayerJoined, EventOptions.OnlyToServer);
                SendUnlockNotification = nhs.Create <MyDefinitionId, string, string>(LearnedById, null, EventOptions.OnlyToTarget);
            }
            catch (Exception e)
            {
                MyLog.Default.WriteLine($"Network Notifications ERROR: {e.StackTrace}");
                MyLog.Default.Flush();
            }
            if (NetworkHandlerSystem.IsClient)
            {
                try
                {
                    MyVisualScriptLogicProvider.ResearchListWhitelist(true);
                    MyVisualScriptLogicProvider.PlayerResearchClear();
                    MyLog.Default.WriteLine($"Check ControlledEntity");
                    if (MyAPIGateway.Session.Player.Controller.ControlledEntity != null &&
                        MyAPIGateway.Session.Player.Controller.ControlledEntity.Entity is IMyCharacter)
                    {
                        MyLog.Default.WriteLine($"InvokeOnGameThread Start");
                        MyLog.Default.Flush();
                        MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                        {
                            try
                            {
                                MyLog.Default.WriteLine($"Start InitPlayer");
                                MyLog.Default.Flush();
                                PlayerInit(MyAPIGateway.Session.Player.PlayerID);
                            }
                            catch (Exception e)
                            {
                                MyLog.Default.WriteLine($"PlayerInit: {e.Message}");
                                MyLog.Default.Flush();
                            }
                        });
                    }
                    else
                    {
                        MyLog.Default.WriteLine($"ControlledEntityChanged");
                        MyLog.Default.Flush();
                        MyAPIGateway.Session.Player.Controller.ControlledEntityChanged += Controller_ControlledEntityChanged;
                    }
                }
                catch (Exception e)
                {
                    MyLog.Default.WriteLine($"NetworkHandlerSystem INIT: {e.Message}");
                    MyLog.Default.Flush();
                }
            }
            GetAllBlocks();
            MyLog.Default.WriteLine($"SUCCESSFUL INIT!");
            MyLog.Default.Flush();
            return(true);
        }
Exemplo n.º 16
0
 public MySessionComponentDescriptor(MyUpdateOrder updateOrder, int priority, Type type)
 {
     UpdateOrder       = updateOrder;
     Priority          = priority;
     ObjectBuilderType = type;
 }
Exemplo n.º 17
0
 void IMySession.RegisterComponent(MySessionComponentBase component, MyUpdateOrder updateOrder, int priority)
 {
     RegisterComponent(component, updateOrder, priority);
 }
Exemplo n.º 18
0
 public MySessionComponentDescriptor(MyUpdateOrder updateOrder, int priority)
     : this(updateOrder, priority, null)
 {
 }
Exemplo n.º 19
0
 public MySessionComponentDescriptor(MyUpdateOrder updateOrder)
     : this(updateOrder, 1000)
 {
 }
Exemplo n.º 20
0
 public void SetUpdateOrder(MyUpdateOrder order)
 {
     Session.SetComponentUpdateOrder(this, order);
     UpdateOrder = order;
 }
Exemplo n.º 21
0
 void IMySession.RegisterComponent(MySessionComponentBase component, MyUpdateOrder updateOrder, int priority)
 {
     RegisterComponent(component, updateOrder, priority);
 }
Exemplo n.º 22
0
 public abstract bool Initialize(out MyUpdateOrder order);