Example #1
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());
            }
        }
Example #2
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());
            }
        }