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(); } } } }
@Override public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) { int load = 0; for (ChannelServer cservs : ChannelServer.getAllInstances()) { load += LoginServer.getInstance().getLoad().get(cservs.getChannel()); } if (LoginServer.getInstance().getUserLimit() <= load) { c.getSession().write(MaplePacketCreator.getServerStatus(2)); } else if (LoginServer.getInstance().getUserLimit() * 0.9 <= load) { c.getSession().write(MaplePacketCreator.getServerStatus(1)); } else { c.getSession().write(MaplePacketCreator.getServerStatus(0)); } }
public static void listBBSThreads(MapleClient c, int start) { int gid = c.getPlayer().getGuildId(); try { Connection con = DatabaseConnection.getConnection(); PreparedStatement ps = con.prepareStatement( "SELECT * FROM bbs_threads WHERE guildid = ? ORDER BY localthreadid DESC"); ps.setInt(1, gid); ResultSet rs = ps.executeQuery(); c.getSession().write(MaplePacketCreator.BBSThreadList(rs, start)); rs.close(); ps.close(); } catch (SQLException se) { log.error("SQLException: " + se.getLocalizedMessage(), se); } }
@Override public void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) { if (!MapleGuild.ENABLE_BBS) { c.getSession() .write( MaplePacketCreator.serverNotice( 1, "Your server administrator has currently disabled Guild BBS.")); return; } if (c.getPlayer().getGuildId() <= 0) { return; // expelled while viewing bbs or hax } byte mode = slea.readByte(); int localthreadid = 0; switch (mode) { case 0: // start a new post boolean bEdit = slea.readByte() == 1 ? true : false; if (bEdit) { localthreadid = slea.readInt(); } boolean bNotice = slea.readByte() == 1 ? true : false; String title = correctLength(slea.readMapleAsciiString(), 25); String text = correctLength(slea.readMapleAsciiString(), 600); int icon = slea.readInt(); if (icon >= 0x64 && icon <= 0x6a) { if (!c.getPlayer().haveItem(5290000 + icon - 0x64, 1, false, true)) { return; // hax, using an nx icon that s/he doesn't have } } else if (!(icon >= 0 && icon <= 2)) { return; // hax, using an invalid icon } if (!bEdit) { newBBSThread(c, title, text, icon, bNotice); } else { editBBSThread(c, title, text, icon, localthreadid); } break; case 1: // delete a thread localthreadid = slea.readInt(); deleteBBSThread(c, localthreadid); break; case 2: int start = slea.readInt(); // list threads listBBSThreads(c, start * 10); break; case 3: // list thread + reply, followed by id (int) localthreadid = slea.readInt(); displayThread(c, localthreadid); break; case 4: // reply localthreadid = slea.readInt(); text = correctLength(slea.readMapleAsciiString(), 25); newBBSReply(c, localthreadid, text); break; case 5: // delete reply localthreadid = slea.readInt(); // we don't use this int replyid = slea.readInt(); deleteBBSReply(c, replyid); break; default: log.warn("Unhandled BBS mode: " + mode); } }
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) { } } }