Support for custom mail manager.

This commit is contained in:
MobiusDev 2019-03-06 15:50:31 +00:00
parent f6c0fd7679
commit 2600c3d395
60 changed files with 1986 additions and 31 deletions

View File

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS `custom_mail` (
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`receiver` INT UNSIGNED NOT NULL DEFAULT 0,
`subject` TINYTEXT NOT NULL DEFAULT "",
`message` TEXT NOT NULL DEFAULT "",
`items` TEXT NOT NULL DEFAULT "" -- format: itemId1 count1;itemId2 count2;itemId3 count3...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,11 @@
# ---------------------------------------------------------------------------
# Custom Mail Manager
# ---------------------------------------------------------------------------
# Enable/Disable sending mail through the custom_mail SQL table.
# Default: False
CustomMailManagerEnabled = False
# Database query delay in seconds.
# Default: 30
DatabaseQueryDelay = 30

View File

@ -112,6 +112,7 @@ public final class Config
private static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
private static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
private static final String CUSTOM_COMMUNITY_BOARD_CONFIG_FILE = "./config/Custom/CommunityBoard.ini";
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/Custom/CustomMailManager.ini";
private static final String CUSTOM_DUALBOX_CHECK_CONFIG_FILE = "./config/Custom/DualboxCheck.ini";
private static final String CUSTOM_FACTION_SYSTEM_CONFIG_FILE = "./config/Custom/FactionSystem.ini";
private static final String CUSTOM_FAKE_PLAYERS_CONFIG_FILE = "./config/Custom/FakePlayers.ini";
@ -1090,6 +1091,8 @@ public final class Config
public static int COMMUNITY_PREMIUM_PRICE_PER_DAY;
public static List<Integer> COMMUNITY_AVAILABLE_BUFFS;
public static Map<String, Location> COMMUNITY_AVAILABLE_TELEPORTS;
public static boolean CUSTOM_MAIL_MANAGER_ENABLED;
public static int CUSTOM_MAIL_MANAGER_DELAY;
public static boolean FACTION_SYSTEM_ENABLED;
public static Location FACTION_STARTING_LOCATION;
public static Location FACTION_MANAGER_LOCATION;
@ -2426,6 +2429,12 @@ public final class Config
COMMUNITY_AVAILABLE_TELEPORTS.put(splitInfo[0], new Location(Integer.parseInt(splitInfo[1]), Integer.parseInt(splitInfo[2]), Integer.parseInt(splitInfo[3])));
}
// Load CustomMailManager config file (if exists)
final PropertiesParser CustomMailManager = new PropertiesParser(CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE);
CUSTOM_MAIL_MANAGER_ENABLED = CustomMailManager.getBoolean("CustomMailManagerEnabled", false);
CUSTOM_MAIL_MANAGER_DELAY = CustomMailManager.getInt("DatabaseQueryDelay", 30) * 1000;
// Load DualboxCheck config file (if exists)
final PropertiesParser DualboxCheck = new PropertiesParser(CUSTOM_DUALBOX_CHECK_CONFIG_FILE);

View File

@ -111,6 +111,7 @@ import com.l2jmobius.gameserver.instancemanager.ClanEntryManager;
import com.l2jmobius.gameserver.instancemanager.ClanHallAuctionManager;
import com.l2jmobius.gameserver.instancemanager.CommissionManager;
import com.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
import com.l2jmobius.gameserver.instancemanager.CustomMailManager;
import com.l2jmobius.gameserver.instancemanager.DBSpawnManager;
import com.l2jmobius.gameserver.instancemanager.FactionManager;
import com.l2jmobius.gameserver.instancemanager.FakePlayerChatManager;
@ -402,6 +403,10 @@ public class GameServer
{
MailManager.getInstance();
}
if (Config.CUSTOM_MAIL_MANAGER_ENABLED)
{
CustomMailManager.getInstance();
}
PunishmentManager.getInstance();

View File

@ -0,0 +1,131 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.enums.MailType;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.entity.Message;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
import com.l2jmobius.gameserver.model.itemcontainer.Mail;
import com.l2jmobius.gameserver.util.Util;
/**
* @author Mobius
*/
public class CustomMailManager
{
private static final Logger LOGGER = Logger.getLogger(CustomMailManager.class.getName());
// SQL Statements
private static final String READ_SQL = "SELECT * FROM custom_mail";
private static final String DELETE_SQL = "DELETE FROM custom_mail WHERE date=? AND receiver=?";
protected CustomMailManager()
{
ThreadPool.scheduleAtFixedRate(() ->
{
try (Connection con = DatabaseFactory.getConnection();
Statement ps = con.createStatement();
ResultSet rs = ps.executeQuery(READ_SQL))
{
while (rs.next())
{
final int playerId = rs.getInt("receiver");
final L2PcInstance player = L2World.getInstance().getPlayer(playerId);
if ((player != null) && player.isOnline())
{
// Create message.
final String items = rs.getString("items");
final Message msg = new Message(playerId, rs.getString("subject"), rs.getString("message"), items.length() > 0 ? MailType.PRIME_SHOP_GIFT : MailType.REGULAR);
final List<ItemHolder> itemHolders = new ArrayList<>();
for (String str : items.split(";"))
{
if (str.toLowerCase().contains(" "))
{
final String itemId = str.toLowerCase().split(" ")[0];
final String itemCount = str.toLowerCase().split(" ")[1];
if (Util.isDigit(itemId) && Util.isDigit(itemCount))
{
itemHolders.add(new ItemHolder(Integer.parseInt(itemId), Long.parseLong(itemCount)));
}
}
else if (Util.isDigit(str))
{
itemHolders.add(new ItemHolder(Integer.parseInt(str), 1));
}
}
if (!itemHolders.isEmpty())
{
final Mail attachments = msg.createAttachments();
for (ItemHolder itemHolder : itemHolders)
{
attachments.addItem("Custom-Mail", itemHolder.getId(), itemHolder.getCount(), null, null);
}
}
// Delete entry from database.
try (Connection con2 = DatabaseFactory.getConnection();
PreparedStatement stmt = con2.prepareStatement(DELETE_SQL))
{
stmt.setString(1, rs.getString("date"));
stmt.setInt(2, playerId);
stmt.execute();
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting entry from database:", e);
}
// Send message.
MailManager.getInstance().sendMessage(msg);
LOGGER.info(getClass().getSimpleName() + ": Sent message at " + player.getName() + ".");
}
}
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:", e);
}
}, Config.CUSTOM_MAIL_MANAGER_DELAY, Config.CUSTOM_MAIL_MANAGER_DELAY);
LOGGER.info(getClass().getSimpleName() + ": Enabled.");
}
public static CustomMailManager getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final CustomMailManager INSTANCE = new CustomMailManager();
}
}

View File

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS `custom_mail` (
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`receiver` INT UNSIGNED NOT NULL DEFAULT 0,
`subject` TINYTEXT NOT NULL DEFAULT "",
`message` TEXT NOT NULL DEFAULT "",
`items` TEXT NOT NULL DEFAULT "" -- format: itemId1 count1;itemId2 count2;itemId3 count3...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,11 @@
# ---------------------------------------------------------------------------
# Custom Mail Manager
# ---------------------------------------------------------------------------
# Enable/Disable sending mail through the custom_mail SQL table.
# Default: False
CustomMailManagerEnabled = False
# Database query delay in seconds.
# Default: 30
DatabaseQueryDelay = 30

View File

@ -113,6 +113,7 @@ public final class Config
private static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
private static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
private static final String CUSTOM_COMMUNITY_BOARD_CONFIG_FILE = "./config/Custom/CommunityBoard.ini";
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/Custom/CustomMailManager.ini";
private static final String CUSTOM_DUALBOX_CHECK_CONFIG_FILE = "./config/Custom/DualboxCheck.ini";
private static final String CUSTOM_FACTION_SYSTEM_CONFIG_FILE = "./config/Custom/FactionSystem.ini";
private static final String CUSTOM_FAKE_PLAYERS_CONFIG_FILE = "./config/Custom/FakePlayers.ini";
@ -1097,6 +1098,8 @@ public final class Config
public static int COMMUNITY_PREMIUM_PRICE_PER_DAY;
public static List<Integer> COMMUNITY_AVAILABLE_BUFFS;
public static Map<String, Location> COMMUNITY_AVAILABLE_TELEPORTS;
public static boolean CUSTOM_MAIL_MANAGER_ENABLED;
public static int CUSTOM_MAIL_MANAGER_DELAY;
public static boolean FACTION_SYSTEM_ENABLED;
public static Location FACTION_STARTING_LOCATION;
public static Location FACTION_MANAGER_LOCATION;
@ -2442,6 +2445,12 @@ public final class Config
COMMUNITY_AVAILABLE_TELEPORTS.put(splitInfo[0], new Location(Integer.parseInt(splitInfo[1]), Integer.parseInt(splitInfo[2]), Integer.parseInt(splitInfo[3])));
}
// Load CustomMailManager config file (if exists)
final PropertiesParser CustomMailManager = new PropertiesParser(CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE);
CUSTOM_MAIL_MANAGER_ENABLED = CustomMailManager.getBoolean("CustomMailManagerEnabled", false);
CUSTOM_MAIL_MANAGER_DELAY = CustomMailManager.getInt("DatabaseQueryDelay", 30) * 1000;
// Load DualboxCheck config file (if exists)
final PropertiesParser DualboxCheck = new PropertiesParser(CUSTOM_DUALBOX_CHECK_CONFIG_FILE);

View File

@ -115,6 +115,7 @@ import com.l2jmobius.gameserver.instancemanager.ClanEntryManager;
import com.l2jmobius.gameserver.instancemanager.ClanHallAuctionManager;
import com.l2jmobius.gameserver.instancemanager.CommissionManager;
import com.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
import com.l2jmobius.gameserver.instancemanager.CustomMailManager;
import com.l2jmobius.gameserver.instancemanager.DBSpawnManager;
import com.l2jmobius.gameserver.instancemanager.FactionManager;
import com.l2jmobius.gameserver.instancemanager.FakePlayerChatManager;
@ -410,6 +411,10 @@ public class GameServer
{
MailManager.getInstance();
}
if (Config.CUSTOM_MAIL_MANAGER_ENABLED)
{
CustomMailManager.getInstance();
}
PunishmentManager.getInstance();

View File

