Migrate yet another batch of FilePrinter users to Slf4j

One FilePrinter.printError() method removed, one more to go
This commit is contained in:
P0nk
2022-02-09 21:05:22 +01:00
parent 0c60606b4e
commit 8b630f7357
12 changed files with 84 additions and 149 deletions

View File

@@ -7551,7 +7551,7 @@ public class Character extends AbstractCharacterObject {
} }
} }
} catch (Exception e) { } catch (Exception e) {
FilePrinter.printError(FilePrinter.EXCEPTION_CAUGHT, e, "Character.mobKilled. CID: " + this.id + " last Quest Processed: " + lastQuestProcessed); log.warn("Character.mobKilled. chrId {}, last quest processed: {}", this.id, lastQuestProcessed, e);
} }
} }
@@ -8332,7 +8332,7 @@ public class Character extends AbstractCharacterObject {
con.setAutoCommit(true); con.setAutoCommit(true);
} }
} catch (Throwable t) { } catch (Throwable t) {
FilePrinter.printError(FilePrinter.INSERT_CHAR, t, "Error creating " + name + " Level: " + level + " Job: " + job.getId()); log.error("Error creating chr {}, level: {}, job: {}", name, level, job.getId(), t);
} }
return false; return false;
@@ -8754,7 +8754,7 @@ public class Character extends AbstractCharacterObject {
con.setAutoCommit(true); con.setAutoCommit(true);
} }
} catch (Exception e) { } catch (Exception e) {
FilePrinter.printError(FilePrinter.SAVE_CHAR, e, "Error saving " + name + " Level: " + level + " Job: " + job.getId()); log.error("Error saving chr {}, level: {}, job: {}", name, level, job.getId(), e);
} }
} }
@@ -10691,8 +10691,7 @@ public class Character extends AbstractCharacterObject {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); log.error("Failed to register name change for chr {}", getName(), e);
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e, "Failed to register name change for character " + getName() + ".");
return false; return false;
} }
@@ -10704,12 +10703,10 @@ public class Character extends AbstractCharacterObject {
this.pendingNameChange = true; this.pendingNameChange = true;
return true; return true;
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); log.error("Failed to register name change for chr {}", getName(), e);
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e, "Failed to register name change for character " + getName() + ".");
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); log.error("Failed to get DB connection while registering name change", e);
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e, "Failed to get DB connection.");
} }
return false; return false;
} }
@@ -10724,8 +10721,7 @@ public class Character extends AbstractCharacterObject {
} }
return affectedRows > 0; //rows affected return affectedRows > 0; //rows affected
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); log.error("Failed to cancel name change for chr {}", getName(), e);
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e, "Failed to cancel name change for character " + getName() + ".");
return false; return false;
} }
} }
@@ -11009,8 +11005,7 @@ public class Character extends AbstractCharacterObject {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); log.error("Failed to register world transfer for chr {}", getName(), e);
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Failed to register world transfer for character " + getName() + ".");
return false; return false;
} }
@@ -11021,12 +11016,10 @@ public class Character extends AbstractCharacterObject {
ps.executeUpdate(); ps.executeUpdate();
return true; return true;
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); log.error("Failed to register world transfer for chr {}", getName(), e);
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Failed to register world transfer for character " + getName() + ".");
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); log.error("Failed to get DB connection while registering world transfer", e);
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Failed to get DB connection.");
} }
return false; return false;
} }
@@ -11038,8 +11031,7 @@ public class Character extends AbstractCharacterObject {
int affectedRows = ps.executeUpdate(); int affectedRows = ps.executeUpdate();
return affectedRows > 0; //rows affected return affectedRows > 0; //rows affected
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); log.error("Failed to cancel pending world transfer for chr {}", getName(), e);
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Failed to cancel pending world transfer for character " + getName() + ".");
return false; return false;
} }
} }
@@ -11050,13 +11042,12 @@ public class Character extends AbstractCharacterObject {
ps.setInt(1, characterId); ps.setInt(1, characterId);
ResultSet rs = ps.executeQuery(); ResultSet rs = ps.executeQuery();
if (!rs.next()) { if (!rs.next()) {
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, "Character data invalid? (charid " + characterId + ")"); log.warn("Character data invalid for world transfer? chrId {}", characterId);
return false; return false;
} }
mesos = rs.getInt("meso"); mesos = rs.getInt("meso");
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); log.error("Failed to do world transfer for chrId {}", characterId, e);
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Character ID : " + characterId);
return false; return false;
} }
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET world = ?, meso = ?, guildid = ?, guildrank = ? WHERE id = ?")) { try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET world = ?, meso = ?, guildid = ?, guildrank = ? WHERE id = ?")) {
@@ -11067,8 +11058,7 @@ public class Character extends AbstractCharacterObject {
ps.setInt(5, characterId); ps.setInt(5, characterId);
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); log.error("Failed to update chrId {} during world transfer", characterId, e);
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Character ID : " + characterId);
return false; return false;
} }
try (PreparedStatement ps = con.prepareStatement("DELETE FROM buddies WHERE characterid = ? OR buddyid = ?")) { try (PreparedStatement ps = con.prepareStatement("DELETE FROM buddies WHERE characterid = ? OR buddyid = ?")) {
@@ -11076,8 +11066,7 @@ public class Character extends AbstractCharacterObject {
ps.setInt(2, characterId); ps.setInt(2, characterId);
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); log.error("Failed to delete buddies for chrId {} during world transfer", characterId, e);
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Character ID : " + characterId);
return false; return false;
} }
if (worldTransferId != -1) { if (worldTransferId != -1) {
@@ -11086,8 +11075,7 @@ public class Character extends AbstractCharacterObject {
ps.setInt(2, worldTransferId); ps.setInt(2, worldTransferId);
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); log.error("Failed to update world transfer for chrId {}", characterId, e);
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Character ID : " + characterId);
return false; return false;
} }
} }

