Browse Source

Two new logs added: enchant items log and enchant skills log.
Both logs save date/time, player (nick,id,account,ip), used items(if any), skill level and id(if any), used chance.
Not forget to update log.cfg

_DS_ 16 years ago
parent
commit
5d7a3984e8

+ 6 - 0
L2_GameServer/java/config/General.properties

@@ -88,6 +88,12 @@ LogChat = False
 # Default: False
 LogItems = False
 
+# Default: False
+LogItemEnchants = False
+
+# Default: False
+LogSkillEnchants = False
+
 # Default: False
 GMAudit = False
 

+ 16 - 0
L2_GameServer/java/log.cfg

@@ -20,6 +20,9 @@ item.handlers = net.sf.l2j.log.ItemLogHandler
 item.useParentHandlers = false
 audit.handlers = net.sf.l2j.log.AuditLogHandler
 audit.useParentHandlers = false
+enchant.handlers = net.sf.l2j.log.EnchantItemLogHandler,\
+           net.sf.l2j.log.EnchantSkillLogHandler
+enchant.useParentHandlers = false
 
 
 # Default global logging level.
@@ -81,6 +84,19 @@ net.sf.l2j.log.AuditLogHandler.filter = net.sf.l2j.log.AuditFilter
 net.sf.l2j.log.AuditLogHandler.append = true
 net.sf.l2j.log.AuditLogHandler.level = INFO
 
+# enchant item log
+net.sf.l2j.log.EnchantItemLogHandler.pattern = log/enchantitem.log
+net.sf.l2j.log.EnchantItemLogHandler.formatter = net.sf.l2j.log.EnchantFormatter
+net.sf.l2j.log.EnchantItemLogHandler.filter = net.sf.l2j.log.EnchantItemFilter
+net.sf.l2j.log.EnchantItemLogHandler.append = true
+net.sf.l2j.log.EnchantItemLogHandler.level = INFO
+
+# enchant skill log
+net.sf.l2j.log.EnchantSkillLogHandler.pattern = log/enchantskill.log
+net.sf.l2j.log.EnchantSkillLogHandler.formatter = net.sf.l2j.log.EnchantFormatter
+net.sf.l2j.log.EnchantSkillLogHandler.filter = net.sf.l2j.log.EnchantSkillFilter
+net.sf.l2j.log.EnchantSkillLogHandler.append = true
+net.sf.l2j.log.EnchantSkillLogHandler.level = INFO
 
 ############################################################
 # Facility specific properties.

+ 4 - 0
L2_GameServer/java/net/sf/l2j/Config.java

@@ -343,6 +343,8 @@ public final class Config
 	public static boolean GAMEGUARD_PROHIBITACTION;
 	public static boolean LOG_CHAT;
 	public static boolean LOG_ITEMS;
+	public static boolean LOG_ITEM_ENCHANTS;
+	public static boolean LOG_SKILL_ENCHANTS;
 	public static boolean GMAUDIT;
 	public static boolean LOG_GAME_DAMAGE;
 	public static boolean DEBUG;
@@ -1380,6 +1382,8 @@ public final class Config
 					GAMEGUARD_PROHIBITACTION = Boolean.parseBoolean(General.getProperty("GameGuardProhibitAction", "True"));
 					LOG_CHAT = Boolean.parseBoolean(General.getProperty("LogChat", "false"));
 					LOG_ITEMS = Boolean.parseBoolean(General.getProperty("LogItems", "false"));
+					LOG_ITEM_ENCHANTS = Boolean.parseBoolean(General.getProperty("LogItemEnchants", "false"));
+					LOG_SKILL_ENCHANTS = Boolean.parseBoolean(General.getProperty("LogSkillEnchants", "false"));
 					GMAUDIT = Boolean.parseBoolean(General.getProperty("GMAudit", "False"));
 					LOG_GAME_DAMAGE = Boolean.parseBoolean(General.getProperty("LogGameDamage", "False"));
 					DEBUG = Boolean.parseBoolean(General.getProperty("Debug", "false"));