@ -0,0 +1,131 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.enums.MailType;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.entity.Message;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
import com.l2jmobius.gameserver.model.itemcontainer.Mail;
import com.l2jmobius.gameserver.util.Util;
/**
* @author Mobius
*/
public class CustomMailManager
{
private static final Logger LOGGER = Logger.getLogger(CustomMailManager.class.getName());
// SQL Statements
private static final String READ_SQL = "SELECT * FROM custom_mail";
private static final String DELETE_SQL = "DELETE FROM custom_mail WHERE date=? AND receiver=?";
protected CustomMailManager()
{
ThreadPool.scheduleAtFixedRate(() ->
{
try (Connection con = DatabaseFactory.getConnection();
Statement ps = con.createStatement();
ResultSet rs = ps.executeQuery(READ_SQL))
{
while (rs.next())
{
final int playerId = rs.getInt("receiver");
final L2PcInstance player = L2World.getInstance().getPlayer(playerId);
if ((player != null) && player.isOnline())
{
// Create message.
final String items = rs.getString("items");
final Message msg = new Message(playerId, rs.getString("subject"), rs.getString("message"), items.length() > 0 ? MailType.PRIME_SHOP_GIFT : MailType.REGULAR);
final List<ItemHolder> itemHolders = new ArrayList<>();
for (String str : items.split(";"))
{
if (str.toLowerCase().contains(" "))
{
final String itemId = str.toLowerCase().split(" ")[0];
final String itemCount = str.toLowerCase().split(" ")[1];
if (Util.isDigit(itemId) && Util.isDigit(itemCount))
{
itemHolders.add(new ItemHolder(Integer.parseInt(itemId), Long.parseLong(itemCount)));
}
}
else if (Util.isDigit(str))
{
itemHolders.add(new ItemHolder(Integer.parseInt(str), 1));
}
}
if (!itemHolders.isEmpty())
{
final Mail attachments = msg.createAttachments();
for (ItemHolder itemHolder : itemHolders)
{
attachments.addItem("Custom-Mail", itemHolder.getId(), itemHolder.getCount(), null, null);
}
}
// Delete entry from database.
try (Connection con2 = DatabaseFactory.getConnection();
PreparedStatement stmt = con2.prepareStatement(DELETE_SQL))
{
stmt.setString(1, rs.getString("date"));
stmt.setInt(2, playerId);
stmt.execute();
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting entry from database:", e);
}
// Send message.
MailManager.getInstance().sendMessage(msg);
LOGGER.info(getClass().getSimpleName() + ": Sent message at " + player.getName() + ".");
}
}
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:", e);
}
}, Config.CUSTOM_MAIL_MANAGER_DELAY, Config.CUSTOM_MAIL_MANAGER_DELAY);
LOGGER.info(getClass().getSimpleName() + ": Enabled.");
}
public static CustomMailManager getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final CustomMailManager INSTANCE = new CustomMailManager();
}
}

View File

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS `custom_mail` (
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`receiver` INT UNSIGNED NOT NULL DEFAULT 0,
`subject` TINYTEXT NOT NULL DEFAULT "",
`message` TEXT NOT NULL DEFAULT "",
`items` TEXT NOT NULL DEFAULT "" -- format: itemId1 count1;itemId2 count2;itemId3 count3...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,11 @@
# ---------------------------------------------------------------------------
# Custom Mail Manager
# ---------------------------------------------------------------------------
# Enable/Disable sending mail through the custom_mail SQL table.
# Default: False
CustomMailManagerEnabled = False
# Database query delay in seconds.
# Default: 30
DatabaseQueryDelay = 30

View File

@ -113,6 +113,7 @@ public final class Config
private static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
private static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
private static final String CUSTOM_COMMUNITY_BOARD_CONFIG_FILE = "./config/Custom/CommunityBoard.ini";
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/Custom/CustomMailManager.ini";
private static final String CUSTOM_DUALBOX_CHECK_CONFIG_FILE = "./config/Custom/DualboxCheck.ini";
private static final String CUSTOM_FACTION_SYSTEM_CONFIG_FILE = "./config/Custom/FactionSystem.ini";
private static final String CUSTOM_FAKE_PLAYERS_CONFIG_FILE = "./config/Custom/FakePlayers.ini";
@ -1105,6 +1106,8 @@ public final class Config
public static int COMMUNITY_PREMIUM_PRICE_PER_DAY;
public static List<Integer> COMMUNITY_AVAILABLE_BUFFS;
public static Map<String, Location> COMMUNITY_AVAILABLE_TELEPORTS;
public static boolean CUSTOM_MAIL_MANAGER_ENABLED;
public static int CUSTOM_MAIL_MANAGER_DELAY;
public static boolean FACTION_SYSTEM_ENABLED;
public static Location FACTION_STARTING_LOCATION;
public static Location FACTION_MANAGER_LOCATION;
@ -2457,6 +2460,12 @@ public final class Config
COMMUNITY_AVAILABLE_TELEPORTS.put(splitInfo[0], new Location(Integer.parseInt(splitInfo[1]), Integer.parseInt(splitInfo[2]), Integer.parseInt(splitInfo[3])));
}
// Load CustomMailManager config file (if exists)
final PropertiesParser CustomMailManager = new PropertiesParser(CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE);
CUSTOM_MAIL_MANAGER_ENABLED = CustomMailManager.getBoolean("CustomMailManagerEnabled", false);
CUSTOM_MAIL_MANAGER_DELAY = CustomMailManager.getInt("DatabaseQueryDelay", 30) * 1000;
// Load DualboxCheck config file (if exists)
final PropertiesParser DualboxCheck = new PropertiesParser(CUSTOM_DUALBOX_CHECK_CONFIG_FILE);

View File

@ -115,6 +115,7 @@ import com.l2jmobius.gameserver.instancemanager.ClanEntryManager;
import com.l2jmobius.gameserver.instancemanager.ClanHallAuctionManager;
import com.l2jmobius.gameserver.instancemanager.CommissionManager;
import com.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
import com.l2jmobius.gameserver.instancemanager.CustomMailManager;
import com.l2jmobius.gameserver.instancemanager.DBSpawnManager;
import com.l2jmobius.gameserver.instancemanager.FactionManager;
import com.l2jmobius.gameserver.instancemanager.FakePlayerChatManager;
@ -410,6 +411,10 @@ public class GameServer
{
MailManager.getInstance();
}
if (Config.CUSTOM_MAIL_MANAGER_ENABLED)
{
CustomMailManager.getInstance();
}
PunishmentManager.getInstance();

View File

@ -0,0 +1,131 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.enums.MailType;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.entity.Message;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
import com.l2jmobius.gameserver.model.itemcontainer.Mail;
import com.l2jmobius.gameserver.util.Util;
/**
* @author Mobius
*/
public class CustomMailManager
{
private static final Logger LOGGER = Logger.getLogger(CustomMailManager.class.getName());
// SQL Statements
private static final String READ_SQL = "SELECT * FROM custom_mail";
private static final String DELETE_SQL = "DELETE FROM custom_mail WHERE date=? AND receiver=?";
protected CustomMailManager()
{
ThreadPool.scheduleAtFixedRate(() ->
{
try (Connection con = DatabaseFactory.getConnection();
Statement ps = con.createStatement();
ResultSet rs = ps.executeQuery(READ_SQL))
{
while (rs.next())
{
final int playerId = rs.getInt("receiver");
final L2PcInstance player = L2World.getInstance().getPlayer(playerId);
if ((player != null) && player.isOnline())
{
// Create message.
final String items = rs.getString("items");
final Message msg = new Message(playerId, rs.getString("subject"), rs.getString("message"), items.length() > 0 ? MailType.PRIME_SHOP_GIFT : MailType.REGULAR);
final List<ItemHolder> itemHolders = new ArrayList<>();
for (String str : items.split(";"))
{
if (str.toLowerCase().contains(" "))
{
final String itemId = str.toLowerCase().split(" ")[0];
final String itemCount = str.toLowerCase().split(" ")[1];
if (Util.isDigit(itemId) && Util.isDigit(itemCount))
{
itemHolders.add(new ItemHolder(Integer.parseInt(itemId), Long.parseLong(itemCount)));
}
}
else if (Util.isDigit(str))
{
itemHolders.add(new ItemHolder(Integer.parseInt(str), 1));
}
}
if (!itemHolders.isEmpty())
{
final Mail attachments = msg.createAttachments();
for (ItemHolder itemHolder : itemHolders)
{
attachments.addItem("Custom-Mail", itemHolder.getId(), itemHolder.getCount(), null, null);
}
}
// Delete entry from database.
try (Connection con2 = DatabaseFactory.getConnection();
PreparedStatement stmt = con2.prepareStatement(DELETE_SQL))
{
stmt.setString(1, rs.getString("date"));
stmt.setInt(2, playerId);
stmt.execute();
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting entry from database:", e);
}
// Send message.
MailManager.getInstance().sendMessage(msg);
LOGGER.info(getClass().getSimpleName() + ": Sent message at " + player.getName() + ".");
}
}
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:", e);
}
}, Config.CUSTOM_MAIL_MANAGER_DELAY, Config.CUSTOM_MAIL_MANAGER_DELAY);
LOGGER.info(getClass().getSimpleName() + ": Enabled.");
}
public static CustomMailManager getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final CustomMailManager INSTANCE = new CustomMailManager();
}
}

View File

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS `custom_mail` (
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`receiver` INT UNSIGNED NOT NULL DEFAULT 0,
`subject` TINYTEXT NOT NULL DEFAULT "",
`message` TEXT NOT NULL DEFAULT "",
`items` TEXT NOT NULL DEFAULT "" -- format: itemId1 count1;itemId2 count2;itemId3 count3...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,11 @@
# ---------------------------------------------------------------------------
# Custom Mail Manager
# ---------------------------------------------------------------------------
# Enable/Disable sending mail through the custom_mail SQL table.
# Default: False
CustomMailManagerEnabled = False
# Database query delay in seconds.
# Default: 30
DatabaseQueryDelay = 30

View File

@ -113,6 +113,7 @@ public final class Config
private static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
private static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
private static final String CUSTOM_COMMUNITY_BOARD_CONFIG_FILE = "./config/Custom/CommunityBoard.ini";
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/Custom/CustomMailManager.ini";
private static final String CUSTOM_DUALBOX_CHECK_CONFIG_FILE = "./config/Custom/DualboxCheck.ini";
private static final String CUSTOM_FACTION_SYSTEM_CONFIG_FILE = "./config/Custom/FactionSystem.ini";
private static final String CUSTOM_FAKE_PLAYERS_CONFIG_FILE = "./config/Custom/FakePlayers.ini";
@ -1098,6 +1099,8 @@ public final class Config
public static int COMMUNITY_PREMIUM_PRICE_PER_DAY;
public static List<Integer> COMMUNITY_AVAILABLE_BUFFS;
public static Map<String, Location> COMMUNITY_AVAILABLE_TELEPORTS;
public static boolean CUSTOM_MAIL_MANAGER_ENABLED;
public static int CUSTOM_MAIL_MANAGER_DELAY;
public static boolean FACTION_SYSTEM_ENABLED;
public static Location FACTION_STARTING_LOCATION;
public static Location FACTION_MANAGER_LOCATION;
@ -2443,6 +2446,12 @@ public final class Config
COMMUNITY_AVAILABLE_TELEPORTS.put(splitInfo[0], new Location(Integer.parseInt(splitInfo[1]), Integer.parseInt(splitInfo[2]), Integer.parseInt(splitInfo[3])));
}
// Load CustomMailManager config file (if exists)
final PropertiesParser CustomMailManager = new PropertiesParser(CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE);
CUSTOM_MAIL_MANAGER_ENABLED = CustomMailManager.getBoolean("CustomMailManagerEnabled", false);
CUSTOM_MAIL_MANAGER_DELAY = CustomMailManager.getInt("DatabaseQueryDelay", 30) * 1000;
// Load DualboxCheck config file (if exists)
final PropertiesParser DualboxCheck = new PropertiesParser(CUSTOM_DUALBOX_CHECK_CONFIG_FILE);

