public static void editBBSThread( MapleClient client, String title, String text, int icon, int localthreadid) { MapleCharacter c = client.getPlayer(); if (c.getGuildId() <= 0) { return; // expelled while viewing? } try { Connection con = DatabaseConnection.getConnection(); PreparedStatement ps = con.prepareStatement( "UPDATE bbs_threads SET " + "`name` = ?, " + "`timestamp` = ?, " + "`icon` = ?, " + "`startpost` = ? " + "WHERE guildid = ? AND localthreadid = ? AND (postercid = ? OR ?)"); ps.setString(1, title); ps.setLong(2, System.currentTimeMillis()); ps.setInt(3, icon); ps.setString(4, text); ps.setInt(5, c.getGuildId()); ps.setInt(6, localthreadid); ps.setInt(7, c.getId()); ps.setBoolean(8, c.getGuildRank() <= 2); ps.execute(); ps.close(); displayThread(client, localthreadid); } catch (SQLException se) { log.error("SQLException: " + se.getLocalizedMessage(), se); } }
@Override public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) { int oid = slea.readInt(); Point startPos = StreamUtil.readShortPoint(slea); List<LifeMovementFragment> res = parseMovement(slea); MapleCharacter player = c.getPlayer(); Collection<MapleSummon> summons = player.getSummons().values(); MapleSummon summon = null; for (MapleSummon sum : summons) { if (sum.getObjectId() == oid) { summon = sum; } } if (summon != null) { updatePosition(res, summon, 0); // player = ((MapleCharacter) c.getPlayer().getMap().getMapObject(30000)); player .getMap() .broadcastMessage( player, MaplePacketCreator.moveSummon(player.getId(), oid, startPos, res), summon.getPosition()); } }
public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) { byte mode = slea.readByte(); if (mode == 6) { // whisper String recipient = slea.readMapleAsciiString(); String text = slea.readMapleAsciiString(); if (!CommandProcessor.getInstance().processCommand(c, text)) { MapleCharacter player = c.getChannelServer().getPlayerStorage().getCharacterByName(recipient); if (player != null) { player .getClient() .getSession() .write(MaplePacketCreator.getWhisper(c.getPlayer().getName(), c.getChannel(), text)); c.getSession().write(MaplePacketCreator.getWhisperReply(recipient, (byte) 1)); } else { // not found try { if (ChannelServer.getInstance(c.getChannel()) .getWorldInterface() .isConnected(recipient)) { ChannelServer.getInstance(c.getChannel()) .getWorldInterface() .whisper(c.getPlayer().getName(), recipient, c.getChannel(), text); c.getSession().write(MaplePacketCreator.getWhisperReply(recipient, (byte) 1)); } else { c.getSession().write(MaplePacketCreator.getWhisperReply(recipient, (byte) 0)); } } catch (RemoteException e) { c.getSession().write(MaplePacketCreator.getWhisperReply(recipient, (byte) 0)); c.getChannelServer().reconnectWorld(); } } } } else if (mode == 5) { // - /find String recipient = slea.readMapleAsciiString(); MapleCharacter player = c.getChannelServer().getPlayerStorage().getCharacterByName(recipient); if (player != null && (c.getPlayer().isGM() || !player.isHidden())) { if (player.inCS()) { c.getSession().write(MaplePacketCreator.getFindReplyWithCS(player.getName())); } else { c.getSession() .write( MaplePacketCreator.getFindReplyWithMap( player.getName(), player.getMap().getId())); } } else { // not found try { int channel = ChannelServer.getInstance(c.getChannel()).getWorldInterface().find(recipient); if (channel > -1) { c.getSession().write(MaplePacketCreator.getFindReply(recipient, channel)); } else { c.getSession().write(MaplePacketCreator.getWhisperReply(recipient, (byte) 0)); } } catch (RemoteException e) { c.getChannelServer().reconnectWorld(); } } } }
public static void deleteBBSReply(MapleClient client, int replyid) { MapleCharacter mc = client.getPlayer(); if (mc.getGuildId() <= 0) { return; } int threadid; Connection con = DatabaseConnection.getConnection(); try { PreparedStatement ps = con.prepareStatement("SELECT postercid, threadid FROM bbs_replies WHERE replyid = ?"); ps.setInt(1, replyid); ResultSet rs = ps.executeQuery(); if (!rs.next()) { rs.close(); ps.close(); return; // reply no longer exists, deleted already? } if (mc.getId() != rs.getInt("postercid") && mc.getGuildRank() > 2) { rs.close(); ps.close(); return; // [hax] deleting a reply that he didn't make } threadid = rs.getInt("threadid"); rs.close(); ps.close(); ps = con.prepareStatement("DELETE FROM bbs_replies WHERE replyid = ?"); ps.setInt(1, replyid); ps.execute(); ps.close(); ps = con.prepareStatement( "UPDATE bbs_threads SET replycount = replycount - 1 WHERE threadid = ?"); ps.setInt(1, threadid); ps.execute(); ps.close(); displayThread(client, threadid, false); } catch (SQLException se) { log.error("SQLException: " + se.getLocalizedMessage(), se); } }
public static void newBBSThread( MapleClient client, String title, String text, int icon, boolean bNotice) { MapleCharacter c = client.getPlayer(); if (c.getGuildId() <= 0) { return; // expelled while viewing? } int nextId = 0; try { Connection con = DatabaseConnection.getConnection(); PreparedStatement ps; if (!bNotice) { ps = con.prepareStatement( "SELECT MAX(localthreadid) AS lastLocalId FROM bbs_threads WHERE guildid = ?"); ps.setInt(1, c.getGuildId()); ResultSet rs = ps.executeQuery(); rs.next(); nextId = rs.getInt("lastLocalId") + 1; rs.close(); ps.close(); } ps = con.prepareStatement( "INSERT INTO bbs_threads " + "(`postercid`, `name`, `timestamp`, `icon`, `startpost`, " + "`guildid`, `localthreadid`) " + "VALUES(?, ?, ?, ?, ?, ?, ?)"); ps.setInt(1, c.getId()); ps.setString(2, title); ps.setLong(3, System.currentTimeMillis()); ps.setInt(4, icon); ps.setString(5, text); ps.setInt(6, c.getGuildId()); ps.setInt(7, nextId); ps.execute(); ps.close(); displayThread(client, nextId); } catch (SQLException se) { log.error("SQLException: " + se.getLocalizedMessage(), se); } }
public static void newBBSReply(MapleClient client, int localthreadid, String text) { MapleCharacter mc = client.getPlayer(); if (mc.getGuildId() <= 0) { return; } Connection con = DatabaseConnection.getConnection(); try { PreparedStatement ps = con.prepareStatement( "SELECT threadid FROM bbs_threads WHERE guildid = ? AND localthreadid = ?"); ps.setInt(1, mc.getGuildId()); ps.setInt(2, localthreadid); ResultSet threadRS = ps.executeQuery(); if (!threadRS.next()) { return; // thread no longer exists, deleted? } int threadid = threadRS.getInt("threadid"); threadRS.close(); ps.close(); ps = con.prepareStatement( "INSERT INTO bbs_replies (`threadid`, `postercid`, `timestamp`, `content`) VALUES " + "(?, ?, ?, ?)"); ps.setInt(1, threadid); ps.setInt(2, mc.getId()); ps.setLong(3, System.currentTimeMillis()); ps.setString(4, text); ps.execute(); ps.close(); ps = con.prepareStatement( "UPDATE bbs_threads SET replycount = replycount + 1 WHERE threadid = ?"); ps.setInt(1, threadid); ps.execute(); ps.close(); displayThread(client, localthreadid); } catch (SQLException se) { log.error("SQLException: " + se.getLocalizedMessage(), se); } }
public static void deleteBBSThread(MapleClient client, int localthreadid) { MapleCharacter mc = client.getPlayer(); if (mc.getGuildId() <= 0) { return; } Connection con = DatabaseConnection.getConnection(); try { PreparedStatement ps = con.prepareStatement( "SELECT threadid, postercid FROM bbs_threads WHERE guildid = ? AND localthreadid = ?"); ps.setInt(1, mc.getGuildId()); ps.setInt(2, localthreadid); ResultSet threadRS = ps.executeQuery(); if (!threadRS.next()) { threadRS.close(); ps.close(); return; // thread no longer exists, deleted? } if (mc.getId() != threadRS.getInt("postercid") && mc.getGuildRank() > 2) { threadRS.close(); ps.close(); return; // [hax] deleting a thread that he didn't make } int threadid = threadRS.getInt("threadid"); threadRS.close(); ps.close(); ps = con.prepareStatement("DELETE FROM bbs_replies WHERE threadid = ?"); ps.setInt(1, threadid); ps.execute(); ps.close(); ps = con.prepareStatement("DELETE FROM bbs_threads WHERE threadid = ?"); ps.setInt(1, threadid); ps.execute(); ps.close(); } catch (SQLException se) { log.error("SQLException: " + se.getLocalizedMessage(), se); } }
public static void displayThread(MapleClient client, int threadid, boolean bIsThreadIdLocal) { MapleCharacter mc = client.getPlayer(); if (mc.getGuildId() <= 0) { return; } Connection con = DatabaseConnection.getConnection(); try { PreparedStatement ps = con.prepareStatement( "SELECT * FROM bbs_threads WHERE guildid = ? AND " + (bIsThreadIdLocal ? "local" : "") + "threadid = ?"); ps.setInt(1, mc.getGuildId()); ps.setInt(2, threadid); ResultSet threadRS = ps.executeQuery(); if (!threadRS.next()) { threadRS.close(); ps.close(); return; // thread no longer exists, deleted? } ResultSet repliesRS = null; PreparedStatement ps2 = null; if (threadRS.getInt("replycount") > 0) { ps2 = con.prepareStatement("SELECT * FROM bbs_replies WHERE threadid = ?"); ps2.setInt(1, !bIsThreadIdLocal ? threadid : threadRS.getInt("threadid")); repliesRS = ps2.executeQuery(); // the lack of repliesRS.next() is intentional } client .getSession() .write( MaplePacketCreator.showThread( bIsThreadIdLocal ? threadid : threadRS.getInt("localthreadid"), threadRS, repliesRS)); if (ps2 != null) { ps2.close(); } if (repliesRS != null) { repliesRS.close(); } threadRS.close(); ps.close(); } catch (SQLException se) { log.error("SQLException: " + se.getLocalizedMessage(), se); } catch (RuntimeException re) { log.error( "The number of reply rows does not match the replycount in thread. ThreadId = " + re.getMessage(), re); try { PreparedStatement ps = con.prepareStatement("DELETE FROM bbs_threads WHERE threadid = ?"); ps.setInt(1, Integer.parseInt(re.getMessage())); ps.execute(); ps.close(); ps = con.prepareStatement("DELETE FROM bbs_replies WHERE threadid = ?"); ps.setInt(1, Integer.parseInt(re.getMessage())); ps.execute(); ps.close(); } catch (Exception e) { } } }