+ 43 - 0
L2_GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestEnchantItem.java

@@ -14,6 +14,8 @@
  */
 package net.sf.l2j.gameserver.network.clientpackets;
 
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
 import java.util.logging.Logger;
 
 import net.sf.l2j.Config;
@@ -32,6 +34,7 @@ import net.sf.l2j.util.Rnd;
 public final class RequestEnchantItem extends AbstractEnchantPacket
 {
 	protected static final Logger _log = Logger.getLogger(RequestEnchantItem.class.getName());
+	protected static final Logger _logEnchant = Logger.getLogger("enchant");
 
 	private static final String _C__58_REQUESTENCHANTITEM = "[C] 58 RequestEnchantItem";
 
@@ -152,6 +155,14 @@ public final class RequestEnchantItem extends AbstractEnchantPacket
 				item.setEnchantLevel(item.getEnchantLevel() + 1);
 				item.updateDatabase();
 				activeChar.sendPacket(new EnchantResult(0, 0, 0));
+
+				if (Config.LOG_ITEM_ENCHANTS)
+				{
+					LogRecord record = new LogRecord(Level.INFO, "Success");
+					record.setParameters(new Object[]{activeChar, item, scroll, support, chance});
+					record.setLoggerName("item");
+					_logEnchant.log(record);
+				}
 			}
 			else
 			{
@@ -160,6 +171,14 @@ public final class RequestEnchantItem extends AbstractEnchantPacket
 					// safe enchant - remain old value
 					// need retail message
 					activeChar.sendPacket(new EnchantResult(5, 0, 0));
+
+					if (Config.LOG_ITEM_ENCHANTS)
+					{
+						LogRecord record = new LogRecord(Level.INFO, "Safe Fail");
+						record.setParameters(new Object[]{activeChar, item, scroll, support, chance});
+						record.setLoggerName("item");
+						_logEnchant.log(record);
+					}
 				}
 				else
 				{
@@ -199,6 +218,14 @@ public final class RequestEnchantItem extends AbstractEnchantPacket
 						item.setEnchantLevel(0);
 						item.updateDatabase();
 						activeChar.sendPacket(new EnchantResult(3, 0, 0));
+
+						if (Config.LOG_ITEM_ENCHANTS)
+						{
+							LogRecord record = new LogRecord(Level.INFO, "Blessed Fail");
+							record.setParameters(new Object[]{activeChar, item, scroll, support, chance});
+							record.setLoggerName("item");
+							_logEnchant.log(record);
+						}
 					}
 					else 
 					{
@@ -215,6 +242,14 @@ public final class RequestEnchantItem extends AbstractEnchantPacket
 							Util.handleIllegalPlayerAction(activeChar, "Unable to delete item on enchant failure from player " + activeChar.getName() + ", possible cheater !", Config.DEFAULT_PUNISH);
 							activeChar.setActiveEnchantItem(null);
 							activeChar.sendPacket(new EnchantResult(2, 0, 0));
+
+							if (Config.LOG_ITEM_ENCHANTS)
+							{
+								LogRecord record = new LogRecord(Level.INFO, "Unable to destroy");
+								record.setParameters(new Object[]{activeChar, item, scroll, support, chance});
+								record.setLoggerName("item");
+								_logEnchant.log(record);
+							}
 							return;
 						}
 
@@ -250,6 +285,14 @@ public final class RequestEnchantItem extends AbstractEnchantPacket
 							activeChar.sendPacket(new EnchantResult(4, 0, 0));
 						else
 							activeChar.sendPacket(new EnchantResult(1, crystalId, count));
+
+						if (Config.LOG_ITEM_ENCHANTS)
+						{
+							LogRecord record = new LogRecord(Level.INFO, "Fail");
+							record.setParameters(new Object[]{activeChar, item, scroll, support, chance});
+							record.setLoggerName("item");
+							_logEnchant.log(record);
+						}
 					}
 				}
 			}

