1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-09 17:02:53 +00:00

Teleporter implementation

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-22 02:04:35 -03:00
parent b3ff0795ec
commit 87ce7bb987
31 changed files with 900 additions and 31 deletions

View File

@@ -0,0 +1,48 @@
/*
* 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.admin;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.Service;
/**
* This service handles administrators in the server
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface AdministratorService extends Service {
/**
* Executes an command
*
* @param character
* the admin character
* @param command
* the command
* @param args
* the arguments
*/
void command(L2Character character, String command, String... args);
/**
* The base interface for Administrator commands
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface AdministratorCommand {
void administrator(L2Character character, String... args);
}
}

View File

@@ -16,13 +16,21 @@
*/
package com.l2jserver.service.admin;
import com.l2jserver.service.Service;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.AbstractService;
/**
* This service handles administrators in the server
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public interface AdminService extends Service {
public class AdministratorServiceImpl extends AbstractService implements
AdministratorService {
@Override
public void command(L2Character character, String command, String... args) {
if(command.equals("log")) {
if(args.length == 2) {
}
}
}
}

View File

@@ -16,6 +16,7 @@
*/
package com.l2jserver.service.admin;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.Service;
/**
@@ -24,5 +25,9 @@ import com.l2jserver.service.Service;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface GMService extends Service {
void command(L2Character character, String command, String... args);
public interface GMCommand {
void gm(L2Character character, String... args);
}
}

View File

@@ -37,6 +37,7 @@ public class Log4JLoggingService extends AbstractService implements
private Logger rootLogger;
private Logger l2jLogger;
private Logger scriptLogger;
private Logger nettyLogger;
@Override
protected void doStart() throws ServiceStartException {
@@ -47,6 +48,7 @@ public class Log4JLoggingService extends AbstractService implements
rootLogger = Logger.getRootLogger();
l2jLogger = Logger.getLogger("com.l2jserver");
scriptLogger = Logger.getLogger("script");
nettyLogger = Logger.getLogger("org.jboss.netty");
rootLogger.removeAllAppenders();
rootLogger.setLevel(Level.WARN);
@@ -54,6 +56,7 @@ public class Log4JLoggingService extends AbstractService implements
l2jLogger.setLevel(Level.DEBUG);
scriptLogger.setLevel(Level.DEBUG);
nettyLogger.setLevel(Level.DEBUG);
}
@Override

View File

@@ -81,6 +81,16 @@ public interface CharacterService extends Service {
void attack(L2Character character, Actor target)
throws CannotSetTargetServiceException;
/**
* Informs that an given <tt>character</tt> is appearing in the world.
* <p>
* This is normally called after an teleport.
*
* @param character
* the character
*/
void appearing(L2Character character);
/**
* Jails the given <tt>character</tt> for <tt>time</tt> seconds.
*

View File

@@ -24,6 +24,7 @@ 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;
import com.l2jserver.game.net.packet.server.CharacterInformationExtraPacket;
import com.l2jserver.game.net.packet.server.CharacterInformationPacket;
import com.l2jserver.game.net.packet.server.CharacterInventoryPacket;
import com.l2jserver.game.net.packet.server.CharacterMovementTypePacket;
@@ -46,6 +47,7 @@ import com.l2jserver.model.world.character.event.CharacterMoveEvent;
import com.l2jserver.model.world.character.event.CharacterTargetDeselectedEvent;
import com.l2jserver.model.world.character.event.CharacterTargetSelectedEvent;
import com.l2jserver.model.world.npc.event.NPCSpawnEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportedEvent;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.game.chat.ChatMessageDestination;
@@ -165,8 +167,21 @@ public class CharacterServiceImpl extends AbstractService implements
// TODO char broadcast
} else if (e instanceof CharacterMoveEvent) {
final CharacterMoveEvent evt = (CharacterMoveEvent) e;
if (object.equals(character))
return true;
conn.write(new ActorMovementPacket((L2Character) object,
evt.getPoint().getCoordinate()));
} else if (e instanceof PlayerTeleportedEvent) {
// TODO this should not be here!
System.out.println(((PlayerTeleportedEvent) e).getPoint()
.getCoordinate());
System.out.println(character.getPosition());
for (final WorldObject o : worldService
.iterable(new KnownListFilter(character))) {
if (o instanceof NPC) {
conn.write(new NPCInformationPacket((NPC) o));
}
}
}
// keep listener alive
return true;
@@ -202,6 +217,7 @@ public class CharacterServiceImpl extends AbstractService implements
// send this user information
conn.write(new CharacterInformationPacket(character));
conn.write(new CharacterInformationExtraPacket(character));
// TODO game guard enforcing
conn.write(new GameGuardQueryPacket());
conn.write(new CharacterInventoryPacket(character.getInventory()));
@@ -220,7 +236,6 @@ public class CharacterServiceImpl extends AbstractService implements
character))) {
if (o instanceof NPC) {
conn.write(new NPCInformationPacket((NPC) o));
// conn.write(new ServerObjectPacket((NPC) o));
}
}
@@ -300,6 +315,20 @@ public class CharacterServiceImpl extends AbstractService implements
}
}
@Override
public void appearing(L2Character character) {
Preconditions.checkNotNull(character, "character");
final CharacterID id = character.getID();
final Lineage2Connection conn = networkService.discover(id);
character.setState(null);
conn.write(new CharacterInformationPacket(character));
conn.write(new CharacterInformationExtraPacket(character));
eventDispatcher.dispatch(new PlayerTeleportedEvent(character, character
.getPoint()));
}
@Override
public void jail(L2Character character, long time, String reason)
throws CharacterInJailServiceException {
@@ -346,6 +375,10 @@ public class CharacterServiceImpl extends AbstractService implements
public void receivedValidation(L2Character character, Point point) {
Preconditions.checkNotNull(character, "character");
Preconditions.checkNotNull(point, "point");
if (character.isTeleporting())
// ignore while teleporting, for some reason the client sends a
// validation just before teleport packet
return;
character.setPoint(point);
eventDispatcher.dispatch(new CharacterMoveEvent(character, point));
}

View File

@@ -111,7 +111,6 @@ public class SimpleChatService extends AbstractService implements ChatService {
ChatBanActiveChatServiceException {
Preconditions.checkNotNull(sender, "sender");
Preconditions.checkNotNull(message, "message");
Preconditions.checkNotNull(extra, "extra");
final ChatChannel channel;
switch (chat) {

View File

@@ -42,6 +42,20 @@ public interface NPCService extends Service {
void action(NPC npc, L2Character character, CharacterAction action)
throws ActionServiceException;
/**
* Executes an action for an NPC. Each {@link NPCTemplate} have it's own
* actions.
*
* @param npc
* the npc
* @param character
* the character
* @param args
* the action arguments
*/
void action(NPC npc, L2Character character, String... args)
throws ActionServiceException;
/**
* Attacks an given NPC, if possible.
*

View File

@@ -39,7 +39,23 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
final NPCTemplate template = npc.getTemplate();
try {
template.action(npc, character, action);
template.action(npc, character, new String[0]);
} catch (L2Exception e) {
throw new ActionServiceException(e);
}
}
@Override
public void action(NPC npc, L2Character character, String... args)
throws ActionServiceException {
Preconditions.checkNotNull(npc, "npc");
Preconditions.checkNotNull(character, "character");
if (args == null)
args = new String[0];
final NPCTemplate template = npc.getTemplate();
try {
template.action(npc, character, args);
} catch (L2Exception e) {
throw new ActionServiceException(e);
}

View File

@@ -70,7 +70,7 @@ public class MapperPathingService extends AbstractService implements
private final WorldEventDispatcher eventDispatcher;
/**
* The database channel, will reamain open until service is stopped.
* The database channel, will remain open until service is stopped.
*/
private FileChannel channel;
@@ -102,6 +102,7 @@ public class MapperPathingService extends AbstractService implements
.fromCoordinate(point.getCoordinate());
try {
channel.write(struct.getByteBuffer());
channel.force(true);
} catch (IOException e1) {
log.warn("Error writing pathing file!", e1);
}

