Exemplo n.º 1
0
        public void Log(string message, ConsoleColor color, string prefix = "default",
                        string suffix = "default", bool parseColors = false)
        {
            if (prefix == "default")
            {
                prefix = Prefix;
            }
            if (suffix == "default")
            {
                suffix = System.Environment.NewLine;
            }

            var lastColor = Console.ForegroundColor;

            Console.ForegroundColor = color;

            lock (Console.Out) {
                Write(prefix + message + suffix, parseColors);
            }

            Console.ForegroundColor = lastColor;

            try {
                if (R.Settings.Instance.RCON.Enabled)
                {
                    RCONServer.Broadcast(message);
                }
            } catch (Exception ex) {
                Console.WriteLine($"ConsoleLogger error: {ex.ToString()}");
            }
        }
Exemplo n.º 2
0
        public void SendMessage(object message, Color color)
        {
            string sMessage = message is string
                              ?AeiouToAscii((string)message)
                                  : message.ToString();

            try
            {
                if (R.Settings.Instance.RCON.Enabled)
                {
                    RCONServer.Broadcast(sMessage);
                }
            }
            catch (Exception ex)
            {
                UEssentials.Logger.LogError("Failed to broadcast a message to RCON.");
                UEssentials.Logger.LogException(ex);
            }

            var oldColor = Console.ForegroundColor;

            Console.ForegroundColor = ColorUtil.UnityColorToConsoleColor(color);
            Console.WriteLine(sMessage);
            Console.ForegroundColor = oldColor;
        }
Exemplo n.º 3
0
        private void processLog(LogEntry entry)
        {
            StreamWriter streamWriter = File.AppendText(Path.Combine(Environment.LogsDirectory, Environment.LogFile));

            streamWriter.WriteLine("[" + DateTime.Now + "] [" + entry.Severity.ToString() + "] " + entry.Message);
            streamWriter.Close();
            if (entry.RCON && R.Settings != null && R.Settings.Instance.RCON.Enabled)
            {
                RCONServer.Broadcast(entry.Message);
            }
        }