View File

@ -115,6 +115,7 @@ import com.l2jmobius.gameserver.instancemanager.ClanEntryManager;
import com.l2jmobius.gameserver.instancemanager.ClanHallAuctionManager;
import com.l2jmobius.gameserver.instancemanager.CommissionManager;
import com.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
import com.l2jmobius.gameserver.instancemanager.CustomMailManager;
import com.l2jmobius.gameserver.instancemanager.DBSpawnManager;
import com.l2jmobius.gameserver.instancemanager.FactionManager;
import com.l2jmobius.gameserver.instancemanager.FakePlayerChatManager;
@ -410,6 +411,10 @@ public class GameServer
{
MailManager.getInstance();
}
if (Config.CUSTOM_MAIL_MANAGER_ENABLED)
{
CustomMailManager.getInstance();
}
PunishmentManager.getInstance();

View File

@ -0,0 +1,131 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.enums.MailType;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.entity.Message;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
import com.l2jmobius.gameserver.model.itemcontainer.Mail;
import com.l2jmobius.gameserver.util.Util;
/**
* @author Mobius
*/
public class CustomMailManager
{
private static final Logger LOGGER = Logger.getLogger(CustomMailManager.class.getName());
// SQL Statements
private static final String READ_SQL = "SELECT * FROM custom_mail";
private static final String DELETE_SQL = "DELETE FROM custom_mail WHERE date=? AND receiver=?";
protected CustomMailManager()
{
ThreadPool.scheduleAtFixedRate(() ->
{
try (Connection con = DatabaseFactory.getConnection();
Statement ps = con.createStatement();
ResultSet rs = ps.executeQuery(READ_SQL))
{
while (rs.next())
{
final int playerId = rs.getInt("receiver");
final L2PcInstance player = L2World.getInstance().getPlayer(playerId);
if ((player != null) && player.isOnline())
{
// Create message.
final String items = rs.getString("items");
final Message msg = new Message(playerId, rs.getString("subject"), rs.getString("message"), items.length() > 0 ? MailType.PRIME_SHOP_GIFT : MailType.REGULAR);
final List<ItemHolder> itemHolders = new ArrayList<>();
for (String str : items.split(";"))
{
if (str.toLowerCase().contains(" "))
{
final String itemId = str.toLowerCase().split(" ")[0];
final String itemCount = str.toLowerCase().split(" ")[1];
if (Util.isDigit(itemId) && Util.isDigit(itemCount))
{
itemHolders.add(new ItemHolder(Integer.parseInt(itemId), Long.parseLong(itemCount)));
}
}
else if (Util.isDigit(str))
{
itemHolders.add(new ItemHolder(Integer.parseInt(str), 1));
}
}
if (!itemHolders.isEmpty())
{
final Mail attachments = msg.createAttachments();
for (ItemHolder itemHolder : itemHolders)
{
attachments.addItem("Custom-Mail", itemHolder.getId(), itemHolder.getCount(), null, null);
}
}
// Delete entry from database.
try (Connection con2 = DatabaseFactory.getConnection();
PreparedStatement stmt = con2.prepareStatement(DELETE_SQL))
{
stmt.setString(1, rs.getString("date"));
stmt.setInt(2, playerId);
stmt.execute();
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting entry from database:", e);
}
// Send message.
MailManager.getInstance().sendMessage(msg);
LOGGER.info(getClass().getSimpleName() + ": Sent message at " + player.getName() + ".");
}
}
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:", e);
}
}, Config.CUSTOM_MAIL_MANAGER_DELAY, Config.CUSTOM_MAIL_MANAGER_DELAY);
LOGGER.info(getClass().getSimpleName() + ": Enabled.");
}
public static CustomMailManager getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final CustomMailManager INSTANCE = new CustomMailManager();
}
}

View File

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS `custom_mail` (
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`receiver` INT UNSIGNED NOT NULL DEFAULT 0,
`subject` TINYTEXT NOT NULL DEFAULT "",
`message` TEXT NOT NULL DEFAULT "",
`items` TEXT NOT NULL DEFAULT "" -- format: itemId1 count1;itemId2 count2;itemId3 count3...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,11 @@
# ---------------------------------------------------------------------------
# Custom Mail Manager
# ---------------------------------------------------------------------------
# Enable/Disable sending mail through the custom_mail SQL table.
# Default: False
CustomMailManagerEnabled = False
# Database query delay in seconds.
# Default: 30
DatabaseQueryDelay = 30

View File

@ -113,6 +113,7 @@ public final class Config
private static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
private static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
private static final String CUSTOM_COMMUNITY_BOARD_CONFIG_FILE = "./config/Custom/CommunityBoard.ini";
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/Custom/CustomMailManager.ini";
private static final String CUSTOM_DUALBOX_CHECK_CONFIG_FILE = "./config/Custom/DualboxCheck.ini";
private static final String CUSTOM_FACTION_SYSTEM_CONFIG_FILE = "./config/Custom/FactionSystem.ini";
private static final String CUSTOM_FAKE_PLAYERS_CONFIG_FILE = "./config/Custom/FakePlayers.ini";
@ -1098,6 +1099,8 @@ public final class Config
public static int COMMUNITY_PREMIUM_PRICE_PER_DAY;
public static List<Integer> COMMUNITY_AVAILABLE_BUFFS;
public static Map<String, Location> COMMUNITY_AVAILABLE_TELEPORTS;
public static boolean CUSTOM_MAIL_MANAGER_ENABLED;
public static int CUSTOM_MAIL_MANAGER_DELAY;
public static boolean FACTION_SYSTEM_ENABLED;
public static Location FACTION_STARTING_LOCATION;
public static Location FACTION_MANAGER_LOCATION;
@ -2443,6 +2446,12 @@ public final class Config
COMMUNITY_AVAILABLE_TELEPORTS.put(splitInfo[0], new Location(Integer.parseInt(splitInfo[1]), Integer.parseInt(splitInfo[2]), Integer.parseInt(splitInfo[3])));
}
// Load CustomMailManager config file (if exists)
final PropertiesParser CustomMailManager = new PropertiesParser(CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE);
CUSTOM_MAIL_MANAGER_ENABLED = CustomMailManager.getBoolean("CustomMailManagerEnabled", false);
CUSTOM_MAIL_MANAGER_DELAY = CustomMailManager.getInt("DatabaseQueryDelay", 30) * 1000;
// Load DualboxCheck config file (if exists)
final PropertiesParser DualboxCheck = new PropertiesParser(CUSTOM_DUALBOX_CHECK_CONFIG_FILE);

View File

@ -117,6 +117,7 @@ import com.l2jmobius.gameserver.instancemanager.ClanEntryManager;
import com.l2jmobius.gameserver.instancemanager.ClanHallAuctionManager;
import com.l2jmobius.gameserver.instancemanager.CommissionManager;
import com.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
import com.l2jmobius.gameserver.instancemanager.CustomMailManager;
import com.l2jmobius.gameserver.instancemanager.DBSpawnManager;
import com.l2jmobius.gameserver.instancemanager.FactionManager;
import com.l2jmobius.gameserver.instancemanager.FakePlayerChatManager;
@ -414,6 +415,10 @@ public class GameServer
{
MailManager.getInstance();
}
if (Config.CUSTOM_MAIL_MANAGER_ENABLED)
{
CustomMailManager.getInstance();
}
PunishmentManager.getInstance();

View File

@ -0,0 +1,131 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.enums.MailType;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.entity.Message;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
import com.l2jmobius.gameserver.model.itemcontainer.Mail;
import com.l2jmobius.gameserver.util.Util;
/**
* @author Mobius
*/
public class CustomMailManager
{
private static final Logger LOGGER = Logger.getLogger(CustomMailManager.class.getName());
// SQL Statements
private static final String READ_SQL = "SELECT * FROM custom_mail";
private static final String DELETE_SQL = "DELETE FROM custom_mail WHERE date=? AND receiver=?";
protected CustomMailManager()
{
ThreadPool.scheduleAtFixedRate(() ->
{
try (Connection con = DatabaseFactory.getConnection();
Statement ps = con.createStatement();
ResultSet rs = ps.executeQuery(READ_SQL))
{
while (rs.next())
{
final int playerId = rs.getInt("receiver");
final L2PcInstance player = L2World.getInstance().getPlayer(playerId);
if ((player != null) && player.isOnline())
{
// Create message.
final String items = rs.getString("items");
final Message msg = new Message(playerId, rs.getString("subject"), rs.getString("message"), items.length() > 0 ? MailType.PRIME_SHOP_GIFT : MailType.REGULAR);
final List<ItemHolder> itemHolders = new ArrayList<>();
for (String str : items.split(";"))
{
if (str.toLowerCase().contains(" "))
{
final String itemId = str.toLowerCase().split(" ")[0];
final String itemCount = str.toLowerCase().split(" ")[1];
if (Util.isDigit(itemId) && Util.isDigit(itemCount))
{
itemHolders.add(new ItemHolder(Integer.parseInt(itemId), Long.parseLong(itemCount)));
}
}
else if (Util.isDigit(str))
{
itemHolders.add(new ItemHolder(Integer.parseInt(str), 1));
}
}
if (!itemHolders.isEmpty())
{
final Mail attachments = msg.createAttachments();
for (ItemHolder itemHolder : itemHolders)
{
attachments.addItem("Custom-Mail", itemHolder.getId(), itemHolder.getCount(), null, null);
}
}
// Delete entry from database.
try (Connection con2 = DatabaseFactory.getConnection();
PreparedStatement stmt = con2.prepareStatement(DELETE_SQL))
{
stmt.setString(1, rs.getString("date"));
stmt.setInt(2, playerId);
stmt.execute();
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting entry from database:", e);
}
// Send message.
MailManager.getInstance().sendMessage(msg);
LOGGER.info(getClass().getSimpleName() + ": Sent message at " + player.getName() + ".");
}
}
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:", e);
}
}, Config.CUSTOM_MAIL_MANAGER_DELAY, Config.CUSTOM_MAIL_MANAGER_DELAY);
LOGGER.info(getClass().getSimpleName() + ": Enabled.");
}
public static CustomMailManager getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final CustomMailManager INSTANCE = new CustomMailManager();
}
}