+ 20 - 1
L2_GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestExEnchantSkill.java

@@ -14,6 +14,8 @@
  */
 package net.sf.l2j.gameserver.network.clientpackets;
 
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
 import java.util.logging.Logger;
 
 import net.sf.l2j.Config;
@@ -47,7 +49,8 @@ import net.sf.l2j.util.Rnd;
 public final class RequestExEnchantSkill extends L2GameClientPacket
 {
     private static final String _C__D0_07_REQUESTEXENCHANTSKILL = "[C] D0:07 RequestExEnchantSkill";
-    private static Logger _log = Logger.getLogger(RequestAquireSkill.class.getName());
+    private static final Logger _log = Logger.getLogger(RequestAquireSkill.class.getName());
+	private static final Logger _logEnchant = Logger.getLogger("enchant");
     
     private int _skillId;
     private int _skillLvl;
@@ -149,6 +152,13 @@ public final class RequestExEnchantSkill extends L2GameClientPacket
                 // ok.  Destroy ONE copy of the book
                 if (Rnd.get(100) <= rate)
                 {
+                	if (Config.LOG_SKILL_ENCHANTS)
+                	{
+                        LogRecord record = new LogRecord(Level.INFO, "Success");
+        				record.setParameters(new Object[]{player, skill, spb, rate});
+        				record.setLoggerName("skill");
+        				_logEnchant.log(record);
+                	}
                     
                     player.addSkill(skill, true);
                     
@@ -163,12 +173,21 @@ public final class RequestExEnchantSkill extends L2GameClientPacket
                     SystemMessage sm = new SystemMessage(SystemMessageId.YOU_HAVE_SUCCEEDED_IN_ENCHANTING_THE_SKILL_S1);
                     sm.addSkillName(_skillId);
                     player.sendPacket(sm);
+
                 }
                 else
                 {
                     player.addSkill(SkillTable.getInstance().getInfo(_skillId, s.getBaseLevel()), true);
                     player.sendSkillList(); 
                     player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_FAILED_TO_ENCHANT_THE_SKILL_S1));
+
+                    if (Config.LOG_SKILL_ENCHANTS)
+                    {
+                        LogRecord record = new LogRecord(Level.INFO, "Fail");
+        				record.setParameters(new Object[]{player, skill, spb, rate});
+        				record.setLoggerName("skill");
+        				_logEnchant.log(record);
+                    }
                 }
                 ((L2NpcInstance)trainer).showEnchantSkillList(player, false);
                 

+ 13 - 1
L2_GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestExEnchantSkillRouteChange.java

@@ -14,6 +14,8 @@
  */
 package net.sf.l2j.gameserver.network.clientpackets;
 
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
 import java.util.logging.Logger;
 
 import net.sf.l2j.Config;
