mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-08 08:23:11 +00:00
Implemented new packets and several services
Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.model.id.object.ClanID;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
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;
|
||||
|
||||
/**
|
||||
* This service chatting in the server
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface ChatService extends Service {
|
||||
/**
|
||||
* @return the global {@link ChatChannel}
|
||||
*/
|
||||
PublicChatChannel getGlobalChannel();
|
||||
|
||||
/**
|
||||
* @param character
|
||||
* the character in the region
|
||||
* @return the global {@link ChatChannel}
|
||||
*/
|
||||
PublicChatChannel getRegionChannel(L2Character character);
|
||||
|
||||
/**
|
||||
* Get an private {@link ChatChannel} to {@link CharacterID}
|
||||
*
|
||||
* @param character
|
||||
* the target character
|
||||
* @return the private {@link ChatChannel}
|
||||
*/
|
||||
PrivateChatChannel getChannel(CharacterID character);
|
||||
|
||||
/**
|
||||
* @param clan
|
||||
* the clan
|
||||
* @return the public clan {@link ChatChannel}
|
||||
*/
|
||||
PublicChatChannel getChannel(ClanID clan);
|
||||
|
||||
// TODO party chat
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.model.id.object.ClanID;
|
||||
import com.l2jserver.model.world.Clan;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.game.chat.channel.ChatChannel;
|
||||
import com.l2jserver.service.game.chat.channel.ChatChannelListener;
|
||||
import com.l2jserver.service.game.chat.channel.PrivateChatChannel;
|
||||
import com.l2jserver.service.game.chat.channel.PublicChatChannel;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
/**
|
||||
* Default {@link ChatService} implementation
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class SimpleChatService extends AbstractService implements ChatService {
|
||||
/**
|
||||
* The global chat channel
|
||||
*/
|
||||
private GlobalChatChannelImpl global;
|
||||
/**
|
||||
* The list of private chat channels
|
||||
*/
|
||||
// TODO remove private chats from disconnected characters. Maybe plugging it
|
||||
// in the NetworkService?
|
||||
private Map<CharacterID, PrivateChatChannelImpl> privateChannels;
|
||||
/**
|
||||
* The list of clan chat channels
|
||||
*/
|
||||
private Map<ClanID, ClanChatChannelImpl> clanChannels;
|
||||
|
||||
@Override
|
||||
public void start() throws ServiceStartException {
|
||||
this.global = new GlobalChatChannelImpl();
|
||||
this.privateChannels = CollectionFactory.newMap(null, null);
|
||||
this.clanChannels = CollectionFactory.newMap(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublicChatChannel getGlobalChannel() {
|
||||
return global;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublicChatChannel getRegionChannel(L2Character character) {
|
||||
// TODO Region chat channels
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrivateChatChannel getChannel(CharacterID character) {
|
||||
PrivateChatChannelImpl channel = privateChannels.get(character);
|
||||
if (channel == null) {
|
||||
channel = new PrivateChatChannelImpl(character);
|
||||
privateChannels.put(character, channel);
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublicChatChannel getChannel(ClanID clan) {
|
||||
ClanChatChannelImpl channel = clanChannels.get(clan);
|
||||
if (channel == null) {
|
||||
channel = new ClanChatChannelImpl(clan);
|
||||
clanChannels.put(clan, channel);
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ChatChannel} abstract implementation
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
private abstract class ChatChannelImpl implements ChatChannel {
|
||||
/**
|
||||
* The list of all listeners on this channel
|
||||
*/
|
||||
protected final Set<ChatChannelListener> listeners = CollectionFactory
|
||||
.newSet(null);
|
||||
|
||||
@Override
|
||||
public void send(CharacterID sender, String message) {
|
||||
for (final ChatChannelListener listener : listeners) {
|
||||
listener.onMessage(this, sender, message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChatChannelListener(ChatChannelListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChatChannelListener(ChatChannelListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link PrivateChatChannel} implementation
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
private class PrivateChatChannelImpl extends ChatChannelImpl implements
|
||||
PrivateChatChannel {
|
||||
private final CharacterID character;
|
||||
|
||||
public PrivateChatChannelImpl(CharacterID character) {
|
||||
this.character = character;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharacterID getTarget() {
|
||||
return character;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Global {@link PublicChatChannel} implemenetation
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
private class GlobalChatChannelImpl extends ChatChannelImpl implements
|
||||
PublicChatChannel {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link PublicChatChannel} implemenetation for {@link Clan clans}
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
private class ClanChatChannelImpl extends ChatChannelImpl implements
|
||||
PublicChatChannel {
|
||||
/**
|
||||
* The clan ID
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private final ClanID clanID;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param clanID
|
||||
*/
|
||||
public ClanChatChannelImpl(ClanID clanID) {
|
||||
this.clanID = clanID;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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.channel;
|
||||
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
|
||||
/**
|
||||
* The {@link ChatChannel} object is used to send messages to a channel.
|
||||
* <p>
|
||||
* Note that this is a base for all types of channel.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* @see PrivateChatChannel
|
||||
* @see PublicChatChannel
|
||||
*/
|
||||
public interface ChatChannel {
|
||||
/**
|
||||
* Sends a message to this channel
|
||||
*
|
||||
* @param sender
|
||||
* the character sending the message
|
||||
* @param message
|
||||
* the message to be sent
|
||||
*/
|
||||
void send(CharacterID sender, String message);
|
||||
|
||||
/**
|
||||
* Adds a {@link ChatChannelListener} that will be notified once a message
|
||||
* has been received.
|
||||
*
|
||||
* @param listener
|
||||
* the listener
|
||||
*/
|
||||
void addChatChannelListener(ChatChannelListener listener);
|
||||
|
||||
/**
|
||||
* Removes a {@link ChatChannelListener}.
|
||||
*
|
||||
* @param listener
|
||||
* the listener
|
||||
*/
|
||||
void removeChatChannelListener(ChatChannelListener listener);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.channel;
|
||||
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
|
||||
/**
|
||||
* This listener is used to received notifications once a new message is sent to
|
||||
* an given {@link ChatChannel}.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface ChatChannelListener {
|
||||
/**
|
||||
* Notification of a new message received
|
||||
*
|
||||
* @param channel
|
||||
* the chat channel
|
||||
* @param source
|
||||
* the character sending this message
|
||||
* @param message
|
||||
* the message
|
||||
*/
|
||||
void onMessage(ChatChannel channel, CharacterID source, String message);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.channel;
|
||||
|
||||
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()}.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface PrivateChatChannel extends ChatChannel {
|
||||
/**
|
||||
* @return the target of this private chat channel.
|
||||
*/
|
||||
CharacterID getTarget();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.channel;
|
||||
|
||||
/**
|
||||
* An public {@link ChatChannel}. Please note that the concept of "public" does
|
||||
* not mean it is available to anyone, but there are more than 2 player chatting
|
||||
* (i.e. clan, global, region, etc...)
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface PublicChatChannel extends ChatChannel {
|
||||
}
|
||||
Reference in New Issue
Block a user