GMAudit.java 2.4 KB

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