예제 #1
0
        public TicketList writeFile(string file)
        {
            TextWriter tw = new StreamWriter(file, true);

            TicketList ticList = new TicketList();
            tw.Write(JsonConvert.SerializeObject(ticList, Formatting.Indented));
            tw.Close();

            return ticList;
        }
예제 #2
0
 public static void Reload(CommandArgs args)
 {
     TicketReader Reader = new TicketReader();
     try
     {
         ticketlist = Reader.readFile(save);
         Console.ForegroundColor = ConsoleColor.Yellow;
         Console.WriteLine("Ticket System being reloaded...");
         args.Player.SendMessage("Ticket System being reloaded...", Color.Yellow);
         Log.Info("Ticket System Reloading...");
         if (ticketlist.Tickets.Count != 0)
         {
             Console.WriteLine(ticketlist.Tickets.Count + " tickets have been reloaded.");
             args.Player.SendMessage(ticketlist.Tickets.Count + " tickets have been reloaded.", Color.Yellow);
         }
         else
         {
             Console.WriteLine("There are no tickets.");
             args.Player.SendMessage("There are no tickets.", Color.Yellow);
         }
         Console.ResetColor();
         args.Player.SendMessage("Ticket System reloaded.", Color.Yellow);
         Log.Info("Ticket System Reloaded.");
     }
     catch (Exception e)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine("Error in Tickets.json file! Check log for more details.");
         args.Player.SendMessage("Error in Tickets.json file! Check log for more details.", Color.Red);
         Console.WriteLine(e.Message);
         Console.ResetColor();
         Log.Error("--------- Config Exception in TicketSystem Config file (Tickets.json) ---------");
         Log.Error(e.Message);
         Log.Error("---------------------------------- Error End ----------------------------------");
     }
 }