View File

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS `custom_mail` (
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`receiver` INT UNSIGNED NOT NULL DEFAULT 0,
`subject` TINYTEXT NOT NULL DEFAULT "",
`message` TEXT NOT NULL DEFAULT "",
`items` TEXT NOT NULL DEFAULT "" -- format: itemId1 count1;itemId2 count2;itemId3 count3...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,11 @@
# ---------------------------------------------------------------------------
# Custom Mail Manager
# ---------------------------------------------------------------------------
# Enable/Disable sending mail through the custom_mail SQL table.
# Default: False
CustomMailManagerEnabled = False
# Database query delay in seconds.
# Default: 30
DatabaseQueryDelay = 30

View File

@ -113,6 +113,7 @@ public final class Config
private static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
private static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
private static final String CUSTOM_COMMUNITY_BOARD_CONFIG_FILE = "./config/Custom/CommunityBoard.ini";
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/Custom/CustomMailManager.ini";
private static final String CUSTOM_DUALBOX_CHECK_CONFIG_FILE = "./config/Custom/DualboxCheck.ini";
private static final String CUSTOM_FACTION_SYSTEM_CONFIG_FILE = "./config/Custom/FactionSystem.ini";
private static final String CUSTOM_FAKE_PLAYERS_CONFIG_FILE = "./config/Custom/FakePlayers.ini";
@ -1098,6 +1099,8 @@ public final class Config
public static int COMMUNITY_PREMIUM_PRICE_PER_DAY;
public static List<Integer> COMMUNITY_AVAILABLE_BUFFS;
public static Map<String, Location> COMMUNITY_AVAILABLE_TELEPORTS;
public static boolean CUSTOM_MAIL_MANAGER_ENABLED;
public static int CUSTOM_MAIL_MANAGER_DELAY;
public static boolean FACTION_SYSTEM_ENABLED;
public static Location FACTION_STARTING_LOCATION;
public static Location FACTION_MANAGER_LOCATION;
@ -2443,6 +2446,12 @@ public final class Config
COMMUNITY_AVAILABLE_TELEPORTS.put(splitInfo[0], new Location(Integer.parseInt(splitInfo[1]), Integer.parseInt(splitInfo[2]), Integer.parseInt(splitInfo[3])));
}
// Load CustomMailManager config file (if exists)
final PropertiesParser CustomMailManager = new PropertiesParser(CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE);
CUSTOM_MAIL_MANAGER_ENABLED = CustomMailManager.getBoolean("CustomMailManagerEnabled", false);
CUSTOM_MAIL_MANAGER_DELAY = CustomMailManager.getInt("DatabaseQueryDelay", 30) * 1000;
// Load DualboxCheck config file (if exists)
final PropertiesParser DualboxCheck = new PropertiesParser(CUSTOM_DUALBOX_CHECK_CONFIG_FILE);

View File

@ -117,6 +117,7 @@ import com.l2jmobius.gameserver.instancemanager.ClanEntryManager;
import com.l2jmobius.gameserver.instancemanager.ClanHallAuctionManager;
import com.l2jmobius.gameserver.instancemanager.CommissionManager;
import com.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
import com.l2jmobius.gameserver.instancemanager.CustomMailManager;
import com.l2jmobius.gameserver.instancemanager.DBSpawnManager;
import com.l2jmobius.gameserver.instancemanager.FactionManager;
import com.l2jmobius.gameserver.instancemanager.FakePlayerChatManager;
@ -414,6 +415,10 @@ public class GameServer
{
MailManager.getInstance();
}
if (Config.CUSTOM_MAIL_MANAGER_ENABLED)
{
CustomMailManager.getInstance();
}
PunishmentManager.getInstance();

View File

@ -0,0 +1,131 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.enums.MailType;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.entity.Message;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
import com.l2jmobius.gameserver.model.itemcontainer.Mail;
import com.l2jmobius.gameserver.util.Util;
/**
* @author Mobius
*/
public class CustomMailManager
{
private static final Logger LOGGER = Logger.getLogger(CustomMailManager.class.getName());
// SQL Statements
private static final String READ_SQL = "SELECT * FROM custom_mail";
private static final String DELETE_SQL = "DELETE FROM custom_mail WHERE date=? AND receiver=?";
protected CustomMailManager()
{
ThreadPool.scheduleAtFixedRate(() ->
{
try (Connection con = DatabaseFactory.getConnection();
Statement ps = con.createStatement();
ResultSet rs = ps.executeQuery(READ_SQL))
{
while (rs.next())
{
final int playerId = rs.getInt("receiver");
final L2PcInstance player = L2World.getInstance().getPlayer(playerId);
if ((player != null) && player.isOnline())
{
// Create message.
final String items = rs.getString("items");
final Message msg = new Message(playerId, rs.getString("subject"), rs.getString("message"), items.length() > 0 ? MailType.PRIME_SHOP_GIFT : MailType.REGULAR);
final List<ItemHolder> itemHolders = new ArrayList<>();
for (String str : items.split(";"))
{
if (str.toLowerCase().contains(" "))
{
final String itemId = str.toLowerCase().split(" ")[0];
final String itemCount = str.toLowerCase().split(" ")[1];
if (Util.isDigit(itemId) && Util.isDigit(itemCount))
{
itemHolders.add(new ItemHolder(Integer.parseInt(itemId), Long.parseLong(itemCount)));
}
}
else if (Util.isDigit(str))
{
itemHolders.add(new ItemHolder(Integer.parseInt(str), 1));
}
}
if (!itemHolders.isEmpty())
{
final Mail attachments = msg.createAttachments();
for (ItemHolder itemHolder : itemHolders)
{
attachments.addItem("Custom-Mail", itemHolder.getId(), itemHolder.getCount(), null, null);
}
}
// Delete entry from database.
try (Connection con2 = DatabaseFactory.getConnection();
PreparedStatement stmt = con2.prepareStatement(DELETE_SQL))
{
stmt.setString(1, rs.getString("date"));
stmt.setInt(2, playerId);
stmt.execute();
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting entry from database:", e);
}
// Send message.
MailManager.getInstance().sendMessage(msg);
LOGGER.info(getClass().getSimpleName() + ": Sent message at " + player.getName() + ".");
}
}
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:", e);
}
}, Config.CUSTOM_MAIL_MANAGER_DELAY, Config.CUSTOM_MAIL_MANAGER_DELAY);
LOGGER.info(getClass().getSimpleName() + ": Enabled.");
}
public static CustomMailManager getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final CustomMailManager INSTANCE = new CustomMailManager();
}
}

View File

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS `custom_mail` (
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`receiver` INT UNSIGNED NOT NULL DEFAULT 0,
`subject` TINYTEXT NOT NULL DEFAULT "",
`message` TEXT NOT NULL DEFAULT "",
`items` TEXT NOT NULL DEFAULT "" -- format: itemId1 count1;itemId2 count2;itemId3 count3...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,11 @@
# ---------------------------------------------------------------------------
# Custom Mail Manager
# ---------------------------------------------------------------------------
# Enable/Disable sending mail through the custom_mail SQL table.
# Default: False
CustomMailManagerEnabled = False
# Database query delay in seconds.
# Default: 30
DatabaseQueryDelay = 30

View File

@ -113,6 +113,7 @@ public final class Config
private static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
private static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
private static final String CUSTOM_COMMUNITY_BOARD_CONFIG_FILE = "./config/Custom/CommunityBoard.ini";
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/Custom/CustomMailManager.ini";
private static final String CUSTOM_DUALBOX_CHECK_CONFIG_FILE = "./config/Custom/DualboxCheck.ini";
private static final String CUSTOM_FACTION_SYSTEM_CONFIG_FILE = "./config/Custom/FactionSystem.ini";
private static final String CUSTOM_FAKE_PLAYERS_CONFIG_FILE = "./config/Custom/FakePlayers.ini";
@ -1104,6 +1105,8 @@ public final class Config
public static int COMMUNITY_PREMIUM_PRICE_PER_DAY;
public static List<Integer> COMMUNITY_AVAILABLE_BUFFS;
public static Map<String, Location> COMMUNITY_AVAILABLE_TELEPORTS;
public static boolean CUSTOM_MAIL_MANAGER_ENABLED;
public static int CUSTOM_MAIL_MANAGER_DELAY;
public static boolean FACTION_SYSTEM_ENABLED;
public static Location FACTION_STARTING_LOCATION;
public static Location FACTION_MANAGER_LOCATION;
@ -2454,6 +2457,12 @@ public final class Config
COMMUNITY_AVAILABLE_TELEPORTS.put(splitInfo[0], new Location(Integer.parseInt(splitInfo[1]), Integer.parseInt(splitInfo[2]), Integer.parseInt(splitInfo[3])));
}
// Load CustomMailManager config file (if exists)
final PropertiesParser CustomMailManager = new PropertiesParser(CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE);
CUSTOM_MAIL_MANAGER_ENABLED = CustomMailManager.getBoolean("CustomMailManagerEnabled", false);
CUSTOM_MAIL_MANAGER_DELAY = CustomMailManager.getInt("DatabaseQueryDelay", 30) * 1000;
// Load DualboxCheck config file (if exists)
final PropertiesParser DualboxCheck = new PropertiesParser(CUSTOM_DUALBOX_CHECK_CONFIG_FILE);

View File

@ -117,6 +117,7 @@ import com.l2jmobius.gameserver.instancemanager.ClanEntryManager;
import com.l2jmobius.gameserver.instancemanager.ClanHallAuctionManager;
import com.l2jmobius.gameserver.instancemanager.CommissionManager;
import com.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
import com.l2jmobius.gameserver.instancemanager.CustomMailManager;
import com.l2jmobius.gameserver.instancemanager.DBSpawnManager;
import com.l2jmobius.gameserver.instancemanager.FactionManager;
import com.l2jmobius.gameserver.instancemanager.FakePlayerChatManager;
@ -414,6 +415,10 @@ public class GameServer
{
MailManager.getInstance();
}
if (Config.CUSTOM_MAIL_MANAGER_ENABLED)
{
CustomMailManager.getInstance();
}
PunishmentManager.getInstance();

View File