View File

@@ -24,8 +24,9 @@ package client;
import net.packet.Packet; import net.packet.Packet;
import net.server.Server; import net.server.Server;
import net.server.world.World; import net.server.world.World;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.DatabaseConnection; import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.PacketCreator; import tools.PacketCreator;
import tools.Pair; import tools.Pair;
@@ -34,7 +35,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@@ -45,7 +45,7 @@ import java.util.concurrent.atomic.AtomicInteger;
* @author Ubaware * @author Ubaware
*/ */
public class Family { public class Family {
private static final Logger log = LoggerFactory.getLogger(Family.class);
private static final AtomicInteger familyIDCounter = new AtomicInteger(); private static final AtomicInteger familyIDCounter = new AtomicInteger();
private final int id, world; private final int id, world;
@@ -121,8 +121,7 @@ public class Family {
ps.setInt(2, getLeader().getChrId()); ps.setInt(2, getLeader().getChrId());
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not save new precepts for family " + getID() + "."); log.error("Could not save new precepts for family {}", getID(), e);
e.printStackTrace();
} }
} }
} }
@@ -209,11 +208,11 @@ public class Family {
level = rs.getInt("level"); level = rs.getInt("level");
jobID = rs.getInt("job"); jobID = rs.getInt("job");
} else { } else {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Could not load character information of " + cid + " in loadAllFamilies(). (RECORD DOES NOT EXIST)"); log.error("Could not load character information of chrId {} in loadAllFamilies(). (RECORD DOES NOT EXIST)", cid);
continue; continue;
} }
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not load character information of " + cid + " in loadAllFamilies(). (SQL ERROR)"); log.error("Could not load character information of chrId {} in loadAllFamilies(). (SQL ERROR)", cid, e);
continue; continue;
} }
int familyid = rsEntries.getInt("familyid"); int familyid = rsEntries.getInt("familyid");
@@ -261,8 +260,7 @@ public class Family {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get family_character entries."); log.error("Could not get family_character entries", e);
e.printStackTrace();
} }
// link missing ones (out of order) // link missing ones (out of order)
for (Pair<Pair<Integer, Integer>, FamilyEntry> unmatchedJunior : unmatchedJuniors) { for (Pair<Pair<Integer, Integer>, FamilyEntry> unmatchedJunior : unmatchedJuniors) {
@@ -273,7 +271,7 @@ public class Family {
if (senior != null) { if (senior != null) {
junior.setSenior(senior, false); junior.setSenior(senior, false);
} else { } else {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Missing senior for character " + junior.getName() + " in world " + world); log.error("Missing senior for chr {} in world {}", junior.getName(), world);
} }
} }
@@ -296,7 +294,7 @@ public class Family {
} }
if (!success) { if (!success) {
con.rollback(); con.rollback();
FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Family rep autosave failed for family " + getID() + " on " + Calendar.getInstance().getTime() + "."); log.error("Family rep autosave failed for family {}", getID());
} }
con.setAutoCommit(true); con.setAutoCommit(true);
//reset repChanged after successful save //reset repChanged after successful save
@@ -304,8 +302,7 @@ public class Family {
entry.savedSuccessfully(); entry.savedSuccessfully();
} }
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB."); log.error("Could not get connection to DB while saving all members rep", e);
e.printStackTrace();
} }
} }
} }

