Addition of MessageDeletionTaskManager.
This commit is contained in:
@@ -29,16 +29,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.enums.MailType;
|
import org.l2jmobius.gameserver.enums.MailType;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -63,21 +62,11 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
@@ -207,7 +196,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,16 +29,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.enums.MailType;
|
import org.l2jmobius.gameserver.enums.MailType;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -63,21 +62,11 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
@@ -207,7 +196,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,16 +29,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.enums.MailType;
|
import org.l2jmobius.gameserver.enums.MailType;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -63,21 +62,11 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
@@ -207,7 +196,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,16 +29,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.enums.MailType;
|
import org.l2jmobius.gameserver.enums.MailType;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -63,21 +62,11 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
@@ -207,7 +196,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,16 +29,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.enums.MailType;
|
import org.l2jmobius.gameserver.enums.MailType;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -63,21 +62,11 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
@@ -207,7 +196,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,16 +29,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.enums.MailType;
|
import org.l2jmobius.gameserver.enums.MailType;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -63,21 +62,11 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
@@ -207,7 +196,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,16 +29,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.enums.MailType;
|
import org.l2jmobius.gameserver.enums.MailType;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -63,21 +62,11 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
@@ -207,7 +196,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,16 +29,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.enums.MailType;
|
import org.l2jmobius.gameserver.enums.MailType;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -63,21 +62,11 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
@@ -207,7 +196,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,14 +29,13 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -61,28 +60,18 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:" + e.getMessage(), e);
|
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:", e);
|
||||||
}
|
}
|
||||||
LOGGER.info(getClass().getSimpleName() + ": Successfully loaded " + count + " messages.");
|
LOGGER.info(getClass().getSimpleName() + ": Loaded " + count + " messages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message getMessage(int msgId)
|
public Message getMessage(int msgId)
|
||||||
@@ -170,7 +159,7 @@ public class MailManager
|
|||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error saving message:" + e.getMessage(), e);
|
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error saving message:", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
@@ -179,7 +168,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(ExNoticePostArrived.valueOf(true));
|
receiver.sendPacket(ExNoticePostArrived.valueOf(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
@@ -192,7 +181,7 @@ public class MailManager
|
|||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error marking as read message:" + e.getMessage(), e);
|
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error marking as read message:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +195,7 @@ public class MailManager
|
|||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error marking as deleted by sender message:" + e.getMessage(), e);
|
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error marking as deleted by sender message:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +209,7 @@ public class MailManager
|
|||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error marking as deleted by receiver message:" + e.getMessage(), e);
|
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error marking as deleted by receiver message:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +223,7 @@ public class MailManager
|
|||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error removing attachments in message:" + e.getMessage(), e);
|
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error removing attachments in message:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +237,7 @@ public class MailManager
|
|||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting message:" + e.getMessage(), e);
|
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting message:", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
_messages.remove(msgId);
|
_messages.remove(msgId);
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,14 +29,13 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -61,28 +60,18 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:" + e.getMessage(), e);
|
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error loading from database:", e);
|
||||||
}
|
}
|
||||||
LOGGER.info(getClass().getSimpleName() + ": Successfully loaded " + count + " messages.");
|
LOGGER.info(getClass().getSimpleName() + ": Loaded " + count + " messages.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message getMessage(int msgId)
|
public Message getMessage(int msgId)
|
||||||
@@ -170,7 +159,7 @@ public class MailManager
|
|||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error saving message:" + e.getMessage(), e);
|
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error saving message:", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
@@ -179,7 +168,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(ExNoticePostArrived.valueOf(true));
|
receiver.sendPacket(ExNoticePostArrived.valueOf(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
@@ -192,7 +181,7 @@ public class MailManager
|
|||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error marking as read message:" + e.getMessage(), e);
|
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error marking as read message:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +195,7 @@ public class MailManager
|
|||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error marking as deleted by sender message:" + e.getMessage(), e);
|
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error marking as deleted by sender message:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,7 +209,7 @@ public class MailManager
|
|||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error marking as deleted by receiver message:" + e.getMessage(), e);
|
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error marking as deleted by receiver message:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,7 +223,7 @@ public class MailManager
|
|||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error removing attachments in message:" + e.getMessage(), e);
|
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error removing attachments in message:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +237,7 @@ public class MailManager
|
|||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
{
|
{
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting message:" + e.getMessage(), e);
|
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error deleting message:", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
_messages.remove(msgId);
|
_messages.remove(msgId);
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,16 +29,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.enums.MailType;
|
import org.l2jmobius.gameserver.enums.MailType;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -63,21 +62,11 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
@@ -207,7 +196,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,16 +29,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.enums.MailType;
|
import org.l2jmobius.gameserver.enums.MailType;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -63,21 +62,11 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
@@ -207,7 +196,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,16 +29,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.enums.MailType;
|
import org.l2jmobius.gameserver.enums.MailType;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -63,21 +62,11 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
@@ -207,7 +196,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,16 +29,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.enums.MailType;
|
import org.l2jmobius.gameserver.enums.MailType;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -63,21 +62,11 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
@@ -207,7 +196,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,16 +29,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.enums.MailType;
|
import org.l2jmobius.gameserver.enums.MailType;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -63,21 +62,11 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
@@ -207,7 +196,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,16 +29,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.enums.MailType;
|
import org.l2jmobius.gameserver.enums.MailType;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -63,21 +62,11 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
@@ -207,7 +196,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
@@ -29,16 +29,15 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.l2jmobius.commons.concurrent.ThreadPool;
|
|
||||||
import org.l2jmobius.commons.database.DatabaseFactory;
|
import org.l2jmobius.commons.database.DatabaseFactory;
|
||||||
import org.l2jmobius.gameserver.enums.MailType;
|
import org.l2jmobius.gameserver.enums.MailType;
|
||||||
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
import org.l2jmobius.gameserver.idfactory.IdFactory;
|
||||||
import org.l2jmobius.gameserver.instancemanager.tasks.MessageDeletionTask;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
import org.l2jmobius.gameserver.model.World;
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
import org.l2jmobius.gameserver.network.serverpackets.ExNoticePostArrived;
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
import org.l2jmobius.gameserver.network.serverpackets.ExUnReadMailCount;
|
||||||
|
import org.l2jmobius.gameserver.taskmanager.MessageDeletionTaskManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Migi, DS
|
* @author Migi, DS
|
||||||
@@ -63,21 +62,11 @@ public class MailManager
|
|||||||
{
|
{
|
||||||
while (rs.next())
|
while (rs.next())
|
||||||
{
|
{
|
||||||
|
count++;
|
||||||
final Message msg = new Message(rs);
|
final Message msg = new Message(rs);
|
||||||
final int msgId = msg.getId();
|
final int msgId = msg.getId();
|
||||||
_messages.put(msgId, msg);
|
_messages.put(msgId, msg);
|
||||||
|
MessageDeletionTaskManager.getInstance().add(msgId, msg.getExpiration());
|
||||||
count++;
|
|
||||||
|
|
||||||
final long expiration = msg.getExpiration();
|
|
||||||
if (expiration < System.currentTimeMillis())
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), 10000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msgId), expiration - System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException e)
|
catch (SQLException e)
|
||||||
@@ -207,7 +196,7 @@ public class MailManager
|
|||||||
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
receiver.sendPacket(new ExUnReadMailCount(receiver));
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadPool.schedule(new MessageDeletionTask(msg.getId()), msg.getExpiration() - System.currentTimeMillis());
|
MessageDeletionTaskManager.getInstance().add(msg.getId(), msg.getExpiration());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void markAsReadInDb(int msgId)
|
public void markAsReadInDb(int msgId)
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 org.l2jmobius.gameserver.instancemanager.tasks;
|
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
|
||||||
import org.l2jmobius.gameserver.model.World;
|
|
||||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
|
||||||
import org.l2jmobius.gameserver.model.entity.Message;
|
|
||||||
import org.l2jmobius.gameserver.network.SystemMessageId;
|
|
||||||
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Message deletion task.
|
|
||||||
* @author xban1x
|
|
||||||
*/
|
|
||||||
public class MessageDeletionTask implements Runnable
|
|
||||||
{
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageDeletionTask.class.getName());
|
|
||||||
|
|
||||||
final int _msgId;
|
|
||||||
|
|
||||||
public MessageDeletionTask(int msgId)
|
|
||||||
{
|
|
||||||
_msgId = msgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
final Message msg = MailManager.getInstance().getMessage(_msgId);
|
|
||||||
if (msg == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg.hasAttachments())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
|
||||||
if (sender != null)
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(sender.getWarehouse());
|
|
||||||
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msg.getAttachments().returnToWh(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.getAttachments().deleteMe();
|
|
||||||
msg.removeAttachments();
|
|
||||||
|
|
||||||
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
|
||||||
if (receiver != null)
|
|
||||||
{
|
|
||||||
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
LOGGER.log(Level.WARNING, getClass().getSimpleName() + ": Error returning items:" + e.getMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MailManager.getInstance().deleteMessageInDb(msg.getId());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* 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 org.l2jmobius.gameserver.taskmanager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import org.l2jmobius.commons.concurrent.ThreadPool;
|
||||||
|
import org.l2jmobius.gameserver.instancemanager.MailManager;
|
||||||
|
import org.l2jmobius.gameserver.model.World;
|
||||||
|
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||||
|
import org.l2jmobius.gameserver.model.entity.Message;
|
||||||
|
import org.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Mobius
|
||||||
|
*/
|
||||||
|
public class MessageDeletionTaskManager
|
||||||
|
{
|
||||||
|
private static final Map<Integer, Long> PENDING_MESSAGES = new ConcurrentHashMap<>();
|
||||||
|
private static boolean _working = false;
|
||||||
|
|
||||||
|
public MessageDeletionTaskManager()
|
||||||
|
{
|
||||||
|
ThreadPool.scheduleAtFixedRate(() ->
|
||||||
|
{
|
||||||
|
if (_working)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_working = true;
|
||||||
|
|
||||||
|
int msgId;
|
||||||
|
Message msg;
|
||||||
|
final long time = System.currentTimeMillis();
|
||||||
|
for (Entry<Integer, Long> entry : PENDING_MESSAGES.entrySet())
|
||||||
|
{
|
||||||
|
if (time > entry.getValue())
|
||||||
|
{
|
||||||
|
msgId = entry.getKey();
|
||||||
|
msg = MailManager.getInstance().getMessage(msgId);
|
||||||
|
if (msg == null)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.hasAttachments())
|
||||||
|
{
|
||||||
|
final PlayerInstance sender = World.getInstance().getPlayer(msg.getSenderId());
|
||||||
|
if (sender != null)
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(sender.getWarehouse());
|
||||||
|
sender.sendPacket(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg.getAttachments().returnToWh(null);
|
||||||
|
}
|
||||||
|
msg.getAttachments().deleteMe();
|
||||||
|
msg.removeAttachments();
|
||||||
|
|
||||||
|
final PlayerInstance receiver = World.getInstance().getPlayer(msg.getReceiverId());
|
||||||
|
if (receiver != null)
|
||||||
|
{
|
||||||
|
receiver.sendPacket(new SystemMessage(SystemMessageId.THE_MAIL_WAS_RETURNED_DUE_TO_THE_EXCEEDED_WAITING_TIME));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MailManager.getInstance().deleteMessageInDb(msgId);
|
||||||
|
PENDING_MESSAGES.remove(msgId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_working = false;
|
||||||
|
}, 10000, 10000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(int msgId, long deletionTime)
|
||||||
|
{
|
||||||
|
PENDING_MESSAGES.put(msgId, deletionTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MessageDeletionTaskManager getInstance()
|
||||||
|
{
|
||||||
|
return SingletonHolder.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class SingletonHolder
|
||||||
|
{
|
||||||
|
protected static final MessageDeletionTaskManager INSTANCE = new MessageDeletionTaskManager();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user