@ -0,0 +1,131 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.enums.MailType;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.entity.Message;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
import com.l2jmobius.gameserver.model.itemcontainer.Mail;
import com.l2jmobius.gameserver.util.Util;
/**
* @author Mobius
*/
public class CustomMailManager
{
private static final Logger LOGGER = Logger.getLogger(CustomMailManager.class.getName());
// SQL Statements
private static final String READ_SQL = "SELECT * FROM custom_mail";
private static final String DELETE_SQL = "DELETE FROM custom_mail WHERE date=? AND receiver=?";
protected CustomMailManager()
{
ThreadPool.scheduleAtFixedRate(() ->
{
try (Connection con = DatabaseFactory.getConnection();
Statement ps = con.createStatement();
ResultSet rs = ps.executeQuery(READ_SQL))
{
while (rs.next())
{
final int playerId = rs.getInt("receiver");
final L2PcInstance player = L2World.getInstance().getPlayer(playerId);
if ((player != null) && player.isOnline())
{
// Create message.
final String items = rs.getString("items");
final Message msg = new Message(playerId, rs.getString("subject"), rs.getString("message"), items.length() > 0 ? MailType.PRIME_SHOP_GIFT : MailType.REGULAR);
final List<ItemHolder> itemHolders = new ArrayList<>();
for (String str : items.split(";"))
{
if (str.toLowerCase().contains(" "))
{
final String itemId = str.toLowerCase().split(" ")[0];
final String itemCount = str.toLowerCase().split(" ")[1];
if (Util.isDigit(itemId) && Util.isDigit(itemCount))
{
itemHolders.add(new ItemHolder(Integer.parseInt(itemId), Long.parseLong(itemCount)));
}
}
else if (Util.isDigit(str))
{
itemHolders.add(new ItemHolder(Integer.parseInt(str), 1));
}
}
if (!itemHolders.isEmpty())
{
final Mail attachments = msg.createAttachments();
for (ItemHolder itemHolder : itemHolders)
{
attachments.addItem("Custom-Mail", itemHolder.getId(), itemHolder.getCount(), null, null);
}
}
// Delete entry from database.
try (Connection con2 = DatabaseFactory.getConnection();
PreparedStatement stmt = con2.prepareStatement(DELETE_SQL))
{
stmt.setString(1, rs.getString("date"));
stmt.setInt(2, playerId);
stmt.execute();
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting entry from database:", e);
}
// Send message.
MailManager.getInstance().sendMessage(msg);
LOGGER.info(getClass().getSimpleName() + ": Sent message at " + player.getName() + ".");
}
}
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:", e);
}
}, Config.CUSTOM_MAIL_MANAGER_DELAY, Config.CUSTOM_MAIL_MANAGER_DELAY);
LOGGER.info(getClass().getSimpleName() + ": Enabled.");
}
public static CustomMailManager getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final CustomMailManager INSTANCE = new CustomMailManager();
}
}

View File

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS `custom_mail` (
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`receiver` INT UNSIGNED NOT NULL DEFAULT 0,
`subject` TINYTEXT NOT NULL DEFAULT "",
`message` TEXT NOT NULL DEFAULT "",
`items` TEXT NOT NULL DEFAULT "" -- format: itemId1 count1;itemId2 count2;itemId3 count3...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,11 @@
# ---------------------------------------------------------------------------
# Custom Mail Manager
# ---------------------------------------------------------------------------
# Enable/Disable sending mail through the custom_mail SQL table.
# Default: False
CustomMailManagerEnabled = False
# Database query delay in seconds.
# Default: 30
DatabaseQueryDelay = 30

View File

@ -106,37 +106,38 @@ public final class Config
// --------------------------------------------------
// Custom Config File Definitions
// --------------------------------------------------
public static final String CUSTOM_ALLOWED_PLAYER_RACES_CONFIG_FILE = "./config/Custom/AllowedPlayerRaces.ini";
public static final String CUSTOM_AUTO_POTIONS_CONFIG_FILE = "./config/Custom/AutoPotions.ini";
public static final String CUSTOM_BANKING_CONFIG_FILE = "./config/Custom/Banking.ini";
public static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
public static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
public static final String CUSTOM_COMMUNITY_BOARD_CONFIG_FILE = "./config/Custom/CommunityBoard.ini";
public static final String CUSTOM_DUALBOX_CHECK_CONFIG_FILE = "./config/Custom/DualboxCheck.ini";
public static final String CUSTOM_FACTION_SYSTEM_CONFIG_FILE = "./config/Custom/FactionSystem.ini";
public static final String CUSTOM_FAKE_PLAYERS_CONFIG_FILE = "./config/Custom/FakePlayers.ini";
public static final String CUSTOM_FIND_PVP_CONFIG_FILE = "./config/Custom/FindPvP.ini";
public static final String CUSTOM_HELLBOUND_STATUS_CONFIG_FILE = "./config/Custom/HellboundStatus.ini";
public static final String CUSTOM_MULTILANGUAL_SUPPORT_CONFIG_FILE = "./config/Custom/MultilingualSupport.ini";
public static final String CUSTOM_NPC_STAT_MULTIPIERS_CONFIG_FILE = "./config/Custom/NpcStatMultipliers.ini";
public static final String CUSTOM_OFFLINE_TRADE_CONFIG_FILE = "./config/Custom/OfflineTrade.ini";
public static final String CUSTOM_PASSWORD_CHANGE_CONFIG_FILE = "./config/Custom/PasswordChange.ini";
public static final String CUSTOM_PREMIUM_SYSTEM_CONFIG_FILE = "./config/Custom/PremiumSystem.ini";
public static final String CUSTOM_PRIVATE_STORE_RANGE_CONFIG_FILE = "./config/Custom/PrivateStoreRange.ini";
public static final String CUSTOM_PVP_ANNOUNCE_CONFIG_FILE = "./config/Custom/PvpAnnounce.ini";
public static final String CUSTOM_PVP_REWARD_ITEM_CONFIG_FILE = "./config/Custom/PvpRewardItem.ini";
public static final String CUSTOM_PVP_TITLE_CONFIG_FILE = "./config/Custom/PvpTitleColor.ini";
public static final String CUSTOM_RANDOM_SPAWNS_CONFIG_FILE = "./config/Custom/RandomSpawns.ini";
public static final String CUSTOM_SCREEN_WELCOME_MESSAGE_CONFIG_FILE = "./config/Custom/ScreenWelcomeMessage.ini";
public static final String CUSTOM_SELL_BUFFS_CONFIG_FILE = "./config/Custom/SellBuffs.ini";
public static final String CUSTOM_SERVER_TIME_CONFIG_FILE = "./config/Custom/ServerTime.ini";
public static final String CUSTOM_SCHEME_BUFFER_CONFIG_FILE = "./config/Custom/ShemeBuffer.ini";
public static final String CUSTOM_STARTING_LOCATION_CONFIG_FILE = "./config/Custom/StartingLocation.ini";
public static final String CUSTOM_TVT_CONFIG_FILE = "./config/Custom/TeamVersusTeam.ini";
public static final String CUSTOM_VOTE_REWARD_CONFIG_FILE = "./config/Custom/VoteReward.ini";
public static final String CUSTOM_WAREHOUSE_SORTING_CONFIG_FILE = "./config/Custom/WarehouseSorting.ini";
public static final String CUSTOM_WEDDING_CONFIG_FILE = "./config/Custom/Wedding.ini";
public static final String CUSTOM_WALKER_BOT_PROTECTION_CONFIG_FILE = "./config/Custom/WalkerBotProtection.ini";
private static final String CUSTOM_ALLOWED_PLAYER_RACES_CONFIG_FILE = "./config/Custom/AllowedPlayerRaces.ini";
private static final String CUSTOM_AUTO_POTIONS_CONFIG_FILE = "./config/Custom/AutoPotions.ini";
private static final String CUSTOM_BANKING_CONFIG_FILE = "./config/Custom/Banking.ini";
private static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
private static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
private static final String CUSTOM_COMMUNITY_BOARD_CONFIG_FILE = "./config/Custom/CommunityBoard.ini";
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/Custom/CustomMailManager.ini";
private static final String CUSTOM_DUALBOX_CHECK_CONFIG_FILE = "./config/Custom/DualboxCheck.ini";
private static final String CUSTOM_FACTION_SYSTEM_CONFIG_FILE = "./config/Custom/FactionSystem.ini";
private static final String CUSTOM_FAKE_PLAYERS_CONFIG_FILE = "./config/Custom/FakePlayers.ini";
private static final String CUSTOM_FIND_PVP_CONFIG_FILE = "./config/Custom/FindPvP.ini";
private static final String CUSTOM_HELLBOUND_STATUS_CONFIG_FILE = "./config/Custom/HellboundStatus.ini";
private static final String CUSTOM_MULTILANGUAL_SUPPORT_CONFIG_FILE = "./config/Custom/MultilingualSupport.ini";
private static final String CUSTOM_NPC_STAT_MULTIPIERS_CONFIG_FILE = "./config/Custom/NpcStatMultipliers.ini";
private static final String CUSTOM_OFFLINE_TRADE_CONFIG_FILE = "./config/Custom/OfflineTrade.ini";
private static final String CUSTOM_PASSWORD_CHANGE_CONFIG_FILE = "./config/Custom/PasswordChange.ini";
private static final String CUSTOM_PREMIUM_SYSTEM_CONFIG_FILE = "./config/Custom/PremiumSystem.ini";
private static final String CUSTOM_PRIVATE_STORE_RANGE_CONFIG_FILE = "./config/Custom/PrivateStoreRange.ini";
private static final String CUSTOM_PVP_ANNOUNCE_CONFIG_FILE = "./config/Custom/PvpAnnounce.ini";
private static final String CUSTOM_PVP_REWARD_ITEM_CONFIG_FILE = "./config/Custom/PvpRewardItem.ini";
private static final String CUSTOM_PVP_TITLE_CONFIG_FILE = "./config/Custom/PvpTitleColor.ini";
private static final String CUSTOM_RANDOM_SPAWNS_CONFIG_FILE = "./config/Custom/RandomSpawns.ini";
private static final String CUSTOM_SCREEN_WELCOME_MESSAGE_CONFIG_FILE = "./config/Custom/ScreenWelcomeMessage.ini";
private static final String CUSTOM_SELL_BUFFS_CONFIG_FILE = "./config/Custom/SellBuffs.ini";
private static final String CUSTOM_SERVER_TIME_CONFIG_FILE = "./config/Custom/ServerTime.ini";
private static final String CUSTOM_SCHEME_BUFFER_CONFIG_FILE = "./config/Custom/ShemeBuffer.ini";
private static final String CUSTOM_STARTING_LOCATION_CONFIG_FILE = "./config/Custom/StartingLocation.ini";
private static final String CUSTOM_TVT_CONFIG_FILE = "./config/Custom/TeamVersusTeam.ini";
private static final String CUSTOM_VOTE_REWARD_CONFIG_FILE = "./config/Custom/VoteReward.ini";
private static final String CUSTOM_WAREHOUSE_SORTING_CONFIG_FILE = "./config/Custom/WarehouseSorting.ini";
private static final String CUSTOM_WEDDING_CONFIG_FILE = "./config/Custom/Wedding.ini";
private static final String CUSTOM_WALKER_BOT_PROTECTION_CONFIG_FILE = "./config/Custom/WalkerBotProtection.ini";
// --------------------------------------------------
// Variable Definitions
@ -1278,6 +1279,8 @@ public final class Config
public static int COMMUNITY_PREMIUM_PRICE_PER_DAY;
public static List<Integer> COMMUNITY_AVAILABLE_BUFFS;
public static Map<String, Location> COMMUNITY_AVAILABLE_TELEPORTS;
public static boolean CUSTOM_MAIL_MANAGER_ENABLED;
public static int CUSTOM_MAIL_MANAGER_DELAY;
public static boolean FACTION_SYSTEM_ENABLED;
public static Location FACTION_STARTING_LOCATION;
public static Location FACTION_MANAGER_LOCATION;
@ -2757,6 +2760,12 @@ public final class Config
COMMUNITY_AVAILABLE_TELEPORTS.put(splitInfo[0], new Location(Integer.parseInt(splitInfo[1]), Integer.parseInt(splitInfo[2]), Integer.parseInt(splitInfo[3])));
}
// Load CustomMailManager config file (if exists)
final PropertiesParser CustomMailManager = new PropertiesParser(CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE);
CUSTOM_MAIL_MANAGER_ENABLED = CustomMailManager.getBoolean("CustomMailManagerEnabled", false);
CUSTOM_MAIL_MANAGER_DELAY = CustomMailManager.getInt("DatabaseQueryDelay", 30) * 1000;
// Load DualboxCheck config file (if exists)
final PropertiesParser DualboxCheck = new PropertiesParser(CUSTOM_DUALBOX_CHECK_CONFIG_FILE);

