StringTokenizer st = new StringTokenizer(bypass, "_");
String cmd = st.nextToken();
player.setSessionVar("add_fav", null);
if ("bbsclan".equals(cmd))
{
Clan clan = player.getClan();
if ((clan != null) && (clan.getLevel() > 1))
{
onBypassCommand(player, "_clbbsclan_" + player.getClanId());
return;
}
onBypassCommand(player, "_clbbslist_1_0_");
}
else if ("clbbslist".equals(cmd))
{
int page = Integer.parseInt(st.nextToken());
int byCL = Integer.parseInt(st.nextToken());
String search = st.hasMoreTokens() ? st.nextToken() : "";
HashMap<Integer, String> tpls = Util.parseTemplate(HtmCache.getInstance().getNotNull(Config.BBS_HOME_DIR + "bbs_clanlist.htm", player));
String html = tpls.get(0);
Clan playerClan = player.getClan();
if (playerClan != null)
{
String my_clan = tpls.get(1);
my_clan = my_clan.replace("%PLEDGE_ID%", String.valueOf(playerClan.getClanId()));
my_clan = my_clan.replace("%MY_PLEDGE_NAME%", playerClan.getLevel() > 1 ? playerClan.getName() : "");
html = html.replace("<?my_clan_link?>", my_clan);
}
else
{
html = html.replace("<?my_clan_link?>", "");
}
List<Clan> clanList = getClanList(search, byCL == 1);
int start = (page - 1) * CLANS_PER_PAGE;
int end = Math.min(page * CLANS_PER_PAGE, clanList.size());
if (page == 1)
{
html = html.replace("%ACTION_GO_LEFT%", "");
html = html.replace("%GO_LIST%", "");
html = html.replace("%NPAGE%", "1");
}
else
{
html = html.replace("%ACTION_GO_LEFT%", "bypass _clbbslist_" + (page - 1) + "_" + byCL + "_" + search);
html = html.replace("%NPAGE%", String.valueOf(page));
StringBuilder goList = new StringBuilder("");
for (int i = page > 10 ? page - 10 : 1; i < page; i++)
{
goList.append("<td><a action=\"bypass _clbbslist_").append(i).append('_').append(byCL).append('_').append(search).append("\"> ").append(i).append(" </a> </td>\n\n");
}
html = html.replace("%GO_LIST%", goList.toString());
}
int pages = Math.max(clanList.size() / CLANS_PER_PAGE, 1);
if (clanList.size() > (pages * CLANS_PER_PAGE))
{
pages++;
}
if (pages > page)
{
html = html.replace("%ACTION_GO_RIGHT%", "bypass _clbbslist_" + (page + 1) + "_" + byCL + "_" + search);
int ep = Math.min(page + 10, pages);
StringBuilder goList = new StringBuilder("");
for (int i = page + 1; i <= ep; i++)
{
goList.append("<td><a action=\"bypass _clbbslist_").append(i).append('_').append(byCL).append('_').append(search).append("\"> ").append(i).append(" </a> </td>\n\n");
}
html = html.replace("%GO_LIST2%", goList.toString());
}
else
{
html = html.replace("%ACTION_GO_RIGHT%", "");
html = html.replace("%GO_LIST2%", "");
}
StringBuilder cl = new StringBuilder("");
String tpl = HtmCache.getInstance().getNotNull(Config.BBS_HOME_DIR + "bbs_clantpl.htm", player);
for (int i = start; i < end; i++)
{
Clan clan = clanList.get(i);
String clantpl = tpl;
clantpl = clantpl.replace("%action_clanhome%", "bypass _clbbsclan_" + clan.getClanId());
clantpl = clantpl.replace("%clan_name%", clan.getName());
clantpl = clantpl.replace("%clan_owner%", clan.getLeaderName());
clantpl = clantpl.replace("%skill_level%", String.valueOf(clan.getLevel()));
clantpl = clantpl.replace("%member_count%", String.valueOf(clan.getAllSize()));
cl.append(clantpl);
}
html = html.replace("%CLAN_LIST%", cl.toString());
ShowBoard.separateAndSend(html, player);
}
else if ("clbbsclan".equals(cmd))
{
int clanId = Integer.parseInt(st.nextToken());
if (clanId == 0)
{
player.sendPacket(new SystemMessage(SystemMessage.NOT_JOINED_IN_ANY_CLAN));
onBypassCommand(player, "_clbbslist_1_0");
return;
}
Clan clan = ClanTable.getInstance().getClan(clanId);
if (clan == null)
{
onBypassCommand(player, "_clbbslist_1_0");
return;
}
if (clan.getLevel() < 2)
{
player.sendPacket(new SystemMessage(SystemMessage.THERE_ARE_NO_COMMUNITIES_IN_MY_CLAN_CLAN_COMMUNITIES_ARE_ALLOWED_FOR_CLANS_WITH_SKILL_LEVELS_OF_2_AND_HIGHER));
onBypassCommand(player, "_clbbslist_1_0");
return;
}
Connection con = null;
PreparedStatement statement = null;
ResultSet rset = null;
String intro = "";
try
{
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT * FROM `bbs_clannotice` WHERE `clan_id` = ? and type = 2");
statement.setInt(1, clanId);
rset = statement.executeQuery();
if (rset.next())
{
intro = rset.getString("notice");
}
}
catch (Exception e)
{
}
finally
{
DbUtils.closeQuietly(con, statement, rset);
}
HashMap<Integer, String> tpls = Util.parseTemplate(HtmCache.getInstance().getNotNull(Config.BBS_HOME_DIR + "bbs_clan.htm", player));
String html = tpls.get(0);
html = html.replace("%PLEDGE_ID%", String.valueOf(clanId));
html = html.replace("%ACTION_ANN%", "");
html = html.replace("%ACTION_FREE%", "");
if ((player.getClanId() == clanId) && player.isClanLeader())
{
html = html.replace("<?menu?>", tpls.get(1));
}
else
{
html = html.replace("<?menu?>", "");
}
html = html.replace("%CLAN_INTRO%", intro.replace("\n", "<br1>"));
html = html.replace("%CLAN_NAME%", clan.getName());
html = html.replace("%SKILL_LEVEL%", String.valueOf(clan.getLevel()));
html = html.replace("%CLAN_MEMBERS%", String.valueOf(clan.getAllSize()));
html = html.replace("%OWNER_NAME%", clan.getLeaderName());
html = html.replace("%ALLIANCE_NAME%", clan.getAlliance() != null ? clan.getAlliance().getAllyName() : "");
html = html.replace("%ANN_LIST%", "");
html = html.replace("%THREAD_LIST%", "");
ShowBoard.separateAndSend(html, player);
}
else if ("clbbsadmi".equals(cmd))
{
Clan clan = player.getClan();
if ((clan == null) || (clan.getLevel() < 2) || !player.isClanLeader())
{
onBypassCommand(player, "_clbbsclan_" + player.getClanId());
return;
}
String html = HtmCache.getInstance().getNotNull(Config.BBS_HOME_DIR + "bbs_clanadmin.htm", player);
html = html.replace("%PLEDGE_ID%", String.valueOf(clan.getClanId()));
html = html.replace("%ACTION_ANN%", "");
html = html.replace("%ACTION_FREE%", "");
html = html.replace("%CLAN_NAME%", clan.getName());
html = html.replace("%per_list%", "");
Connection con = null;
PreparedStatement statement = null;
ResultSet rset = null;
String intro = "";
try
{
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT * FROM `bbs_clannotice` WHERE `clan_id` = ? and type = 2");
statement.setInt(1, clan.getClanId());
rset = statement.executeQuery();
if (rset.next())
{
intro = rset.getString("notice");
}
}
catch (Exception e)
{
}
finally
{
DbUtils.closeQuietly(con, statement, rset);
}
List<String> args = new ArrayList<>();
args.add("0");
args.add("0");
args.add("0");
args.add("0");
args.add("0");
args.add("0");
args.add("");
args.add("0");
args.add("");
args.add("0");
args.add("");
args.add("");
args.add(intro);
args.add("");
args.add("");
args.add("0");
args.add("0");
args.add("");
player.sendPacket(new ShowBoard(html, "1001", player));
player.sendPacket(new ShowBoard(args));
}
else if ("mailwritepledgeform".equals(cmd))
{
Clan clan = player.getClan();
if ((clan == null) || (clan.getLevel() < 2) || !player.isClanLeader())
{
onBypassCommand(player, "_clbbsclan_" + player.getClanId());
return;
}
String html = HtmCache.getInstance().getNotNull(Config.BBS_HOME_DIR + "bbs_pledge_mail_write.htm", player);
html = html.replace("%PLEDGE_ID%", String.valueOf(clan.getClanId()));
html = html.replace("%pledge_id%", String.valueOf(clan.getClanId()));
html = html.replace("%pledge_name%", clan.getName());
ShowBoard.separateAndSend(html, player);
}
else if ("announcepledgewriteform".equals(cmd))
{
Clan clan = player.getClan();
if ((clan == null) || (clan.getLevel() < 2) || !player.isClanLeader())
{
onBypassCommand(player, "_clbbsclan_" + player.getClanId());
return;
}
HashMap<Integer, String> tpls = Util.parseTemplate(HtmCache.getInstance().getNotNull(Config.BBS_HOME_DIR + "bbs_clanannounce.htm", player));
String html = tpls.get(0);
html = html.replace("%PLEDGE_ID%", String.valueOf(clan.getClanId()));
html = html.replace("%ACTION_ANN%", "");
html = html.replace("%ACTION_FREE%", "");
Connection con = null;
PreparedStatement statement = null;
ResultSet rset = null;
String notice = "";
int type = 0;
try
{
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT * FROM `bbs_clannotice` WHERE `clan_id` = ? and type != 2");
statement.setInt(1, clan.getClanId());
rset = statement.executeQuery();
if (rset.next())
{
notice = rset.getString("notice");
type = rset.getInt("type");
}
}
catch (Exception e)
{
}
finally
{
DbUtils.closeQuietly(con, statement, rset);
}
if (type == 0)
{
html = html.replace("<?usage?>", tpls.get(1));
}
else
{
html = html.replace("<?usage?>", tpls.get(2));
}
html = html.replace("%flag%", String.valueOf(type));
List<String> args = new ArrayList<>();
args.add("0");
args.add("0");
args.add("0");
args.add("0");
args.add("0");
args.add("0");
args.add("");
args.add("0");
args.add("");
args.add("0");
args.add("");
args.add("");
args.add(notice);
args.add("");
args.add("");
args.add("0");
args.add("0");
args.add("");
player.sendPacket(new ShowBoard(html, "1001", player));
player.sendPacket(new ShowBoard(args));
}
else if ("announcepledgeswitchshowflag".equals(cmd))
{
Clan clan = player.getClan();
if ((clan == null) || (clan.getLevel() < 2) || !player.isClanLeader())
{
onBypassCommand(player, "_clbbsclan_" + player.getClanId());
return;
}
int type = Integer.parseInt(st.nextToken());
Connection con = null;
PreparedStatement statement = null;
try
{
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("UPDATE `bbs_clannotice` SET type = ? WHERE `clan_id` = ? and type = ?");
statement.setInt(1, type);
statement.setInt(2, clan.getClanId());
statement.setInt(3, type == 1 ? 0 : 1);
statement.execute();
}
catch (Exception e)
{
}
finally
{
DbUtils.closeQuietly(con, statement);
}
clan.setNotice(type == 0 ? "" : null);
onBypassCommand(player, "_announcepledgewriteform");
}
}