示例#1
0
        private void CMDgetnews(CommandArgs args)
        {
            try
            {
                int page = 1;
                if (args.Parameters.Count > 0)
                {
                    int.TryParse(args.Parameters[0], out page);
                }
                page--;

                string path = Path.Combine(SavePath, getConfig.news_file);
                TSUtils.CheckFile(path);
                var NewsFile = File.ReadAllLines(path);

                Dictionary <string, Color> messages = new Dictionary <string, Color>();
                foreach (var n in NewsFile)
                {
                    messages.Add(n, Color.SeaGreen);
                }

                var header = TSUtils.GetPaginationHeader("Get News", "/gnews", page + 1, (messages.Count / 6) + 1);

                TSUtils.Paginate(header, messages, page, args.Player);
            }
            catch (Exception ex)
            {
                args.Player.SendErrorMessage("An error occoured while reading the news file! Check the logs.", Color.IndianRed);
                TShock.Log.Error("[TSDocs] error while reading the news file: \n" + ex.ToString());
            }
        }
示例#2
0
        private void CMDsetnews(CommandArgs args)
        {
            try
            {
                if (args.Parameters.Count < 2)
                {
                    args.Player.SendErrorMessage("Usage: /snews <add / line number to edit> <new text>");
                    return;
                }
                if (args.Parameters[0] == "add" || args.Parameters[0] == "a")
                {
                    var path = Path.Combine(SavePath, getConfig.news_file);
                    TSUtils.CheckFile(path);
                    var NewsFile = File.ReadAllLines(path);

                    var textParams = args.Parameters;
                    textParams.RemoveAt(0);

                    var NewNews = new List <string>();
                    NewNews.Add(string.Join(" ", textParams));
                    NewNews.AddRange(NewsFile);

                    File.WriteAllLines(path, NewNews);

                    args.Player.SendSuccessMessage("Sucessfuly added line to the news");
                }
                else
                {
                    int line = 1;
                    if (!int.TryParse(args.Parameters[0], out line))
                    {
                        args.Player.SendErrorMessage("Error: Line number is not an integer!");
                        return;
                    }
                    if (line > getConfig.news_lines)
                    {
                        args.Player.SendErrorMessage("Error: You can only set up to line {0}.", getConfig.news_lines.ToString());
                        return;
                    }

                    var path = Path.Combine(SavePath, getConfig.news_file);
                    TSUtils.CheckFile(path);
                    var NewsFile = File.ReadAllLines(path);

                    var textParams = args.Parameters;
                    textParams.RemoveAt(0);

                    NewsFile[line - 1] = string.Join(" ", textParams);
                    File.WriteAllLines(path, NewsFile);
                    args.Player.SendInfoMessage("Sucessfuly wrote line to the news");
                }
            }
            catch (Exception ex)
            {
                args.Player.SendErrorMessage("An error occoured while writing to the news file! Check the logs.", Color.IndianRed);
                TShock.Log.Error("[TSDocs] error while writing to the news file: \n" + ex.ToString());
            }
        }
示例#3
0
        public static void ShowFile(TSCommand command, string chat, TSPlayer player)
        {
            try
            {
                String filetoshow = Path.Combine(SavePath, command.file);
                foreach (var group in command.groups)
                {
                    if (group.Key == player.Group.Name)
                    {
                        filetoshow = Path.Combine(SavePath, group.Value);
                    }
                }

                Dictionary <string, Color> displayLines = new Dictionary <string, Color>();

                TSUtils.CheckFile(filetoshow);

                var file = File.ReadAllLines(filetoshow);

                var messages = TSUtils.ReplaceVariables(file, player);

                int page = 0;
                if (chat.Contains(" "))
                {
                    var data = chat.Split(' ');
                    if (int.TryParse(data[1], out page))
                    {
                        page--;
                    }
                    else
                    {
                        player.SendErrorMessage(string.Format("Invalid page number ({0})", data[1]), Color.Red);
                    }
                }

                TSUtils.Paginate(TSUtils.GetPaginationHeader(command.name, command.command, page + 1, (messages.Count / 6) + 1),
                                 messages, page, player);
            }
            catch (Exception ex)
            {
                TShock.Log.ConsoleError("Something when wrong when showing {0} \"{1}\". Check the Logs.".SFormat(player.Name, command.command));
                TShock.Log.Error(ex.ToString());
            }
        }
示例#4
0
        private void ShowMOTD(TSPlayer player)
        {
            try
            {
                string filetoshow = Path.Combine(SavePath, getConfig.motd.file);
                foreach (var group in getConfig.motd.groups)
                {
                    if (group.Key == player.Group.Name)
                    {
                        filetoshow = Path.Combine(SavePath, group.Value);
                    }
                }

                TSUtils.CheckFile(filetoshow);
                var file = File.ReadAllLines(filetoshow);

                var messages = TSUtils.ReplaceVariables(file, player);

                foreach (var msg in messages)
                {
                    if (msg.Key.StartsWith("%command%") && msg.Key.EndsWith("%"))
                    {
                        string docmd = msg.Key.Split('%')[2];
                        if (!docmd.StartsWith("/"))
                        {
                            docmd = "/" + docmd;
                        }
                        Commands.HandleCommand(player, docmd);
                        continue;
                    }
                    else
                    {
                        player.SendInfoMessage(msg.Key, msg.Value);
                    }
                }
            }
            catch (Exception ex)
            {
                TShock.Log.ConsoleError("Something when wrong when showing {0} a motd. Check the logs.".SFormat(player.Name));
                TShock.Log.Error(ex.ToString());
            }
        }
示例#5
0
        private static void Re_LoadConfig()
        {
            //config
            if (!Directory.Exists(TSDocs.SavePath))
            {
                NewConfig();
            }

            TSDocs.getConfig = TSConfig.Read(TSDocs.ConfigPath);
            TSDocs.getConfig.Write(TSDocs.ConfigPath);

            //motd
            if (TSDocs.getConfig.motd != null)
            {
                if (TSDocs.getConfig.motd.file != null)
                {
                    TSUtils.CheckFile(Path.Combine(TSDocs.SavePath, TSDocs.getConfig.motd.file));
                }

                if (TSDocs.getConfig.motd_enabled && File.ReadAllText(Path.Combine(TShock.SavePath, "motd.txt")) != "")
                {
                    File.WriteAllText(Path.Combine(TShock.SavePath, "motd.txt"), "");
                }

                if (TSDocs.getConfig.motd.groups != null)
                {
                    foreach (var motd in TSDocs.getConfig.motd.groups)
                    {
                        TSUtils.CheckFile(Path.Combine(TSDocs.SavePath, motd.Value));
                    }
                }
            }
            //news
            TSUtils.CheckFile(Path.Combine(TSDocs.SavePath, TSDocs.getConfig.news_file));

            //commands
            int i = 0;

            foreach (var command in TSDocs.getConfig.commands)
            {
                if (command == null)
                {
                    continue;
                }
                if (command.command != null && !command.command.StartsWith("/"))
                {
                    TSDocs.getConfig.commands[i].command = "/{0}".SFormat(command.command);
                }
                i++;
                foreach (var group in command.groups)
                {
                    if (!string.IsNullOrEmpty(group.Value))
                    {
                        TSUtils.CheckFile(Path.Combine(TSDocs.SavePath, group.Value));
                    }
                }

                if (!string.IsNullOrEmpty(command.file))
                {
                    TSUtils.CheckFile(Path.Combine(TSDocs.SavePath, command.file));
                }
            }
        }