View File

@@ -21,8 +21,9 @@ package client;
import net.packet.Packet; import net.packet.Packet;
import net.server.Server; import net.server.Server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.DatabaseConnection; import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.PacketCreator; import tools.PacketCreator;
import tools.Pair; import tools.Pair;
@@ -38,6 +39,8 @@ import java.util.List;
*/ */
public class FamilyEntry { public class FamilyEntry {
private static final Logger log = LoggerFactory.getLogger(FamilyEntry.class);
private final int characterID; private final int characterID;
private volatile Family family; private volatile Family family;
private volatile Character character; private volatile Character character;
@@ -114,12 +117,11 @@ public class FamilyEntry {
} }
if (!success) { if (!success) {
con.rollback(); con.rollback();
FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Could not absorb " + oldFamily.getName() + " family into " + newFamily.getName() + " family. (SQL ERROR)"); log.error("Could not absorb {}'s family into {}'s family. (SQL ERROR)", oldFamily.getName(), newFamily.getName());
} }
con.setAutoCommit(true); con.setAutoCommit(true);
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB."); log.error("Could not get connection to DB when joining families", e);
e.printStackTrace();
} }
} }
@@ -159,13 +161,12 @@ public class FamilyEntry {
} }
if (!success) { if (!success) {
con.rollback(); con.rollback();
FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Could not fork family with new leader " + getName() + ". (Old senior : " + oldSenior.getName() + ", leader :" + oldFamily.getLeader().getName() + ")"); log.error("Could not fork family with new leader {}. (Old senior: {}, leader: {})", getName(), oldSenior.getName(), oldFamily.getLeader().getName());
} }
con.setAutoCommit(true); con.setAutoCommit(true);
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB."); log.error("Could not get connection to DB when forking families", e);
e.printStackTrace();
} }
} }
@@ -193,8 +194,7 @@ public class FamilyEntry {
ps.setInt(2, cid); ps.setInt(2, cid);
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not update family id in 'family_character' for character id " + cid + ". (fork)"); log.error("Could not update family id in 'family_character' for chrId {}. (fork)", cid, e);
e.printStackTrace();
return false; return false;
} }
return true; return true;
@@ -375,8 +375,7 @@ public class FamilyEntry {
try (Connection con = DatabaseConnection.getConnection()) { try (Connection con = DatabaseConnection.getConnection()) {
return updateDBChangeFamily(con, cid, familyid, seniorid); return updateDBChangeFamily(con, cid, familyid, seniorid);
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB."); log.error("Could not get connection to DB while changing family", e);
e.printStackTrace();
return false; return false;
} }
} }
@@ -388,8 +387,7 @@ public class FamilyEntry {
ps.setInt(3, cid); ps.setInt(3, cid);
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not update seniorid in 'family_character' for character id " + cid + "."); log.error("Could not update seniorId in 'family_character' for chrId {}", cid, e);
e.printStackTrace();
return false; return false;
} }
return updateCharacterFamilyDB(con, cid, familyid, false); return updateCharacterFamilyDB(con, cid, familyid, false);
@@ -401,8 +399,7 @@ public class FamilyEntry {
ps.setInt(2, charid); ps.setInt(2, charid);
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not update familyid in 'characters' for character id " + charid + " when changing family. " + (fork ? "(fork)" : "")); log.error("Could not update familyId in 'characters' for chrId {} when changing family. {}", charid, fork ? "(fork)" : "", e);
e.printStackTrace();
return false; return false;
} }
return true; return true;
@@ -549,8 +546,7 @@ public class FamilyEntry {
ps.setLong(3, System.currentTimeMillis()); ps.setLong(3, System.currentTimeMillis());
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not insert new row in 'family_entitlement' for character " + getName() + "."); log.error("Could not insert new row in 'family_entitlement' for chr {}", getName(), e);
e.printStackTrace();
} }
entitlements[id]++; entitlements[id]++;
return true; return true;
@@ -563,8 +559,7 @@ public class FamilyEntry {
ps.setInt(2, getChrId()); ps.setInt(2, getChrId());
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not refund family entitlement \"" + entitlement.getName() + "\" for character " + getName() + "."); log.error("Could not refund family entitlement \"{}\" for chr {}", entitlement.getName(), getName(), e);
e.printStackTrace();
} }
entitlements[id] = 0; entitlements[id] = 0;
return true; return true;
@@ -595,8 +590,7 @@ public class FamilyEntry {
try (Connection con = DatabaseConnection.getConnection()) { try (Connection con = DatabaseConnection.getConnection()) {
return saveReputation(con); return saveReputation(con);
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB."); log.error("Could not get connection to DB while saving reputation", e);
e.printStackTrace();
return false; return false;
} }
} }
@@ -613,8 +607,7 @@ public class FamilyEntry {
ps.setInt(5, getChrId()); ps.setInt(5, getChrId());
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Failed to autosave rep to 'family_character' for charid " + getChrId()); log.error("Failed to autosave rep to 'family_character' for chrId {}", getChrId(), e);
e.printStackTrace();
return false; return false;
} }
return true; return true;

