Migrate another batch of FilePrinter users to slf4j.Logger

Another FilePrinter method removed.
This commit is contained in:
P0nk
2022-02-08 21:00:51 +01:00
parent 53465bba25
commit 0c60606b4e
15 changed files with 97 additions and 120 deletions

View File

@@ -8071,7 +8071,7 @@ public class Character extends AbstractCharacterObject {
if (tap >= 0) {
updateStrDexIntLukSp(tstr, tdex, tint, tluk, tap, tsp, GameConstants.getSkillBook(job.getId()));
} else {
FilePrinter.print(FilePrinter.EXCEPTION_CAUGHT, name + " tried to get their stats reseted, without having enough AP available.");
log.warn("Chr {} tried to have its stats reset without enough AP available");
}
} finally {
statWlock.unlock();
@@ -8361,12 +8361,7 @@ public class Character extends AbstractCharacterObject {
}
Calendar c = Calendar.getInstance();
if (notAutosave) {
FilePrinter.print(FilePrinter.SAVING_CHARACTER, "Attempting to save " + name + " at " + c.getTime());
} else {
FilePrinter.print(FilePrinter.AUTOSAVING_CHARACTER, "Attempting to autosave " + name + " at " + c.getTime());
}
log.debug("Attempting to {} chr {}", notAutosave ? "save" : "autosave", name);
Server.getInstance().updateCharacterEntry(this);
@@ -8775,14 +8770,13 @@ public class Character extends AbstractCharacterObject {
}
public void sendPolice(String text) {
String message = getName() + " received this - " + text;
final String message = getName() + " received this - " + text;
if (Server.getInstance().isGmOnline(this.getWorld())) { //Alert and log if a GM is online
Server.getInstance().broadcastGMMessage(this.getWorld(), PacketCreator.sendYellowTip(message));
FilePrinter.print(FilePrinter.AUTOBAN_WARNING, message);
} else { //Auto DC and log if no GM is online
client.disconnect(false, false);
FilePrinter.print(FilePrinter.AUTOBAN_DC, message);
}
log.info(message);
//Server.getInstance().broadcastGMMessage(0, PacketCreator.serverNotice(1, getName() + " received this - " + text));
//sendPacket(PacketCreator.sendPolice(text));
//this.isbanned = true;
@@ -10754,8 +10748,7 @@ public class Character extends AbstractCharacterObject {
newName = rs.getString("new");
}
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e, "Failed to retrieve pending name changes for character " + getName() + ".");
log.error("Failed to retrieve pending name changes for chr {}", this.name, e);
}
con.setAutoCommit(false);
@@ -10763,12 +10756,11 @@ public class Character extends AbstractCharacterObject {
if (!success) {
con.rollback();
} else {
FilePrinter.print(FilePrinter.CHANGE_CHARACTER_NAME, "Name change applied : from \"" + getName() + "\" to \"" + newName + "\" at " + Calendar.getInstance().getTime());
log.info("Name change applied: from {} to {}", this.name, newName);
}
con.setAutoCommit(true);
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e, "Failed to get DB connection.");
log.error("Failed to get DB connection for pending chr name change", e);
}
}
@@ -10781,8 +10773,7 @@ public class Character extends AbstractCharacterObject {
}
con.setAutoCommit(true);
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e, "Failed to get DB connection.");
log.error("Failed to get DB connection for chr name change", e);
}
}
@@ -10792,8 +10783,7 @@ public class Character extends AbstractCharacterObject {
ps.setInt(2, characterId);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e, "Character ID : " + characterId);
log.error("Failed to perform chr name change in database for chrId {}", characterId, e);
return false;
}
@@ -10802,8 +10792,7 @@ public class Character extends AbstractCharacterObject {
ps.setString(2, oldName);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e, "Character ID : " + characterId);
log.error("Failed to update rings during chr name change for chrId {}", characterId, e);
return false;
}
@@ -10922,8 +10911,7 @@ public class Character extends AbstractCharacterObject {
ps.setInt(2, nameChangeId);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e, "Character ID : " + characterId);
log.error("Failed to save chr name change for chrId {}", nameChangeId, e);
return false;
}
}

View File

