Jump to content

Recommended Posts

Posted (edited)

Hey guys i was fooling arround with this one and decided to share it with you , i didnt test it on live server.  It might have some issues feel free to point them out so i can fix them.

 

It shows the 5 latest news posts, on every restart it clears the oldests and it keeps the 5 recent.

 

Requirements : Your own .menu + custom menu command handlers <-- i made a share for that.

 

If you don't have custom menu command handlers you can either trigger it with another custom command handler like .news or use the on enter server show news html that is included on acis (i dont know about other projects).

 

credits : me

 

58d65eb051901cb03abdf89eb226eadc.png.7294587b352e71efe3a711054d37e3fb.png

 

9fe144a6390f4fe92af8ff96de90b580.png.6ff178bc31ad28970a8b14c97142b07b.png

 

AdminNews.java

package net.sf.l2j.gameserver.handler.admincommandhandlers;

import net.sf.l2j.gameserver.custom.usermenu.menuhandlers.NewsHandler;
import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
import net.sf.l2j.gameserver.model.actor.instance.Player;

/**
 * @author LordPanic
 *
 */
public class AdminNews implements IAdminCommandHandler
{

	private static final String[] ADMIN_COMMANDS =
	{
		"admin_news"
	};
	
	@Override
	public boolean useAdminCommand(String command, Player activeChar)
	{
		if (command.equals("admin_news"))
	       {
				NewsHandler.adminNewsWindow(activeChar);
	       }
		return false;
	}

	
	
	
	@Override
	public String[] getAdminCommandList()
	{
		
		return ADMIN_COMMANDS;
	}
	
}

 

AdminCommandHandler.java

+registerAdminCommandHandler(new AdminNews());

 

NewsHandler.java

package net.sf.l2j.gameserver.custom.usermenu.menuhandlers;
 
 
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.StringTokenizer;
import java.util.logging.Logger;
 
 
import net.sf.l2j.L2DatabaseFactory;
import net.sf.l2j.gameserver.model.WorldObject;
import net.sf.l2j.gameserver.model.actor.instance.Player;
import net.sf.l2j.gameserver.network.clientpackets.Say2;
import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
import net.sf.l2j.gameserver.util.Broadcast;


 
/**
 * @author LordPanic
 * 
 */
