Jump to content

Recommended Posts

Posted

Hello there summoners.

 

Untill now, I haven't shared anything coded in Java. So I decided to code and share a message system (or mail system). It gives the possibility to players to send messages to each other even if the recipient is offline. Coded in l2jfrozen.

 

 

First, run this code at your mysql:

DROP TABLE IF EXISTS `mails`;
CREATE TABLE `mails` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `from` text,
  `to` text,
  `title` text,
  `message` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=latin1;

 

Core Side:

### Eclipse Workspace Patch 1.0
#P L2jFrozen_GS
Index: head-src/com/l2jfrozen/gameserver/network/clientpackets/RequestBypassToServer.java
===================================================================
--- head-src/com/l2jfrozen/gameserver/network/clientpackets/RequestBypassToServer.java	(revision 948)
+++ head-src/com/l2jfrozen/gameserver/network/clientpackets/RequestBypassToServer.java	(working copy)
@@ -18,8 +18,11 @@
  */
package com.l2jfrozen.gameserver.network.clientpackets;

+import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.Logger;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;

import com.l2jfrozen.Config;
import com.l2jfrozen.gameserver.ai.CtrlIntention;
@@ -40,9 +43,12 @@
import com.l2jfrozen.gameserver.model.entity.event.L2Event;
import com.l2jfrozen.gameserver.model.entity.event.TvT;
import com.l2jfrozen.gameserver.model.entity.event.VIP;
+import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.MailCmd;
import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jfrozen.gameserver.util.GMAudit;
+import com.l2jfrozen.util.database.L2DatabaseFactory;
+import com.mysql.jdbc.Connection;

