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);
}
}
}