@@ -47,6 +49,8 @@ import net.sf.l2j.util.Rnd;
 public final class RequestExEnchantSkillRouteChange extends L2GameClientPacket
 {
     protected static final Logger _log = Logger.getLogger(RequestExEnchantSkillRouteChange.class.getName());
+	private static final Logger _logEnchant = Logger.getLogger("enchant");
+
 	private int _skillId;
 	private int _skillLvl;
 	
@@ -163,7 +167,15 @@ public final class RequestExEnchantSkillRouteChange extends L2GameClientPacket
                 
                 if (skill != null)
                 {
-                    player.addSkill(skill, true);
+                	if (Config.LOG_SKILL_ENCHANTS)
+                	{
+                        LogRecord record = new LogRecord(Level.INFO, "Route Change");
+        				record.setParameters(new Object[]{player, skill, spb});
+        				record.setLoggerName("skill");
+        				_logEnchant.log(record);
+                	}
+
+    				player.addSkill(skill, true);
                 }
                 
                 if (Config.DEBUG)

+ 21 - 2
L2_GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestExEnchantSkillSafe.java

@@ -14,6 +14,8 @@
  */
 package net.sf.l2j.gameserver.network.clientpackets;
 
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
 import java.util.logging.Logger;
 
 import net.sf.l2j.Config;
@@ -46,7 +48,9 @@ import net.sf.l2j.util.Rnd;
  */
 public final class RequestExEnchantSkillSafe extends L2GameClientPacket
 {
-    protected static final Logger _log = Logger.getLogger(RequestExEnchantSkillSafe.class.getName());
+    private static final Logger _log = Logger.getLogger(RequestExEnchantSkillSafe.class.getName());
+	private static final Logger _logEnchant = Logger.getLogger("enchant");
+
 	private int _skillId;
 	private int _skillLvl;
 	
@@ -140,6 +144,13 @@ public final class RequestExEnchantSkillSafe extends L2GameClientPacket
                 // ok.  Destroy ONE copy of the book
                 if (Rnd.get(100) <= rate)
                 {
+                	if (Config.LOG_SKILL_ENCHANTS)
+                	{
+                        LogRecord record = new LogRecord(Level.INFO, "Safe Success");
+        				record.setParameters(new Object[]{player, skill, spb, rate});
+        				record.setLoggerName("skill");
+        				_logEnchant.log(record);
+                	}
                     
                     player.addSkill(skill, true);
                     
@@ -157,7 +168,15 @@ public final class RequestExEnchantSkillSafe extends L2GameClientPacket
                 }
                 else
                 {
-                    SystemMessage sm = new SystemMessage(SystemMessageId.SKILL_ENCHANT_FAILED_S1_LEVEL_WILL_REMAIN);
+                	if (Config.LOG_SKILL_ENCHANTS)
+                	{
+                        LogRecord record = new LogRecord(Level.INFO, "Safe Fail");
+        				record.setParameters(new Object[]{player, skill, spb, rate});
+        				record.setLoggerName("skill");
+        				_logEnchant.log(record);
+                	}
+
+                	SystemMessage sm = new SystemMessage(SystemMessageId.SKILL_ENCHANT_FAILED_S1_LEVEL_WILL_REMAIN);
                     sm.addSkillName(_skillId);
                     player.sendPacket(sm);
                 }

+ 14 - 2
L2_GameServer/java/net/sf/l2j/gameserver/network/clientpackets/RequestExEnchantSkillUntrain.java

@@ -14,6 +14,8 @@
  */
 package net.sf.l2j.gameserver.network.clientpackets;
 
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
 import java.util.logging.Logger;
 
 import net.sf.l2j.Config;
@@ -44,7 +46,9 @@ import net.sf.l2j.gameserver.network.serverpackets.UserInfo;
  */
 public final class RequestExEnchantSkillUntrain extends L2GameClientPacket
 {
-	protected static final Logger _log = Logger.getLogger(RequestExEnchantSkillUntrain.class.getName());
+	private static final Logger _log = Logger.getLogger(RequestExEnchantSkillUntrain.class.getName());
+	private static final Logger _logEnchant = Logger.getLogger("enchant");
+
 	private int _skillId;
 	private int _skillLvl;
 	
@@ -124,7 +128,15 @@ public final class RequestExEnchantSkillUntrain extends L2GameClientPacket
 		{
 			_skillLvl = s.getBaseLevel();
 		}
-		
+
+		if (Config.LOG_SKILL_ENCHANTS)
+		{
+	        LogRecord record = new LogRecord(Level.INFO, "Untrain");
+			record.setParameters(new Object[]{player, skill, spb});
+			record.setLoggerName("skill");
+			_logEnchant.log(record);
+		}
+
 		player.addSkill(skill, true);
 		
 		if (Config.DEBUG)

+ 80 - 0
L2_GameServer/java/net/sf/l2j/log/EnchantFormatter.java

@@ -0,0 +1,80 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.log;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.logging.Formatter;
+import java.util.logging.LogRecord;
+
+import net.sf.l2j.gameserver.model.L2ItemInstance;
+import net.sf.l2j.gameserver.model.L2Skill;
+import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+import net.sf.l2j.gameserver.util.StringUtil;
+
+public class EnchantFormatter extends Formatter
+{
+	private static final String CRLF = "\r\n";
+	private SimpleDateFormat dateFmt = new SimpleDateFormat("dd MMM H:mm:ss");
+	
+	@Override
+	public String format(LogRecord record)
+	{
+		final Object[] params = record.getParameters();
+		final StringBuilder output = StringUtil.startAppend(30
+		        + record.getMessage().length()
+		        + (params == null ? 0 : params.length * 10), "[", dateFmt.format(new Date(record.getMillis())), "] ", record.getMessage());
+		for (Object p : params)
+		{
+			if (p == null)
+				continue;
+
+			StringUtil.append(output, ", ");
+
+			if (p instanceof L2PcInstance)
+			{
+				L2PcInstance player = (L2PcInstance)p;
+				StringUtil.append(output, "Character:", player.getName(),
+						" ["+String.valueOf(player.getObjectId())+"] Account:",
+						player.getAccountName());
+				if (player.getClient() != null && !player.getClient().isDetached())
+					StringUtil.append(output, " IP:", player.getClient().getConnection().getInetAddress().getHostAddress());
+			}
+			else if (p instanceof L2ItemInstance)
+			{
+				L2ItemInstance item = (L2ItemInstance)p;
+				if (item.getEnchantLevel() > 0)
+				{
+					StringUtil.append(output, "+", String.valueOf(item.getEnchantLevel()), " ");
+				}
+				StringUtil.append(output, item.getItem().getName(), "(", String.valueOf(item.getCount()), ")");
+				StringUtil.append(output, " [", String.valueOf(item.getObjectId()), "]");
+			}
+			else if (p instanceof L2Skill)
+			{
+				L2Skill skill = (L2Skill)p;
+				if (skill.getLevel() > 100)
+				{
+					StringUtil.append(output, "+", String.valueOf(skill.getLevel() % 100), " ");
+				}
+				StringUtil.append(output, skill.getName(), "(", String.valueOf(skill.getId())," ", String.valueOf(skill.getLevel()), ")");
+			}
+			else
+				StringUtil.append(output, p.toString());
+		}
+		output.append(CRLF);
+		return output.toString();
+	}
+}

+ 26 - 0
L2_GameServer/java/net/sf/l2j/log/EnchantItemFilter.java

@@ -0,0 +1,26 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.log;
+
+import java.util.logging.Filter;
+import java.util.logging.LogRecord;
+
+public class EnchantItemFilter implements Filter
+{
+	public boolean isLoggable(LogRecord record)
+	{
+		return record.getLoggerName().equalsIgnoreCase("item");
+	}
+}

+ 26 - 0
L2_GameServer/java/net/sf/l2j/log/EnchantItemLogHandler.java

@@ -0,0 +1,26 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.log;
+
+import java.io.IOException;
+import java.util.logging.FileHandler;
+
+public class EnchantItemLogHandler extends FileHandler
+{
+	public EnchantItemLogHandler() throws IOException, SecurityException
+	{
+		super();
+	}
+}

+ 26 - 0
L2_GameServer/java/net/sf/l2j/log/EnchantSkillFilter.java

@@ -0,0 +1,26 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.log;
+
+import java.util.logging.Filter;
+import java.util.logging.LogRecord;
+
+public class EnchantSkillFilter implements Filter
+{
+	public boolean isLoggable(LogRecord record)
+	{
+		return record.getLoggerName().equalsIgnoreCase("skill");
+	}
+}

+ 26 - 0
L2_GameServer/java/net/sf/l2j/log/EnchantSkillLogHandler.java

@@ -0,0 +1,26 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package net.sf.l2j.log;
+
+import java.io.IOException;
+import java.util.logging.FileHandler;
+
+public class EnchantSkillLogHandler extends FileHandler
+{
+	public EnchantSkillLogHandler() throws IOException, SecurityException
+	{
+		super();
+	}
+}