View File

@@ -31,7 +31,8 @@ import net.PacketHandler;
import net.PacketProcessor; import net.PacketProcessor;
import net.packet.ByteBufInPacket; import net.packet.ByteBufInPacket;
import net.packet.InPacket; import net.packet.InPacket;
import tools.FilePrinter; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.HexTool; import tools.HexTool;
import java.io.FileReader; import java.io.FileReader;
@@ -44,6 +45,8 @@ public class PeCommand extends Command {
setDescription("Handle synthesized packets from file, and handle them as if sent from a client"); setDescription("Handle synthesized packets from file, and handle them as if sent from a client");
} }
private static final Logger log = LoggerFactory.getLogger(PeCommand.class);
@Override @Override
public void execute(Client c, String[] params) { public void execute(Client c, String[] params) {
Character player = c.getPlayer(); Character player = c.getPlayer();
@@ -70,7 +73,9 @@ public class PeCommand extends Command {
player.yellowMessage("Receiving: " + packet); player.yellowMessage("Receiving: " + packet);
packetHandler.handlePacket(inPacket, c); packetHandler.handlePacket(inPacket, c);
} catch (final Throwable t) { } catch (final Throwable t) {
FilePrinter.printError(FilePrinter.PACKET_HANDLER + packetHandler.getClass().getName() + ".txt", t, "Error for " + (c.getPlayer() == null ? "" : "player ; " + c.getPlayer() + " on map ; " + c.getPlayer().getMapId() + " - ") + "account ; " + c.getAccountName() + "\r\n" + inPacket); final String chrInfo = player != null ? player.getName() + " on map " + player.getMapId() : "?";
log.warn("Error in packet handler {}. Chr {}, account {}. Packet: {}", packetHandler.getClass().getSimpleName(),
chrInfo, c.getAccountName(), packet, t);
} }
} }
} }

View File

@@ -63,7 +63,6 @@ import server.expeditions.ExpeditionBossLog;
import server.life.PlayerNPCFactory; import server.life.PlayerNPCFactory;
import server.quest.Quest; import server.quest.Quest;
import tools.DatabaseConnection; import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.Pair; import tools.Pair;
import java.sql.Connection; import java.sql.Connection;
@@ -1106,7 +1105,7 @@ public class Server {
mc.setMGC(mgc); mc.setMGC(mgc);
mgc.setCharacter(mc); mgc.setCharacter(mc);
} else { } else {
FilePrinter.printError(FilePrinter.GUILD_CHAR_ERROR, "Could not find " + mc.getName() + " when loading guild " + id + "."); log.error("Could not find chr {} when loading guild {}", mc.getName(), id);
} }
g.setOnline(mc.getId(), true, mc.getClient().getChannel()); g.setOnline(mc.getId(), true, mc.getClient().getChannel());
@@ -1622,8 +1621,7 @@ public class Server {
delPs.setInt(1, nameChangeId); delPs.setInt(1, nameChangeId);
delPs.executeUpdate(); delPs.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); log.error("Failed to delete world transfer for chrId {}", characterId, e);
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Failed to delete world transfer for character ID " + characterId);
} }
} }
} }

