mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-09 17:02:53 +00:00
@@ -18,7 +18,7 @@ package com.l2jserver.service.game;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.packet.client.CharacterChatMessagePacket.MessageDestination;
|
||||
import com.l2jserver.game.net.SystemMessage;
|
||||
import com.l2jserver.game.net.packet.server.ActionFailedPacket;
|
||||
import com.l2jserver.game.net.packet.server.ActorChatMessagePacket;
|
||||
import com.l2jserver.game.net.packet.server.ActorMovementPacket;
|
||||
@@ -46,6 +46,7 @@ import com.l2jserver.model.world.npc.event.NPCSpawnEvent;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.game.ai.AIService;
|
||||
import com.l2jserver.service.game.chat.ChatMessageDestination;
|
||||
import com.l2jserver.service.game.chat.ChatService;
|
||||
import com.l2jserver.service.game.chat.channel.ChatChannel;
|
||||
import com.l2jserver.service.game.chat.channel.ChatChannelListener;
|
||||
@@ -120,7 +121,15 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
public void onMessage(ChatChannel channel, CharacterID source,
|
||||
String message) {
|
||||
conn.write(new ActorChatMessagePacket(source.getObject(),
|
||||
MessageDestination.ALL, message));
|
||||
ChatMessageDestination.ALL, message));
|
||||
}
|
||||
};
|
||||
final ChatChannelListener tradeChatListener = new ChatChannelListener() {
|
||||
@Override
|
||||
public void onMessage(ChatChannel channel, CharacterID source,
|
||||
String message) {
|
||||
conn.write(new ActorChatMessagePacket(source.getObject(),
|
||||
ChatMessageDestination.TRADE, message));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -158,7 +167,9 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
// remove chat listeners
|
||||
chatService.getGlobalChannel().removeChatChannelListener(
|
||||
globalChatListener);
|
||||
|
||||
chatService.getTradeChannel().removeChatChannelListener(
|
||||
tradeChatListener);
|
||||
|
||||
// remove broadcast listener
|
||||
eventDispatcher.removeListener(broadcastListener);
|
||||
|
||||
@@ -170,6 +181,7 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
// register global chat listener
|
||||
chatService.getGlobalChannel().addChatChannelListener(
|
||||
globalChatListener);
|
||||
chatService.getTradeChannel().addChatChannelListener(tradeChatListener);
|
||||
|
||||
// send this user information
|
||||
conn.write(new CharacterInformationPacket(character));
|
||||
@@ -177,6 +189,10 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
conn.write(new GameGuardQueryPacket());
|
||||
conn.write(new CharacterInventoryPacket(character.getInventory()));
|
||||
|
||||
conn.sendSystemMessage(SystemMessage.WELCOME_TO_LINEAGE);
|
||||
conn.sendMessage("This an an development version for l2jserver 2.0");
|
||||
conn.sendMessage("Please note that many of the features are not yet implemented.");
|
||||
|
||||
// characters start in run mode
|
||||
run(character);
|
||||
|
||||
@@ -237,6 +253,8 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
eventDispatcher.dispatch(new CharacterTargetSelectedEvent(
|
||||
character, target));
|
||||
conn.write(new CharacterTargetSelectedPacket(target));
|
||||
} else {
|
||||
conn.sendActionFailed();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of l2jserver <l2jserver.com>.
|
||||
*
|
||||
* l2jserver 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.
|
||||
*
|
||||
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.l2jserver.service.game.chat;
|
||||
|
||||
public enum ChatMessageDestination {
|
||||
/**
|
||||
* Everyone
|
||||
*/
|
||||
ALL(0),
|
||||
/**
|
||||
* !
|
||||
*/
|
||||
SHOUT(1),
|
||||
/**
|
||||
* Private message
|
||||
*/
|
||||
TELL(2),
|
||||
/**
|
||||
* #
|
||||
*/
|
||||
PARTY(3),
|
||||
/**
|
||||
* @
|
||||
*/
|
||||
CLAN(4), GM(5), PETITION_PLAYER(6), PETITION_GM(7),
|
||||
/**
|
||||
* +
|
||||
*/
|
||||
TRADE(8),
|
||||
/**
|
||||
* $
|
||||
*/
|
||||
ALLIANCE(9), ANNOUNCEMENT(10), BOAT(11), L2FRIEND(12), MSNCHAT(13), PARTYMATCH_ROOM(
|
||||
14), PARTYROOM_COMMANDER(15), PARTYROOM_ALL(16), HERO_VOICE(17), CRITICAL_ANNOUNCE(
|
||||
18), SCREEN_ANNOUNCE(19), BATTLEFIELD(20), MPCC_ROOM(21);
|
||||
|
||||
public final int id;
|
||||
|
||||
ChatMessageDestination(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static ChatMessageDestination fromID(int id) {
|
||||
for (final ChatMessageDestination dest : values()) {
|
||||
if (dest.id == id)
|
||||
return dest;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import com.l2jserver.service.Service;
|
||||
import com.l2jserver.service.game.chat.channel.ChatChannel;
|
||||
import com.l2jserver.service.game.chat.channel.PrivateChatChannel;
|
||||
import com.l2jserver.service.game.chat.channel.PublicChatChannel;
|
||||
import com.l2jserver.util.exception.L2ChatServiceException;
|
||||
|
||||
/**
|
||||
* This service chatting in the server
|
||||
@@ -30,6 +31,29 @@ import com.l2jserver.service.game.chat.channel.PublicChatChannel;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface ChatService extends Service {
|
||||
/**
|
||||
* Sends a message to a public chat channel.
|
||||
*
|
||||
* @param sender
|
||||
* the sender
|
||||
* @param chat
|
||||
* the chat type
|
||||
* @param message
|
||||
* the message
|
||||
* @param extra
|
||||
* the the extra message field
|
||||
* @throws TargetNotFoundChatServiceException
|
||||
* if target object not found
|
||||
* @throws CannotChatToSelfChatServiceException
|
||||
* if trying to send a private message to self
|
||||
* @throws ChatBanActiveChatServiceException
|
||||
* if there is chat ban active
|
||||
*/
|
||||
void send(CharacterID sender, ChatMessageDestination chat, String message,
|
||||
String extra) throws TargetNotFoundChatServiceException,
|
||||
CannotChatToSelfChatServiceException,
|
||||
ChatBanActiveChatServiceException;
|
||||
|
||||
/**
|
||||
* Get the Global {@link ChatChannel}. Messages sent in this chat are
|
||||
* broadcasted to everyone online.
|
||||
@@ -38,6 +62,22 @@ public interface ChatService extends Service {
|
||||
*/
|
||||
PublicChatChannel getGlobalChannel();
|
||||
|
||||
/**
|
||||
* Get the Trade {@link ChatChannel}. Messages sent in this chat are
|
||||
* broadcasted to everyone online.
|
||||
*
|
||||
* @return the trade {@link ChatChannel}
|
||||
*/
|
||||
PublicChatChannel getTradeChannel();
|
||||
|
||||
/**
|
||||
* Get the Announcement {@link ChatChannel}. Messages sent in this chat are
|
||||
* broadcasted to everyone online.
|
||||
*
|
||||
* @return the announcement {@link ChatChannel}
|
||||
*/
|
||||
PublicChatChannel getAnnouncementChannel();
|
||||
|
||||
/**
|
||||
* Get the Region {@link ChatChannel}. Messages sent in this chat are
|
||||
* broadcasted to everyone nearby.
|
||||
@@ -69,4 +109,19 @@ public interface ChatService extends Service {
|
||||
PublicChatChannel getChannel(ClanID clan);
|
||||
|
||||
// TODO party chat
|
||||
|
||||
public class TargetNotFoundChatServiceException extends
|
||||
L2ChatServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
public class CannotChatToSelfChatServiceException extends
|
||||
L2ChatServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
public class ChatBanActiveChatServiceException extends
|
||||
L2ChatServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.db.dao.CharacterDAO;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.model.id.object.ClanID;
|
||||
import com.l2jserver.model.world.Clan;
|
||||
@@ -42,12 +43,27 @@ import com.l2jserver.util.factory.CollectionFactory;
|
||||
*/
|
||||
// @Depends(RegionService.class)
|
||||
public class SimpleChatService extends AbstractService implements ChatService {
|
||||
/**
|
||||
* The {@link RegionService}
|
||||
*/
|
||||
private final RegionService regionService;
|
||||
/**
|
||||
* The {@link L2Character} DAO
|
||||
*/
|
||||
private final CharacterDAO charDao;
|
||||
|
||||
/**
|
||||
* The global chat channel
|
||||
* The global {@link ChatChannel}
|
||||
*/
|
||||
private GlobalChatChannelImpl global;
|
||||
/**
|
||||
* The trade {@link ChatChannel}
|
||||
*/
|
||||
private TradeChatChannelImpl trade;
|
||||
/**
|
||||
* The announcement {@link ChatChannel}
|
||||
*/
|
||||
private AnnouncementChatChannelImpl announcement;
|
||||
/**
|
||||
* The list of private chat channels
|
||||
*/
|
||||
@@ -70,24 +86,70 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
* the region service
|
||||
*/
|
||||
@Inject
|
||||
public SimpleChatService() {
|
||||
public SimpleChatService(CharacterDAO charDao) {
|
||||
// this.regionService = regionService;
|
||||
this.regionService = null;
|
||||
this.charDao = charDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() throws ServiceStartException {
|
||||
this.global = new GlobalChatChannelImpl();
|
||||
this.trade = new TradeChatChannelImpl();
|
||||
this.announcement = new AnnouncementChatChannelImpl();
|
||||
this.privateChannels = CollectionFactory.newMap();
|
||||
this.clanChannels = CollectionFactory.newMap();
|
||||
this.regionChannels = CollectionFactory.newMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(CharacterID sender, ChatMessageDestination chat,
|
||||
String message, String extra)
|
||||
throws TargetNotFoundChatServiceException,
|
||||
CannotChatToSelfChatServiceException {
|
||||
final ChatChannel channel;
|
||||
switch (chat) {
|
||||
case ALL:
|
||||
channel = getGlobalChannel();
|
||||
break;
|
||||
case TRADE:
|
||||
channel = getTradeChannel();
|
||||
break;
|
||||
case CLAN:
|
||||
channel = getChannel(sender.getObject().getClanID());
|
||||
break;
|
||||
case TELL:
|
||||
final L2Character character = charDao.selectByName(extra);
|
||||
if (character == null)
|
||||
throw new TargetNotFoundChatServiceException();
|
||||
if (character.equals(sender))
|
||||
throw new CannotChatToSelfChatServiceException();
|
||||
channel = getChannel(character.getID());
|
||||
break;
|
||||
case ANNOUNCEMENT:
|
||||
channel = getAnnouncementChannel();
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
channel.send(sender, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublicChatChannel getGlobalChannel() {
|
||||
return global;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublicChatChannel getTradeChannel() {
|
||||
return trade;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublicChatChannel getAnnouncementChannel() {
|
||||
return announcement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublicChatChannel getRegionChannel(L2Character character) {
|
||||
final Region region = regionService.getRegion(character);
|
||||
@@ -101,6 +163,8 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
|
||||
@Override
|
||||
public PrivateChatChannel getChannel(CharacterID character) {
|
||||
if (character == null)
|
||||
return null;
|
||||
PrivateChatChannelImpl channel = privateChannels.get(character);
|
||||
if (channel == null) {
|
||||
channel = new PrivateChatChannelImpl(character);
|
||||
@@ -111,6 +175,8 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
|
||||
@Override
|
||||
public PublicChatChannel getChannel(ClanID clan) {
|
||||
if (clan == null)
|
||||
return null;
|
||||
ClanChatChannelImpl channel = clanChannels.get(clan);
|
||||
if (channel == null) {
|
||||
channel = new ClanChatChannelImpl(clan);
|
||||
@@ -171,13 +237,13 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharacterID getTarget() {
|
||||
public CharacterID getDestination() {
|
||||
return character;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Global {@link PublicChatChannel} implemenetation
|
||||
* Global {@link PublicChatChannel} implementation
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@@ -186,7 +252,25 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link PublicChatChannel} implemenetation for {@link Clan clans}
|
||||
* Trade {@link PublicChatChannel} implementation
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
private class TradeChatChannelImpl extends ChatChannelImpl implements
|
||||
PublicChatChannel {
|
||||
}
|
||||
|
||||
/**
|
||||
* Announcement {@link PublicChatChannel} implementation
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
private class AnnouncementChatChannelImpl extends ChatChannelImpl implements
|
||||
PublicChatChannel {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link PublicChatChannel} implementation for {@link Clan clans}
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@@ -209,7 +293,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link PublicChatChannel} implemenetation for {@link Region regions}
|
||||
* {@link PublicChatChannel} implementation for {@link Region regions}
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
|
||||
@@ -22,13 +22,13 @@ import com.l2jserver.model.id.object.CharacterID;
|
||||
* An private {@link ChatChannel}. Please note that the concept of "private"
|
||||
* does not mean it requires a password or something like that to join, but the
|
||||
* message is only broadcasted to a single character (i.e. private messages).
|
||||
* The target can be retrieved by {@link #getTarget()}.
|
||||
* The destination can be retrieved by {@link #getDestination()}.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface PrivateChatChannel extends ChatChannel {
|
||||
/**
|
||||
* @return the target of this private chat channel.
|
||||
* @return the destination of this private chat channel.
|
||||
*/
|
||||
CharacterID getTarget();
|
||||
CharacterID getDestination();
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public class CachedWorldIDService extends AbstractService implements
|
||||
cache = new Cache(new CacheConfiguration("id-cache",
|
||||
IDAllocator.ALLOCABLE_IDS)
|
||||
.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU)
|
||||
.overflowToDisk(true).eternal(false).timeToLiveSeconds(60)
|
||||
.overflowToDisk(true).eternal(true).timeToLiveSeconds(60)
|
||||
.timeToIdleSeconds(30).diskPersistent(false)
|
||||
.diskExpiryThreadIntervalSeconds(0));
|
||||
cacheService.register(cache);
|
||||
@@ -113,6 +113,7 @@ public class CachedWorldIDService extends AbstractService implements
|
||||
public <I extends ObjectID<?>> void add(I id) {
|
||||
if(id == null)
|
||||
return;
|
||||
System.out.println("Registering ID: "+id);
|
||||
cache.put(new Element(id.getID(), id));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user