Ejemplo n.º 1
0
        /// <summary>
        /// Inform the server to send message to autopilot block.
        /// </summary>
        private static void ToServer(long sender, string recipientGrid, string recipientBlock, string message)
        {
            Static.bytes.Clear();

            ByteConverter.AppendBytes(Static.bytes, MessageHandler.SubMod.Message);
            ByteConverter.AppendBytes(Static.bytes, sender);
            ByteConverter.AppendBytes(Static.bytes, recipientGrid);
            ByteConverter.AppendBytes(Static.bytes, recipientBlock);
            ByteConverter.AppendBytes(Static.bytes, message);

            if (MyAPIGateway.Multiplayer.TrySendMessageToServer(Static.bytes.ToArray()))
            {
                Logger.DebugLog("Sent message to server");
            }
            else
            {
                Logger.AlwaysLog("Message too long", Logger.severity.WARNING);

                IMyEntity entity;
                if (MyAPIGateway.Entities.TryGetEntityById(sender, out entity))
                {
                    IMyTerminalBlock block = entity as IMyTerminalBlock;
                    if (block != null)
                    {
                        block.AppendCustomInfo("Failed to send message:\nMessage too long (" + Static.bytes.Count + " > 4096 bytes)\n");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void FailedToSet(long entityId, string value)
        {
            string message = "Cannot convert \"" + value + "\" to " + typeof(TValue);

            Logger.Notify(message, level: Logger.severity.WARNING);
            alwaysLog(message + ", entity ID: " + entityId, Logger.severity.INFO);

            IMyEntity entity;

            if (!MyAPIGateway.Entities.TryGetEntityById(entityId, out entity))
            {
                alwaysLog("Failed to get entity for " + entityId, Logger.severity.WARNING);
                return;
            }

            IMyTerminalBlock termBlock = entity as IMyTerminalBlock;

            if (termBlock != null)
            {
                termBlock.AppendCustomInfo(message);
                return;
            }

            alwaysLog("Expected IMyTerminalBlock, got: " + entity.nameWithId(), Logger.severity.ERROR);
        }