diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/Java7VFSService.java b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/Java7VFSService.java index 2fef9baf2..54cb23b11 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/Java7VFSService.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/Java7VFSService.java @@ -17,6 +17,7 @@ package com.l2jserver.service.core.vfs; import java.nio.file.Path; +import java.nio.file.Paths; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,16 +68,27 @@ public class Java7VFSService extends @Override public Path resolve(String path) { + return resolve(Paths.get(path)); + } + + @Override + public Path resolve(Path path) { log.debug("Resolving file {}", path); return root.resolve(path); } @Override public Path resolveDataFile(String path) { + return resolveDataFile(Paths.get(path)); + } + + @Override + public Path resolveDataFile(Path path) { log.debug("Resolving data file {}", path); return dataRoot.resolve(path); } + @Override protected void doStop() throws ServiceStopException { root = null; diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/TrueZipVFSService.java b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/TrueZipVFSService.java index ce92d0804..9fe01c65b 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/TrueZipVFSService.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/TrueZipVFSService.java @@ -17,6 +17,7 @@ package com.l2jserver.service.core.vfs; import java.nio.file.Path; +import java.nio.file.Paths; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,7 +64,7 @@ public class TrueZipVFSService extends @Override protected void doStart() throws ServiceStartException { - root = new TPath(config.getRoot().toAbsolutePath()); + root = new TPath(config.getRoot().normalize()); log.debug("Root path is {}", root); dataRoot = root.resolve(config.getDataPath()); @@ -72,12 +73,22 @@ public class TrueZipVFSService extends @Override public Path resolve(String path) { + return resolve(Paths.get(path)); + } + + @Override + public Path resolve(Path path) { log.debug("Resolving file {}", path); return root.resolve(path); } @Override public Path resolveDataFile(String path) { + return resolveDataFile(Paths.get(path)); + } + + @Override + public Path resolveDataFile(Path path) { log.debug("Resolving data file {}", path); return dataRoot.resolve(path); } diff --git a/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/VFSService.java b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/VFSService.java index d0853d100..e647afa96 100644 --- a/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/VFSService.java +++ b/l2jserver2-common/src/main/java/com/l2jserver/service/core/vfs/VFSService.java @@ -38,6 +38,18 @@ public interface VFSService extends Service { * @return the resolved file. Will return null if could not resolve. */ Path resolve(String path); + + /** + * Resolves an file. If the file cannot be resolved, null will be returned. + *
+ * Please note that even if the file DOES NOT exists a valid object will be + * returned. + * + * @param path + * the file path + * @return the resolved file. Will return null if could not resolve. + */ + Path resolve(Path path); /** * Resolves an file inside the data storage file system. If the file cannot @@ -51,4 +63,17 @@ public interface VFSService extends Service { * @return the resolved file. Will return null if could not resolve. */ Path resolveDataFile(String path); + + /** + * Resolves an file inside the data storage file system. If the file cannot + * be resolved, null will be returned. + *
+ * Please note that, differently from {@link #resolve(String)}, if the file
+ * does not exists, null is returned.
+ *
+ * @param path
+ * the file path
+ * @return the resolved file. Will return null if could not resolve.
+ */
+ Path resolveDataFile(Path path);
}
diff --git a/l2jserver2-gameserver/.gitignore b/l2jserver2-gameserver/.gitignore
index 4c6512dac..b2ea08db6 100644
--- a/l2jserver2-gameserver/.gitignore
+++ b/l2jserver2-gameserver/.gitignore
@@ -1,3 +1,2 @@
/log
/derby.log
-/services.xml
diff --git a/l2jserver2-gameserver/l2jserver2-gameserver-core/src/main/java/com/l2jserver/service/game/map/pathing/MapperPathingService.java b/l2jserver2-gameserver/l2jserver2-gameserver-core/src/main/java/com/l2jserver/service/game/map/pathing/MapperPathingService.java
index 93806eca8..93e2487b2 100755
--- a/l2jserver2-gameserver/l2jserver2-gameserver-core/src/main/java/com/l2jserver/service/game/map/pathing/MapperPathingService.java
+++ b/l2jserver2-gameserver/l2jserver2-gameserver-core/src/main/java/com/l2jserver/service/game/map/pathing/MapperPathingService.java
@@ -16,10 +16,14 @@
*/
package com.l2jserver.service.game.map.pathing;
-import java.io.File;
+import static java.nio.file.StandardOpenOption.APPEND;
+import static java.nio.file.StandardOpenOption.CREATE;
+import static java.nio.file.StandardOpenOption.WRITE;
+
import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.channels.FileChannel;
+import java.nio.channels.SeekableByteChannel;
+import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Iterator;
@@ -35,6 +39,7 @@ 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.core.vfs.VFSService;
import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.event.TypedWorldListener;
@@ -53,13 +58,13 @@ import com.l2jserver.util.geometry.Point3D;
*
* @author Rogiel
*/
-@Depends({ CharacterService.class, WorldService.class })
+@Depends({ VFSService.class, 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");
+ private static final java.nio.file.Path file = Paths.get("pathing.db");
/**
* The logger
@@ -70,28 +75,35 @@ public class MapperPathingService extends AbstractService implements
* The {@link WorldService} event dispatcher
*/
private final WorldEventDispatcherService eventDispatcher;
+ /**
+ * The {@link VFSService} implementation
+ */
+ private final VFSService vfsService;
/**
* The database channel, will remain open until service is stopped.
*/
- private FileChannel channel;
+ private SeekableByteChannel channel;
/**
* Creates a new instance
*
* @param eventDispatcher
* the world event dispatcher
+ * @param vfsService the VFS service implementation
*/
@Inject
- public MapperPathingService(WorldEventDispatcherService eventDispatcher) {
+ public MapperPathingService(WorldEventDispatcherService eventDispatcher,
+ VFSService vfsService) {
this.eventDispatcher = eventDispatcher;
+ this.vfsService = vfsService;
}
@Override
protected void doStart() throws ServiceStartException {
try {
- this.channel = new RandomAccessFile(file, "rw").getChannel();
- this.channel.position(file.length());
+ final java.nio.file.Path dbFile = vfsService.resolveDataFile(file);
+ this.channel = Files.newByteChannel(dbFile, CREATE, APPEND, WRITE);
} catch (IOException e) {
throw new ServiceStartException(
"Could not open pathing database file", e);
@@ -105,7 +117,7 @@ public class MapperPathingService extends AbstractService implements
.fromCoordinate(point.getCoordinate());
try {
channel.write(struct.getByteBuffer());
- channel.force(true);
+ //channel.force(true);
} catch (IOException e1) {
log.warn("Error writing pathing file!", e1);
}
diff --git a/l2jserver2-gameserver/l2jserver2-gameserver-freya/.gitignore b/l2jserver2-gameserver/l2jserver2-gameserver-freya/.gitignore
new file mode 100644
index 000000000..a5f32eadb
--- /dev/null
+++ b/l2jserver2-gameserver/l2jserver2-gameserver-freya/.gitignore
@@ -0,0 +1 @@
+/services.xml
diff --git a/l2jserver2-gameserver/distribution/services.xml b/l2jserver2-gameserver/l2jserver2-gameserver-freya/distribution/services.xml
old mode 100644
new mode 100755
similarity index 100%
rename from l2jserver2-gameserver/distribution/services.xml
rename to l2jserver2-gameserver/l2jserver2-gameserver-freya/distribution/services.xml
diff --git a/l2jserver2-gameserver/services-sample.xml b/l2jserver2-gameserver/l2jserver2-gameserver-freya/services-sample.xml
old mode 100644
new mode 100755
similarity index 98%
rename from l2jserver2-gameserver/services-sample.xml
rename to l2jserver2-gameserver/l2jserver2-gameserver-freya/services-sample.xml
index 37fd67c6b..9c23f0b08
--- a/l2jserver2-gameserver/services-sample.xml
+++ b/l2jserver2-gameserver/l2jserver2-gameserver-freya/services-sample.xml
@@ -35,7 +35,7 @@