예제 #3
0
        public static void Ticket(CommandArgs args)
        {
            if (!File.Exists(save))
            {
                if (Directory.Exists(Path.Combine(TShock.SavePath, "TicketSystem")))
                {
                    TicketReader reader = new TicketReader();
                    ticketlist = reader.writeFile(save);
                }
                else
                {
                    Setup();
                }
            }

            var FindMe = Player.GetPlayerByName(args.Player.Name);
            if (FindMe.GetTicState() == Player.CanSubmitTickets.no)
            {
                args.Player.SendMessage("You cannot send tickets because you have had that privilege revoked.", Color.Red);
            }
            else if ((FindMe.GetTicState() == Player.CanSubmitTickets.yes) && (args.Parameters.Count < 1))
            {
                args.Player.SendMessage("/Ticket <-t:[tag]/tags/responses/clearresponses> <message>:", bluebase);
                args.Player.SendMessage("- /Ticket <message>: This submits a message with a tag marked as the default tag.", bluesecondarybase);
                args.Player.SendMessage("- /Ticket -t:<tag> <message>: This submits a message with a defined tag. Ex: \"/ticket -t:report Bob griefed my house!\" (notice: -t:<tag> has no spaces between the colon and the specified tag).", bluesecondarybase);
                args.Player.SendMessage("- /Ticket tags: This shows a list of the valid tags defined in the \"tags.txt\" file.", bluesecondarybase);
                args.Player.SendMessage("- /Ticket responses: This shows a list of the tickets that were responded too, and their specific response.", bluesecondarybase);
                args.Player.SendMessage("- /Ticket clearresponses: This clears all of the tickets you have submitted that have responses.", bluesecondarybase);
                args.Player.SendMessage("WARNING: If you misuse the privalege of submitting tickets, you will have that privalege taken away.", Color.Red);
            }
            else if (args.Parameters[0].ToLower() == "clearresponses")
            {
                try
                {
                    lock (ticketlist.Tickets)
                    {
                        for (int i = ticketlist.Tickets.Count - 1; i >= 0; i++)
                        {
                            if (ticketlist.Tickets[i].getName() == args.Player.Name)
                            {
                                if (ticketlist.Tickets[i].getResponse() != null)
                                    ticketlist.Tickets.Remove(ticketlist.Tickets[i]);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                }
                UpdateTicketsInJSON(save);
                args.Player.SendMessage("Your responses have been cleared!", bluebase);
            }
            else if (args.Parameters[0].ToLower() == "responses")
            {
                if (File.Exists(save))
                {
                    int i = ticketlist.responseCount(args.Player.Name);
                    int x = ticketlist.ticketCount(args.Player.Name);
                    if (i != 0)
                    {
                        args.Player.SendMessage("--- Responses for Tickets (" + i + "/" + x + ") ---", bluebase);
                        lock (ticketlist.Tickets)
                        {
                            foreach (StandardTicket t in ticketlist.Tickets)
                            {
                                if (t.getName() == args.Player.Name)
                                {
                                    if (t.getResponse() != null)
                                    {
                                        args.Player.SendMessage("(" + t.getTicket().Trim() + "): " + t.getResponse(), bluesecondarybase);
                                    }
                                }
                            }
                        }
                        args.Player.SendMessage("To clear the responses, type /ticket clearresponses", bluebase);
                    }
                }
            }
            else if ((FindMe.GetTicState() == Player.CanSubmitTickets.yes) && (args.Parameters[0].ToLower() == "tags") || (args.Parameters[0].ToLower() == "tag") || (args.Parameters[0].ToLower() == "taglist"))
            {
                if (File.Exists(tagpath))
                {
                    string[] officialtags = File.ReadAllText(tagpath).Split('\n');
                    args.Player.SendMessage("Tags:", bluebase);
                    foreach (string officialtag in officialtags)
                    {
                        if (officialtag.StartsWith(" ") || officialtag == null || officialtag == "")
                            continue;
                        args.Player.SendMessage(officialtag, bluesecondarybase);
                    }
                }
            }
            else if ((FindMe.GetTicState() == Player.CanSubmitTickets.yes) && (args.Parameters[0].ToLower().StartsWith("-tag:") || args.Parameters[0].ToLower().StartsWith("-t:")))
            {
                string tag = args.Parameters[0].ToLower().Split(':')[1];
                string[] officialtags = File.ReadAllText(tagpath).Split('\n');
                for (int i = 0; i < officialtags.Length; i++)
                {
                    officialtags[i] = officialtags[i].Trim().ToLower();
                }
                if (!((IList<string>)officialtags).Contains(tag.Trim()))
                    tag = officialtags[0];
                if ((tag == "") || (tag == null))
                {
                    if (!((IList<string>)officialtags).Contains(args.Parameters[1].ToLower().Trim()))
                        tag = officialtags[0];
                }
                try
                {
                    string text = "";
                    foreach (string word in args.Parameters)
                    {
                        if (word == args.Parameters[0])
                            continue;
                        else
                            text = text + word + " ";
                    }

                    ticketlist.AddItem(new StandardTicket(args.Player.Name, text, null, DateTime.Now.ToString(), tag));

                    UpdateTicketsInJSON(save);

                    args.Player.SendMessage("Your Ticket has been sent!", bluebase);
                    args.Player.SendMessage("Note: It has been tagged as " + tag + ". Use \"/ticket tags\" to view a list of valid tags.", bluesecondarybase);
                    foreach (Player player in TicketSystem.Players)
                    {
                        if (player.TSPlayer.Group.HasPermission("TicketList"))
                        {
                            player.TSPlayer.SendMessage(string.Format("{0} just submitted a ticket: {1}", args.Player.Name, text), bluebase);
                        }
                    }
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.Write(args.Player.Name + " just submitted a ticket: ", bluebase);
                    Console.ResetColor();
                    Console.WriteLine(text);
                    if (Config.beepOnTicketSubmission)
                        Console.Beep(637, 100);
                }
                catch (Exception e)
                {
                    args.Player.SendMessage("Your ticket could not be sent, contact an administrator.", Color.Red);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(e.Message);
                    Console.ResetColor();
                    Log.Error(e.Message);
                }
            }
            else if (FindMe.GetTicState() == Player.CanSubmitTickets.yes)
            {
                try
                {
                    string[] officialtags = File.ReadAllText(tagpath).Split('\n');
                    for (int i = 0; i < officialtags.Length; i++)
                    {
                        officialtags[i] = officialtags[i].Trim().ToLower();
                    }
                    string text = "";
                    foreach (string word in args.Parameters)
                    {
                        text = text + word + " ";
                    }

                    ticketlist.AddItem(new StandardTicket(args.Player.Name, text, null, DateTime.Now.ToString(), officialtags[0]));

                    UpdateTicketsInJSON(save);

                    args.Player.SendMessage("Your Ticket has been sent!", bluebase);
                    foreach (Player player in TicketSystem.Players)
                    {
                        if (player.TSPlayer.Group.HasPermission("TicketList"))
                        {
                            player.TSPlayer.SendMessage(string.Format("{0} just submitted a ticket: {1}", args.Player.Name, text), bluebase);
                        }
                    }
                    Console.ForegroundColor = ConsoleColor.Blue;
                    Console.Write(args.Player.Name + " just submitted a ticket: ", bluebase);
                    Console.ResetColor();
                    Console.WriteLine(text);
                    if (Config.beepOnTicketSubmission)
                        Console.Beep(637, 100);
                }
                catch (Exception e)
                {
                    args.Player.SendMessage("Your ticket could not be sent, contact an administrator.", Color.Red);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(e.Message);
                    Console.ResetColor();
                    Log.Error(e.Message);
                }
            }
        }
예제 #4
0
        public static void Setup()
        {
            save = Path.Combine(TShock.SavePath, @"TicketSystem\Tickets.json");
            banned = Path.Combine(TShock.SavePath, @"TicketSystem\Banned.txt");
            TicketReader Reader = new TicketReader();
            Config = new Config();

            if (File.Exists(save))
            {
                try
                {
                    ticketlist = Reader.readFile(save);
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    if (ticketlist.Tickets.Count != 0)
                        Console.WriteLine(ticketlist.Tickets.Count + " tickets have been loaded.");
                    else
                        Console.WriteLine("There are no tickets.");
                    Console.ResetColor();
                    try
                    {
                        if (File.Exists(ConfigPath))
                            Config = Config.Read(ConfigPath);
                        Config.Write(ConfigPath);
                    }
                    catch (Exception e)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Error in TicketSystem Config.json file! Check log for more details.");
                        Console.WriteLine(e.Message);
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Log.Error("Config Exception");
                        Log.Error(e.ToString());
                    }
                }
                catch (Exception e)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Error in Tickets.json file! Check log for more details.");
                    Console.WriteLine(e.Message);
                    Console.ResetColor();
                    Log.Error("------------- Config Exception in Ticket List file (Tickets.json) -------------");
                    Log.Error(e.Message);
                    Log.Error("---------------------------------- Error End ----------------------------------");
                    Console.ForegroundColor = ConsoleColor.Red;
                }
            }
            else
            {
                Directory.CreateDirectory(Path.Combine(TShock.SavePath, "TicketSystem"));
                ticketlist = Reader.writeFile(save);
                using (StreamWriter writer = new StreamWriter(tagpath, true))
                {
                    writer.WriteLine("Default");
                    writer.WriteLine("Grief");
                    writer.WriteLine("Report");
                    writer.WriteLine("High-Importance");
                }
                using (StreamWriter writer = new StreamWriter(Path.Combine(TShock.SavePath, @"TicketSystem\loginmsg.txt"), true))
                {
                    writer.WriteLine("To write a complaint, use \"/ticket [-t:<tag>] <Message>\"");
                    writer.WriteLine("NOTE: Tags are optional. To view a list of tags, use \"/ticket tags\"");
                }
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("There are no tickets.");
                Console.ResetColor();
                Log.Info("No tickets submitted.");
            }
        }