public class NewsHandler
{	

private final List<NewsInfo> _list = new ArrayList<>();	
String clcDB = "DELETE FROM news_server WHERE char_id NOT IN ( SELECT char_id FROM ( SELECT char_id FROM news_server ORDER BY char_id DESC LIMIT 5 ) foo )";
String loadDt = "SELECT charname,content,content_date,categ FROM news_server ORDER BY content_date DESC LIMIT 5";
static String insertDt = "INSERT INTO news_server (charname,content,content_date,categ) VALUES (?,?,?,?)";
private static final Logger _log = Logger.getLogger(WorldObject.class.getName());
 
public static NewsHandler getInstance()
{
	return SingletonHolder._instance;
}

public class NewsInfo{
	public String name;
	public String content;
	public Long date;
	public String category;
}


public void parseCmd(String command, Player activeChar)
{
	StringTokenizer st = new StringTokenizer(command, " ");
	String actualCommand = st.nextToken();
 
	if(activeChar.isGM()) 
		activeChar.sendMessage("[CMD]: "+command);
 
	if(actualCommand.startsWith("_menuNewsPage")) {
					
		showNews(activeChar);
		
	}else if(actualCommand.startsWith("_menuNewsPost")) {
		String cntpost =  "";
		String nameOFchar = activeChar.getName();
		Long currentTime = Calendar.getInstance().getTimeInMillis();
		String catgPost = "";
 
		if (st.hasMoreTokens())
			catgPost = st.nextToken();
		
		int cmdPst = actualCommand.length();
		int lnPst = catgPost.length();		
		int ttlSb = cmdPst + lnPst;
		cntpost = command.substring(ttlSb);
		
		adminWriteToDB(nameOFchar,cntpost.substring(2),currentTime,catgPost);
		Broadcast.toAllOnlinePlayers(new CreatureSay(0, Say2.CRITICAL_ANNOUNCE, "", "["+nameOFchar+"] made a new post. Check your .menu -> News"));
		_list.clear();
		reloadData();

	}
}
 
public void reloadData() {
	 
	try (Connection con = L2DatabaseFactory.getInstance().getConnection();Statement statement = con.createStatement();
		ResultSet rset = statement.executeQuery(loadDt);)
	{			
		while (rset.next())
		{			
			NewsInfo nf = new NewsInfo();
			nf.name = rset.getString("charname");
			nf.content = rset.getString("content");
			nf.date = rset.getLong("content_date");
			nf.category = rset.getString("categ");
			
			_list.add(nf);	
		}		
		_log.info("NewsHandler: Loaded : ["+_list.size()+"] posts");
	}
	catch (SQLException e)
	{
		_log.info("NewsHandler: Couldn't load NewsList.");
	}
}

public void cleanNewsdb() {
	
	try (Connection con = L2DatabaseFactory.getInstance().getConnection();Statement statement = con.createStatement();)
	{
		statement.execute(clcDB);		
		
		_log.info("NewsHandler: Older posts got deleted.");
	}catch (SQLException e) {
		_log.info("NewsHandler: Error while deleting excess data.");
	}
	
}

public void showNews(Player player) {
final StringBuilder sb = new StringBuilder();
for(NewsInfo tempInfo : _list) {
	if(tempInfo == null)
		break;

String cnvHolder = 	ctgConv(tempInfo.name,tempInfo.date,tempInfo.category);	

sb.append(cnvHolder);
sb.append("<img src=L2UI.SquareGray width=260 height=1>");
sb.append("<table width=260 bgcolor=\"000000\">");
sb.append("<tr><td><font color=b09979>"+tempInfo.content.replaceAll("\\s+"," ")+"</font></td></tr>");					
sb.append("</table>");
sb.append("<img src=L2UI.SquareGray width=260 height=1><br>");

}
NpcHtmlMessage html = new NpcHtmlMessage(0);
html.setFile("data/html/mods/user/news_menu.htm");
html.replace("%newslist%", sb.toString());
player.sendPacket(html);	

}


public static void adminNewsWindow(Player player) {
	final NpcHtmlMessage html = new NpcHtmlMessage(0);
	html.setFile("data/html/mods/user/adminnews_menu.htm");
	player.sendPacket(html);
}
 
private static void adminWriteToDB(String charName,String cont,long dateposted,String catg) {
	try (Connection con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement statement = con.prepareStatement(insertDt);)
	{						
		statement.setString(1, charName);
		statement.setString(2, cont);
		statement.setLong(3, dateposted);
		statement.setString(4, catg);
		statement.execute();
	}
	catch (SQLException e)
	{
		_log.info("NewsHandler: couldn't insert data to DB.");
	}
 
}

private static String ctgConv(String nm,long dt,String ctgr) {
	String otpVl = "";
	switch(ctgr) {
		case "Important":
			 otpVl = "<br><font color=F33B3B>"+ctgr+"</font>&nbsp;&nbsp;&nbsp;"+"<font color=b09979>By</font>&nbsp;&nbsp;<font color=F2F5A9>"+nm+"</font>&nbsp;&nbsp;&nbsp;&nbsp;"+"<font color=AB40A0>"+new SimpleDateFormat("dd MMMM HH:mm").format(dt)+"</font><br1>";
			return otpVl;
		case "Patch":
			 otpVl = "<br><font color=6CDA4B>"+ctgr+"</font>&nbsp;&nbsp;&nbsp;"+"<font color=b09979>By</font>&nbsp;&nbsp;<font color=F2F5A9>"+nm+"</font>&nbsp;&nbsp;&nbsp;&nbsp;"+"<font color=AB40A0>"+new SimpleDateFormat("dd MMMM HH:mm").format(dt)+"</font><br1>"; 
			 return otpVl;
		case "Event":
			 otpVl = "<br><font color=26BEF5>"+ctgr+"</font>&nbsp;&nbsp;&nbsp;"+"<font color=b09979>By</font>&nbsp;&nbsp;<font color=F2F5A9>"+nm+"</font>&nbsp;&nbsp;&nbsp;&nbsp;"+"<font color=AB40A0>"+new SimpleDateFormat("dd MMMM HH:mm").format(dt)+"</font><br1>";  
			return otpVl;
	}	
	return "";	
}
 
 
private static class SingletonHolder
{
	protected static final NewsHandler _instance = new NewsHandler();
}
}

 

GameServer.java

StringUtil.printSection("News");
NewsHandler.getInstance().cleanNewsdb();
NewsHandler.getInstance().reloadData();

 

Html loc -> \gameserver\data\html\mods\user

adminnews_menu.htm

<html><title>Admin - News</title><body><center>
<center>
	<table width=260>
		<tr>
			<td><button value="Main" action="bypass -h admin_admin" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
			<td><button value="Game" action="bypass -h admin_admin2" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
			<td><button value="Effects" action="bypass -h admin_admin3" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
			<td><button value="Server" action="bypass -h admin_admin4" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
		</tr>
	</table>
		<br>