@@ -64,7 +64,10 @@ import server.life.Monster;
import server.maps.FieldLimit;
import server.maps.MapleMap;
import server.maps.MiniDungeonInfo;
import tools.*;
import tools.BCrypt;
import tools.DatabaseConnection;
import tools.HexTool;
import tools.PacketCreator;
import javax.script.ScriptEngine;
import java.io.IOException;
@@ -204,7 +207,9 @@ public class Client extends ChannelInboundHandlerAdapter {
MonitoredChrLogger.logPacketIfMonitored(this, opcode, packet.getBytes());
handler.handlePacket(packet, this);
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.PACKET_HANDLER + handler.getClass().getName() + ".txt", t, "Error for " + (getPlayer() == null ? "" : "player ; " + getPlayer() + " on map ; " + getPlayer().getMapId() + " - ") + "account ; " + getAccountName() + "\r\n" + packet);
final String chrInfo = player != null ? player.getName() + " on map " + player.getMapId() : "?";
log.warn("Error in packet handler {}. Chr {}, account {}. Packet: {}", handler.getClass().getSimpleName(),
chrInfo, getAccountName(), packet, t);
//client.sendPacket(PacketCreator.enableActions());//bugs sometimes
}
}
@@ -639,7 +644,7 @@ public class Client extends ChannelInboundHandlerAdapter {
if (rs.next()) {
accId = rs.getInt("id");
if (accId <= 0) {
FilePrinter.printError(FilePrinter.LOGIN_EXCEPTION, "Tried to login with accid " + accId);
log.warn("Tried to log in with accId {}", accId);
return 15;
}
@@ -1226,7 +1231,7 @@ public class Client extends ChannelInboundHandlerAdapter {
for (World w : Server.getInstance().getWorlds()) {
for (Character chr : w.getPlayerStorage().getAllCharacters()) {
if (accid == chr.getAccountID()) {
FilePrinter.print(FilePrinter.EXPLOITS, "Player: " + chr.getName() + " has been removed from " + GameConstants.WORLD_NAMES[w.getId()] + ". Possible Dupe attempt.");
log.warn("Chr {} has been removed from world {}. Possible Dupe attempt.", chr.getName(), GameConstants.WORLD_NAMES[w.getId()]);
chr.getClient().forceDisconnect();
w.getPlayerStorage().removePlayer(chr.getId());
}

View File

@@ -25,7 +25,8 @@ package client.autoban;
import client.Character;
import config.YamlConfig;
import net.server.Server;
import tools.FilePrinter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.PacketCreator;
import java.util.Collection;
@@ -59,6 +60,7 @@ public enum AutobanFactory {
FAST_ATTACK(10, SECONDS.toMillis(30)),
MPCON(25, SECONDS.toMillis(30));
private static final Logger log = LoggerFactory.getLogger(AutobanFactory.class);
private static final Set<Integer> ignoredChrIds = new HashSet<>();
private final int points;
@@ -98,7 +100,8 @@ public enum AutobanFactory {
Server.getInstance().broadcastGMMessage((chr != null ? chr.getWorld() : 0), PacketCreator.sendYellowTip((chr != null ? Character.makeMapleReadable(chr.getName()) : "") + " caused " + this.name() + " " + reason));
}
if (YamlConfig.config.server.USE_AUTOBAN_LOG) {
FilePrinter.print(FilePrinter.AUTOBAN_WARNING, (chr != null ? Character.makeMapleReadable(chr.getName()) : "") + " caused " + this.name() + " " + reason);
final String chrName = chr != null ? Character.makeMapleReadable(chr.getName()) : "";
log.info("Autoban alert - chr {} caused {}-{}", chrName, this.name(), reason);
}
}

View File

@@ -8,7 +8,8 @@ package client.autoban;
import client.Character;
import config.YamlConfig;
import net.server.Server;
import tools.FilePrinter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.HashMap;
import java.util.Map;
@@ -17,6 +18,8 @@ import java.util.Map;
* @author kevintjuh93
*/
public class AutobanManager {
private static final Logger log = LoggerFactory.getLogger(AutobanManager.class);
private final Character chr;
private final Map<AutobanFactory, Integer> points = new HashMap<>();
private final Map<AutobanFactory, Long> lastTime = new HashMap<>();
@@ -59,7 +62,7 @@ public class AutobanManager {
}
if (YamlConfig.config.server.USE_AUTOBAN_LOG) {
// Lets log every single point too.
FilePrinter.print(FilePrinter.AUTOBAN_WARNING, Character.makeMapleReadable(chr.getName()) + " caused " + fac.name() + " " + reason);
log.info("Autoban - chr {} caused {} {}", Character.makeMapleReadable(chr.getName()), fac.name(), reason);
}
}
@@ -119,7 +122,7 @@ public class AutobanManager {
chr.getClient().disconnect(false, false);
}
FilePrinter.print(FilePrinter.EXPLOITS, "Player " + chr + " was caught spamming TYPE " + type + " and has been disconnected.");
log.info("Autoban - Chr {} was caught spamming TYPE {} and has been disconnected", chr, type);
}
} else {
this.timestamp[type] = time;

View File

@@ -32,23 +32,29 @@ import client.command.commands.gm4.*;
import client.command.commands.gm5.*;
import client.command.commands.gm6.*;
import constants.id.MapId;
import tools.FilePrinter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.Pair;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
public class CommandsExecutor {
private static final Logger log = LoggerFactory.getLogger(CommandsExecutor.class);
private static final CommandsExecutor instance = new CommandsExecutor();
private static final char USER_HEADING = '@';
private static final char GM_HEADING = '!';
public static CommandsExecutor instance = new CommandsExecutor();
private final HashMap<String, Command> registeredCommands = new HashMap<>();
private final List<Pair<List<String>, List<String>>> commandsNameDesc = new ArrayList<>();
private Pair<List<String>, List<String>> levelCommandsCursor;
public static CommandsExecutor getInstance() {
return instance;
}
private static final char USER_HEADING = '@';
private static final char GM_HEADING = '!';
public static boolean isCommand(Client client, String content) {
char heading = content.charAt(0);
if (client.getPlayer().isGM()) {
@@ -57,10 +63,6 @@ public class CommandsExecutor {
return heading == USER_HEADING;
}
private final HashMap<String, Command> registeredCommands = new HashMap<>();
private Pair<List<String>, List<String>> levelCommandsCursor;
private final List<Pair<List<String>, List<String>>> commandsNameDesc = new ArrayList<>();
private CommandsExecutor() {
registerLv0Commands();
registerLv1Commands();
@@ -119,13 +121,7 @@ public class CommandsExecutor {
}
command.execute(client, params);
writeLog(client, message);
}
private void writeLog(Client client, String command) {
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm");
FilePrinter.print(FilePrinter.USED_COMMANDS, client.getPlayer().getName() + " used: " + command + " on "
+ sdf.format(Calendar.getInstance().getTime()));
log.info("Chr {} used command {}", client.getPlayer().getName(), command.getClass().getSimpleName());
}
private void addCommandInfo(String name, Class<? extends Command> commandClass) {

View File

@@ -27,14 +27,16 @@ import client.inventory.InventoryType;
import client.inventory.Item;
import config.YamlConfig;
import net.server.Server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.ItemInformationProvider;
import tools.FilePrinter;
import tools.PacketCreator;
/**
* @author RonanLana
*/
public abstract class CharacterFactory {
private static final Logger log = LoggerFactory.getLogger(CharacterFactory.class);
protected synchronized static int createNewCharacter(Client c, String name, int face, int hair, int skin, int gender, CharacterFactoryRecipe recipe) {
if (YamlConfig.config.server.COLLECTIVE_CHARSLOT ? c.getAvailableCharacterSlots() <= 0 : c.getAvailableCharacterWorldSlots() <= 0) {
@@ -93,7 +95,7 @@ public abstract class CharacterFactory {
Server.getInstance().createCharacterEntry(newchar);
Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.sendYellowTip("[New Char]: " + c.getAccountName() + " has created a new character with IGN " + name));
FilePrinter.print(FilePrinter.CREATED_CHAR + c.getAccountName() + ".txt", c.getAccountName() + " created character with IGN " + name);
log.info("Account {} created chr with name {}", c.getAccountName(), name);
return 0;
}

View File

@@ -32,10 +32,11 @@ import client.inventory.ItemFactory;
import client.inventory.manipulator.InventoryManipulator;
import net.server.Server;
import net.server.world.World;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.ItemInformationProvider;
import server.maps.HiredMerchant;
import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.PacketCreator;
import tools.Pair;
@@ -50,7 +51,7 @@ import static java.util.concurrent.TimeUnit.DAYS;
* @author RonanLana - synchronization of Fredrick modules and operation results
*/
public class FredrickProcessor {
private static final Logger log = LoggerFactory.getLogger(FredrickProcessor.class);
private static final int[] dailyReminders = new int[]{2, 5, 10, 15, 30, 60, 90, Integer.MAX_VALUE};
private static byte canRetrieveFromFredrick(Character chr, List<Pair<Item, InventoryType>> items) {
@@ -293,7 +294,7 @@ public class FredrickProcessor {
Item item = it.getLeft();
InventoryManipulator.addFromDrop(chr.getClient(), item, false);
String itemName = ItemInformationProvider.getInstance().getName(item.getItemId());
FilePrinter.print(FilePrinter.FREDRICK + chr.getName() + ".txt", chr.getName() + " gained " + item.getQuantity() + " " + itemName + " (" + item.getItemId() + ")");
log.debug("Chr {} gained {}x {} ({})", chr.getName(), item.getQuantity(), itemName, item.getItemId());
}
chr.sendPacket(PacketCreator.fredrickMessage((byte) 0x1E));

View File

@@ -33,9 +33,10 @@ import config.YamlConfig;
import constants.id.ItemId;
import constants.inventory.ItemConstants;
import net.packet.InPacket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.ItemInformationProvider;
import server.Storage;
import tools.FilePrinter;
import tools.PacketCreator;
/**
@@ -43,6 +44,7 @@ import tools.PacketCreator;
* @author Ronan - inventory concurrency protection on storing items
*/
public class StorageProcessor {
private static final Logger log = LoggerFactory.getLogger(StorageProcessor.class);
public static void storageAction(InPacket p, Client c) {
ItemInformationProvider ii = ItemInformationProvider.getInstance();
@@ -63,7 +65,7 @@ public class StorageProcessor {
byte slot = p.readByte();
if (slot < 0 || slot > storage.getSlots()) { // removal starts at zero
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with storage.");
FilePrinter.print(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to work with storage slot " + slot);
log.warn("Chr {} tried to work with storage slot {}", c.getPlayer().getName(), slot);
c.disconnect(true, false);
return;
}
@@ -91,7 +93,7 @@ public class StorageProcessor {
InventoryManipulator.addFromDrop(c, item, false);
String itemName = ii.getName(item.getItemId());
FilePrinter.print(FilePrinter.STORAGE + c.getAccountName() + ".txt", c.getPlayer().getName() + " took out " + item.getQuantity() + " " + itemName + " (" + item.getItemId() + ")");
log.debug("Chr {} took out {}x {} ({})", c.getPlayer().getName(), item.getQuantity(), itemName, item.getItemId());
storage.sendTakenOut(c, item.getInventoryType());
} else {
@@ -110,7 +112,7 @@ public class StorageProcessor {
Inventory inv = chr.getInventory(invType);
if (slot < 1 || slot > inv.getSlotLimit()) { //player inv starts at one
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with storage.");
FilePrinter.print(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to store item at slot " + slot);
log.warn("Chr {} tried to store item at slot {}", c.getPlayer().getName(), slot);
c.disconnect(true, false);
return;
}
@@ -162,8 +164,7 @@ public class StorageProcessor {
chr.setUsedStorage();
String itemName = ii.getName(item.getItemId());
FilePrinter.print(FilePrinter.STORAGE + c.getAccountName() + ".txt", c.getPlayer().getName() + " stored " + item.getQuantity() + " " + itemName + " (" + item.getItemId() + ")");
log.debug("Chr {} stored {}x {} ({})", c.getPlayer().getName(), item.getQuantity(), itemName, item.getItemId());
storage.sendStored(c, ItemConstants.getInventoryType(itemId));
}
} else if (mode == 6) { // arrange items
@@ -192,7 +193,7 @@ public class StorageProcessor {
storage.setMeso(storageMesos - meso);
chr.gainMeso(meso, false, true, false);
chr.setUsedStorage();
FilePrinter.print(FilePrinter.STORAGE + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + (meso > 0 ? " took out " : " stored ") + Math.abs(meso) + " mesos");
log.debug("Chr {} {} {} mesos", c.getPlayer().getName(), meso > 0 ? "took out" : "stored", Math.abs(meso));
storage.sendMeso(c);
} else {
c.sendPacket(PacketCreator.enableActions());