View File

@@ -32,8 +32,9 @@ import net.server.coordinator.world.InviteCoordinator;
import net.server.coordinator.world.InviteCoordinator.InviteResult; import net.server.coordinator.world.InviteCoordinator.InviteResult;
import net.server.coordinator.world.InviteCoordinator.InviteResultType; import net.server.coordinator.world.InviteCoordinator.InviteResultType;
import net.server.coordinator.world.InviteCoordinator.InviteType; import net.server.coordinator.world.InviteCoordinator.InviteType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.DatabaseConnection; import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.PacketCreator; import tools.PacketCreator;
import java.sql.Connection; import java.sql.Connection;
@@ -45,9 +46,10 @@ import java.sql.SQLException;
* @author Ubaware * @author Ubaware
*/ */
public final class AcceptFamilyHandler extends AbstractPacketHandler { public final class AcceptFamilyHandler extends AbstractPacketHandler {
private static final Logger log = LoggerFactory.getLogger(AcceptFamilyHandler.class);
@Override @Override
public final void handlePacket(InPacket p, Client c) { public void handlePacket(InPacket p, Client c) {
if (!YamlConfig.config.server.USE_FAMILY_SYSTEM) { if (!YamlConfig.config.server.USE_FAMILY_SYSTEM) {
return; return;
} }
@@ -134,8 +136,7 @@ public final class AcceptFamilyHandler extends AbstractPacketHandler {
ps.setInt(3, seniorID); ps.setInt(3, seniorID);
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not save new family record for char id " + characterID + "."); log.error("Could not save new family record for chrId {}", characterID, e);
e.printStackTrace();
} }
if (updateChar) { if (updateChar) {
try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET familyid = ? WHERE id = ?")) { try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET familyid = ? WHERE id = ?")) {
@@ -143,13 +144,11 @@ public final class AcceptFamilyHandler extends AbstractPacketHandler {
ps.setInt(2, characterID); ps.setInt(2, characterID);
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not update 'characters' 'familyid' record for char id " + characterID + "."); log.error("Could not update 'characters' 'familyid' record for chrId {}", characterID, e);
e.printStackTrace();
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB."); log.error("Could not get connection to DB while inserting new family record", e);
e.printStackTrace();
} }
} }
} }

View File

@@ -35,6 +35,8 @@ import constants.id.ItemId;
import constants.inventory.ItemConstants; import constants.inventory.ItemConstants;
import net.AbstractPacketHandler; import net.AbstractPacketHandler;
import net.packet.InPacket; import net.packet.InPacket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.ItemInformationProvider; import server.ItemInformationProvider;
import server.Trade; import server.Trade;
import server.maps.*; import server.maps.*;
@@ -51,6 +53,8 @@ import java.util.Arrays;
* @author Ronan - concurrency safety and reviewed minigames * @author Ronan - concurrency safety and reviewed minigames
*/ */
public final class PlayerInteractionHandler extends AbstractPacketHandler { public final class PlayerInteractionHandler extends AbstractPacketHandler {
private static final Logger log = LoggerFactory.getLogger(PlayerInteractionHandler.class);
public enum Action { public enum Action {
CREATE(0), CREATE(0),
INVITE(2), INVITE(2),
@@ -550,7 +554,7 @@ public final class PlayerInteractionHandler extends AbstractPacketHandler {
} }
} }
} catch (Exception e) { } catch (Exception e) {
FilePrinter.printError(FilePrinter.TRADE_EXCEPTION, e, "Player '" + chr + "' tried to add " + ii.getName(item.getItemId()) + " qty. " + item.getQuantity() + " in trade (slot " + targetSlot + ") then exception occurred."); log.warn("Chr {} tried to add {}x {} in trade (slot {}), then exception occurred", chr, ii.getName(item.getItemId()), item.getQuantity(), targetSlot, e);
} finally { } finally {
inv.unlockInventory(); inv.unlockInventory();
} }