<img src=L2UI.SquareGray width=260 height=1>

<br><img src="L2UI_CH3.herotower_deco" width=256 height=32><br>
<img src=L2UI.SquareGray width=260 height=1>
<br>New post:<combobox width=120 height=10 var="cat" list=Important;Patch;Event;
<table width=240>
		<tr><td align=center FIXWIDTH=666><MultiEdit var ="cntpost" width=256 height=100></td></tr>	

		<tr><td align=center><button value="confirm" action="bypass -h _menuNewsPost $cat $cntpost" width=55 height=15 back="sek.cbui94" fore="sek.cbui92"></td></tr>
	</table>
	<br>

</center></body></html>

 

news_menu.html

<html><title>User Menu - News</title><body><center>
<center>
	<table width=260>
		<tr>
			<td><button value="Home" action="bypass -h _menuHomePage" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
			<td><button value="Premium" action="bypass -h _menuVipPage" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
			<td><button value="Buffs" action="bypass -h _menuBuffsPage" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
			<td><button value="News" action="bypass -h _menuNewsPage" width=65 height=19 back="L2UI_ch3.smallbutton2_over" fore="L2UI_ch3.smallbutton2"></td>
		</tr>
	</table>
		<br>
<img src=L2UI.SquareGray width=260 height=1>

<br><img src="L2UI_CH3.herotower_deco" width=256 height=32><br>
<img src=L2UI.SquareGray width=260 height=1>
<table width=260 height=27 bgcolor="000000">
	<tr>
	<td align=center width=260><font color=b09979>Latest News</font></td>
</tr>
</table>
<img src=L2UI.SquareGray width=260 height=1>
<br><br>
</center>

%newslist%

</body></html>

 

html loc -> \gameserver\data\html\admin

main_menu.html

<td><button value="Get Buffs" action="bypass -h admin_getbuffs $menu_command" width=55 height=15 back="sek.cbui94" fore="sek.cbui92"></td>
+<td><button value="News" action="bypass -h admin_news" width=55 height=15 back="sek.cbui94" fore="sek.cbui92"></td>

 

adminCommands.xml

+<aCar name="admin_news" accessLevel="7"/>

 

SQL

