use of client.MapleCharacter in project HeavenMS by ronancpl.
the class BuddylistModifyHandler method handlePacket.
@Override
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int mode = slea.readByte();
MapleCharacter player = c.getPlayer();
BuddyList buddylist = player.getBuddylist();
if (mode == 1) {
// add
String addName = slea.readMapleAsciiString();
String group = slea.readMapleAsciiString();
if (group.length() > 16 || addName.length() < 4 || addName.length() > 13) {
// hax.
return;
}
BuddylistEntry ble = buddylist.get(addName);
if (ble != null && !ble.isVisible() && group.equals(ble.getGroup())) {
c.announce(MaplePacketCreator.serverNotice(1, "You already have \"" + ble.getName() + "\" on your Buddylist"));
} else if (buddylist.isFull() && ble == null) {
c.announce(MaplePacketCreator.serverNotice(1, "Your buddylist is already full"));
} else if (ble == null) {
try {
World world = c.getWorldServer();
CharacterIdNameBuddyCapacity charWithId;
int channel;
MapleCharacter otherChar = c.getChannelServer().getPlayerStorage().getCharacterByName(addName);
if (otherChar != null) {
channel = c.getChannel();
charWithId = new CharacterIdNameBuddyCapacity(otherChar.getId(), otherChar.getName(), otherChar.getBuddylist().getCapacity());
} else {
channel = world.find(addName);
charWithId = getCharacterIdAndNameFromDatabase(addName);
}
if (charWithId != null) {
BuddyAddResult buddyAddResult = null;
if (channel != -1) {
buddyAddResult = world.requestBuddyAdd(addName, c.getChannel(), player.getId(), player.getName());
} else {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) as buddyCount FROM buddies WHERE characterid = ? AND pending = 0");
ps.setInt(1, charWithId.getId());
ResultSet rs = ps.executeQuery();
if (!rs.next()) {
throw new RuntimeException("Result set expected");
} else if (rs.getInt("buddyCount") >= charWithId.getBuddyCapacity()) {
buddyAddResult = BuddyAddResult.BUDDYLIST_FULL;
}
rs.close();
ps.close();
ps = con.prepareStatement("SELECT pending FROM buddies WHERE characterid = ? AND buddyid = ?");
ps.setInt(1, charWithId.getId());
ps.setInt(2, player.getId());
rs = ps.executeQuery();
if (rs.next()) {
buddyAddResult = BuddyAddResult.ALREADY_ON_LIST;
}
rs.close();
ps.close();
con.close();
}
if (buddyAddResult == BuddyAddResult.BUDDYLIST_FULL) {
c.announce(MaplePacketCreator.serverNotice(1, "\"" + addName + "\"'s Buddylist is full"));
} else {
int displayChannel;
displayChannel = -1;
int otherCid = charWithId.getId();
if (buddyAddResult == BuddyAddResult.ALREADY_ON_LIST && channel != -1) {
displayChannel = channel;
notifyRemoteChannel(c, channel, otherCid, ADDED);
} else if (buddyAddResult != BuddyAddResult.ALREADY_ON_LIST && channel == -1) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("INSERT INTO buddies (characterid, `buddyid`, `pending`) VALUES (?, ?, 1)")) {
ps.setInt(1, charWithId.getId());
ps.setInt(2, player.getId());
ps.executeUpdate();
}
con.close();
}
buddylist.put(new BuddylistEntry(charWithId.getName(), group, otherCid, displayChannel, true));
c.announce(MaplePacketCreator.updateBuddylist(buddylist.getBuddies()));
}
} else {
c.announce(MaplePacketCreator.serverNotice(1, "A character called \"" + addName + "\" does not exist"));
}
} catch (SQLException e) {
e.printStackTrace();
}
} else {
ble.changeGroup(group);
c.announce(MaplePacketCreator.updateBuddylist(buddylist.getBuddies()));
}
} else if (mode == 2) {
// accept buddy
int otherCid = slea.readInt();
if (!buddylist.isFull()) {
try {
// worldInterface.find(otherCid);
int channel = c.getWorldServer().find(otherCid);
String otherName = null;
MapleCharacter otherChar = c.getChannelServer().getPlayerStorage().getCharacterById(otherCid);
if (otherChar == null) {
Connection con = DatabaseConnection.getConnection();
try (PreparedStatement ps = con.prepareStatement("SELECT name FROM characters WHERE id = ?")) {
ps.setInt(1, otherCid);
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
otherName = rs.getString("name");
}
}
}
con.close();
} else {
otherName = otherChar.getName();
}
if (otherName != null) {
buddylist.put(new BuddylistEntry(otherName, "Default Group", otherCid, channel, true));
c.announce(MaplePacketCreator.updateBuddylist(buddylist.getBuddies()));
notifyRemoteChannel(c, channel, otherCid, ADDED);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
nextPendingRequest(c);
} else if (mode == 3) {
// delete
int otherCid = slea.readInt();
player.deleteBuddy(otherCid);
}
}
use of client.MapleCharacter in project HeavenMS by ronancpl.
the class CancelChairHandler method handlePacket.
@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
int id = slea.readShort();
MapleCharacter mc = c.getPlayer();
if (id == -1) {
// Cancel Chair
mc.setChair(0);
mc.unregisterChairBuff();
c.announce(MaplePacketCreator.cancelChair(-1));
c.getPlayer().getMap().broadcastMessage(c.getPlayer(), MaplePacketCreator.showChair(c.getPlayer().getId(), 0), false);
} else {
// Use In-Map Chair
mc.setChair(id);
mc.registerChairBuff();
c.announce(MaplePacketCreator.cancelChair(id));
}
}
use of client.MapleCharacter in project HeavenMS by ronancpl.
the class NewYearCardRecord method startNewYearCardTask.
public void startNewYearCardTask() {
if (sendTask != null)
return;
sendTask = TimerManager.getInstance().register(new Runnable() {
@Override
public void run() {
int world = getCharacterWorld(receiverId);
if (world == -1) {
sendTask.cancel(false);
sendTask = null;
return;
}
MapleCharacter target = Server.getInstance().getWorld(world).getPlayerStorage().getCharacterById(receiverId);
if (target != null && target.isLoggedin() && !target.isAwayFromWorld()) {
target.announce(MaplePacketCreator.onNewYearCardRes(target, NewYearCardRecord.this, 0xC, 0));
}
}
}, // 1 Hour
1000 * 60 * 60);
}
use of client.MapleCharacter in project HeavenMS by ronancpl.
the class AbstractPlayerInteraction method givePartyItems.
public void givePartyItems(int id, short quantity, List<MapleCharacter> party) {
for (MapleCharacter chr : party) {
MapleClient cl = chr.getClient();
if (quantity >= 0) {
MapleInventoryManipulator.addById(cl, id, quantity);
} else {
MapleInventoryManipulator.removeById(cl, ItemConstants.getInventoryType(id), id, -quantity, true, false);
}
cl.announce(MaplePacketCreator.getShowItemGain(id, quantity, true));
}
}
use of client.MapleCharacter in project HeavenMS by ronancpl.
the class AbstractPlayerInteraction method givePartyExp.
public void givePartyExp(String PQ, boolean instance) {
// 1 player = +0% bonus (100)
// 2 players = +0% bonus (100)
// 3 players = +0% bonus (100)
// 4 players = +10% bonus (110)
// 5 players = +20% bonus (120)
// 6 players = +30% bonus (130)
MapleParty party = getPlayer().getParty();
int size = party.getMembers().size();
if (instance) {
for (MaplePartyCharacter member : party.getMembers()) {
if (member == null || !member.isOnline() || member.getPlayer().getEventInstance() == null) {
size--;
}
}
}
int bonus = size < 4 ? 100 : 70 + (size * 10);
for (MaplePartyCharacter member : party.getMembers()) {
if (member == null || !member.isOnline()) {
continue;
}
MapleCharacter player = member.getPlayer();
if (instance && player.getEventInstance() == null) {
// They aren't in the instance, don't give EXP.
continue;
}
int base = PartyQuest.getExp(PQ, player.getLevel());
int exp = base * bonus / 100;
player.gainExp(exp, true, true);
if (ServerConstants.PQ_BONUS_EXP_RATE > 0 && System.currentTimeMillis() <= ServerConstants.EVENT_END_TIMESTAMP) {
player.gainExp((int) (exp * ServerConstants.PQ_BONUS_EXP_RATE), true, true);
}
}
}
Aggregations