View File

@ -100,6 +100,7 @@ import com.l2jmobius.gameserver.instancemanager.ClanHallAuctionManager;
import com.l2jmobius.gameserver.instancemanager.ClanHallManager;
import com.l2jmobius.gameserver.instancemanager.CoupleManager;
import com.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
import com.l2jmobius.gameserver.instancemanager.CustomMailManager;
import com.l2jmobius.gameserver.instancemanager.DayNightSpawnManager;
import com.l2jmobius.gameserver.instancemanager.DimensionalRiftManager;
import com.l2jmobius.gameserver.instancemanager.FactionManager;
@ -410,6 +411,10 @@ public class GameServer
{
MailManager.getInstance();
}
if (Config.CUSTOM_MAIL_MANAGER_ENABLED)
{
CustomMailManager.getInstance();
}
PunishmentManager.getInstance();

View File

@ -0,0 +1,130 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.entity.Message;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
import com.l2jmobius.gameserver.model.itemcontainer.Mail;
import com.l2jmobius.gameserver.util.Util;
/**
* @author Mobius
*/
public class CustomMailManager
{
private static final Logger LOGGER = Logger.getLogger(CustomMailManager.class.getName());
// SQL Statements
private static final String READ_SQL = "SELECT * FROM custom_mail";
private static final String DELETE_SQL = "DELETE FROM custom_mail WHERE date=? AND receiver=?";
protected CustomMailManager()
{
ThreadPool.scheduleAtFixedRate(() ->
{
try (Connection con = DatabaseFactory.getConnection();
Statement ps = con.createStatement();
ResultSet rs = ps.executeQuery(READ_SQL))
{
while (rs.next())
{
final int playerId = rs.getInt("receiver");
final L2PcInstance player = L2World.getInstance().getPlayer(playerId);
if ((player != null) && player.isOnline())
{
// Create message.
final String items = rs.getString("items");
final Message msg = new Message(playerId, rs.getString("subject"), rs.getString("message"), Message.SendBySystem.NEWS);
final List<ItemHolder> itemHolders = new ArrayList<>();
for (String str : items.split(";"))
{
if (str.toLowerCase().contains(" "))
{
final String itemId = str.toLowerCase().split(" ")[0];
final String itemCount = str.toLowerCase().split(" ")[1];
if (Util.isDigit(itemId) && Util.isDigit(itemCount))
{
itemHolders.add(new ItemHolder(Integer.parseInt(itemId), Long.parseLong(itemCount)));
}
}
else if (Util.isDigit(str))
{
itemHolders.add(new ItemHolder(Integer.parseInt(str), 1));
}
}
if (!itemHolders.isEmpty())
{
final Mail attachments = msg.createAttachments();
for (ItemHolder itemHolder : itemHolders)
{
attachments.addItem("Custom-Mail", itemHolder.getId(), itemHolder.getCount(), null, null);
}
}
// Delete entry from database.
try (Connection con2 = DatabaseFactory.getConnection();
PreparedStatement stmt = con2.prepareStatement(DELETE_SQL))
{
stmt.setString(1, rs.getString("date"));
stmt.setInt(2, playerId);
stmt.execute();
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting entry from database:", e);
}
// Send message.
MailManager.getInstance().sendMessage(msg);
LOGGER.info(getClass().getSimpleName() + ": Sent message at " + player.getName() + ".");
}
}
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:", e);
}
}, Config.CUSTOM_MAIL_MANAGER_DELAY, Config.CUSTOM_MAIL_MANAGER_DELAY);
LOGGER.info(getClass().getSimpleName() + ": Enabled.");
}
public static CustomMailManager getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final CustomMailManager INSTANCE = new CustomMailManager();
}
}

View File

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS `custom_mail` (
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`receiver` INT UNSIGNED NOT NULL DEFAULT 0,
`subject` TINYTEXT NOT NULL DEFAULT "",
`message` TEXT NOT NULL DEFAULT "",
`items` TEXT NOT NULL DEFAULT "" -- format: itemId1 count1;itemId2 count2;itemId3 count3...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,11 @@
# ---------------------------------------------------------------------------
# Custom Mail Manager
# ---------------------------------------------------------------------------
# Enable/Disable sending mail through the custom_mail SQL table.
# Default: False
CustomMailManagerEnabled = False
# Database query delay in seconds.
# Default: 30
DatabaseQueryDelay = 30

View File

@ -113,6 +113,7 @@ public final class Config
private static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
private static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
private static final String CUSTOM_COMMUNITY_BOARD_CONFIG_FILE = "./config/Custom/CommunityBoard.ini";
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/Custom/CustomMailManager.ini";
private static final String CUSTOM_DUALBOX_CHECK_CONFIG_FILE = "./config/Custom/DualboxCheck.ini";
private static final String CUSTOM_FACTION_SYSTEM_CONFIG_FILE = "./config/Custom/FactionSystem.ini";
private static final String CUSTOM_FAKE_PLAYERS_CONFIG_FILE = "./config/Custom/FakePlayers.ini";
@ -1043,6 +1044,8 @@ public final class Config
public static int COMMUNITY_PREMIUM_PRICE_PER_DAY;
public static List<Integer> COMMUNITY_AVAILABLE_BUFFS;
public static Map<String, Location> COMMUNITY_AVAILABLE_TELEPORTS;
public static boolean CUSTOM_MAIL_MANAGER_ENABLED;
public static int CUSTOM_MAIL_MANAGER_DELAY;
public static boolean FACTION_SYSTEM_ENABLED;
public static Location FACTION_STARTING_LOCATION;
public static Location FACTION_MANAGER_LOCATION;
@ -2338,6 +2341,12 @@ public final class Config
COMMUNITY_AVAILABLE_TELEPORTS.put(splitInfo[0], new Location(Integer.parseInt(splitInfo[1]), Integer.parseInt(splitInfo[2]), Integer.parseInt(splitInfo[3])));
}
// Load CustomMailManager config file (if exists)
final PropertiesParser CustomMailManager = new PropertiesParser(CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE);
CUSTOM_MAIL_MANAGER_ENABLED = CustomMailManager.getBoolean("CustomMailManagerEnabled", false);
CUSTOM_MAIL_MANAGER_DELAY = CustomMailManager.getInt("DatabaseQueryDelay", 30) * 1000;
// Load DualboxCheck config file (if exists)
final PropertiesParser DualboxCheck = new PropertiesParser(CUSTOM_DUALBOX_CHECK_CONFIG_FILE);

View File

@ -114,6 +114,7 @@ import com.l2jmobius.gameserver.instancemanager.ClanEntryManager;
import com.l2jmobius.gameserver.instancemanager.ClanHallAuctionManager;
import com.l2jmobius.gameserver.instancemanager.CommissionManager;
import com.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
import com.l2jmobius.gameserver.instancemanager.CustomMailManager;
import com.l2jmobius.gameserver.instancemanager.DBSpawnManager;
import com.l2jmobius.gameserver.instancemanager.FactionManager;
import com.l2jmobius.gameserver.instancemanager.FakePlayerChatManager;
@ -403,6 +404,10 @@ public class GameServer
{
MailManager.getInstance();
}
if (Config.CUSTOM_MAIL_MANAGER_ENABLED)
{
CustomMailManager.getInstance();
}
PunishmentManager.getInstance();

View File

@ -0,0 +1,131 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.enums.MailType;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.entity.Message;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
import com.l2jmobius.gameserver.model.itemcontainer.Mail;
import com.l2jmobius.gameserver.util.Util;
/**
* @author Mobius
*/
public class CustomMailManager
{
private static final Logger LOGGER = Logger.getLogger(CustomMailManager.class.getName());
// SQL Statements
private static final String READ_SQL = "SELECT * FROM custom_mail";
private static final String DELETE_SQL = "DELETE FROM custom_mail WHERE date=? AND receiver=?";
protected CustomMailManager()
{
ThreadPool.scheduleAtFixedRate(() ->
{
try (Connection con = DatabaseFactory.getConnection();
Statement ps = con.createStatement();
ResultSet rs = ps.executeQuery(READ_SQL))
{
while (rs.next())
{
final int playerId = rs.getInt("receiver");
final L2PcInstance player = L2World.getInstance().getPlayer(playerId);
if ((player != null) && player.isOnline())
{
// Create message.
final String items = rs.getString("items");
final Message msg = new Message(playerId, rs.getString("subject"), rs.getString("message"), items.length() > 0 ? MailType.PRIME_SHOP_GIFT : MailType.REGULAR);
final List<ItemHolder> itemHolders = new ArrayList<>();
for (String str : items.split(";"))
{
if (str.toLowerCase().contains(" "))
{
final String itemId = str.toLowerCase().split(" ")[0];
final String itemCount = str.toLowerCase().split(" ")[1];
if (Util.isDigit(itemId) && Util.isDigit(itemCount))
{
itemHolders.add(new ItemHolder(Integer.parseInt(itemId), Long.parseLong(itemCount)));
}
}
else if (Util.isDigit(str))
{
itemHolders.add(new ItemHolder(Integer.parseInt(str), 1));
}
}
if (!itemHolders.isEmpty())
{
final Mail attachments = msg.createAttachments();
for (ItemHolder itemHolder : itemHolders)
{
attachments.addItem("Custom-Mail", itemHolder.getId(), itemHolder.getCount(), null, null);
}
}
// Delete entry from database.
try (Connection con2 = DatabaseFactory.getConnection();
PreparedStatement stmt = con2.prepareStatement(DELETE_SQL))
{
stmt.setString(1, rs.getString("date"));
stmt.setInt(2, playerId);
stmt.execute();
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting entry from database:", e);
}
// Send message.
MailManager.getInstance().sendMessage(msg);
LOGGER.info(getClass().getSimpleName() + ": Sent message at " + player.getName() + ".");
}
}
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:", e);
}
}, Config.CUSTOM_MAIL_MANAGER_DELAY, Config.CUSTOM_MAIL_MANAGER_DELAY);
LOGGER.info(getClass().getSimpleName() + ": Enabled.");
}
public static CustomMailManager getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final CustomMailManager INSTANCE = new CustomMailManager();
}
}