View File

@@ -2,8 +2,9 @@ package net.server.task;
import client.Family; import client.Family;
import net.server.world.World; import net.server.world.World;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.DatabaseConnection; import tools.DatabaseConnection;
import tools.FilePrinter;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@@ -11,7 +12,7 @@ import java.sql.SQLException;
import java.util.Calendar; import java.util.Calendar;
public class FamilyDailyResetTask implements Runnable { public class FamilyDailyResetTask implements Runnable {
private static final Logger log = LoggerFactory.getLogger(FamilyDailyResetTask.class);
private final World world; private final World world;
public FamilyDailyResetTask(World world) { public FamilyDailyResetTask(World world) {
@@ -38,19 +39,16 @@ public class FamilyDailyResetTask implements Runnable {
ps.setLong(1, resetTime.getTimeInMillis()); ps.setLong(1, resetTime.getTimeInMillis());
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not reset daily rep for families. On " + Calendar.getInstance().getTime()); log.error("Could not reset daily rep for families", e);
e.printStackTrace();
} }
try (PreparedStatement ps = con.prepareStatement("DELETE FROM family_entitlement WHERE timestamp <= ?")) { try (PreparedStatement ps = con.prepareStatement("DELETE FROM family_entitlement WHERE timestamp <= ?")) {
ps.setLong(1, resetTime.getTimeInMillis()); ps.setLong(1, resetTime.getTimeInMillis());
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not do daily reset for family entitlements. On " + Calendar.getInstance().getTime()); log.error("Could not do daily reset for family entitlements", e);
e.printStackTrace();
} }
} catch (SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB."); log.error("Could not get connection to DB", e);
e.printStackTrace();
} }
} }
} }

View File

