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) {
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);
}
} 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;
@@ -8754,7 +8754,7 @@ public class Character extends AbstractCharacterObject {
con.setAutoCommit(true);
}
} 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) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e, "Failed to register name change for character " + getName() + ".");
log.error("Failed to register name change for chr {}", getName(), e);
return false;
}
@@ -10704,12 +10703,10 @@ public class Character extends AbstractCharacterObject {
this.pendingNameChange = true;
return true;
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e, "Failed to register name change for character " + getName() + ".");
log.error("Failed to register name change for chr {}", getName(), e);
}
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e, "Failed to get DB connection.");
log.error("Failed to get DB connection while registering name change", e);
}
return false;
}
@@ -10724,8 +10721,7 @@ public class Character extends AbstractCharacterObject {
}
return affectedRows > 0; //rows affected
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e, "Failed to cancel name change for character " + getName() + ".");
log.error("Failed to cancel name change for chr {}", getName(), e);
return false;
}
}
@@ -11009,8 +11005,7 @@ public class Character extends AbstractCharacterObject {
}
}
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Failed to register world transfer for character " + getName() + ".");
log.error("Failed to register world transfer for chr {}", getName(), e);
return false;
}
@@ -11021,12 +11016,10 @@ public class Character extends AbstractCharacterObject {
ps.executeUpdate();
return true;
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Failed to register world transfer for character " + getName() + ".");
log.error("Failed to register world transfer for chr {}", getName(), e);
}
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Failed to get DB connection.");
log.error("Failed to get DB connection while registering world transfer", e);
}
return false;
}
@@ -11038,8 +11031,7 @@ public class Character extends AbstractCharacterObject {
int affectedRows = ps.executeUpdate();
return affectedRows > 0; //rows affected
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Failed to cancel pending world transfer for character " + getName() + ".");
log.error("Failed to cancel pending world transfer for chr {}", getName(), e);
return false;
}
}
@@ -11050,13 +11042,12 @@ public class Character extends AbstractCharacterObject {
ps.setInt(1, characterId);
ResultSet rs = ps.executeQuery();
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;
}
mesos = rs.getInt("meso");
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Character ID : " + characterId);
log.error("Failed to do world transfer for chrId {}", characterId, e);
return false;
}
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.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Character ID : " + characterId);
log.error("Failed to update chrId {} during world transfer", characterId, e);
return false;
}
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.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Character ID : " + characterId);
log.error("Failed to delete buddies for chrId {} during world transfer", characterId, e);
return false;
}
if (worldTransferId != -1) {
@@ -11086,8 +11075,7 @@ public class Character extends AbstractCharacterObject {
ps.setInt(2, worldTransferId);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Character ID : " + characterId);
log.error("Failed to update world transfer for chrId {}", characterId, e);
return false;
}
}

View File

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

View File

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

View File

@@ -31,7 +31,8 @@ import net.PacketHandler;
import net.PacketProcessor;
import net.packet.ByteBufInPacket;
import net.packet.InPacket;
import tools.FilePrinter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.HexTool;
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");
}
private static final Logger log = LoggerFactory.getLogger(PeCommand.class);
@Override
public void execute(Client c, String[] params) {
Character player = c.getPlayer();
@@ -70,7 +73,9 @@ public class PeCommand extends Command {
player.yellowMessage("Receiving: " + packet);
packetHandler.handlePacket(inPacket, c);
} 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.quest.Quest;
import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.Pair;
import java.sql.Connection;
@@ -1106,7 +1105,7 @@ public class Server {
mc.setMGC(mgc);
mgc.setCharacter(mc);
} 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());
@@ -1622,8 +1621,7 @@ public class Server {
delPs.setInt(1, nameChangeId);
delPs.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.WORLD_TRANSFER, e, "Failed to delete world transfer for character ID " + characterId);
log.error("Failed to delete world transfer for chrId {}", characterId, e);
}
}
}

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

View File

@@ -35,6 +35,8 @@ import constants.id.ItemId;
import constants.inventory.ItemConstants;
import net.AbstractPacketHandler;
import net.packet.InPacket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.ItemInformationProvider;
import server.Trade;
import server.maps.*;
@@ -51,6 +53,8 @@ import java.util.Arrays;
* @author Ronan - concurrency safety and reviewed minigames
*/
public final class PlayerInteractionHandler extends AbstractPacketHandler {
private static final Logger log = LoggerFactory.getLogger(PlayerInteractionHandler.class);
public enum Action {
CREATE(0),
INVITE(2),
@@ -550,7 +554,7 @@ public final class PlayerInteractionHandler extends AbstractPacketHandler {
}
}
} 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 {
inv.unlockInventory();
}

View File

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

View File

@@ -24,7 +24,8 @@ package scripting;
import client.Client;
import com.oracle.truffle.js.scriptengine.GraalJSScriptEngine;
import constants.string.CharsetConstants;
import tools.FilePrinter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.script.*;
import java.io.File;
@@ -35,6 +36,7 @@ import java.io.IOException;
* @author Matze
*/
public abstract class AbstractScriptManager {
private static final Logger log = LoggerFactory.getLogger(AbstractScriptManager.class);
private final ScriptEngineFactory sef;
protected AbstractScriptManager() {
@@ -58,7 +60,7 @@ public abstract class AbstractScriptManager {
try (FileReader fr = new FileReader(scriptFile, CharsetConstants.CHARSET)) {
engine.eval(fr);
} 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;
}

View File

@@ -25,13 +25,14 @@ import client.inventory.ItemFactory;
import constants.game.GameConstants;
import net.server.audit.locks.MonitoredLockType;
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import provider.Data;
import provider.DataProvider;
import provider.DataProviderFactory;
import provider.DataTool;
import provider.wz.WZFiles;
import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.PacketCreator;
import tools.Pair;
@@ -46,6 +47,7 @@ import java.util.concurrent.locks.Lock;
* @author Matze
*/
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> trunkPutCache = new HashMap<>();
@@ -94,7 +96,7 @@ public class Storage {
return ret;
} 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);
}
}

View File

@@ -23,11 +23,12 @@ package server.quest.requirements;
import client.Character;
import client.QuestStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import provider.Data;
import provider.DataTool;
import server.quest.Quest;
import server.quest.QuestRequirementType;
import tools.FilePrinter;
import java.util.HashMap;
import java.util.Map;
@@ -36,6 +37,7 @@ import java.util.Map;
* @author Tyler (Twdtwd)
*/
public class MobRequirement extends AbstractQuestRequirement {
private static final Logger log = LoggerFactory.getLogger(MobRequirement.class);
Map<Integer, Integer> mobs = new HashMap<>();
private final int questID;
@@ -68,7 +70,7 @@ public class MobRequirement extends AbstractQuestRequirement {
try {
progress = Integer.parseInt(status.getProgress(mobID));
} 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;
}

View File

@@ -1,6 +1,8 @@
package tools;
import java.io.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
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 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) {
System.out.println("Error thrown: " + name);
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;
}
}