Addition of telnet SendMail handler.
This commit is contained in:
		| @@ -298,6 +298,7 @@ import handlers.telnethandlers.player.GMList; | ||||
| import handlers.telnethandlers.player.Give; | ||||
| import handlers.telnethandlers.player.Jail; | ||||
| import handlers.telnethandlers.player.Kick; | ||||
| import handlers.telnethandlers.player.SendMail; | ||||
| import handlers.telnethandlers.player.Unban; | ||||
| import handlers.telnethandlers.player.UnbanChat; | ||||
| import handlers.telnethandlers.player.Unjail; | ||||
| @@ -748,6 +749,7 @@ public class MasterHandler | ||||
| 			TelnetServer.getInstance().addHandler(new Performance()); | ||||
| 			TelnetServer.getInstance().addHandler(new Purge()); | ||||
| 			TelnetServer.getInstance().addHandler(new Reload()); | ||||
| 			TelnetServer.getInstance().addHandler(new SendMail()); | ||||
| 			TelnetServer.getInstance().addHandler(new ServerAbort()); | ||||
| 			TelnetServer.getInstance().addHandler(new ServerRestart()); | ||||
| 			TelnetServer.getInstance().addHandler(new ServerShutdown()); | ||||
|   | ||||
							
								
								
									
										87
									
								
								L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/telnethandlers/player/SendMail.java
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/telnethandlers/player/SendMail.java
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,87 @@ | ||||
| /* | ||||
|  * This file is part of the L2J Mobius project. | ||||
|  *  | ||||
|  * 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 handlers.telnethandlers.player; | ||||
|  | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
|  | ||||
| import com.l2jmobius.gameserver.data.sql.impl.CharNameTable; | ||||
| import com.l2jmobius.gameserver.enums.MailType; | ||||
| import com.l2jmobius.gameserver.instancemanager.MailManager; | ||||
| import com.l2jmobius.gameserver.model.entity.Message; | ||||
| import com.l2jmobius.gameserver.model.itemcontainer.Mail; | ||||
| import com.l2jmobius.gameserver.network.telnet.ITelnetCommand; | ||||
| import com.l2jmobius.gameserver.util.Util; | ||||
|  | ||||
| import io.netty.channel.ChannelHandlerContext; | ||||
|  | ||||
| /** | ||||
|  * @author Mobius | ||||
|  */ | ||||
| public class SendMail implements ITelnetCommand | ||||
| { | ||||
| 	@Override | ||||
| 	public String getCommand() | ||||
| 	{ | ||||
| 		return "sendmail"; | ||||
| 	} | ||||
| 	 | ||||
| 	@Override | ||||
| 	public String getUsage() | ||||
| 	{ | ||||
| 		return "sendmail <player name> <mail subject (use _ for spaces)> <mail message (use _ for spaces)> <item id/ids seperated by space (optional)>"; | ||||
| 	} | ||||
| 	 | ||||
| 	@Override | ||||
| 	public String handle(ChannelHandlerContext ctx, String[] args) | ||||
| 	{ | ||||
| 		if ((args.length < 3) || args[0].isEmpty()) | ||||
| 		{ | ||||
| 			return null; | ||||
| 		} | ||||
| 		final int objectId = CharNameTable.getInstance().getIdByName(args[0]); | ||||
| 		if (objectId > 0) | ||||
| 		{ | ||||
| 			final Message msg = new Message(objectId, args[1].replace("_", " "), args[2].replace("_", " "), args.length > 3 ? MailType.PRIME_SHOP_GIFT : MailType.REGULAR); | ||||
| 			final List<Integer> itemIds = new ArrayList<>(); | ||||
| 			int counter = -1; | ||||
| 			for (String str : args) | ||||
| 			{ | ||||
| 				counter++; | ||||
| 				if (counter < 3) | ||||
| 				{ | ||||
| 					continue; | ||||
| 				} | ||||
| 				if (Util.isDigit(str)) | ||||
| 				{ | ||||
| 					itemIds.add(Integer.valueOf(str)); | ||||
| 				} | ||||
| 			} | ||||
| 			if (!itemIds.isEmpty()) | ||||
| 			{ | ||||
| 				final Mail attachments = msg.createAttachments(); | ||||
| 				for (int itemId : itemIds) | ||||
| 				{ | ||||
| 					attachments.addItem("Telnet", itemId, 1, null, null); | ||||
| 				} | ||||
| 			} | ||||
| 			MailManager.getInstance().sendMessage(msg); | ||||
| 			return "An ingame mail has been sent to " + args[0] + "."; | ||||
| 		} | ||||
| 		return "Couldn't find player with such name."; | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 MobiusDev
					MobiusDev