2
0
Эх сурвалжийг харах

Damage log handler. Please not forget to update DP and log.cfg.

_DS_ 15 жил өмнө
parent
commit
c76b8f624d

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

@@ -100,6 +100,9 @@ GMAudit = False
 # Default: False
 LogGameDamage = False
 
+# If damage greater than threshold then log it
+# Default: 5000
+LogGameDamageThreshold = 5000
 
 # ---------------------------------------------------------------------------
 # Thread Configuration

+ 21 - 0
L2_GameServer/java/log.cfg

@@ -25,6 +25,9 @@ enchant.handlers = net.sf.l2j.log.EnchantItemLogHandler,\
 enchant.useParentHandlers = false
 olympiad.handlers = net.sf.l2j.log.OlympiadLogHandler
 olympiad.useParentHandlers = false
+damage.handlers = net.sf.l2j.log.AllDamageLogHandler,\
+           net.sf.l2j.log.PDamageLogHandler, net.sf.l2j.log.MDamageLogHandler
+damage.useParentHandlers = false
 
 # Default global logging level.
 # This specifies which kinds of events are logged across
@@ -105,6 +108,24 @@ net.sf.l2j.log.OlympiadLogHandler.formatter = net.sf.l2j.log.OlympiadFormatter
 net.sf.l2j.log.OlympiadLogHandler.append = true
 net.sf.l2j.log.OlympiadLogHandler.level = INFO
 
+# damage logs
+net.sf.l2j.log.AllDamageLogHandler.pattern = log/game/_all.txt
+net.sf.l2j.log.AllDamageLogHandler.formatter = net.sf.l2j.log.DamageFormatter
+net.sf.l2j.log.AllDamageLogHandler.append = true
+net.sf.l2j.log.AllDamageLogHandler.level = INFO
+
+net.sf.l2j.log.PDamageLogHandler.pattern = log/game/damage_pdam.txt
+net.sf.l2j.log.PDamageLogHandler.formatter = net.sf.l2j.log.DamageFormatter
+net.sf.l2j.log.PDamageLogHandler.filter = net.sf.l2j.log.PDamageFilter
+net.sf.l2j.log.PDamageLogHandler.append = true
+net.sf.l2j.log.PDamageLogHandler.level = INFO
+
+net.sf.l2j.log.MDamageLogHandler.pattern = log/game/damage_mdam.txt
+net.sf.l2j.log.MDamageLogHandler.formatter = net.sf.l2j.log.DamageFormatter
+net.sf.l2j.log.MDamageLogHandler.filter = net.sf.l2j.log.MDamageFilter
+net.sf.l2j.log.MDamageLogHandler.append = true
+net.sf.l2j.log.MDamageLogHandler.level = INFO
+
 ############################################################
 # Facility specific properties.
 # Provides extra control for each logger.

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

@@ -350,6 +350,7 @@ public final class Config
 	public static boolean LOG_SKILL_ENCHANTS;
 	public static boolean GMAUDIT;
 	public static boolean LOG_GAME_DAMAGE;
+	public static int LOG_GAME_DAMAGE_THRESHOLD;
 	public static boolean DEBUG;
 	public static boolean PACKET_HANDLER_DEBUG;
 	public static boolean ASSERT;
@@ -1395,6 +1396,7 @@ public final class Config
 					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"));
+					LOG_GAME_DAMAGE_THRESHOLD = Integer.parseInt(General.getProperty("LogGameDamageThreshold", "5000"));
 					DEBUG = Boolean.parseBoolean(General.getProperty("Debug", "false"));
 					PACKET_HANDLER_DEBUG = Boolean.parseBoolean(General.getProperty("PacketHandlerDebug", "false"));
 					ASSERT = Boolean.parseBoolean(General.getProperty("Assert", "false"));

+ 2 - 0
L2_GameServer/java/net/sf/l2j/gameserver/GameServer.java

@@ -198,6 +198,8 @@ public class GameServer
 		_threadpools = ThreadPoolManager.getInstance();
 		
 		new File(Config.DATAPACK_ROOT, "data/crests").mkdirs();
+		if (Config.LOG_GAME_DAMAGE)
+			new File("log/game").mkdirs();
 		
 		// load script engines
 		L2ScriptEngineManager.getInstance();

+ 26 - 0
L2_GameServer/java/net/sf/l2j/log/AllDamageLogHandler.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 AllDamageLogHandler extends FileHandler
+{
+	public AllDamageLogHandler() throws IOException, SecurityException
+	{
+		super();
+	}
+}

+ 77 - 0
L2_GameServer/java/net/sf/l2j/log/DamageFormatter.java

@@ -0,0 +1,77 @@
+/*
+ * 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.L2Skill;
+import net.sf.l2j.gameserver.model.actor.L2Attackable;
+import net.sf.l2j.gameserver.model.actor.L2Character;
+import net.sf.l2j.gameserver.model.actor.L2Summon;
+import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
+import net.sf.l2j.gameserver.util.StringUtil;
+
+public class DamageFormatter extends Formatter
+{
+	private static final String CRLF = "\r\n";
+	private SimpleDateFormat dateFmt = new SimpleDateFormat("yy.MM.dd 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;
+
+			if (p instanceof L2Character)
+			{
+				if (p instanceof L2Attackable && ((L2Attackable)p).isRaid())
+					StringUtil.append(output, "RaidBoss ");
+
+				StringUtil.append(output, ((L2Character)p).getName(),
+						"(", String.valueOf(((L2Character)p).getObjectId()), ") ");
+				StringUtil.append(output, String.valueOf(((L2Character)p).getLevel()),
+				" lvl");
+
+				if (p instanceof L2Summon)
+				{
+					L2PcInstance owner = ((L2Summon)p).getOwner();
+					if (owner != null)
+						StringUtil.append(output, " Owner:", owner.getName(),
+							"(", String.valueOf(owner.getObjectId()), ")");
+				}
+			}
+			else if (p instanceof L2Skill)
+			{
+				StringUtil.append(output, " with skill ",((L2Skill)p).getName(),
+						"(", String.valueOf(((L2Skill)p).getId()), ")");
+			}
+			else
+				StringUtil.append(output, p.toString());
+		}
+		output.append(CRLF);
+		return output.toString();
+	}
+}

+ 26 - 0
L2_GameServer/java/net/sf/l2j/log/MDamageFilter.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 MDamageFilter implements Filter
+{
+	public boolean isLoggable(LogRecord record)
+	{
+		return record.getLoggerName().equalsIgnoreCase("mdam");
+	}
+}

+ 26 - 0
L2_GameServer/java/net/sf/l2j/log/MDamageLogHandler.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 MDamageLogHandler extends FileHandler
+{
+	public MDamageLogHandler() throws IOException, SecurityException
+	{
+		super();
+	}
+}

+ 26 - 0
L2_GameServer/java/net/sf/l2j/log/PDamageFilter.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 PDamageFilter implements Filter
+{
+	public boolean isLoggable(LogRecord record)
+	{
+		return record.getLoggerName().equalsIgnoreCase("pdam");
+	}
+}

+ 26 - 0
L2_GameServer/java/net/sf/l2j/log/PDamageLogHandler.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 PDamageLogHandler extends FileHandler
+{
+	public PDamageLogHandler() throws IOException, SecurityException
+	{
+		super();
+	}
+}