@@ -24,7 +24,8 @@ package scripting;
import client.Client; import client.Client;
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine; import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
import constants.string.CharsetConstants; import constants.string.CharsetConstants;
import tools.FilePrinter; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.script.*; import javax.script.*;
import java.io.File; import java.io.File;
@@ -35,6 +36,7 @@ import java.io.IOException;
* @author Matze * @author Matze
*/ */
public abstract class AbstractScriptManager { public abstract class AbstractScriptManager {
private static final Logger log = LoggerFactory.getLogger(AbstractScriptManager.class);
private final ScriptEngineFactory sef; private final ScriptEngineFactory sef;
protected AbstractScriptManager() { protected AbstractScriptManager() {
@@ -58,7 +60,7 @@ public abstract class AbstractScriptManager {
try (FileReader fr = new FileReader(scriptFile, CharsetConstants.CHARSET)) { try (FileReader fr = new FileReader(scriptFile, CharsetConstants.CHARSET)) {
engine.eval(fr); engine.eval(fr);
} catch (final ScriptException | IOException t) { } catch (final ScriptException | IOException t) {
FilePrinter.printError(FilePrinter.INVOCABLE + path.substring(12), t, path); log.warn("Exception during script eval for file: {}", path, t);
return null; return null;
} }

View File

@@ -25,13 +25,14 @@ import client.inventory.ItemFactory;
import constants.game.GameConstants; import constants.game.GameConstants;
import net.server.audit.locks.MonitoredLockType; import net.server.audit.locks.MonitoredLockType;
import net.server.audit.locks.factory.MonitoredReentrantLockFactory; import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import provider.Data; import provider.Data;
import provider.DataProvider; import provider.DataProvider;
import provider.DataProviderFactory; import provider.DataProviderFactory;
import provider.DataTool; import provider.DataTool;
import provider.wz.WZFiles; import provider.wz.WZFiles;
import tools.DatabaseConnection; import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.PacketCreator; import tools.PacketCreator;
import tools.Pair; import tools.Pair;
@@ -46,6 +47,7 @@ import java.util.concurrent.locks.Lock;
* @author Matze * @author Matze
*/ */
public class Storage { public class Storage {
private static final Logger log = LoggerFactory.getLogger(Storage.class);
private static final Map<Integer, Integer> trunkGetCache = new HashMap<>(); private static final Map<Integer, Integer> trunkGetCache = new HashMap<>();
private static final Map<Integer, Integer> trunkPutCache = new HashMap<>(); private static final Map<Integer, Integer> trunkPutCache = new HashMap<>();
@@ -94,7 +96,7 @@ public class Storage {
return ret; return ret;
} catch (SQLException ex) { // exceptions leading to deploy null storages found thanks to Jefe } catch (SQLException ex) { // exceptions leading to deploy null storages found thanks to Jefe
FilePrinter.printError(FilePrinter.STORAGE, ex, "SQL error occurred when trying to load storage for accountid " + id + ", world " + GameConstants.WORLD_NAMES[world]); log.error("SQL error occurred when trying to load storage for accId {}, world {}", id, GameConstants.WORLD_NAMES[world], ex);
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} }

View File

@@ -23,11 +23,12 @@ package server.quest.requirements;
import client.Character; import client.Character;
import client.QuestStatus; import client.QuestStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import provider.Data; import provider.Data;
import provider.DataTool; import provider.DataTool;
import server.quest.Quest; import server.quest.Quest;
import server.quest.QuestRequirementType; import server.quest.QuestRequirementType;
import tools.FilePrinter;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -36,6 +37,7 @@ import java.util.Map;
* @author Tyler (Twdtwd) * @author Tyler (Twdtwd)
*/ */
public class MobRequirement extends AbstractQuestRequirement { public class MobRequirement extends AbstractQuestRequirement {
private static final Logger log = LoggerFactory.getLogger(MobRequirement.class);
Map<Integer, Integer> mobs = new HashMap<>(); Map<Integer, Integer> mobs = new HashMap<>();
private final int questID; private final int questID;
@@ -68,7 +70,7 @@ public class MobRequirement extends AbstractQuestRequirement {
try { try {
progress = Integer.parseInt(status.getProgress(mobID)); progress = Integer.parseInt(status.getProgress(mobID));
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
FilePrinter.printError(FilePrinter.EXCEPTION_CAUGHT, ex, "Mob: " + mobID + " Quest: " + questID + "CID: " + chr.getId() + " Progress: " + status.getProgress(mobID)); log.warn("Mob: {}, quest: {}, chrId: {}, progress: {}", mobID, questID, chr.getId(), status.getProgress(mobID), ex);
return false; return false;
} }

View File

@@ -1,6 +1,8 @@
package tools; package tools;
import java.io.*; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
@@ -71,37 +73,6 @@ public class FilePrinter {
private static final String FILE_PATH = "logs/" + sdf.format(Calendar.getInstance().getTime()) + "/"; // + sdf.format(Calendar.getInstance().getTime()) + "/" private static final String FILE_PATH = "logs/" + sdf.format(Calendar.getInstance().getTime()) + "/"; // + sdf.format(Calendar.getInstance().getTime()) + "/"
private static final String ERROR = "error/"; private static final String ERROR = "error/";
public static void printError(final String name, final Throwable t, final String info) {
String stringT = getString(t);
System.out.println("Error thrown: " + name);
System.out.println(stringT);
System.out.println();
FileOutputStream out = null;
final String file = FILE_PATH + ERROR + name;
try {
File outputFile = new File(file);
if (outputFile.getParentFile() != null) {
outputFile.getParentFile().mkdirs();
}
out = new FileOutputStream(file, true);
out.write((info + "\r\n").getBytes());
out.write(stringT.getBytes());
out.write("\r\n---------------------------------\r\n".getBytes());
out.write("\r\n".getBytes());
} catch (IOException ess) {
ess.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException ignore) {
ignore.printStackTrace();
}
}
}
public static void printError(final String name, final String s) { public static void printError(final String name, final String s) {
System.out.println("Error thrown: " + name); System.out.println("Error thrown: " + name);
System.out.println(s); System.out.println(s);
@@ -129,28 +100,4 @@ public class FilePrinter {
} }
} }
} }
private static String getString(final Throwable e) {
String retValue = null;
StringWriter sw = null;
PrintWriter pw = null;
try {
sw = new StringWriter();
pw = new PrintWriter(sw);
e.printStackTrace(pw);
retValue = sw.toString();
} finally {
try {
if (pw != null) {
pw.close();
}
if (sw != null) {
sw.close();
}
} catch (IOException ignore) {
ignore.printStackTrace();
}
}
return retValue;
}
} }