GMAudit.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (C) 2004-2014 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. import com.l2jserver.util.lib.Log;
  29. /**
  30. * Audits Game Master's actions.
  31. */
  32. public class GMAudit
  33. {
  34. private static final Logger _log = Logger.getLogger(Log.class.getName());
  35. static
  36. {
  37. new File("log/GMAudit").mkdirs();
  38. }
  39. /**
  40. * Logs a Game Master's action into a file.
  41. * @param gmName the Game Master's name
  42. * @param action the performed action
  43. * @param target the target's name
  44. * @param params the parameters
  45. */
  46. public static void auditGMAction(String gmName, String action, String target, String params)
  47. {
  48. final SimpleDateFormat _formatter = new SimpleDateFormat("dd/MM/yyyy H:mm:ss");
  49. final String date = _formatter.format(new Date());
  50. String name = com.l2jserver.util.Util.replaceIllegalCharacters(gmName);
  51. if (!com.l2jserver.util.Util.isValidFileName(name))
  52. {
  53. name = "INVALID_GM_NAME_" + date;
  54. }
  55. final File file = new File("log/GMAudit/" + name + ".txt");
  56. try (FileWriter save = new FileWriter(file, true))
  57. {
  58. save.write(date + ">" + gmName + ">" + action + ">" + target + ">" + params + Config.EOL);
  59. }
  60. catch (IOException e)
  61. {
  62. _log.log(Level.SEVERE, "GMAudit for GM " + gmName + " could not be saved: ", e);
  63. }
  64. }
  65. /**
  66. * Wrapper method.
  67. * @param gmName the Game Master's name
  68. * @param action the performed action
  69. * @param target the target's name
  70. */
  71. public static void auditGMAction(String gmName, String action, String target)
  72. {
  73. auditGMAction(gmName, action, target, "");
  74. }
  75. }