Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        public static void SyncBlockStateSend(ulong steamId, NanobotBuildAndRepairSystemBlock system)
        {
            if (!MyAPIGateway.Session.IsServer)
            {
                return;
            }
            if (!MyAPIGateway.Multiplayer.MultiplayerActive)
            {
                return;
            }


            var msgSnd = new MsgBlockState();

            msgSnd.EntityId = system.Entity.EntityId;
            msgSnd.State    = system.State.GetTransmit();

            var res = false;

            if (steamId == 0)
            {
                if (Mod.Log.ShouldLog(Logging.Level.Communication))
                {
                    Mod.Log.Write(Logging.Level.Communication, "BuildAndRepairSystemMod: SyncBlockStateSend to others EntityId={0}/{1}, State={2}", system.Entity.EntityId, Logging.BlockName(system.Entity, Logging.BlockNameOptions.None), msgSnd.State.ToString());
                }
                res = MyAPIGateway.Multiplayer.SendMessageToOthers(MSGID_BLOCK_STATE_FROM_SERVER, MyAPIGateway.Utilities.SerializeToBinary(msgSnd), true);
            }
            else
            {
                if (Mod.Log.ShouldLog(Logging.Level.Communication))
                {
                    Mod.Log.Write(Logging.Level.Communication, "BuildAndRepairSystemMod: SyncBlockStateSend to SteamId={0} EntityId={1}/{2}, State={3}", steamId, system.Entity.EntityId, Logging.BlockName(system.Entity, Logging.BlockNameOptions.None), msgSnd.State.ToString());
                }
                res = MyAPIGateway.Multiplayer.SendMessageTo(MSGID_BLOCK_STATE_FROM_SERVER, MyAPIGateway.Utilities.SerializeToBinary(msgSnd), steamId, true);
            }
            system.State.GetTransmit();

            if (!res && Mod.Log.ShouldLog(Logging.Level.Error))
            {
                Mod.Log.Write(Logging.Level.Error, "BuildAndRepairSystemMod: SyncBlockStateSend Failed");
            }
        }
        /// <summary>
        ///
        /// </summary>
        public static void SyncBlockStateSend(ulong steamId, NanobotBuildAndRepairSystemBlock system)
        {
            if (!MyAPIGateway.Utilities.IsDedicated && MyAPIGateway.Session.IsServer)
            {
                return;
            }

            var msgSnd = new MsgBlockState();

            msgSnd.EntityId = system.Welder.EntityId;
            msgSnd.State    = system.State.GetTransmit();

            var res = false;

            if (steamId == 0)
            {
                if (Mod.Log.ShouldLog(Logging.Level.Info))
                {
                    Mod.Log.Write(Logging.Level.Info, "BuildAndRepairSystemMod: SyncBlockStateSend {0} to Others {1}/{2}", Logging.BlockName(system.Welder, Logging.BlockNameOptions.None), msgSnd.State.MissingComponentsSync.Count, msgSnd.State.PossibleWeldTargetsSync.Count);
                }
                res = MyAPIGateway.Multiplayer.SendMessageToOthers(MSGID_BLOCK_STATE_FROM_SERVER, MyAPIGateway.Utilities.SerializeToBinary(msgSnd), true);
            }
            else
            {
                if (Mod.Log.ShouldLog(Logging.Level.Info))
                {
                    Mod.Log.Write(Logging.Level.Info, "BuildAndRepairSystemMod: SyncBlockStateSend {0} to {1} {2}/{3}", Logging.BlockName(system.Welder, Logging.BlockNameOptions.None), steamId, msgSnd.State.MissingComponentsSync.Count, msgSnd.State.PossibleWeldTargetsSync.Count);
                }
                res = MyAPIGateway.Multiplayer.SendMessageTo(MSGID_BLOCK_STATE_FROM_SERVER, MyAPIGateway.Utilities.SerializeToBinary(msgSnd), steamId, true);
            }


            if (!res && Mod.Log.ShouldLog(Logging.Level.Error))
            {
                Mod.Log.Write(Logging.Level.Error, "BuildAndRepairSystemMod: SyncBlockStateSend Failed");
            }
        }