View File

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS `custom_mail` (
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`receiver` INT UNSIGNED NOT NULL DEFAULT 0,
`subject` TINYTEXT NOT NULL DEFAULT "",
`message` TEXT NOT NULL DEFAULT "",
`items` TEXT NOT NULL DEFAULT "" -- format: itemId1 count1;itemId2 count2;itemId3 count3...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,11 @@
# ---------------------------------------------------------------------------
# Custom Mail Manager
# ---------------------------------------------------------------------------
# Enable/Disable sending mail through the custom_mail SQL table.
# Default: False
CustomMailManagerEnabled = False
# Database query delay in seconds.
# Default: 30
DatabaseQueryDelay = 30

View File

@ -113,6 +113,7 @@ public final class Config
private static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
private static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
private static final String CUSTOM_COMMUNITY_BOARD_CONFIG_FILE = "./config/Custom/CommunityBoard.ini";
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/Custom/CustomMailManager.ini";
private static final String CUSTOM_DUALBOX_CHECK_CONFIG_FILE = "./config/Custom/DualboxCheck.ini";
private static final String CUSTOM_FACTION_SYSTEM_CONFIG_FILE = "./config/Custom/FactionSystem.ini";
private static final String CUSTOM_FAKE_PLAYERS_CONFIG_FILE = "./config/Custom/FakePlayers.ini";
@ -1047,6 +1048,8 @@ public final class Config
public static int COMMUNITY_PREMIUM_PRICE_PER_DAY;
public static List<Integer> COMMUNITY_AVAILABLE_BUFFS;
public static Map<String, Location> COMMUNITY_AVAILABLE_TELEPORTS;
public static boolean CUSTOM_MAIL_MANAGER_ENABLED;
public static int CUSTOM_MAIL_MANAGER_DELAY;
public static boolean FACTION_SYSTEM_ENABLED;
public static Location FACTION_STARTING_LOCATION;
public static Location FACTION_MANAGER_LOCATION;
@ -2345,6 +2348,12 @@ public final class Config
COMMUNITY_AVAILABLE_TELEPORTS.put(splitInfo[0], new Location(Integer.parseInt(splitInfo[1]), Integer.parseInt(splitInfo[2]), Integer.parseInt(splitInfo[3])));
}
// Load CustomMailManager config file (if exists)
final PropertiesParser CustomMailManager = new PropertiesParser(CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE);
CUSTOM_MAIL_MANAGER_ENABLED = CustomMailManager.getBoolean("CustomMailManagerEnabled", false);
CUSTOM_MAIL_MANAGER_DELAY = CustomMailManager.getInt("DatabaseQueryDelay", 30) * 1000;
// Load DualboxCheck config file (if exists)
final PropertiesParser DualboxCheck = new PropertiesParser(CUSTOM_DUALBOX_CHECK_CONFIG_FILE);

View File

@ -114,6 +114,7 @@ import com.l2jmobius.gameserver.instancemanager.ClanEntryManager;
import com.l2jmobius.gameserver.instancemanager.ClanHallAuctionManager;
import com.l2jmobius.gameserver.instancemanager.CommissionManager;
import com.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
import com.l2jmobius.gameserver.instancemanager.CustomMailManager;
import com.l2jmobius.gameserver.instancemanager.DBSpawnManager;
import com.l2jmobius.gameserver.instancemanager.FactionManager;
import com.l2jmobius.gameserver.instancemanager.FakePlayerChatManager;
@ -403,6 +404,10 @@ public class GameServer
{
MailManager.getInstance();
}
if (Config.CUSTOM_MAIL_MANAGER_ENABLED)
{
CustomMailManager.getInstance();
}
PunishmentManager.getInstance();

View File

@ -0,0 +1,131 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.enums.MailType;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.entity.Message;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
import com.l2jmobius.gameserver.model.itemcontainer.Mail;
import com.l2jmobius.gameserver.util.Util;
/**
* @author Mobius
*/
public class CustomMailManager
{
private static final Logger LOGGER = Logger.getLogger(CustomMailManager.class.getName());
// SQL Statements
private static final String READ_SQL = "SELECT * FROM custom_mail";
private static final String DELETE_SQL = "DELETE FROM custom_mail WHERE date=? AND receiver=?";
protected CustomMailManager()
{
ThreadPool.scheduleAtFixedRate(() ->
{
try (Connection con = DatabaseFactory.getConnection();
Statement ps = con.createStatement();
ResultSet rs = ps.executeQuery(READ_SQL))
{
while (rs.next())
{
final int playerId = rs.getInt("receiver");
final L2PcInstance player = L2World.getInstance().getPlayer(playerId);
if ((player != null) && player.isOnline())
{
// Create message.
final String items = rs.getString("items");
final Message msg = new Message(playerId, rs.getString("subject"), rs.getString("message"), items.length() > 0 ? MailType.PRIME_SHOP_GIFT : MailType.REGULAR);
final List<ItemHolder> itemHolders = new ArrayList<>();
for (String str : items.split(";"))
{
if (str.toLowerCase().contains(" "))
{
final String itemId = str.toLowerCase().split(" ")[0];
final String itemCount = str.toLowerCase().split(" ")[1];
if (Util.isDigit(itemId) && Util.isDigit(itemCount))
{
itemHolders.add(new ItemHolder(Integer.parseInt(itemId), Long.parseLong(itemCount)));
}
}
else if (Util.isDigit(str))
{
itemHolders.add(new ItemHolder(Integer.parseInt(str), 1));
}
}
if (!itemHolders.isEmpty())
{
final Mail attachments = msg.createAttachments();
for (ItemHolder itemHolder : itemHolders)
{
attachments.addItem("Custom-Mail", itemHolder.getId(), itemHolder.getCount(), null, null);
}
}
// Delete entry from database.
try (Connection con2 = DatabaseFactory.getConnection();
PreparedStatement stmt = con2.prepareStatement(DELETE_SQL))
{
stmt.setString(1, rs.getString("date"));
stmt.setInt(2, playerId);
stmt.execute();
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting entry from database:", e);
}
// Send message.
MailManager.getInstance().sendMessage(msg);
LOGGER.info(getClass().getSimpleName() + ": Sent message at " + player.getName() + ".");
}
}
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:", e);
}
}, Config.CUSTOM_MAIL_MANAGER_DELAY, Config.CUSTOM_MAIL_MANAGER_DELAY);
LOGGER.info(getClass().getSimpleName() + ": Enabled.");
}
public static CustomMailManager getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final CustomMailManager INSTANCE = new CustomMailManager();
}
}

View File

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS `custom_mail` (
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`receiver` INT UNSIGNED NOT NULL DEFAULT 0,
`subject` TINYTEXT NOT NULL DEFAULT "",
`message` TEXT NOT NULL DEFAULT "",
`items` TEXT NOT NULL DEFAULT "" -- format: itemId1 count1;itemId2 count2;itemId3 count3...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,11 @@
# ---------------------------------------------------------------------------
# Custom Mail Manager
# ---------------------------------------------------------------------------
# Enable/Disable sending mail through the custom_mail SQL table.
# Default: False
CustomMailManagerEnabled = False
# Database query delay in seconds.
# Default: 30
DatabaseQueryDelay = 30

View File

@ -113,6 +113,7 @@ public final class Config
private static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
private static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
private static final String CUSTOM_COMMUNITY_BOARD_CONFIG_FILE = "./config/Custom/CommunityBoard.ini";
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/Custom/CustomMailManager.ini";
private static final String CUSTOM_DUALBOX_CHECK_CONFIG_FILE = "./config/Custom/DualboxCheck.ini";
private static final String CUSTOM_FACTION_SYSTEM_CONFIG_FILE = "./config/Custom/FactionSystem.ini";
private static final String CUSTOM_FAKE_PLAYERS_CONFIG_FILE = "./config/Custom/FakePlayers.ini";
@ -1047,6 +1048,8 @@ public final class Config
public static int COMMUNITY_PREMIUM_PRICE_PER_DAY;
public static List<Integer> COMMUNITY_AVAILABLE_BUFFS;
public static Map<String, Location> COMMUNITY_AVAILABLE_TELEPORTS;
public static boolean CUSTOM_MAIL_MANAGER_ENABLED;
public static int CUSTOM_MAIL_MANAGER_DELAY;
public static boolean FACTION_SYSTEM_ENABLED;
public static Location FACTION_STARTING_LOCATION;
public static Location FACTION_MANAGER_LOCATION;
@ -2345,6 +2348,12 @@ public final class Config
COMMUNITY_AVAILABLE_TELEPORTS.put(splitInfo[0], new Location(Integer.parseInt(splitInfo[1]), Integer.parseInt(splitInfo[2]), Integer.parseInt(splitInfo[3])));
}
// Load CustomMailManager config file (if exists)
final PropertiesParser CustomMailManager = new PropertiesParser(CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE);
CUSTOM_MAIL_MANAGER_ENABLED = CustomMailManager.getBoolean("CustomMailManagerEnabled", false);
CUSTOM_MAIL_MANAGER_DELAY = CustomMailManager.getInt("DatabaseQueryDelay", 30) * 1000;
// Load DualboxCheck config file (if exists)
final PropertiesParser DualboxCheck = new PropertiesParser(CUSTOM_DUALBOX_CHECK_CONFIG_FILE);

View File

