Merge pull request #66 from P0nk/logging-consolidation

Consolidate logging
This commit is contained in:
Ponk
2022-02-10 22:06:07 +01:00
committed by GitHub
109 changed files with 932 additions and 924 deletions

View File

@@ -57,6 +57,8 @@ import net.server.services.task.world.CharacterSaveService;
import net.server.services.type.ChannelServices;
import net.server.services.type.WorldServices;
import net.server.world.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import scripting.AbstractPlayerInteraction;
import scripting.event.EventInstanceManager;
import scripting.item.ItemScriptManager;
@@ -95,10 +97,12 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static java.util.concurrent.TimeUnit.*;
public class Character extends AbstractCharacterObject {
private static final Logger log = LoggerFactory.getLogger(Character.class);
private static final ItemInformationProvider ii = ItemInformationProvider.getInstance();
private static final String LEVEL_200 = "[Congrats] %s has reached Level %d! Congratulate %s on such an amazing achievement!";
private static final String[] BLOCKED_NAMES = {"admin", "owner", "moderator", "intern", "donor", "administrator", "FREDRICK", "help", "helper", "alert", "notice", "maplestory", "fuck", "wizet", "fucking", "negro", "fuk", "fuc", "penis", "pussy", "asshole", "gay",
@@ -1721,7 +1725,7 @@ public class Character extends AbstractCharacterObject {
resetHpDecreaseTask();
}
} else {
FilePrinter.printError(FilePrinter.MAPLE_MAP, "Character " + this.getName() + " got stuck when moving to map " + map.getId() + ".");
log.warn("Chr {} got stuck when moving to map {}", getName(), map.getId());
client.disconnect(true, false); // thanks BHB for noticing a player storage stuck case here
return;
}
@@ -3584,26 +3588,25 @@ public class Character extends AbstractCharacterObject {
effLock.lock();
chrLock.lock();
try {
System.out.println("-------------------");
System.out.println("CACHED BUFF COUNT: ");
for (Entry<BuffStat, Byte> bpl : buffEffectsCount.entrySet()) {
System.out.println(bpl.getKey() + ": " + bpl.getValue());
}
System.out.println("-------------------");
System.out.println("CACHED BUFFS: ");
for (Entry<Integer, Map<BuffStat, BuffStatValueHolder>> bpl : buffEffects.entrySet()) {
System.out.print(bpl.getKey() + ": ");
for (Entry<BuffStat, BuffStatValueHolder> pble : bpl.getValue().entrySet()) {
System.out.print(pble.getKey().name() + pble.getValue().value + ", ");
}
System.out.println();
}
System.out.println("-------------------");
log.debug("-------------------");
log.debug("CACHED BUFF COUNT: {}", buffEffectsCount.entrySet().stream()
.map(entry -> entry.getKey() + ": " + entry.getValue())
.collect(Collectors.joining(", "))
);
System.out.println("IN ACTION:");
for (Entry<BuffStat, BuffStatValueHolder> bpl : effects.entrySet()) {
System.out.println(bpl.getKey().name() + " -> " + ItemInformationProvider.getInstance().getName(bpl.getValue().effect.getSourceId()));
}
log.debug("-------------------");
log.debug("CACHED BUFFS: {}", buffEffects.entrySet().stream()
.map(entry -> entry.getKey() + ": (" + entry.getValue().entrySet().stream()
.map(innerEntry -> innerEntry.getKey().name() + innerEntry.getValue().value)
.collect(Collectors.joining(", ")) + ")")
.collect(Collectors.joining(", "))
);
log.debug("-------------------");
log.debug("IN ACTION: {}", effects.entrySet().stream()
.map(entry -> entry.getKey().name() + " -> " + ItemInformationProvider.getInstance().getName(entry.getValue().effect.getSourceId()))
.collect(Collectors.joining(", "))
);
} finally {
chrLock.unlock();
effLock.unlock();
@@ -3614,9 +3617,10 @@ public class Character extends AbstractCharacterObject {
effLock.lock();
chrLock.lock();
try {
for (Entry<BuffStat, Byte> mbsl : buffEffectsCount.entrySet()) {
System.out.println(mbsl.getKey().name() + " -> " + mbsl.getValue());
}
log.debug("ALL BUFFS COUNT: {}", buffEffectsCount.entrySet().stream()
.map(entry -> entry.getKey().name() + " -> " + entry.getValue())
.collect(Collectors.joining(", "))
);
} finally {
chrLock.unlock();
effLock.unlock();
@@ -5604,9 +5608,8 @@ public class Character extends AbstractCharacterObject {
}
try {
merchant.saveItems(false);
} catch (SQLException ex) {
ex.printStackTrace();
FilePrinter.printError(FilePrinter.EXCEPTION_CAUGHT, "Error while saving " + name + "'s Hired Merchant items.");
} catch (SQLException e) {
log.error("Error while saving {}'s Hired Merchant items.", name, e);
}
}
}
@@ -7548,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);
}
}
@@ -8068,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();
@@ -8241,7 +8244,7 @@ public class Character extends AbstractCharacterObject {
int updateRows = ps.executeUpdate();
if (updateRows < 1) {
FilePrinter.printError(FilePrinter.INSERT_CHAR, "Error trying to insert " + name);
log.error("Error trying to insert chr {}", name);
return false;
}
@@ -8249,7 +8252,7 @@ public class Character extends AbstractCharacterObject {
if (rs.next()) {
this.id = rs.getInt(1);
} else {
FilePrinter.printError(FilePrinter.INSERT_CHAR, "Inserting char failed " + name);
log.error("Inserting chr {} failed", name);
return false;
}
}
@@ -8329,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;
@@ -8358,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);
@@ -8756,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);
}
}
@@ -8772,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;
@@ -10694,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;
}
@@ -10707,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;
}
@@ -10727,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;
}
}
@@ -10751,8 +10744,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);
@@ -10760,12 +10752,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);
}
}
@@ -10778,8 +10769,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);
}
}
@@ -10789,8 +10779,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;
}
@@ -10799,8 +10788,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;
}
@@ -10919,8 +10907,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;
}
}
@@ -10968,8 +10955,7 @@ public class Character extends AbstractCharacterObject {
return "Character is the leader of a guild.";
}
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e);
log.error("Change character name", e);
return "SQL Error";
}
try (PreparedStatement ps = con.prepareStatement("SELECT tempban FROM accounts WHERE id = ?")) {
@@ -10983,8 +10969,7 @@ public class Character extends AbstractCharacterObject {
return "Account has been banned.";
}
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e);
log.error("Change character name", e);
return "SQL Error";
}
try (PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) AS rowcount FROM characters WHERE accountid = ? AND world = ?")) {
@@ -10998,8 +10983,7 @@ public class Character extends AbstractCharacterObject {
return "Too many characters on destination world.";
}
} catch (SQLException e) {
e.printStackTrace();
FilePrinter.printError(FilePrinter.CHANGE_CHARACTER_NAME, e);
log.error("Change character name", e);
return "SQL Error";
}
return null;
@@ -11021,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;
}
@@ -11033,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;
}
@@ -11050,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;
}
}
@@ -11062,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 = ?")) {
@@ -11079,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 = ?")) {
@@ -11088,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) {
@@ -11098,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

@@ -34,7 +34,7 @@ import net.netty.InvalidPacketHeaderException;
import net.packet.InPacket;
import net.packet.Packet;
import net.packet.logging.LoggingUtil;
import net.packet.logging.MapleLogger;
import net.packet.logging.MonitoredChrLogger;
import net.server.Server;
import net.server.audit.locks.MonitoredLockType;
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
@@ -57,13 +57,17 @@ import scripting.npc.NPCConversationManager;
import scripting.npc.NPCScriptManager;
import scripting.quest.QuestActionManager;
import scripting.quest.QuestScriptManager;
import server.MapleLeafLogger;
import server.ThreadManager;
import server.TimerManager;
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;
@@ -200,10 +204,12 @@ public class Client extends ChannelInboundHandlerAdapter {
if (handler != null && handler.validateState(this)) {
try {
MapleLogger.logRecv(this, opcode, packet.getBytes());
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
}
}
@@ -380,7 +386,7 @@ public class Client extends ChannelInboundHandlerAdapter {
voteTime = rs.getInt("date");
}
} catch (SQLException e) {
FilePrinter.printError("hasVotedAlready.txt", e);
log.error("Error getting voting time");
return -1;
}
return voteTime;
@@ -638,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;
}
@@ -937,7 +943,7 @@ public class Client extends ChannelInboundHandlerAdapter {
}
} catch (final Throwable t) {
FilePrinter.printError(FilePrinter.ACCOUNT_STUCK, t);
log.error("Account stuck", t);
}
}
@@ -1010,7 +1016,7 @@ public class Client extends ChannelInboundHandlerAdapter {
}
}
} catch (final Exception e) {
FilePrinter.printError(FilePrinter.ACCOUNT_STUCK, e);
log.error("Account stuck", e);
} finally {
if (!this.serverTransition) {
if (chrg != null) {
@@ -1225,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());
}
@@ -1263,7 +1269,7 @@ public class Client extends ChannelInboundHandlerAdapter {
}
votePoints -= points;
saveVotePoints();
LogHelper.logLeaf(player, false, Integer.toString(points));
MapleLeafLogger.log(player, false, Integer.toString(points));
}
private void saveVotePoints() {

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

@@ -24,11 +24,15 @@ package client.autoban;
import client.Character;
import config.YamlConfig;
import net.packet.logging.MapleLogger;
import net.server.Server;
import tools.FilePrinter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.PacketCreator;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.SECONDS;
@@ -56,6 +60,9 @@ 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;
private final long expiretime;
@@ -87,13 +94,14 @@ public enum AutobanFactory {
public void alert(Character chr, String reason) {
if (YamlConfig.config.server.USE_AUTOBAN) {
if (chr != null && MapleLogger.ignored.contains(chr.getId())) {
if (chr != null && isIgnored(chr.getId())) {
return;
}
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);
}
}
@@ -103,4 +111,28 @@ public enum AutobanFactory {
//chr.sendPolice("You will be disconnected for (" + this.name() + ": " + value + ")");
}
}
/**
* Toggle ignored status for a character id.
* An ignored character will not trigger GM alerts.
*
* @return new status. true if the chrId is now ignored, otherwise false.
*/
public static boolean toggleIgnored(int chrId) {
if (ignoredChrIds.contains(chrId)) {
ignoredChrIds.remove(chrId);
return false;
} else {
ignoredChrIds.add(chrId);
return true;
}
}
private static boolean isIgnored(int chrId) {
return ignoredChrIds.contains(chrId);
}
public static Collection<Integer> getIgnoredChrIds() {
return ignoredChrIds;
}
}

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) {
@@ -157,7 +153,7 @@ public class CommandsExecutor {
private void addCommand(String syntax, int rank, Class<? extends Command> commandClass) {
if (registeredCommands.containsKey(syntax.toLowerCase())) {
System.out.println("Error on register command with name: " + syntax + ". Already exists.");
log.warn("Error on register command with name: {}. Already exists.", syntax);
return;
}

View File

@@ -27,7 +27,8 @@ import client.Character;
import client.Client;
import client.command.Command;
import net.server.Server;
import tools.FilePrinter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.PacketCreator;
import tools.Randomizer;
@@ -36,6 +37,8 @@ public class GmCommand extends Command {
setDescription("Send a message to the game masters.");
}
private static final Logger log = LoggerFactory.getLogger(GmCommand.class);
@Override
public void execute(Client c, String[] params) {
String[] tips = {
@@ -53,7 +56,7 @@ public class GmCommand extends Command {
String message = player.getLastCommandMessage();
Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.sendYellowTip("[GM Message]:" + Character.makeMapleReadable(player.getName()) + ": " + message));
Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.serverNotice(1, message));
FilePrinter.printError(FilePrinter.COMMAND_GM, Character.makeMapleReadable(player.getName()) + ": " + message);
log.info("{}: {}", Character.makeMapleReadable(player.getName()), message);
player.dropMessage(5, "Your message '" + message + "' was sent to GMs.");
player.dropMessage(5, tips[Randomizer.nextInt(tips.length)]);
}

View File

@@ -27,7 +27,8 @@ import client.Character;
import client.Client;
import client.command.Command;
import net.server.Server;
import tools.FilePrinter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.PacketCreator;
public class ReportBugCommand extends Command {
@@ -35,6 +36,8 @@ public class ReportBugCommand extends Command {
setDescription("Send in a bug report.");
}
private static final Logger log = LoggerFactory.getLogger(ReportBugCommand.class);
@Override
public void execute(Client c, String[] params) {
Character player = c.getPlayer();
@@ -46,7 +49,7 @@ public class ReportBugCommand extends Command {
String message = player.getLastCommandMessage();
Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.sendYellowTip("[Bug]:" + Character.makeMapleReadable(player.getName()) + ": " + message));
Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.serverNotice(1, message));
FilePrinter.printError(FilePrinter.COMMAND_BUG, Character.makeMapleReadable(player.getName()) + ": " + message);
log.info("{}: {}", Character.makeMapleReadable(player.getName()), message);
player.dropMessage(5, "Your bug '" + message + "' was submitted successfully to our developers. Thank you!");
}

View File

@@ -25,14 +25,14 @@ package client.command.commands.gm3;
import client.Character;
import client.Client;
import client.autoban.AutobanFactory;
import client.command.Command;
import net.packet.logging.MapleLogger;
import net.server.Server;
import tools.PacketCreator;
public class IgnoreCommand extends Command {
{
setDescription("Toggle enable/disable ignore a player in packet logs and autoban.");
setDescription("Toggle ignore a character from auto-ban alerts.");
}
@Override
@@ -47,14 +47,10 @@ public class IgnoreCommand extends Command {
player.message("Player '" + params[0] + "' could not be found on this world.");
return;
}
boolean monitored_ = MapleLogger.ignored.contains(victim.getId());
if (monitored_) {
MapleLogger.ignored.remove(victim.getId());
} else {
MapleLogger.ignored.add(victim.getId());
}
player.yellowMessage(victim.getName() + " is " + (!monitored_ ? "now being ignored." : "no longer being ignored."));
String message_ = player.getName() + (!monitored_ ? " has started ignoring " : " has stopped ignoring ") + victim.getName() + ".";
boolean ignored = AutobanFactory.toggleIgnored(victim.getId());
player.yellowMessage(victim.getName() + " is " + (ignored ? "now being ignored." : "no longer being ignored."));
String message_ = player.getName() + (ignored ? " has started ignoring " : " has stopped ignoring ") + victim.getName() + ".";
Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.serverNotice(5, message_));
}

View File

@@ -25,19 +25,19 @@ package client.command.commands.gm3;
import client.Character;
import client.Client;
import client.autoban.AutobanFactory;
import client.command.Command;
import net.packet.logging.MapleLogger;
public class IgnoredCommand extends Command {
{
setDescription("Show all players being ignored in logs.");
setDescription("Show all characters being ignored in auto-ban alerts.");
}
@Override
public void execute(Client c, String[] params) {
Character player = c.getPlayer();
for (Integer cid : MapleLogger.ignored) {
player.yellowMessage(Character.getNameById(cid) + " is being ignored.");
for (int chrId : AutobanFactory.getIgnoredChrIds()) {
player.yellowMessage(Character.getNameById(chrId) + " is being ignored.");
}
}
}

View File

@@ -26,13 +26,13 @@ package client.command.commands.gm3;
import client.Character;
import client.Client;
import client.command.Command;
import net.packet.logging.MapleLogger;
import net.packet.logging.MonitoredChrLogger;
import net.server.Server;
import tools.PacketCreator;
public class MonitorCommand extends Command {
{
setDescription("Toggle logging the packets of a player.");
setDescription("Toggle monitored packet logging of a character.");
}
@Override
@@ -47,14 +47,9 @@ public class MonitorCommand extends Command {
player.message("Player '" + params[0] + "' could not be found on this world.");
return;
}
boolean monitored = MapleLogger.monitored.contains(victim.getId());
if (monitored) {
MapleLogger.monitored.remove(victim.getId());
} else {
MapleLogger.monitored.add(victim.getId());
}
player.yellowMessage(victim.getId() + " is " + (!monitored ? "now being monitored." : "no longer being monitored."));
String message = player.getName() + (!monitored ? " has started monitoring " : " has stopped monitoring ") + victim.getId() + ".";
boolean monitored = MonitoredChrLogger.toggleMonitored(victim.getId());
player.yellowMessage(victim.getId() + " is " + (monitored ? "now being monitored." : "no longer being monitored."));
String message = player.getName() + (monitored ? " has started monitoring " : " has stopped monitoring ") + victim.getId() + ".";
Server.getInstance().broadcastGMMessage(c.getWorld(), PacketCreator.serverNotice(5, message));
}

View File

@@ -26,18 +26,18 @@ package client.command.commands.gm3;
import client.Character;
import client.Client;
import client.command.Command;
import net.packet.logging.MapleLogger;
import net.packet.logging.MonitoredChrLogger;
public class MonitorsCommand extends Command {
{
setDescription("Show all players having their packets logged.");
setDescription("Show all characters being monitored for packet logging");
}
@Override
public void execute(Client c, String[] params) {
Character player = c.getPlayer();
for (Integer cid : MapleLogger.monitored) {
player.yellowMessage(Character.getNameById(cid) + " is being monitored.");
for (int chrId : MonitoredChrLogger.getMonitoredChrIds()) {
player.yellowMessage(Character.getNameById(chrId) + " is being monitored.");
}
}
}

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

@@ -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

@@ -25,6 +25,8 @@ import client.Client;
import config.YamlConfig;
import constants.game.ExpTable;
import constants.inventory.ItemConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.ItemInformationProvider;
import tools.PacketCreator;
import tools.Pair;
@@ -36,6 +38,7 @@ import java.util.List;
import java.util.Map;
public class Equip extends Item {
private static final Logger log = LoggerFactory.getLogger(Equip.class);
public enum ScrollResult {
@@ -110,7 +113,7 @@ public class Equip extends Item {
ret.itemLevel = itemLevel;
ret.itemExp = itemExp;
ret.level = level;
ret.log = new LinkedList<>(log);
ret.itemLog = new LinkedList<>(itemLog);
ret.setOwner(getOwner());
ret.setQuantity(getQuantity());
ret.setExpiration(getExpiration());
@@ -647,7 +650,8 @@ public class Equip extends Item {
int expNeeded = ExpTable.getEquipExpNeededForLevel(itemLevel);
if (YamlConfig.config.server.USE_DEBUG_SHOW_INFO_EQPEXP) {
System.out.println("'" + ii.getName(this.getItemId()) + "' -> EXP Gain: " + gain + " Mastery: " + masteryModifier + " Base gain: " + baseExpGain + " exp: " + itemExp + " / " + expNeeded + ", Kills TNL: " + expNeeded / (baseExpGain / c.getPlayer().getExpRate()));
log.debug("{} -> EXP Gain: {}, Mastery: {}, Base gain: {}, exp: {} / {}, Kills TNL: {}", ii.getName(getItemId()),
gain, masteryModifier, baseExpGain, itemExp, expNeeded, expNeeded / (baseExpGain / c.getPlayer().getExpRate()));
}
if (itemExp >= expNeeded) {

View File

@@ -27,9 +27,10 @@ import client.inventory.manipulator.InventoryManipulator;
import constants.inventory.ItemConstants;
import net.server.audit.locks.MonitoredLockType;
import net.server.audit.locks.factory.MonitoredReentrantLockFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.ItemInformationProvider;
import server.ThreadManager;
import tools.FilePrinter;
import tools.Pair;
import java.util.*;
@@ -40,6 +41,7 @@ import java.util.concurrent.locks.Lock;
* @author Matze, Ronan
*/
public class Inventory implements Iterable<Item> {
private static final Logger log = LoggerFactory.getLogger(Inventory.class);
protected final Map<Short, Item> inventory;
protected final InventoryType type;
protected final Lock lock = MonitoredReentrantLockFactory.createLock(MonitoredLockType.INVENTORY, true);
@@ -117,7 +119,7 @@ public class Inventory implements Iterable<Item> {
for (Item item : list()) {
String itemName = ii.getName(item.getItemId());
if (itemName == null) {
FilePrinter.printError(FilePrinter.EXCEPTION, "[CRITICAL] Item " + item.getItemId() + " has no name.");
log.error("[CRITICAL] Item {} has no name", item.getItemId());
continue;
}

View File

@@ -42,7 +42,7 @@ public class Item implements Comparable<Item> {
private int petid = -1;
private Pet pet = null;
private String owner = "";
protected List<String> log;
protected List<String> itemLog;
private short flag;
private long expiration = -1;
private String giftFrom = "";
@@ -51,7 +51,7 @@ public class Item implements Comparable<Item> {
this.id = id;
this.position = position;
this.quantity = quantity;
this.log = new LinkedList<>();
this.itemLog = new LinkedList<>();
this.flag = 0;
}
@@ -67,7 +67,7 @@ public class Item implements Comparable<Item> {
}
this.petid = petid;
this.flag = 0;
this.log = new LinkedList<>();
this.itemLog = new LinkedList<>();
}
public Item copy() {
@@ -75,7 +75,7 @@ public class Item implements Comparable<Item> {
ret.flag = flag;
ret.owner = owner;
ret.expiration = expiration;
ret.log = new LinkedList<>(log);
ret.itemLog = new LinkedList<>(itemLog);
return ret;
}
@@ -147,8 +147,8 @@ public class Item implements Comparable<Item> {
return "Item: " + id + " quantity: " + quantity;
}
public List<String> getLog() {
return Collections.unmodifiableList(log);
public List<String> getItemLog() {
return Collections.unmodifiableList(itemLog);
}
public short getFlag() {

View File

@@ -29,9 +29,10 @@ import client.newyear.NewYearCardRecord;
import config.YamlConfig;
import constants.id.ItemId;
import constants.inventory.ItemConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.ItemInformationProvider;
import server.maps.MapleMap;
import tools.FilePrinter;
import tools.PacketCreator;
import java.awt.*;
@@ -45,6 +46,7 @@ import java.util.List;
* @author Ronan - improved check space feature and removed redundant object calls
*/
public class InventoryManipulator {
private static final Logger log = LoggerFactory.getLogger(InventoryManipulator.class);
public static boolean addById(Client c, int itemId, short quantity) {
return addById(c, itemId, quantity, null, -1, -1);
@@ -269,7 +271,7 @@ public class InventoryManipulator {
chr.setHasSandboxItem();
}
} else {
FilePrinter.printError(FilePrinter.ITEM, "Tried to pickup Equip id " + itemid + " containing more than 1 quantity --> " + quantity);
log.warn("Tried to pickup Equip id {} containing more than 1 quantity --> {}", itemid, quantity);
c.sendPacket(PacketCreator.getInventoryFull());
c.sendPacket(PacketCreator.showItemUnavailable());
return false;

View File

@@ -30,10 +30,11 @@ import constants.game.GameConstants;
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.MakerItemFactory;
import server.MakerItemFactory.MakerItemCreateEntry;
import tools.FilePrinter;
import tools.PacketCreator;
import tools.Pair;
@@ -46,7 +47,7 @@ import java.util.Map;
* @author Ronan
*/
public class MakerProcessor {
private static final Logger log = LoggerFactory.getLogger(MakerProcessor.class);
private static final ItemInformationProvider ii = ItemInformationProvider.getInstance();
public static void makerAction(InPacket p, Client c) {
@@ -150,7 +151,7 @@ public class MakerProcessor {
switch (createStatus) {
case -1:// non-available for Maker itemid has been tried to forge
FilePrinter.printError(FilePrinter.EXPLOITS, "Player " + c.getPlayer().getName() + " tried to craft itemid " + toCreate + " using the Maker skill.");
log.warn("Chr {} tried to craft itemid {} using the Maker skill.", c.getPlayer().getName(), toCreate);
c.sendPacket(PacketCreator.serverNotice(1, "The requested item could not be crafted on this operation."));
c.sendPacket(PacketCreator.makerEnableActions());
break;

View File

@@ -36,11 +36,12 @@ import config.YamlConfig;
import constants.id.ItemId;
import constants.inventory.ItemConstants;
import net.server.channel.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import server.DueyPackage;
import server.ItemInformationProvider;
import server.Trade;
import tools.DatabaseConnection;
import tools.FilePrinter;
import tools.PacketCreator;
import tools.Pair;
@@ -54,6 +55,7 @@ import java.util.List;
* @author RonanLana - synchronization of Duey modules
*/
public class DueyProcessor {
private static final Logger log = LoggerFactory.getLogger(DueyProcessor.class);
public enum Actions {
TOSERVER_RECV_ITEM(0x00),
@@ -204,7 +206,7 @@ public class DueyProcessor {
int updateRows = ps.executeUpdate();
if (updateRows < 1) {
FilePrinter.printError(FilePrinter.INSERT_CHAR, "Error trying to create package [mesos: " + mesos + ", " + sender + ", quick: " + quick + ", to CharacterId: " + toCid + "]");
log.error("Error trying to create package [mesos: {}, sender: {}, quick: {}, receiver chrId: {}]", mesos, sender, quick, toCid);
return -1;
}
@@ -213,7 +215,7 @@ public class DueyProcessor {
if (rs.next()) {
packageId = rs.getInt(1);
} else {
FilePrinter.printError(FilePrinter.INSERT_CHAR, "Failed inserting package [mesos: " + mesos + ", " + sender + ", quick: " + quick + ", to CharacterId: " + toCid + "]");
log.error("Failed inserting package [mesos: {}, sender: {}, quick: {}, receiver chrId: {}]", mesos, sender, quick, toCid);
return -1;
}
}
@@ -287,7 +289,7 @@ public class DueyProcessor {
fee += 5000;
} else if (!c.getPlayer().haveItem(ItemId.QUICK_DELIVERY_TICKET)) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with Quick Delivery on duey.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to use duey with Quick Delivery, mesos " + sendMesos + " and amount " + amount);
log.warn("Chr {} tried to use duey with Quick Delivery without a ticket, mesos {} and amount {}", c.getPlayer().getName(), sendMesos, amount);
c.disconnect(true, false);
return;
}
@@ -295,7 +297,7 @@ public class DueyProcessor {
long finalcost = (long) sendMesos + fee;
if (finalcost < 0 || finalcost > Integer.MAX_VALUE || (amount < 1 && sendMesos == 0)) {
AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit with duey.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to use duey with mesos " + sendMesos + " and amount " + amount);
log.warn("Chr {} tried to use duey with mesos {} and amount {}", c.getPlayer().getName(), sendMesos, amount);
c.disconnect(true, false);
return;
}
@@ -394,7 +396,7 @@ public class DueyProcessor {
if (dp == null) {
c.sendPacket(PacketCreator.sendDueyMSG(Actions.TOCLIENT_RECV_UNKNOWN_ERROR.getCode()));
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to receive package from duey with id " + packageId);
log.warn("Chr {} tried to receive package from duey with id {}", c.getPlayer().getName(), packageId);
return;
}

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

View File

@@ -30,13 +30,15 @@ import client.SkillFactory;
import client.autoban.AutobanFactory;
import constants.game.GameConstants;
import constants.skills.Aran;
import tools.FilePrinter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tools.PacketCreator;
/**
* @author RonanLana - synchronization of SP transaction modules
*/
public class AssignSPProcessor {
private static final Logger log = LoggerFactory.getLogger(AssignSPProcessor.class);
public static boolean canSPAssign(Client c, int skillid) {
if (skillid == Aran.HIDDEN_FULL_DOUBLE || skillid == Aran.HIDDEN_FULL_TRIPLE || skillid == Aran.HIDDEN_OVER_DOUBLE || skillid == Aran.HIDDEN_OVER_TRIPLE) {
@@ -47,7 +49,7 @@ public class AssignSPProcessor {
Character player = c.getPlayer();
if ((!GameConstants.isPqSkillMap(player.getMapId()) && GameConstants.isPqSkill(skillid)) || (!player.isGM() && GameConstants.isGMSkills(skillid)) || (!GameConstants.isInJobTree(skillid, player.getJob().getId()) && !player.isGM())) {
AutobanFactory.PACKET_EDIT.alert(player, "tried to packet edit in distributing sp.");
FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to use skill " + skillid + " without it being in their job.");
log.warn("Chr {} tried to use skill {} without it being in their job.", c.getPlayer().getName(), skillid);
c.disconnect(true, false);
return false;