public final class RequestBypassToServer extends L2GameClientPacket
{
@@ -124,6 +130,93 @@
			{
				playerHelp(activeChar, _command.substring(12));
			}
+			else if (_command.startsWith("sendMsg")) {
+				
+				StringTokenizer st = new StringTokenizer(_command);
+				
+				st.nextToken();
+				
+				String to = st.nextToken();
+				String title = st.nextToken();
+				String message = "";
+				
+				while(st.hasMoreTokens()) {
+					
+					message = message + st.nextToken() + " ";
+					
+				}
+				
+				if (to.equalsIgnoreCase(activeChar.getName())) {
+					
+					activeChar.sendMessage("You cannot send a message to yourself.");
+					return;
+				
+				}
+				
+				if (to.equalsIgnoreCase("") || message.equalsIgnoreCase("")) {
+					
+					activeChar.sendMessage("You have to fill all the fields.");
+					return;
+					
+				}
+				
+				if (title.equalsIgnoreCase(""))
+					title = "(No Subject)";
+				
+				java.sql.Connection con = null;
+				
+				try {
+					
+					con = L2DatabaseFactory.getInstance().getConnection(false);
+					
+					PreparedStatement statement = con.prepareStatement("INSERT INTO mails VALUES ('0',?,?,?,?)");
+					
+					statement.setString(1, activeChar.getName());
+					statement.setString(2, to);
+					statement.setString(3, title);
+					statement.setString(4, message);
+					
+					statement.execute();
+					activeChar.sendMessage("Your message has been sent.");
+					statement.close();
+					
+				}catch(Exception e) {
+					
+					e.printStackTrace();
+					_log.log(Level.SEVERE, e.getMessage(), e);
+					
+				}
+				
+			}
+			else if (_command.startsWith("delMsg")) {
+				
+				StringTokenizer st = new StringTokenizer(_command);
+				st.nextToken();
+				
+				int messageId = Integer.parseInt(st.nextToken());
+				
+				java.sql.Connection con = null;
+				
+				try {
+					
+					con = L2DatabaseFactory.getInstance().getConnection(false);
+					
+					PreparedStatement statement = con.prepareStatement("DELETE FROM mails WHERE id=?");
+					
+					statement.setInt(1, messageId);
+					
+					statement.execute();
+					activeChar.sendMessage("The message has been deleted.");
+					statement.close();
+					
+				}catch(Exception e) {
+					
+					e.printStackTrace();
+					_log.log(Level.SEVERE, e.getMessage(), e);
+					
+				}
+				
+			}
			else if(_command.startsWith("npc_"))
			{
				if(!activeChar.validateBypass(_command))
Index: head-src/com/l2jfrozen/gameserver/network/clientpackets/EnterWorld.java
===================================================================
--- head-src/com/l2jfrozen/gameserver/network/clientpackets/EnterWorld.java	(revision 948)
+++ head-src/com/l2jfrozen/gameserver/network/clientpackets/EnterWorld.java	(working copy)
@@ -15,6 +15,7 @@
package com.l2jfrozen.gameserver.network.clientpackets;

import java.io.File;
+import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
@@ -23,6 +24,10 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
import com.l2jfrozen.Config;
import com.l2jfrozen.crypt.nProtect;
import com.l2jfrozen.crypt.nProtect.RestrictionType;
@@ -94,6 +99,7 @@
import com.l2jfrozen.gameserver.thread.TaskPriority;
import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
import com.l2jfrozen.gameserver.util.Util;
+import com.l2jfrozen.util.database.L2DatabaseFactory;

/**
  * Enter World Packet Handler
@@ -277,9 +283,42 @@
		// Welcome to Lineage II
		sendPacket(new SystemMessage(SystemMessageId.WELCOME_TO_LINEAGE));

-		// Credits to L2jfrozen
-		activeChar.sendMessage("This server uses L2JFrozen, a project founded by L2Chef and");
-		activeChar.sendMessage("developed by the L2JFrozen Dev Team at l2jfrozen.com");
+		java.sql.Connection con = null;
+		
+		int results = 0;
+		
+		try {
+			
+			con = L2DatabaseFactory.getInstance().getConnection(false);
+			
+			PreparedStatement statement = con.prepareStatement("SELECT * FROM mails WHERE `to`=?");
+			
+			statement.setString(1, activeChar.getName());
+			
+			ResultSet result = statement.executeQuery();
+			
+			while (result.next()) {
+				
+				results++;
+				
+			}
+			
+		}catch(Exception e) {
+			
+			
+		}
+		
+		activeChar.sendMessage("You have " + results + " messages.");
+		

		SevenSigns.getInstance().sendCurrentPeriodMsg(activeChar);
		Announcements.getInstance().showAnnouncements(activeChar);
Index: head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java
===================================================================
--- head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java	(revision 948)
+++ head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java	(working copy)
@@ -30,6 +30,7 @@
import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.CTFCmd;
import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.DMCmd;
import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.FarmPvpCmd;
+import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.MailCmd;
import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.Online;
import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.StatsCmd;
import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.TvTCmd;
@@ -66,6 +67,8 @@

		registerVoicedCommandHandler( new Voting());

+		registerVoicedCommandHandler(new MailCmd());
+		
		if(Config.BANKING_SYSTEM_ENABLED)
		{
			registerVoicedCommandHandler(new BankingCmd());
Index: head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/MailCmd.java
===================================================================
--- head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/MailCmd.java	(revision 0)
+++ head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/MailCmd.java	(revision 0)
@@ -0,0 +1,148 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package com.l2jfrozen.gameserver.handler.voicedcommandhandlers;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import javolution.text.TextBuilder;
+
+import com.l2jfrozen.gameserver.handler.IVoicedCommandHandler;
+import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
+import com.l2jfrozen.util.database.L2DatabaseFactory;
+
+/**
+ * @author Pauler
+ **/
+
+public class MailCmd implements IVoicedCommandHandler
+{
+	
+	public static final String[] VOICED_COMMANDS = { "mailread", "mailsend" };
+	
+	@Override
+	public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
+	{
+		if (command.equalsIgnoreCase("mailread")) {
+			
+			mailread(activeChar);
+			
+		}
+		
+		if (command.equalsIgnoreCase("mailsend")) {
+			
+			mailsend(activeChar);
+			
+		}
+		
+		return false;
+	}
+	
+	public void mailread(L2PcInstance activeChar) {
+		
+		NpcHtmlMessage msg = new NpcHtmlMessage(20);
+        msg.setHtml(showMailReadWindow(activeChar));
+        msg.replace("%objectId%", String.valueOf(20));
+        activeChar.sendPacket(msg);
+		
+	}
+	
+	public String showMailReadWindow(L2PcInstance activeChar) {
+		
+		TextBuilder tb = new TextBuilder();
+		tb.append("<html><head><title>Inbox</title></head><body>");
+		
+		java.sql.Connection con = null;
+		try
+		{
+			con = L2DatabaseFactory.getInstance().getConnection(false);
+			
+			PreparedStatement statement = con.prepareStatement("SELECT * FROM mails WHERE `to`=? ORDER BY id DESC");
+			
+			statement.setString(1, activeChar.getName());
+			
+			ResultSet result = statement.executeQuery();
+			
+			int messageId = 0;
+			
+			while (result.next()) {
+				
+				tb.append("<font color=\"D6A718\">From:</font> <br>" + result.getString(2) + "<br>");
+				tb.append("<font color=\"D6A718\">Title:</font> <br>" + result.getString(4) + "<br>");
+				tb.append("<font color=\"D6A718\">Message:</font> <br>" + result.getString(5) + "<br>");
+				
+				messageId = result.getInt(1);
+				
+				tb.append("<button value=\"Delete\" action=\"bypass -h delMsg " + messageId +"\" width=100 height=20><br>*******************************<br>");
+				
+		
+			}
+			
+		}
+		catch (SQLException e)
+		{
+			e.printStackTrace();
+		}
+		
+		tb.append("</body></html>");
+		
+		return tb.toString();
+		
+	}
+	
+	public void mailsend(L2PcInstance activeChar) {
+		
+		NpcHtmlMessage msg = new NpcHtmlMessage(20);
+        msg.setHtml(showMailSendWindow(activeChar));
+        msg.replace("%objectId%", String.valueOf(20));
+        activeChar.sendPacket(msg);
+		
+	}
+	
+	public String showMailSendWindow(L2PcInstance activeChar) {
+		
+		TextBuilder tb = new TextBuilder();
+		tb.append("<html><head><title>Send a Mail</title></head><body>");
+		
+		tb.append("<br><font color=\"C99B10\">Welcome to the mail system.<br>Use the fields below in order to send messages to your friends.<br>Attention: Your title must include only 1 word.</font><br><br>");
+		tb.append("<center>");
+		
+		tb.append("To:<br>");
+		tb.append("<edit var=\"to\" width=\"120\" height=\"15\"><br><br>");
+		
+		tb.append("Title:<br>");
+		tb.append("<edit var=\"title\" width=\"120\" height=\"15\"><br><br>");
+		
+		tb.append("Message:<br>");
+		tb.append("<multiedit var=\"message\" width=\"120\" height=\"120\"><br><br>");
+		
+		tb.append("<button value=\"Send\" action=\"bypass -h sendMsg $to $title $message\" width=204 height=20>");
+		
+		tb.append("</center>");
+		
+		tb.append("</body></html>");
+	
+		return tb.toString();
+	}
+	
+	@Override
+	public String[] getVoicedCommandList()
+	{
+		return VOICED_COMMANDS;
+	}
+	
+}

Guest Elfocrash
Posted

Already implemented on acis.

Good one tho. +1

Posted

what if player doesn't exist?:P

(I mean the name is invaild)

 

 

Then, nobody gonna read the message.

Posted

Then, nobody gonna read the message.

hmm :P

 

a floodprotector is must there,since if someone spam it,it'll cause lag.

Posted

+1, this is good keep em commin'

 

hmm :P

 

a floodprotector is must there,since if someone spam it,it'll cause lag.

 

yeap, also if you dont check for not existing players they can just send a shitload just add a couple checkers and a flood protector and it will be nice :)

Posted

also if you dont check for not existing players they can just send a shitload

it was my point when i asked him 'what if players doesn't exist?' :P

 

+1 from me aswell.

Posted

it was my point when i asked him 'what if players doesn't exist?' :P

 

+1 from me aswell.

+1, this is good keep em commin'

 

yeap, also if you dont check for not existing players they can just send a shitload just add a couple checkers and a flood protector and it will be nice :)