Exemplo n.º 4
0
        static void RunBismuth(string[] args)
        {
            //Load plugins
            if (!BismuthConfig.Setup())
            {
                return;
            }

            BismuthThreadPool.Setup();
            SetupManagersFromLoadedAssemblies();

            ModeFlagBindings.AddBindings("HELP", "Displays this help text", new string[] { "h", "help" });
            RCONServer.AddRCONCommand("version", "Lists the Bismuth version information", (a) => { return(Program.GetFullProgramVersionString()); });
            RCONServer.AddRCONCommand("status", "Lists various statistics about the current Bismuth process", (a) => { return(GetStatus(true)); });
            RCONServer.AddRCONCommand("list-managers", "Lists all currently running managers", (a) => { return(ListManagers(true)); });

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i][0] == '-')
                {
                    if (args[i][1] == '-')
                    {
                        ModeFlagBindings.SetFlag(args[i].Substring(2));
                    }
                    else
                    {
                        for (int j = 1; j < args[i].Length; j++)
                        {
                            ModeFlagBindings.SetFlag(args[i][j]);
                        }
                    }
                }
            }

            if (ModeFlagBindings.IsFlagSet("HELP"))
            {
                ModeFlagBindings.PrintHelp();
                return;
            }

            LogManager.Log("Main Thread", "Beginning primary execution loop");
            while (!ShutDown)
            {
                //TODO: Handle plugin receive handler
                NetworkManager.ListenForNewConnections();
                Thread.Sleep(1);
            }
            LogManager.Log("Main Thread", "Primary execution loop quit");
        }
        internal void Report(IRocketPlayer caller, ushort itemId, float range, bool printConsole, bool getPinfo, object data, BuildableType type = BuildableType.Element, int count = 0, ulong lockedOwner = 0, int vindex = 0)
        {
            Category cat;

            if (!elements.ContainsKey(itemId))
            {
                if (type == BuildableType.VehicleElement)
                {
                    if (reportLists[BuildableType.VehicleElement].ContainsKey('!'))
                    {
                        reportLists[BuildableType.VehicleElement]['!'] += 1;
                    }
                    else
                    {
                        reportLists[BuildableType.VehicleElement].Add('!', 1);
                    }
                    cat = categorys['!'];
                }
                else
                {
                    if (reportLists[BuildableType.Element].ContainsKey('!'))
                    {
                        reportLists[BuildableType.Element]['!'] += 1;
                    }
                    else
                    {
                        reportLists[BuildableType.Element].Add('!', 1);
                    }
                    cat = categorys['!'];
                }
            }
            else
            {
                if (type == BuildableType.VehicleElement)
                {
                    if (reportLists[BuildableType.VehicleElement].ContainsKey(elements[itemId].CategoryId))
                    {
                        reportLists[BuildableType.VehicleElement][elements[itemId].CategoryId] += 1;
                    }
                    else
                    {
                        reportLists[BuildableType.VehicleElement].Add(elements[itemId].CategoryId, 1);
                    }
                    cat = categorys[elements[itemId].CategoryId];
                }
                else
                {
                    if (reportLists[BuildableType.Element].ContainsKey(elements[itemId].CategoryId))
                    {
                        reportLists[BuildableType.Element][elements[itemId].CategoryId] += 1;
                    }
                    else
                    {
                        reportLists[BuildableType.Element].Add(elements[itemId].CategoryId, 1);
                    }
                    cat = categorys[elements[itemId].CategoryId];
                }
            }
            if (printConsole || !elements.ContainsKey(itemId))
            {
                string stype = type == BuildableType.VehicleElement ? "Vehicle Element: " : "Element: ";
                string msg   = string.Empty;
                ulong  owner = 0;
                InteractableVehicle vehicle = null;
                StructureData       sData   = null;
                BarricadeData       bData   = null;
                string eName = string.Empty;
                if (data is BarricadeData)
                {
                    bData = data as BarricadeData;
                    owner = bData.owner;
                    eName = bData.barricade.asset.itemName;
                }
                else if (data is StructureData)
                {
                    sData = data as StructureData;
                    owner = sData.owner;
                    eName = sData.structure.asset.itemName;
                }
                else if (data is InteractableVehicle)
                {
                    vehicle = data as InteractableVehicle;
                    itemId  = vehicle.id;
                    eName   = vehicle.asset.vehicleName;
                }
                if (type == BuildableType.Vehicle)
                {
                    DestructionProcessing.HasFlaggedElement(vindex > 0 ? vehicle.trainCars[vindex].root : vehicle.transform, out ulong signOwner);
                    msg = string.Format("{0}{1} (Id: {6}:{2}, Instance ID: {8}) @ {3}m, Barricade Count: {4}, Sign by: {7}, Locked By: {5}", stype, cat.Name, itemId, Math.Round(range, 2), count, lockedOwner > 0 ? getPinfo ? WreckingBall.Instance.PInfoGenerateMessage(lockedOwner) : lockedOwner.ToString() : "N/A", vindex > 0 ? "Train car#" + vindex : eName, signOwner > 0 ? getPinfo ? WreckingBall.Instance.PInfoGenerateMessage(signOwner) : signOwner.ToString() : "N/A", vehicle.instanceID.ToString());
                }
                else
                {
                    // Generate the message in another method, as the Player info one requires special data types that have to be loaded before executing a method.
                    msg = string.Format("{0}{1} (Id: {5}:{2}) @ {3}m, Owner: {4}", stype, cat.Name, itemId, Math.Round(range, 2), owner > 0 ? getPinfo ? WreckingBall.Instance.PInfoGenerateMessage(owner) : owner.ToString() : "N/A", eName);
                }


                if (WreckingBall.Instance.Configuration.Instance.LogScans)
                {
                    Logger.Log(msg, cat.Color);
                }
                else
                {
                    Console.ForegroundColor = cat.Color;
                    Console.WriteLine(msg);
                    Console.ResetColor();
                    if (R.Settings.Instance.RCON.Enabled)
                    {
                        RCONServer.Broadcast(msg);
                    }
                }
                if (WreckingBall.Instance.Configuration.Instance.PrintToChat && !(caller is ConsolePlayer))
                {
                    UnturnedChat.Say(caller, msg, Color.yellow);
                }
            }
        }