CREATE TABLE IF NOT EXISTS `news_server` (
  `char_id` int(11) NOT NULL AUTO_INCREMENT,
  `charname` varchar(20) DEFAULT NULL,
  `content` text DEFAULT NULL,
  `content_date` bigint(20) DEFAULT NULL,
  `categ` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`char_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;

y i know, char_id doesnt make sense post_id would be the ideal name. Too lazy to change it.

Edited by LordPanic
  • Like 1
Posted
  On 5/5/2021 at 11:43 AM, LordPanic said:

DELETE FROM news_server WHERE char_id NOT IN ( SELECT char_id FROM ( SELECT char_id FROM news_server ORDER BY char_id DESC LIMIT 5 ) foo )

Expand  

foo :kappa:

 

  On 5/5/2021 at 11:43 AM, LordPanic said:

PreparedStatement statement = con.prepareStatement("INSERT INTO news_server (charname,content,content_date) VALUES (?,?,?)");

Expand  

 

  On 5/5/2021 at 11:43 AM, LordPanic said:

statement.close();

Expand  

 

  On 5/5/2021 at 11:43 AM, LordPanic said:

PreparedStatement statement = con.prepareStatement("SELECT charname,content,content_date FROM news_server ORDER BY content_date DESC LIMIT 5"); ResultSet rset = statement.executeQuery();

Expand  

 

  On 5/5/2021 at 11:43 AM, LordPanic said:

Broadcast.toAllOnlinePlayers(new CreatureSay(0, Say2.CRITICAL_ANNOUNCE, "", "["+nameOFchar+"] made a new post. Check your .menu -> News"));

Expand  

:notbadn:spam connections and stress testing the database on live servers :anarchy:

 

  On 5/5/2021 at 11:43 AM, LordPanic said:

rset.close(); statement.close();

Expand  

:serious: time travel back in 2009, thank you for bringing back memories.

 

@Kara you cant write better queries, change my mind.

 

find the differences

https://stackoverflow.com/a/8066594

https://stackoverflow.com/q/22671697

Posted
  On 5/6/2021 at 12:51 AM, Rootware said:

Not sure, but bypass string have limitation in 255 symbols. Isn't it? Maybe better to use WriteBBS command and have ability to input large texts?

Expand  

True, menu window is small compared to community board so it's better to keep it with 255 char limit otherwise it would be too much.

Posted (edited)
  On 5/6/2021 at 3:17 AM, LordPanic said:

True, menu window is small compared to community board so it's better to keep it with 255 char limit otherwise it would be too much.

Expand  

So, in your current version it's looks like Server Twitter.

Edited by Rootware
Posted (edited)

Updated: Added 3 categories [Important,Patch,Event], u can add as many u want it's up to you.

Char limit is 255 - (length of command + length of category).

 

58d65eb051901cb03abdf89eb226eadc.png.7294587b352e71efe3a711054d37e3fb.png

 

I also decided to share custom command menu handlers

 

 

Queries got fixed thanks to @Nightwolf.

 

 

Edited by LordPanic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • 🎉 L2NeverPain StuckSub - GRAND OPENING 12 December 2025🎉 After beta, testing, mistakes, laughs and a lot of PvP, the moment has finally come. L2NeverPain StuckSub is officially opening its gates on 12 December 2025.   ⚔️What to expect: ✦Main Class +2 Stuck Sub system ✦Balanced PvP & custom party farm areas ✦Custom events, bosses and strong rewards ✦Competitive clan scene with castle rewards   📌Until the opening: ✦Create your clans and register them in the Clan-Register channel ✦Invite your friends / old parties / CPs ✦Stay tuned for more information (rates, events, siege times, etc.)   Get your setups ready, prepare your macros and your Discord/voice. On 12 December 2025 20:00 GMT+2, we write the first chapter of NeverPain together. 🔥 https://l2neverpain.com/ https://discord.gg/kNP3UXgkmN
    • Check my post where I shared Lucera pack, you can pick textures from there. Here is a link of datapack/srv  https://eu2.contabostorage.com/d4b39866f6bb4084b6c969ec8fe20063:kita/Lucera_Classic_Remaster/Lucera Classic Remaster Server and Datapack files.rar
    • Hi friends, does anyone have these Aden Classic textures for IL + geodata? Please ❤️  
    • New products in our store: ➡Telegram Ukraine +380 | NO USED BEFORE | CLEAR ACCOUNTS | TDATA | No Spam Block | 2FA included | Age: from 3 days | Price from $3.2 ➡Facebook OLD Account 2020–2023 | Geo: EU+ASIA | Age: 2020–2023 | Profile filled with real friends: 50+ | Email Included + 2FA included | Real accounts | Price from $4.5 ➡SORA 2 | Invite code for YOUR account or a READY ChatGPT account + Sora 2 (read the product description) | Price from $2 ➡Instagram REALLY OLD accounts (2010–2013) with/without 2FA access | Country: MIX | Submail included | Price from $4 ➡Reddit FOR ONLYFANS Karma OLD Accounts | 1,000–10,000 KARMA (your choice) | MIX IP Registered | High-Quality Accounts for ONLYFANS WORKERS | Price from $4 ➡Mail.tm (temporary mails) AutoReg Account | Mixed IPs and Mixed Gender | IMAP, POP3, and SMTP Enabled | Price from $0.005 ➡ShadowSocks, VLESS, Trojan VPN Client | Any Country of Your Choice | Works on All Devices and in Any Country (Including Russia!) | Duration: 30/90/180/360 days | Price from $3 ➡TIKTOK ADS VERIFIED ACCOUNTS | GEO: ASIA/USA/EUROPE, AFRICA, ARABIC COUNTRIES, SOUTH AMERICA | Business Verified On ASIA/USA/EUROPE Company + POSTPAY | FULL ACCESS | Price from: $20 ➡TIKTOK ADS ACCOUNTS | GEO: Europe + Australia (your choice) | Business Verified + POSTPAY + BONUS COUPON for $6000 | Manual Registration | Email access + Cookies + VAT Info | Price from: $6 ➡Telegram API/HASH USA +1 Autoreg 1+ month age TDATA + SESSION + JSON + 2FA + API/HASH ID | Price from: $0.95 ➡KYC Business Verification Services | Verification for any service | Available geo: EUROPE, USA, ASIA Companies | Price from $300 ➡Telegram USA/Canada +1 with ACTIVE PREMIUM UP TO 01.12.2025 Autoreg | Age: from 6+ months | TDATA + SESSION + JSON + 2FA + PREMIUM | Price from $0.65 ➡Telegram USA/Canada +1 with ACTIVE PREMIUM (30 DAYS) Autoreg | Age: from 6+ months | TDATA + SESSION + JSON + 2FA + PREMIUM for 30 DAYS | Price from $5 Available for purchase in our store on the website or via the Telegram bot! Active links: Digital goods store (Website): Go to Store Telegram bot: Go to – convenient access to the store through the Telegram messenger. Other services: Virtual numbers service: Go to Telegram bot for purchasing Telegram Stars: Go to – fast and profitable purchase of Stars in Telegram. SMM Panel: Go to – promotion of your social media accounts. We want to present you the current list of promotions and special offers for purchasing our service’s products and services: 1. You can use a promo code for your first purchase: SOCNET (15% discount) 2. Get $1 on your store balance or a 10–20% discount — simply send your username after registering on our website using the following template: "SEND ME BONUS, MY USERNAME IS..." — you need to write this in our forum thread! 3. Get $1 for the first trial start of the SMM Panel: just open a ticket with the subject “Get Trial Bonus” on our website (Support). 4. Weekly Telegram Stars giveaways in our Telegram channel and in our bot for purchasing stars! News: ➡ Telegram channel: https://t.me/accsforyou_shop ➡ WhatsApp channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord server: https://discord.gg/y9AStFFsrh Contacts and Support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • New products in our store: ➡Telegram Ukraine +380 | NO USED BEFORE | CLEAR ACCOUNTS | TDATA | No Spam Block | 2FA included | Age: from 3 days | Price from $3.2 ➡Facebook OLD Account 2020–2023 | Geo: EU+ASIA | Age: 2020–2023 | Profile filled with real friends: 50+ | Email Included + 2FA included | Real accounts | Price from $4.5 ➡SORA 2 | Invite code for YOUR account or a READY ChatGPT account + Sora 2 (read the product description) | Price from $2 ➡Instagram REALLY OLD accounts (2010–2013) with/without 2FA access | Country: MIX | Submail included | Price from $4 ➡Reddit FOR ONLYFANS Karma OLD Accounts | 1,000–10,000 KARMA (your choice) | MIX IP Registered | High-Quality Accounts for ONLYFANS WORKERS | Price from $4 ➡Mail.tm (temporary mails) AutoReg Account | Mixed IPs and Mixed Gender | IMAP, POP3, and SMTP Enabled | Price from $0.005 ➡ShadowSocks, VLESS, Trojan VPN Client | Any Country of Your Choice | Works on All Devices and in Any Country (Including Russia!) | Duration: 30/90/180/360 days | Price from $3 ➡TIKTOK ADS VERIFIED ACCOUNTS | GEO: ASIA/USA/EUROPE, AFRICA, ARABIC COUNTRIES, SOUTH AMERICA | Business Verified On ASIA/USA/EUROPE Company + POSTPAY | FULL ACCESS | Price from: $20 ➡TIKTOK ADS ACCOUNTS | GEO: Europe + Australia (your choice) | Business Verified + POSTPAY + BONUS COUPON for $6000 | Manual Registration | Email access + Cookies + VAT Info | Price from: $6 ➡Telegram API/HASH USA +1 Autoreg 1+ month age TDATA + SESSION + JSON + 2FA + API/HASH ID | Price from: $0.95 ➡KYC Business Verification Services | Verification for any service | Available geo: EUROPE, USA, ASIA Companies | Price from $300 ➡Telegram USA/Canada +1 with ACTIVE PREMIUM UP TO 01.12.2025 Autoreg | Age: from 6+ months | TDATA + SESSION + JSON + 2FA + PREMIUM | Price from $0.65 ➡Telegram USA/Canada +1 with ACTIVE PREMIUM (30 DAYS) Autoreg | Age: from 6+ months | TDATA + SESSION + JSON + 2FA + PREMIUM for 30 DAYS | Price from $5 Available for purchase in our store on the website or via the Telegram bot! Active links: Digital goods store (Website): Go to Store Telegram bot: Go to – convenient access to the store through the Telegram messenger. Other services: Virtual numbers service: Go to Telegram bot for purchasing Telegram Stars: Go to – fast and profitable purchase of Stars in Telegram. SMM Panel: Go to – promotion of your social media accounts. We want to present you the current list of promotions and special offers for purchasing our service’s products and services: 1. You can use a promo code for your first purchase: SOCNET (15% discount) 2. Get $1 on your store balance or a 10–20% discount — simply send your username after registering on our website using the following template: "SEND ME BONUS, MY USERNAME IS..." — you need to write this in our forum thread! 3. Get $1 for the first trial start of the SMM Panel: just open a ticket with the subject “Get Trial Bonus” on our website (Support). 4. Weekly Telegram Stars giveaways in our Telegram channel and in our bot for purchasing stars! News: ➡ Telegram channel: https://t.me/accsforyou_shop ➡ WhatsApp channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord server: https://discord.gg/y9AStFFsrh Contacts and Support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock