Get rid of Character#sendNote, refactor usages of it
This commit is contained in:
@@ -8795,18 +8795,6 @@ public class Character extends AbstractCharacterObject {
|
|||||||
return skillMacros;
|
return skillMacros;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendNote(String to, String msg, byte fame) throws SQLException {
|
|
||||||
try (Connection con = DatabaseConnection.getConnection();
|
|
||||||
PreparedStatement ps = con.prepareStatement("INSERT INTO notes (`to`, `from`, `message`, `timestamp`, `fame`) VALUES (?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS)) {
|
|
||||||
ps.setString(1, to);
|
|
||||||
ps.setString(2, this.getName());
|
|
||||||
ps.setString(3, msg);
|
|
||||||
ps.setLong(4, Server.getInstance().getCurrentTime());
|
|
||||||
ps.setByte(5, fame);
|
|
||||||
ps.executeUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setAriantRoomLeader(int room, String charname) {
|
public static void setAriantRoomLeader(int room, String charname) {
|
||||||
ariantroomleader[room] = charname;
|
ariantroomleader[room] = charname;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ import client.inventory.manipulator.InventoryManipulator;
|
|||||||
import config.YamlConfig;
|
import config.YamlConfig;
|
||||||
import constants.id.ItemId;
|
import constants.id.ItemId;
|
||||||
import constants.inventory.ItemConstants;
|
import constants.inventory.ItemConstants;
|
||||||
|
import database.DaoException;
|
||||||
|
import database.NoteDao;
|
||||||
|
import model.Note;
|
||||||
import net.AbstractPacketHandler;
|
import net.AbstractPacketHandler;
|
||||||
import net.packet.InPacket;
|
import net.packet.InPacket;
|
||||||
import net.server.Server;
|
import net.server.Server;
|
||||||
@@ -128,11 +131,9 @@ public final class CashOperationHandler extends AbstractPacketHandler {
|
|||||||
cs.gift(Integer.parseInt(recipient.get("id")), chr.getName(), message, cItem.getSN());
|
cs.gift(Integer.parseInt(recipient.get("id")), chr.getName(), message, cItem.getSN());
|
||||||
c.sendPacket(PacketCreator.showGiftSucceed(recipient.get("name"), cItem));
|
c.sendPacket(PacketCreator.showGiftSucceed(recipient.get("name"), cItem));
|
||||||
c.sendPacket(PacketCreator.showCash(chr));
|
c.sendPacket(PacketCreator.showCash(chr));
|
||||||
try {
|
|
||||||
chr.sendNote(recipient.get("name"), chr.getName() + " has sent you a gift! Go check out the Cash Shop.", (byte) 0); //fame or not
|
sendGiftNotificationNote(chr.getName(), recipient.get("name"));
|
||||||
} catch (SQLException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
Character receiver = c.getChannelServer().getPlayerStorage().getCharacterByName(recipient.get("name"));
|
Character receiver = c.getChannelServer().getPlayerStorage().getCharacterByName(recipient.get("name"));
|
||||||
if (receiver != null) {
|
if (receiver != null) {
|
||||||
receiver.showNote();
|
receiver.showNote();
|
||||||
@@ -330,11 +331,7 @@ public final class CashOperationHandler extends AbstractPacketHandler {
|
|||||||
cs.gainCash(toCharge, itemRing, chr.getWorld());
|
cs.gainCash(toCharge, itemRing, chr.getWorld());
|
||||||
cs.gift(partner.getId(), chr.getName(), text, eqp.getSN(), rings.getRight());
|
cs.gift(partner.getId(), chr.getName(), text, eqp.getSN(), rings.getRight());
|
||||||
chr.addCrushRing(Ring.loadFromDb(rings.getLeft()));
|
chr.addCrushRing(Ring.loadFromDb(rings.getLeft()));
|
||||||
try {
|
sendGiftNote(text, chr.getName(), partner.getName());
|
||||||
chr.sendNote(partner.getName(), text, (byte) 1);
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
partner.showNote();
|
partner.showNote();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -393,11 +390,7 @@ public final class CashOperationHandler extends AbstractPacketHandler {
|
|||||||
cs.gainCash(payment, -itemRing.getPrice());
|
cs.gainCash(payment, -itemRing.getPrice());
|
||||||
cs.gift(partner.getId(), chr.getName(), text, eqp.getSN(), rings.getRight());
|
cs.gift(partner.getId(), chr.getName(), text, eqp.getSN(), rings.getRight());
|
||||||
chr.addFriendshipRing(Ring.loadFromDb(rings.getLeft()));
|
chr.addFriendshipRing(Ring.loadFromDb(rings.getLeft()));
|
||||||
try {
|
sendGiftNote(text, chr.getName(), partner.getName());
|
||||||
chr.sendNote(partner.getName(), text, (byte) 1);
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
partner.showNote();
|
partner.showNote();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -494,4 +487,23 @@ public final class CashOperationHandler extends AbstractPacketHandler {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendGiftNote(String message, String from, String to) {
|
||||||
|
Note giftNote = Note.createGift(message, from, to, Server.getInstance().getCurrentTime());
|
||||||
|
sendGiftNote(giftNote);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendGiftNotificationNote(String from, String to) {
|
||||||
|
String message = from + " has sent you a gift! Go check out the Cash Shop.";
|
||||||
|
Note giftNotificationNote = Note.createNormal(message, from, to, Server.getInstance().getCurrentTime());
|
||||||
|
sendGiftNote(giftNotificationNote);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendGiftNote(Note giftNote) {
|
||||||
|
try {
|
||||||
|
NoteDao.save(giftNote);
|
||||||
|
} catch (DaoException e) {
|
||||||
|
log.error("Failed to send gift note {}", giftNote, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import database.NoteDao;
|
|||||||
import model.Note;
|
import model.Note;
|
||||||
import net.AbstractPacketHandler;
|
import net.AbstractPacketHandler;
|
||||||
import net.packet.InPacket;
|
import net.packet.InPacket;
|
||||||
|
import net.server.Server;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import tools.PacketCreator;
|
import tools.PacketCreator;
|
||||||
@@ -40,20 +41,18 @@ public final class NoteActionHandler extends AbstractPacketHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void handlePacket(InPacket p, Client c) {
|
public void handlePacket(InPacket p, Client c) {
|
||||||
int action = p.readByte();
|
int action = p.readByte();
|
||||||
if (action == 0 && c.getPlayer().getCashShop().getAvailableNotes() > 0) {
|
if (action == 0 && c.getPlayer().getCashShop().getAvailableNotes() > 0) { // Reply to gift in cash shop
|
||||||
String charname = p.readString();
|
String charname = p.readString();
|
||||||
String message = p.readString();
|
String message = p.readString();
|
||||||
try {
|
if (c.getPlayer().getCashShop().isOpened()) {
|
||||||
if (c.getPlayer().getCashShop().isOpened()) {
|
c.sendPacket(PacketCreator.showCashInventory(c));
|
||||||
c.sendPacket(PacketCreator.showCashInventory(c));
|
|
||||||
}
|
|
||||||
|
|
||||||
c.getPlayer().sendNote(charname, message, (byte) 1);
|
|
||||||
c.getPlayer().getCashShop().decreaseNotes();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
} else if (action == 1) {
|
|
||||||
|
boolean sendNoteSuccess = sendGiftReplyNote(message, c.getPlayer().getName(), charname);
|
||||||
|
if (sendNoteSuccess) {
|
||||||
|
c.getPlayer().getCashShop().decreaseNotes();
|
||||||
|
}
|
||||||
|
} else if (action == 1) { // Discard notes in game
|
||||||
int num = p.readByte();
|
int num = p.readByte();
|
||||||
p.readByte();
|
p.readByte();
|
||||||
p.readByte();
|
p.readByte();
|
||||||
@@ -82,4 +81,16 @@ public final class NoteActionHandler extends AbstractPacketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean sendGiftReplyNote(String message, String from, String to) {
|
||||||
|
Note giftReplyNote = Note.createGift(message, from, to, Server.getInstance().getCurrentTime());
|
||||||
|
try {
|
||||||
|
NoteDao.save(giftReplyNote);
|
||||||
|
} catch (DaoException e) {
|
||||||
|
log.error("Failed to send gift reply note {}", giftReplyNote, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ import constants.game.GameConstants;
|
|||||||
import constants.id.ItemId;
|
import constants.id.ItemId;
|
||||||
import constants.id.MapId;
|
import constants.id.MapId;
|
||||||
import constants.inventory.ItemConstants;
|
import constants.inventory.ItemConstants;
|
||||||
|
import database.DaoException;
|
||||||
|
import database.NoteDao;
|
||||||
|
import model.Note;
|
||||||
import net.AbstractPacketHandler;
|
import net.AbstractPacketHandler;
|
||||||
import net.packet.InPacket;
|
import net.packet.InPacket;
|
||||||
import net.server.Server;
|
import net.server.Server;
|
||||||
@@ -358,10 +361,11 @@ public final class UseCashItemHandler extends AbstractPacketHandler {
|
|||||||
} else if (itemType == 509) {
|
} else if (itemType == 509) {
|
||||||
String sendTo = p.readString();
|
String sendTo = p.readString();
|
||||||
String msg = p.readString();
|
String msg = p.readString();
|
||||||
|
Note note = Note.createNormal(msg, player.getName(), sendTo, Server.getInstance().getCurrentTime());
|
||||||
try {
|
try {
|
||||||
player.sendNote(sendTo, msg, (byte) 0);
|
NoteDao.save(note);
|
||||||
} catch (SQLException e) {
|
} catch (DaoException e) {
|
||||||
e.printStackTrace();
|
log.error("Failed to save note {}", note, e);
|
||||||
}
|
}
|
||||||
remove(c, position, itemId);
|
remove(c, position, itemId);
|
||||||
} else if (itemType == 510) {
|
} else if (itemType == 510) {
|
||||||
|
|||||||
Reference in New Issue
Block a user