@ -114,6 +114,7 @@ import com.l2jmobius.gameserver.instancemanager.ClanEntryManager;
import com.l2jmobius.gameserver.instancemanager.ClanHallAuctionManager;
import com.l2jmobius.gameserver.instancemanager.CommissionManager;
import com.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
import com.l2jmobius.gameserver.instancemanager.CustomMailManager;
import com.l2jmobius.gameserver.instancemanager.DBSpawnManager;
import com.l2jmobius.gameserver.instancemanager.FactionManager;
import com.l2jmobius.gameserver.instancemanager.FakePlayerChatManager;
@ -403,6 +404,10 @@ public class GameServer
{
MailManager.getInstance();
}
if (Config.CUSTOM_MAIL_MANAGER_ENABLED)
{
CustomMailManager.getInstance();
}
PunishmentManager.getInstance();

View File

@ -0,0 +1,131 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.enums.MailType;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.entity.Message;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
import com.l2jmobius.gameserver.model.itemcontainer.Mail;
import com.l2jmobius.gameserver.util.Util;
/**
* @author Mobius
*/
public class CustomMailManager
{
private static final Logger LOGGER = Logger.getLogger(CustomMailManager.class.getName());
// SQL Statements
private static final String READ_SQL = "SELECT * FROM custom_mail";
private static final String DELETE_SQL = "DELETE FROM custom_mail WHERE date=? AND receiver=?";
protected CustomMailManager()
{
ThreadPool.scheduleAtFixedRate(() ->
{
try (Connection con = DatabaseFactory.getConnection();
Statement ps = con.createStatement();
ResultSet rs = ps.executeQuery(READ_SQL))
{
while (rs.next())
{
final int playerId = rs.getInt("receiver");
final L2PcInstance player = L2World.getInstance().getPlayer(playerId);
if ((player != null) && player.isOnline())
{
// Create message.
final String items = rs.getString("items");
final Message msg = new Message(playerId, rs.getString("subject"), rs.getString("message"), items.length() > 0 ? MailType.PRIME_SHOP_GIFT : MailType.REGULAR);
final List<ItemHolder> itemHolders = new ArrayList<>();
for (String str : items.split(";"))
{
if (str.toLowerCase().contains(" "))
{
final String itemId = str.toLowerCase().split(" ")[0];
final String itemCount = str.toLowerCase().split(" ")[1];
if (Util.isDigit(itemId) && Util.isDigit(itemCount))
{
itemHolders.add(new ItemHolder(Integer.parseInt(itemId), Long.parseLong(itemCount)));
}
}
else if (Util.isDigit(str))
{
itemHolders.add(new ItemHolder(Integer.parseInt(str), 1));
}
}
if (!itemHolders.isEmpty())
{
final Mail attachments = msg.createAttachments();
for (ItemHolder itemHolder : itemHolders)
{
attachments.addItem("Custom-Mail", itemHolder.getId(), itemHolder.getCount(), null, null);
}
}
// Delete entry from database.
try (Connection con2 = DatabaseFactory.getConnection();
PreparedStatement stmt = con2.prepareStatement(DELETE_SQL))
{
stmt.setString(1, rs.getString("date"));
stmt.setInt(2, playerId);
stmt.execute();
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting entry from database:", e);
}
// Send message.
MailManager.getInstance().sendMessage(msg);
LOGGER.info(getClass().getSimpleName() + ": Sent message at " + player.getName() + ".");
}
}
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:", e);
}
}, Config.CUSTOM_MAIL_MANAGER_DELAY, Config.CUSTOM_MAIL_MANAGER_DELAY);
LOGGER.info(getClass().getSimpleName() + ": Enabled.");
}
public static CustomMailManager getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final CustomMailManager INSTANCE = new CustomMailManager();
}
}

View File

@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS `custom_mail` (
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`receiver` INT UNSIGNED NOT NULL DEFAULT 0,
`subject` TINYTEXT NOT NULL DEFAULT "",
`message` TEXT NOT NULL DEFAULT "",
`items` TEXT NOT NULL DEFAULT "" -- format: itemId1 count1;itemId2 count2;itemId3 count3...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

View File

@ -0,0 +1,11 @@
# ---------------------------------------------------------------------------
# Custom Mail Manager
# ---------------------------------------------------------------------------
# Enable/Disable sending mail through the custom_mail SQL table.
# Default: False
CustomMailManagerEnabled = False
# Database query delay in seconds.
# Default: 30
DatabaseQueryDelay = 30

View File

@ -113,6 +113,7 @@ public final class Config
private static final String CUSTOM_CHAMPION_MONSTERS_CONFIG_FILE = "./config/Custom/ChampionMonsters.ini";
private static final String CUSTOM_CHAT_MODERATION_CONFIG_FILE = "./config/Custom/ChatModeration.ini";
private static final String CUSTOM_COMMUNITY_BOARD_CONFIG_FILE = "./config/Custom/CommunityBoard.ini";
private static final String CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE = "./config/Custom/CustomMailManager.ini";
private static final String CUSTOM_DUALBOX_CHECK_CONFIG_FILE = "./config/Custom/DualboxCheck.ini";
private static final String CUSTOM_FACTION_SYSTEM_CONFIG_FILE = "./config/Custom/FactionSystem.ini";
private static final String CUSTOM_FAKE_PLAYERS_CONFIG_FILE = "./config/Custom/FakePlayers.ini";
@ -1047,6 +1048,8 @@ public final class Config
public static int COMMUNITY_PREMIUM_PRICE_PER_DAY;
public static List<Integer> COMMUNITY_AVAILABLE_BUFFS;
public static Map<String, Location> COMMUNITY_AVAILABLE_TELEPORTS;
public static boolean CUSTOM_MAIL_MANAGER_ENABLED;
public static int CUSTOM_MAIL_MANAGER_DELAY;
public static boolean FACTION_SYSTEM_ENABLED;
public static Location FACTION_STARTING_LOCATION;
public static Location FACTION_MANAGER_LOCATION;
@ -2345,6 +2348,12 @@ public final class Config
COMMUNITY_AVAILABLE_TELEPORTS.put(splitInfo[0], new Location(Integer.parseInt(splitInfo[1]), Integer.parseInt(splitInfo[2]), Integer.parseInt(splitInfo[3])));
}
// Load CustomMailManager config file (if exists)
final PropertiesParser CustomMailManager = new PropertiesParser(CUSTOM_CUSTOM_MAIL_MANAGER_CONFIG_FILE);
CUSTOM_MAIL_MANAGER_ENABLED = CustomMailManager.getBoolean("CustomMailManagerEnabled", false);
CUSTOM_MAIL_MANAGER_DELAY = CustomMailManager.getInt("DatabaseQueryDelay", 30) * 1000;
// Load DualboxCheck config file (if exists)
final PropertiesParser DualboxCheck = new PropertiesParser(CUSTOM_DUALBOX_CHECK_CONFIG_FILE);

View File

@ -114,6 +114,7 @@ import com.l2jmobius.gameserver.instancemanager.ClanEntryManager;
import com.l2jmobius.gameserver.instancemanager.ClanHallAuctionManager;
import com.l2jmobius.gameserver.instancemanager.CommissionManager;
import com.l2jmobius.gameserver.instancemanager.CursedWeaponsManager;
import com.l2jmobius.gameserver.instancemanager.CustomMailManager;
import com.l2jmobius.gameserver.instancemanager.DBSpawnManager;
import com.l2jmobius.gameserver.instancemanager.FactionManager;
import com.l2jmobius.gameserver.instancemanager.FakePlayerChatManager;
@ -403,6 +404,10 @@ public class GameServer
{
MailManager.getInstance();
}
if (Config.CUSTOM_MAIL_MANAGER_ENABLED)
{
CustomMailManager.getInstance();
}
PunishmentManager.getInstance();

View File

@ -0,0 +1,131 @@
/*
* 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 com.l2jmobius.gameserver.instancemanager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jmobius.Config;
import com.l2jmobius.commons.concurrent.ThreadPool;
import com.l2jmobius.commons.database.DatabaseFactory;
import com.l2jmobius.gameserver.enums.MailType;
import com.l2jmobius.gameserver.model.L2World;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.entity.Message;
import com.l2jmobius.gameserver.model.holders.ItemHolder;
import com.l2jmobius.gameserver.model.itemcontainer.Mail;
import com.l2jmobius.gameserver.util.Util;
/**
* @author Mobius
*/
public class CustomMailManager
{
private static final Logger LOGGER = Logger.getLogger(CustomMailManager.class.getName());
// SQL Statements
private static final String READ_SQL = "SELECT * FROM custom_mail";
private static final String DELETE_SQL = "DELETE FROM custom_mail WHERE date=? AND receiver=?";
protected CustomMailManager()
{
ThreadPool.scheduleAtFixedRate(() ->
{
try (Connection con = DatabaseFactory.getConnection();
Statement ps = con.createStatement();
ResultSet rs = ps.executeQuery(READ_SQL))
{
while (rs.next())
{
final int playerId = rs.getInt("receiver");
final L2PcInstance player = L2World.getInstance().getPlayer(playerId);
if ((player != null) && player.isOnline())
{
// Create message.
final String items = rs.getString("items");
final Message msg = new Message(playerId, rs.getString("subject"), rs.getString("message"), items.length() > 0 ? MailType.PRIME_SHOP_GIFT : MailType.REGULAR);
final List<ItemHolder> itemHolders = new ArrayList<>();
for (String str : items.split(";"))
{
if (str.toLowerCase().contains(" "))
{
final String itemId = str.toLowerCase().split(" ")[0];
final String itemCount = str.toLowerCase().split(" ")[1];
if (Util.isDigit(itemId) && Util.isDigit(itemCount))
{
itemHolders.add(new ItemHolder(Integer.parseInt(itemId), Long.parseLong(itemCount)));
}
}
else if (Util.isDigit(str))
{
itemHolders.add(new ItemHolder(Integer.parseInt(str), 1));
}
}
if (!itemHolders.isEmpty())
{
final Mail attachments = msg.createAttachments();
for (ItemHolder itemHolder : itemHolders)
{
attachments.addItem("Custom-Mail", itemHolder.getId(), itemHolder.getCount(), null, null);
}
}
// Delete entry from database.
try (Connection con2 = DatabaseFactory.getConnection();
PreparedStatement stmt = con2.prepareStatement(DELETE_SQL))
{
stmt.setString(1, rs.getString("date"));
stmt.setInt(2, playerId);
stmt.execute();
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting entry from database:", e);
}
// Send message.
MailManager.getInstance().sendMessage(msg);
LOGGER.info(getClass().getSimpleName() + ": Sent message at " + player.getName() + ".");
}
}
}
catch (SQLException e)
{
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:", e);
}
}, Config.CUSTOM_MAIL_MANAGER_DELAY, Config.CUSTOM_MAIL_MANAGER_DELAY);
LOGGER.info(getClass().getSimpleName() + ": Enabled.");
}
public static CustomMailManager getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final CustomMailManager INSTANCE = new CustomMailManager();
}
}