mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-08 08:23:11 +00:00
Inventory open implementation, Html updates, Pathing generator,
Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
@@ -31,16 +31,18 @@ import com.l2jserver.service.game.SpawnService;
|
||||
import com.l2jserver.service.game.SpawnServiceImpl;
|
||||
import com.l2jserver.service.game.chat.ChatService;
|
||||
import com.l2jserver.service.game.chat.SimpleChatService;
|
||||
import com.l2jserver.service.game.pathing.MapperPathingService;
|
||||
import com.l2jserver.service.game.pathing.PathingService;
|
||||
import com.l2jserver.service.game.scripting.ScriptingService;
|
||||
import com.l2jserver.service.game.scripting.ScriptingServiceImpl;
|
||||
import com.l2jserver.service.game.template.ScriptTemplateService;
|
||||
import com.l2jserver.service.game.template.TemplateService;
|
||||
import com.l2jserver.service.game.world.CachedWorldIDService;
|
||||
import com.l2jserver.service.game.world.WorldIDService;
|
||||
import com.l2jserver.service.game.world.WorldService;
|
||||
import com.l2jserver.service.game.world.WorldServiceImpl;
|
||||
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
|
||||
import com.l2jserver.service.game.world.event.WorldEventDispatcherImpl;
|
||||
import com.l2jserver.service.game.world.id.CachedWorldIDService;
|
||||
import com.l2jserver.service.game.world.id.WorldIDService;
|
||||
import com.l2jserver.service.logging.Log4JLoggingService;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.service.network.NettyNetworkService;
|
||||
@@ -67,6 +69,9 @@ public class ServiceModule extends AbstractModule {
|
||||
bind(WorldIDService.class).to(CachedWorldIDService.class).in(
|
||||
Scopes.SINGLETON);
|
||||
|
||||
bind(PathingService.class).to(MapperPathingService.class).in(
|
||||
Scopes.SINGLETON);
|
||||
|
||||
bind(BlowfishKeygenService.class).to(SecureBlowfishKeygenService.class)
|
||||
.in(Scopes.SINGLETON);
|
||||
bind(NetworkService.class).to(NettyNetworkService.class).in(
|
||||
|
||||
@@ -25,6 +25,8 @@ import net.sf.ehcache.Cache;
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import net.sf.ehcache.Element;
|
||||
import net.sf.ehcache.config.CacheConfiguration;
|
||||
import net.sf.ehcache.config.Configuration;
|
||||
import net.sf.ehcache.config.DiskStoreConfiguration;
|
||||
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
|
||||
|
||||
import com.l2jserver.service.AbstractService;
|
||||
@@ -48,7 +50,8 @@ public class EhCacheService extends AbstractService implements CacheService {
|
||||
|
||||
@Override
|
||||
protected void doStart() throws ServiceStartException {
|
||||
manager = new CacheManager();
|
||||
manager = new CacheManager(new Configuration().updateCheck(false)
|
||||
.diskStore(new DiskStoreConfiguration().path("data/cache")));
|
||||
interfaceCache = createCache("interface-cache");
|
||||
}
|
||||
|
||||
|
||||
@@ -122,8 +122,7 @@ public class MySQLDatabaseService extends AbstractService implements
|
||||
objectCache = new Cache(new CacheConfiguration("database-service",
|
||||
IDAllocator.ALLOCABLE_IDS)
|
||||
.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU)
|
||||
.overflowToDisk(true).eternal(false).timeToLiveSeconds(60)
|
||||
.timeToIdleSeconds(30).diskPersistent(false)
|
||||
.overflowToDisk(true).eternal(true).diskPersistent(false)
|
||||
.diskExpiryThreadIntervalSeconds(0));
|
||||
cacheService.register(objectCache);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.capability.Actor;
|
||||
import com.l2jserver.service.Service;
|
||||
import com.l2jserver.util.dimensional.Coordinate;
|
||||
import com.l2jserver.util.dimensional.Point;
|
||||
|
||||
/**
|
||||
* This service manages {@link L2Character} instances
|
||||
@@ -73,6 +74,26 @@ public interface CharacterService extends Service {
|
||||
*/
|
||||
void move(L2Character character, Coordinate coordinate);
|
||||
|
||||
/**
|
||||
* Validates the position of an character
|
||||
*
|
||||
* @param character
|
||||
* the character
|
||||
* @param point
|
||||
* the validated point
|
||||
*/
|
||||
void validate(L2Character character, Point point);
|
||||
|
||||
/**
|
||||
* Called when received the validation of the position of an character
|
||||
*
|
||||
* @param character
|
||||
* the character
|
||||
* @param point
|
||||
* the validated point
|
||||
*/
|
||||
void receivedValidation(L2Character character, Point point);
|
||||
|
||||
/**
|
||||
* Set the character to walking mode
|
||||
*
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.l2jserver.service.game;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.db.dao.ItemDAO;
|
||||
import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.SystemMessage;
|
||||
import com.l2jserver.game.net.packet.server.ActionFailedPacket;
|
||||
@@ -45,7 +46,6 @@ import com.l2jserver.model.world.character.event.CharacterTargetSelectedEvent;
|
||||
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;
|
||||
@@ -58,6 +58,7 @@ import com.l2jserver.service.game.world.event.WorldListener;
|
||||
import com.l2jserver.service.game.world.filter.impl.KnownListFilter;
|
||||
import com.l2jserver.service.network.NetworkService;
|
||||
import com.l2jserver.util.dimensional.Coordinate;
|
||||
import com.l2jserver.util.dimensional.Point;
|
||||
|
||||
/**
|
||||
* Default implementation for {@link CharacterService}.
|
||||
@@ -65,7 +66,7 @@ import com.l2jserver.util.dimensional.Coordinate;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@Depends({ WorldService.class, ChatService.class, NetworkService.class,
|
||||
SpawnService.class, AIService.class })
|
||||
SpawnService.class })
|
||||
public class CharacterServiceImpl extends AbstractService implements
|
||||
CharacterService {
|
||||
/**
|
||||
@@ -88,6 +89,10 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
* The {@link SpawnService}
|
||||
*/
|
||||
private final SpawnService spawnService;
|
||||
/**
|
||||
* The {@link ItemDAO}
|
||||
*/
|
||||
private final ItemDAO itemDao;
|
||||
|
||||
// /**
|
||||
// * The {@link AIService}
|
||||
@@ -97,12 +102,14 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
@Inject
|
||||
public CharacterServiceImpl(WorldService worldService,
|
||||
WorldEventDispatcher eventDispatcher, ChatService chatService,
|
||||
NetworkService networkService, SpawnService spawnService) {
|
||||
NetworkService networkService, SpawnService spawnService,
|
||||
ItemDAO itemDao) {
|
||||
this.worldService = worldService;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
this.chatService = chatService;
|
||||
this.networkService = networkService;
|
||||
this.spawnService = spawnService;
|
||||
this.itemDao = itemDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -114,6 +121,8 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
if (!worldService.add(character))
|
||||
// character is already in the world!
|
||||
return;
|
||||
|
||||
itemDao.loadInventory(character);
|
||||
|
||||
// chat listener
|
||||
final ChatChannelListener globalChatListener = new ChatChannelListener() {
|
||||
@@ -221,10 +230,11 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
// aiService.walk(character, coordinate);
|
||||
|
||||
final Coordinate source = character.getPosition();
|
||||
character.setPosition(coordinate);
|
||||
conn.write(new ActorMovementPacket(character, source));
|
||||
// we don't set the character coordinate yet, this will be done by
|
||||
// validate coordinate
|
||||
conn.write(new ActorMovementPacket(character, coordinate));
|
||||
// we don't dispatch events here, they will be dispatched by
|
||||
// CharacterValidatePositionPacket packets at fixed time intervals.
|
||||
// receivedValidation at fixed time intervals.
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -273,6 +283,17 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(L2Character character, Point point) {
|
||||
// TODO implement position validation
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedValidation(L2Character character, Point point) {
|
||||
character.setPoint(point);
|
||||
eventDispatcher.dispatch(new CharacterMoveEvent(character, point));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void walk(L2Character character) {
|
||||
final CharacterID id = character.getID();
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 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.pathing;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
import javolution.io.Struct;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.model.world.character.event.CharacterMoveEvent;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
import com.l2jserver.service.game.CharacterService;
|
||||
import com.l2jserver.service.game.world.WorldService;
|
||||
import com.l2jserver.service.game.world.event.TypedWorldListener;
|
||||
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
|
||||
import com.l2jserver.util.dimensional.Coordinate;
|
||||
import com.l2jserver.util.dimensional.Point;
|
||||
|
||||
/**
|
||||
* <h1>This implementation does not validate pathing!</h1>
|
||||
* <p>
|
||||
* This service does not handle pathing yet, instead in monitors client packets
|
||||
* that send a location validation. With those packets, a database will be
|
||||
* generated will all valid points in terrain. Later on, an system that allows
|
||||
* uploading this data will be implemented and allowing the pathing data to be
|
||||
* shared across all servers.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@Depends({ CharacterService.class, WorldService.class })
|
||||
public class MapperPathingService extends AbstractService implements
|
||||
PathingService {
|
||||
/**
|
||||
* The database file for the pathing engine
|
||||
*/
|
||||
private static final File file = new File("data/pathing.db");
|
||||
|
||||
/**
|
||||
* The logger
|
||||
*/
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
/**
|
||||
* The {@link WorldService} event dispatcher
|
||||
*/
|
||||
private final WorldEventDispatcher eventDispatcher;
|
||||
|
||||
/**
|
||||
* The database channel, will reamain open until service is stopped.
|
||||
*/
|
||||
private FileChannel channel;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param eventDispatcher
|
||||
* the world event dispatcher
|
||||
*/
|
||||
@Inject
|
||||
public MapperPathingService(WorldEventDispatcher eventDispatcher) {
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() throws ServiceStartException {
|
||||
try {
|
||||
this.channel = new FileOutputStream(file).getChannel();
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new ServiceStartException(
|
||||
"Could not open pathing database file", e);
|
||||
}
|
||||
eventDispatcher.addListener(new TypedWorldListener<CharacterMoveEvent>(
|
||||
CharacterMoveEvent.class) {
|
||||
@Override
|
||||
protected boolean dispatch(CharacterMoveEvent e) {
|
||||
final Point point = e.getPoint();
|
||||
final CoordinateStruct struct = CoordinateStruct
|
||||
.fromCoordinate(point.getCoordinate());
|
||||
try {
|
||||
channel.write(struct.getByteBuffer());
|
||||
} catch (IOException e1) {
|
||||
log.warn("Error writing pathing file!", e1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStop() throws ServiceStopException {
|
||||
try {
|
||||
this.channel.close();
|
||||
} catch (IOException e) {
|
||||
throw new ServiceStopException(
|
||||
"Could not close the pathing database file", e);
|
||||
} finally {
|
||||
this.channel = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is an Javolution {@link Struct} that represents a set of coordinate
|
||||
* stored in the database file
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public static class CoordinateStruct extends Struct {
|
||||
public final Signed32 x = new Signed32();
|
||||
public final Signed32 y = new Signed32();
|
||||
public final Signed32 z = new Signed32();
|
||||
|
||||
public static CoordinateStruct fromCoordinate(Coordinate coordinate) {
|
||||
final CoordinateStruct struct = new CoordinateStruct();
|
||||
struct.x.set(coordinate.getX());
|
||||
struct.y.set(coordinate.getY());
|
||||
struct.z.set(coordinate.getZ());
|
||||
return struct;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.pathing;
|
||||
|
||||
import com.l2jserver.service.Service;
|
||||
|
||||
/**
|
||||
* This service handles the pathing.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface PathingService extends Service {
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* 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.id;
|
||||
package com.l2jserver.service.game.world;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -25,6 +25,7 @@ import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.db.dao.CharacterDAO;
|
||||
import com.l2jserver.db.dao.ItemDAO;
|
||||
import com.l2jserver.model.id.ID;
|
||||
import com.l2jserver.model.id.ObjectID;
|
||||
import com.l2jserver.model.id.object.allocator.IDAllocator;
|
||||
@@ -58,18 +59,28 @@ public class CachedWorldIDService extends AbstractService implements
|
||||
* The {@link CharacterDAO}
|
||||
*/
|
||||
private final CharacterDAO characterDao;
|
||||
/**
|
||||
* The {@link ItemDAO}
|
||||
*/
|
||||
private final ItemDAO itemDao;
|
||||
|
||||
/**
|
||||
* The ID cache
|
||||
*/
|
||||
private Cache cache;
|
||||
|
||||
/**
|
||||
* The loaded state
|
||||
*/
|
||||
private boolean loaded = false;
|
||||
|
||||
@Inject
|
||||
public CachedWorldIDService(CacheService cacheService,
|
||||
IDAllocator allocator, CharacterDAO characterDao) {
|
||||
IDAllocator allocator, CharacterDAO characterDao, ItemDAO itemDao) {
|
||||
this.cacheService = cacheService;
|
||||
this.allocator = allocator;
|
||||
this.characterDao = characterDao;
|
||||
this.itemDao = itemDao;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,9 +93,13 @@ public class CachedWorldIDService extends AbstractService implements
|
||||
.timeToIdleSeconds(30).diskPersistent(false)
|
||||
.diskExpiryThreadIntervalSeconds(0));
|
||||
cacheService.register(cache);
|
||||
}
|
||||
|
||||
// load all ids
|
||||
@Override
|
||||
public void load() {
|
||||
load(characterDao.listIDs());
|
||||
load(itemDao.listIDs());
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,6 +118,11 @@ public class CachedWorldIDService extends AbstractService implements
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <I extends ObjectID<?>> I resolve(int id) {
|
||||
if (!loaded) {
|
||||
// ignore resolving before all IDs are loaded
|
||||
return null;
|
||||
}
|
||||
|
||||
final Element element = cache.get(id);
|
||||
if (element == null)
|
||||
return null;
|
||||
@@ -111,9 +131,8 @@ public class CachedWorldIDService extends AbstractService implements
|
||||
|
||||
@Override
|
||||
public <I extends ObjectID<?>> void add(I id) {
|
||||
if(id == null)
|
||||
if (id == null)
|
||||
return;
|
||||
System.out.println("Registering ID: "+id);
|
||||
cache.put(new Element(id.getID(), id));
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* 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.id;
|
||||
package com.l2jserver.service.game.world;
|
||||
|
||||
import com.l2jserver.model.id.ObjectID;
|
||||
import com.l2jserver.model.id.object.allocator.IDAllocator;
|
||||
@@ -30,6 +30,11 @@ import com.l2jserver.service.database.DatabaseService;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface WorldIDService extends Service {
|
||||
/**
|
||||
* Load all {@link ObjectID} from the database
|
||||
*/
|
||||
void load();
|
||||
|
||||
/**
|
||||
* Tries to resolve an ID based on its raw value
|
||||
*
|
||||
@@ -43,7 +48,23 @@ public interface WorldIDService extends Service {
|
||||
*/
|
||||
<I extends ObjectID<?>> I resolve(int id);
|
||||
|
||||
/**
|
||||
* Adds a new ID to be managed by this service
|
||||
*
|
||||
* @param <I>
|
||||
* the ID type
|
||||
* @param id
|
||||
* the id
|
||||
*/
|
||||
<I extends ObjectID<?>> void add(I id);
|
||||
|
||||
/**
|
||||
* Decouples an ID from this service
|
||||
*
|
||||
* @param <I>
|
||||
* the ID type
|
||||
* @param id
|
||||
* the id
|
||||
*/
|
||||
<I extends ObjectID<?>> void remove(I id);
|
||||
}
|
||||
@@ -50,7 +50,7 @@ import com.l2jserver.util.factory.CollectionFactory;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@Depends({ LoggingService.class, TemplateService.class, ScriptingService.class,
|
||||
DatabaseService.class })
|
||||
DatabaseService.class, WorldIDService.class })
|
||||
public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
/**
|
||||
* The logger
|
||||
@@ -66,15 +66,22 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
* The world event dispatcher
|
||||
*/
|
||||
private final WorldEventDispatcherImpl dispatcher;
|
||||
/**
|
||||
* The {@link WorldIDService}
|
||||
*/
|
||||
private final WorldIDService idService;
|
||||
|
||||
@Inject
|
||||
public WorldServiceImpl(WorldEventDispatcher dispatcher) {
|
||||
public WorldServiceImpl(WorldEventDispatcher dispatcher,
|
||||
WorldIDService idService) {
|
||||
this.dispatcher = (WorldEventDispatcherImpl) dispatcher;
|
||||
this.idService = idService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() throws ServiceStartException {
|
||||
objects.clear();
|
||||
idService.load();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user