I really appreciate it.
Guest
This topic is now closed to further replies.



  • Posts

    • Продам комплекты (Custom Colour) Apella Сеты. Контакт со мной/Contact with me  Telegram. Custom Colour Apella Light YouTube Video
    • haha, I don't say it, chatgpt says it. discuss it with him if you have problems 😉 or sue chatgpt for lying, for example when he tells you that you are an idiot and tells you that I do things that are light years ahead of you.
    • hey i make enough to live comfortably you, on the other hand... doubt that'd be the case if you were as competent as you claim to be
    • all your doubts ask chatgpt, also ask what you could do yourself hahaha
    • This post originally appeared on MmoGah. Odin: Valhalla Rising is an ambitious open-world MMORPG developed with Unreal Engine 4, offering breathtaking visuals and immersive gameplay. I will share everything you need to know before starting it.     Re-rolling In Odin, re-rolling isn't a practical strategy. Unlike most gacha games, where it's common to reset for better initial pulls, Odin focuses heavily on long-term growth. The earlier you begin playing and developing your character, the more advantages you'll gain over time. Instead of spending your efforts on re-rolling for ideal equipment, it's better to dive in and start progressing right away.   Server Selection Before starting your character, selecting a server is a crucial step. Since Odin doesn't support cross-server gameplay, coordinating with your friends, family, or guildmates is essential to ensure everyone creates their characters on the same server. Take the time to plan with your group beforehand. After deciding on a server, your next major choice will be picking a class.   Class Breakdown Odin features four primary starting classes: Warrior, Sorceress, Rogue, and Priest. Each class comes with its own distinct playstyle and unique strengths, so choose wisely, as your selection is permanent. However, even free-to-play players can create up to three characters on one server, giving you the flexibility to try different options and find the one that matches your preferences.   Quest and Leveling Once your character is created, your initial objective is to work through the main questline. This acts as both a tutorial and a method for early leveling. Odin simplifies the process with a convenient quest button that handles navigation, starts dialogues, and even enables auto-combat. This user-friendly feature allows beginners to grasp the basics of the game without feeling overloaded.   Auto Combat and No Kill-steal Mode Auto combat is an essential feature in Odin, enabling your character to battle monsters autonomously. This system allows you to effortlessly gain experience and loot, even while you're busy studying, cooking, or unwinding. To optimize its use, activate the no-kill-steal mode. This setting prevents your character from targeting monsters already engaged by other players, helping you avoid conflicts or potential PvP situations. However, if a quest becomes difficult to complete due to overcrowded areas, you can temporarily disable this mode to overcome the obstacle and move forward.   Item Management and Potions Don't overlook the importance of consumable items, especially health potions. These can be purchased, along with buffs, from general merchants in villages, and they play a crucial role in improving your combat efficiency and ensuring your survival. Always aim to keep a full stock of HP potions and carry buffs that boost attack, defense, or regeneration in batches of 5-10 for convenience.   Once you've acquired your consumables, assign them to your quick slots located at the bottom center of the screen. Swiping down activates these slots, and items like potions will automatically be used when necessary, so you don't need to worry about them mid-battle. Keep a close eye on your potion reserves, as running out during a tough fight could leave you vulnerable before reaching a safe area. In the early stages of the game, it's better to return to town for a restock if supplies are low rather than risking unnecessary defeats. You can also enable notifications to alert you when your health or potion count drops too low—a handy feature for staying prepared if your attention is elsewhere.   Leveling and AFK Farming Once you've mastered the fundamentals, the next step is to focus on leveling up and enhancing your character. Gaining levels is your primary source of progression early on, as it not only improves your stats but also unlocks crucial game features and new abilities. At this stage, simply sticking to the main questline provides a reliable and efficient way to gain experience.   Additionally, Odin includes a highly convenient idle feature called AFK mode. This allows your character to keep farming for resources and experience even when the game is closed, with a maximum duration of 8 hours per day. It's an excellent option for making progress while you're asleep, commuting, or otherwise occupied.   Gear Upgrades When the time comes to improve your gear, the initial focus should be on upgrading from normal-grade equipment to high-grade items. These provide significantly better stats and can be enhanced further to increase their effectiveness. Enhancing requires enhancement stones and gold, but it's important to stay within the safe enhancement limit. Attempting upgrades beyond this limit carries the risk of destroying your gear if the enhancement fails. Stick to safe enhancements until you've gained more experience and accumulated spare equipment to mitigate potential losses.   Skill Purchases When you've accumulated enough gold, it's time to invest in skills. These are crucial for enhancing your combat abilities and provide key benefits tailored to your class, whether it's increasing damage output, improving healing capabilities, or adding valuable utility. Before purchasing, ensure your character meets the level prerequisites for each skill. Your ultimate goal will be progressing through and completing the main questline in Midgard as you continue to develop your character.   Unlocking Jotenheim Finishing this milestone grants you access to the next region, Jetunheim, unlocking a variety of new content and challenges. This marks your first significant achievement in the game and is an essential early objective to strive for as you progress.   Joining a Guild Joining a guild is a highly beneficial step in Odin. Guilds not only provide opportunities for social interaction and group activities but also offer passive bonuses that can significantly enhance your gameplay. Even if you're not particularly active socially, being part of any guild is advantageous. The guild feature becomes accessible after completing Chapter 4, Quest 19 of the main story.   Guilds provide various perks, including buffs that scale with the guild's level. Additionally, you can earn guild coins by contributing through donations, quest completions, or regular logins. These coins can be exchanged for valuable rewards, such as epic-grade armor. The more you actively contribute to your guild, the greater the overall benefits for both you and the guild itself. Joining early and staying involved will undoubtedly strengthen your progression in the game.   Conclusion Here is the end of this beginners' guide. I hope these tips will help you level fast in Odin.
  • Topics

×
×
  • Create New...