View File

@@ -19,7 +19,7 @@ package com.l2jserver.service.game.spawn;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.model.world.event.SpawnEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportingEvent;
import com.l2jserver.service.Service;
import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.dimensional.Point;
@@ -54,7 +54,7 @@ public interface SpawnService extends Service {
/**
* Teleports the object to the given <tt>point</tt>.
* <p>
* An {@link PlayerTeleportEvent} will be dispatched and the new position
* An {@link PlayerTeleportingEvent} will be dispatched and the new position
* will be broadcast to all clients.
*
* @param player

View File

@@ -25,12 +25,13 @@ import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.server.CharacterTeleportPacket;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.L2Character.CharacterState;
import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.model.world.event.SpawnEvent;
import com.l2jserver.model.world.npc.event.NPCSpawnEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportingEvent;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.game.world.WorldService;
@@ -113,6 +114,7 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
public void teleport(Player player, Coordinate coordinate) {
Preconditions.checkNotNull(player, "player");
Preconditions.checkNotNull(coordinate, "coordinate");
System.out.println("teleport: "+coordinate);
player.setPosition(coordinate);
if (player instanceof L2Character) {
final Lineage2Connection conn = networkService
@@ -121,9 +123,10 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
// TODO throw an exception here
return;
conn.write(new CharacterTeleportPacket(conn.getCharacter()));
((L2Character) player).setState(CharacterState.TELEPORTING);
}
// dispatch teleport event
eventDispatcher.dispatch(new PlayerTeleportEvent(player, coordinate
eventDispatcher.dispatch(new PlayerTeleportingEvent(player, coordinate
.toPoint()));
// remember: broadcasting is done through events!
}

View File

@@ -200,7 +200,10 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
set = CollectionFactory.newSet();
listeners.put(id, set);
}
return set;
final Set<WorldListener> union = CollectionFactory.newSet();
union.addAll(set);
union.addAll(globalListeners);
return union;
}
public void stop() {

View File

@@ -0,0 +1,65 @@
/*
* 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.world.filter;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.util.factory.CollectionFactory;
/**
* And filter that accepts all values that are not in <tt>objects</tt>
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
* @param <O>
* the object type
*/
public class ExcludeFilter<O extends WorldObject> implements
WorldObjectFilter<O> {
/**
* The objects to be exluded
*/
private Set<WorldObject> objects = CollectionFactory.newSet();
/**
* Creates a new instance
*
* @param objects
* the excluded objects
*/
public ExcludeFilter(WorldObject... objects) {
Collections.addAll(this.objects, objects);
}
/**
* Creates a new instance
*
* @param objects
* the excluded objects
*/
public ExcludeFilter(Collection<WorldObject> objects) {
this.objects.addAll(objects);
}
@Override
public boolean accept(O object) {
return objects.contains(object);
}
}

View File

@@ -27,7 +27,7 @@ import com.l2jserver.service.game.world.filter.AndFilter;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class KnownListFilter extends AndFilter<Positionable> {
public static final int KNOWNLIST_RANGE = 200;
public static final int KNOWNLIST_RANGE = 2000;
@SuppressWarnings("unchecked")
public KnownListFilter(Positionable object) {