コード例 #1
0
        public Session()
        {
            // Only load if the steam version has been loaded too.
            var steamComponent = ReflectionHelper.FindModSessionComponent("GardenConquest", 450540708, "Steam", "GC.Notify");

            if (steamComponent == null)
            {
                return;
            }

            Log.Log("GC steam component found, loading mod.");

            Log.Trace("Registering session components");
            ComponentSession.RegisterComponentGroup((int)Groups.Sessions);
            //UpdateManager.RegisterSessionComponent(new ServerTestSession());

            Log.Trace("Registering entity components");
            //UpdateManager.RegisterEntityComponent(
            //    ((e) => { return new EnforcedGrid(e); }),
            //    typeof(MyObjectBuilder_CubeGrid),
            //    RunLocation.Server);
            //UpdateManager.RegisterEntityComponent(
            //	((e) => {
            //		return LootCrate.IsLootCrate(e) ?
            //			new LootCrate(e) :
            //			null;
            //	}),
            //	typeof(MyObjectBuilder_CubeGrid),
            //	RunLocation.Server);

            // Tell the steam code we've loaded successfully.
            ReflectionHelper.SetInstanceField(steamComponent, "PluginLoaded", true);
        }
コード例 #2
0
        private void TryAttachSession()
        {
            if (Sandbox.Game.World.MySession.Static == null || MyAPIGateway.Entities == null)
            {
                return;
            }

            Log.Trace("Attaching MySession");
            Sandbox.Game.World.MySession.Static.RegisterComponentsFromAssembly(Assembly.GetExecutingAssembly(), true);
            MyAPIGateway.Entities.OnCloseAll += DetachSession;
            SessionAttached = true;
        }
コード例 #3
0
        ////public static ClientSession Static;
        //public static ClientMessageHandler Messenger;
        ////public Settings Settings;
        //public ulong LocalSteamId;

        public ClientSession()
        {
            Log.Trace("Initializing Client Session");
            RegisterMessageHandlers();
            ////GardenGateway.Commands.addCommands(Commands.FullTree);
            //Messenger = new ClientMessageHandler();
            ////new LoginRequest().SendToServer();
            //new SettingsRequest().SendToServer();
            //m_Player = MyAPIGateway.Session.Player;
            ////Static = this;
            SendLoginRequest();
            Log.Trace("Finished Initializing Client Session");
        }
コード例 #4
0
ファイル: Messenger.cs プロジェクト: Rynchodon/SEPC
        /*
         * public void SendToFaction(BitStream data, ushort domainId, ushort typeId, long factionId, bool reliable = true)
         * {
         *  IMyFaction faction = MyAPIGateway.Session.Factions.TryGetFactionById(factionId);
         *  if (faction == null)
         *      Log.Error("Failed to find faction " + factionId);
         *  else
         *      foreach (ulong steamId in faction.SteamIds())
         *          SendToPlayer(data, domainId, typeId, steamId, reliable);
         * }
         */

        static void Send(BitStream data, ushort domainId, ushort typeId, MessageDestination dest, ulong destId = 0, bool reliable = true)
        {
            Log.Trace($"Sending {data.ByteLength} bytes to {dest}/{destId}/{domainId}/{typeId}");
            ulong senderId = (MyAPIGateway.Session.Player != null) ? MyAPIGateway.Session.Player.SteamUserId : 0;

            byte[] bytes = FormatMessage(data, domainId, typeId, senderId);

            MainThread.TryOnMainThread(() =>
            {
                if (!SendMessageToDest(bytes, dest, destId, reliable))
                {
                    Log.Error(new MessageTooLongException(bytes.Length));
                }
            });
        }
コード例 #5
0
        //private static Action<int, List<long>, List<IMyPlayer>, ControlPoint> rewardDistribution;
        //public static event Action<int, List<long>, List<IMyPlayer>, ControlPoint> RewardsDistributed {
        //    add { rewardDistribution += value; }
        //    remove { rewardDistribution -= value; }
        //}
        //private static void notifyRewardsDistributed(int distributed, List<long> winningFleets,
        //    List<IMyPlayer> nearbyPlayers, ControlPoint cp) {
        //    if (rewardDistribution != null)
        //        rewardDistribution(distributed, winningFleets, nearbyPlayers, cp);
        //}

        ////public Settings Settings;
        //public List<EnforcedGrid> Grids = new List<EnforcedGrid>();

        ////private Queue<ControlPoint> CPsToUpdate = new Queue<ControlPoint>();

        #region Init / Terminate

        public ServerSession()
        {
            Log.Trace("Initializing Server Session");

            RegisterMessageHandlers();

            ////if (ModInfo.DebugMode && !RunTests()) {
            ////    Log.Info("Tests failed, aborting init.", "Initialize");
            ////    return;
            ////}

            ////if (!Settings.TryLoadOrCreate(out Settings)) {
            ////    Log.Info("Settings load failed, aborting init.", "Initialize");
            ////    return;
            ////}

            ////Settings.ControlPoints.ForEach(x => x.Initialize());

            //Log.Trace("Registering concealment manager", "Initialize");
            //Manager = new ConcealmentManager();
            //Manager.Initialize();
            //if (!Manager.Loaded) {
            //    Log.Error("Error loading sector, conceal disabled.", "Initialize");
            //    Messenger.Disabled = true;
            //}

            // Start round timer
            //m_RoundTimer = new MyTimer(s_Settings.CPPeriod * 1000, roundEnd);
            //m_RoundTimer.Start();
            //log("Round timer started with " + s_Settings.CPPeriod + " seconds");

            // Subscribe events
            //GridEnforcer.OnPlacementViolation += eventPlacementViolation;
            //GridEnforcer.OnCleanupViolation += eventCleanupViolation;
            //GridEnforcer.OnCleanupTimerStart += eventCleanupTimerStart;
            //GridEnforcer.OnCleanupTimerEnd += eventCleanupTimerEnd;
            //ControlPoint.OnRewardsDistributed += notifyPlayersOfCPResults;

            Log.Trace("Finished Initializing Server Session");
        }
コード例 #6
0
ファイル: MySession.cs プロジェクト: Rynchodon/SEPC
        public override void UpdateAfterSimulation()
        {
            base.UpdateAfterSimulation();

            if (IsUpdatingStopped)
            {
                UpdatingResumed();
            }

            if (!SessionClosedAttached && MyAPIGateway.Entities != null)
            {
                Log.Trace("Attaching SessionClosed");
                MyAPIGateway.Entities.OnCloseAll += SessionClosed;
                SessionClosedAttached             = true;
            }

            ComponentSession.Update();
        }
コード例 #7
0
 public bool ShouldRunOn(RunLocation location)
 {
     Log.Trace($"Does component RunsOn {RunsOn} apply to {location} ? {(RunsOn & location) != 0}");
     return((RunsOn & location) != 0);
 }
コード例 #8
0
ファイル: HandlerRegistrar.cs プロジェクト: Rynchodon/SEPC
 /// <summary>
 /// Register a Handler for messages with a given type and domain.
 /// Throws an exception if already registered.
 /// </summary>
 public static void Register(ushort domainId, ushort typeId, MessageHandler handler)
 {
     Log.Trace($"Registering handler for domainId: {domainId} & typeId: {typeId}");
     Static?.AddHandler(domainId, typeId, handler);
 }