GMAudit.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.util;
  16. import java.io.File;
  17. import java.io.FileWriter;
  18. import java.io.IOException;
  19. import java.text.SimpleDateFormat;
  20. import java.util.Date;
  21. import java.util.logging.Level;
  22. import java.util.logging.Logger;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.util.lib.Log;
  25. /**
  26. * Audits Game Master's actions.
  27. */
  28. public class GMAudit
  29. {
  30. private static final Logger _log = Logger.getLogger(Log.class.getName());
  31. static
  32. {
  33. new File("log/GMAudit").mkdirs();
  34. }
  35. /**
  36. * Logs a Game Master's action into a file.
  37. * @param gmName the Game Master's name
  38. * @param action the performed action
  39. * @param target the target's name
  40. * @param params the parameters
  41. */
  42. public static void auditGMAction(String gmName, String action, String target, String params)
  43. {
  44. final SimpleDateFormat _formatter = new SimpleDateFormat("dd/MM/yyyy H:mm:ss");
  45. final String date = _formatter.format(new Date());
  46. String name = com.l2jserver.util.Util.replaceIllegalCharacters(gmName);
  47. if (!com.l2jserver.util.Util.isValidFileName(name))
  48. {
  49. name = "INVALID_GM_NAME_" + date;
  50. }
  51. final File file = new File("log/GMAudit/" + name + ".txt");
  52. try (FileWriter save = new FileWriter(file, true))
  53. {
  54. save.write(date + ">" + gmName + ">" + action + ">" + target + ">" + params + Config.EOL);
  55. }
  56. catch (IOException e)
  57. {
  58. _log.log(Level.SEVERE, "GMAudit for GM " + gmName + " could not be saved: ", e);
  59. }
  60. }
  61. /**
  62. * Wrapper method.
  63. * @param gmName the Game Master's name
  64. * @param action the performed action
  65. * @param target the target's name
  66. */
  67. public static void auditGMAction(String gmName, String action, String target)
  68. {
  69. auditGMAction(gmName, action, target, "");
  70. }
  71. }