mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-09 08:52:51 +00:00
@@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.service.core.LoggingService;
|
||||
import com.l2jserver.util.ClassUtils;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ import com.l2jserver.service.cache.CacheService;
|
||||
import com.l2jserver.service.cache.EhCacheService;
|
||||
import com.l2jserver.service.configuration.ConfigurationService;
|
||||
import com.l2jserver.service.configuration.ProxyConfigurationService;
|
||||
import com.l2jserver.service.core.Log4JLoggingService;
|
||||
import com.l2jserver.service.core.LoggingService;
|
||||
import com.l2jserver.service.database.DatabaseService;
|
||||
import com.l2jserver.service.database.MySQLDatabaseService;
|
||||
import com.l2jserver.service.game.CharacterService;
|
||||
@@ -43,8 +45,6 @@ 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.logging.Log4JLoggingService;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.service.network.NettyNetworkService;
|
||||
import com.l2jserver.service.network.NetworkService;
|
||||
import com.l2jserver.service.network.keygen.BlowfishKeygenService;
|
||||
|
||||
@@ -29,6 +29,7 @@ import net.sf.ehcache.config.Configuration;
|
||||
import net.sf.ehcache.config.DiskStoreConfiguration;
|
||||
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
@@ -58,6 +59,9 @@ public class EhCacheService extends AbstractService implements CacheService {
|
||||
@Override
|
||||
public <T extends Cacheable> T decorate(final Class<T> interfaceType,
|
||||
final T instance) {
|
||||
Preconditions.checkNotNull(interfaceType, "interfaceType");
|
||||
Preconditions.checkNotNull(instance, "instance");
|
||||
|
||||
if (!interfaceType.isInterface())
|
||||
return null;
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -85,6 +89,9 @@ public class EhCacheService extends AbstractService implements CacheService {
|
||||
|
||||
@Override
|
||||
public Cache createCache(String name, int size) {
|
||||
Preconditions.checkNotNull(name, "name");
|
||||
Preconditions.checkArgument(size > 0, "size <= 0");
|
||||
|
||||
Cache cache = new Cache(new CacheConfiguration(name, size)
|
||||
.memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU)
|
||||
.overflowToDisk(true).eternal(false).timeToLiveSeconds(60)
|
||||
@@ -96,16 +103,19 @@ public class EhCacheService extends AbstractService implements CacheService {
|
||||
|
||||
@Override
|
||||
public Cache createCache(String name) {
|
||||
Preconditions.checkNotNull(name, "name");
|
||||
return createCache(name, 200);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(Cache cache) {
|
||||
Preconditions.checkNotNull(cache, "cache");
|
||||
manager.addCache(cache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(Cache cache) {
|
||||
Preconditions.checkNotNull(cache, "cache");
|
||||
manager.removeCache(cache.getName());
|
||||
}
|
||||
|
||||
|
||||
@@ -26,11 +26,11 @@ import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
@@ -38,7 +38,7 @@ import com.l2jserver.service.cache.CacheService;
|
||||
import com.l2jserver.service.configuration.Configuration.ConfigurationName;
|
||||
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertyGetter;
|
||||
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertySetter;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.service.core.LoggingService;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
import com.l2jserver.util.transformer.Transformer;
|
||||
import com.l2jserver.util.transformer.TransformerFactory;
|
||||
@@ -77,6 +77,8 @@ public class ProxyConfigurationService extends AbstractService implements
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <C extends Configuration> C get(Class<C> config) {
|
||||
Preconditions.checkNotNull(config, "config");
|
||||
|
||||
if (cache.containsKey(config))
|
||||
return (C) cache.get(config);
|
||||
logger.info("Trying to create {} proxy", config);
|
||||
@@ -242,6 +244,8 @@ public class ProxyConfigurationService extends AbstractService implements
|
||||
* if any i/o error occur
|
||||
*/
|
||||
private Properties findProperties(Class<?> clazz) throws IOException {
|
||||
Preconditions.checkNotNull(clazz, "clazz");
|
||||
|
||||
ConfigurationName config = findAnnotation(ConfigurationName.class,
|
||||
clazz);
|
||||
if (config == null)
|
||||
@@ -270,6 +274,9 @@ public class ProxyConfigurationService extends AbstractService implements
|
||||
*/
|
||||
private <T extends Annotation> T findAnnotation(Class<T> annotationClass,
|
||||
Class<?> clazz) {
|
||||
Preconditions.checkNotNull(annotationClass, "annotationClass");
|
||||
Preconditions.checkNotNull(clazz, "clazz");
|
||||
|
||||
T ann = clazz.getAnnotation(annotationClass);
|
||||
if (ann != null)
|
||||
return ann;
|
||||
@@ -298,6 +305,7 @@ public class ProxyConfigurationService extends AbstractService implements
|
||||
* the directory
|
||||
*/
|
||||
public void setDirectory(File directory) {
|
||||
Preconditions.checkNotNull(directory, "directory");
|
||||
this.directory = directory;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.core;
|
||||
|
||||
import com.l2jserver.service.Service;
|
||||
|
||||
/**
|
||||
* Service used to manage unhandled exceptions
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface ExceptionService extends Service {
|
||||
/**
|
||||
* Handles an unhandled exception
|
||||
*
|
||||
* @param t
|
||||
* the exception
|
||||
*/
|
||||
void thrown(Throwable t);
|
||||
|
||||
/**
|
||||
* Handles an unhandled exception and rethrows it again
|
||||
*
|
||||
* @param <T>
|
||||
* the exception type
|
||||
* @param t
|
||||
* the exception
|
||||
* @throws T
|
||||
* same exception in <tt>t</tt>
|
||||
*/
|
||||
<T extends Throwable> void rethrown(T t) throws T;
|
||||
}
|
||||
@@ -14,12 +14,13 @@
|
||||
* 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.logging;
|
||||
package com.l2jserver.service.core;
|
||||
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
|
||||
/**
|
||||
* Logging service implementation for Log4J
|
||||
@@ -32,4 +33,9 @@ public class Log4JLoggingService extends AbstractService implements
|
||||
protected void doStart() throws ServiceStartException {
|
||||
BasicConfigurator.configure();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStop() throws ServiceStopException {
|
||||
BasicConfigurator.resetConfiguration();
|
||||
}
|
||||
}
|
||||
@@ -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.logging;
|
||||
package com.l2jserver.service.core;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* 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.core.threading;
|
||||
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
/**
|
||||
* This future instance extends {@link Future} but also adds some additional
|
||||
* features, such as waiting for an given task to finish.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface AsyncFuture<T> extends Future<T> {
|
||||
/**
|
||||
* Waits until the task is executed
|
||||
*
|
||||
* @throws InterruptedException
|
||||
* if the thread has been interrupted while waiting
|
||||
*/
|
||||
void await() throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Waits until the task is executed
|
||||
*
|
||||
* @param timeout
|
||||
* the timeout
|
||||
* @param unit
|
||||
* the timeout unit
|
||||
*
|
||||
* @throws InterruptedException
|
||||
* if the thread has been interrupted while waiting
|
||||
* @throws TimeoutException
|
||||
* if timeout was exceeded
|
||||
*/
|
||||
void await(long timeout, TimeUnit unit) throws InterruptedException,
|
||||
TimeoutException;
|
||||
|
||||
/**
|
||||
* Waits until the task is executed
|
||||
*
|
||||
* @return true if execution ended with no error, false otherwise
|
||||
*/
|
||||
boolean awaitUninterruptibly();
|
||||
|
||||
/**
|
||||
* Waits until the task is executed
|
||||
*
|
||||
* @param timeout
|
||||
* the timeout
|
||||
* @param unit
|
||||
* the timeout unit
|
||||
*
|
||||
* @return true if execution ended with no error, false otherwise. Please
|
||||
* note that false will be returned if the timeout has expired too!
|
||||
*/
|
||||
boolean awaitUninterruptibly(long timeout, TimeUnit unit);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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.core.threading;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.l2jserver.service.Service;
|
||||
|
||||
/**
|
||||
* This service is responsible for scheduling tasks and executing them in
|
||||
* parallel.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface ThreadService extends Service {
|
||||
/**
|
||||
* Executes an asynchronous tasks.
|
||||
*
|
||||
* @param <T>
|
||||
* the task return type
|
||||
* @param callable
|
||||
* the callable instance
|
||||
* @return the {@link AsyncFuture} notified once the task has completed
|
||||
*/
|
||||
<T> AsyncFuture<T> async(Callable<T> callable);
|
||||
|
||||
/**
|
||||
* Executes an asynchronous tasks at an scheduled time. <b>Please note that
|
||||
* resources in scheduled thread pool are limited and tasks should be
|
||||
* performed fast.</b>
|
||||
*
|
||||
* @param <T>
|
||||
* the task return type
|
||||
* @param callable
|
||||
* the callable instance
|
||||
* @param delay
|
||||
* the initial delay to wait before the task is executed
|
||||
* @param unit
|
||||
* the time unit of delay
|
||||
* @return the {@link AsyncFuture} notified once the task has completed
|
||||
*/
|
||||
<T> AsyncFuture<T> async(long delay, TimeUnit unit, Callable<T> callable);
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
/*
|
||||
* 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.core.threading;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
|
||||
/**
|
||||
* The default implementation for {@link ThreadService}
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class ThreadServiceImpl extends AbstractService implements ThreadService {
|
||||
/**
|
||||
* The logger
|
||||
*/
|
||||
private final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
/**
|
||||
* The scheduler Thread pool
|
||||
*/
|
||||
private ScheduledExecutorService scheduler;
|
||||
/**
|
||||
* The asynchronous Thread pool
|
||||
*/
|
||||
private ExecutorService async;
|
||||
|
||||
@Override
|
||||
protected void doStart() throws ServiceStartException {
|
||||
scheduler = Executors.newScheduledThreadPool(10);
|
||||
async = Executors.newCachedThreadPool();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> AsyncFuture<T> async(Callable<T> callable) {
|
||||
Preconditions.checkNotNull(callable, "callable");
|
||||
return new AsyncFutureImpl<T>(async.submit(callable));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> AsyncFuture<T> async(long delay, TimeUnit unit,
|
||||
Callable<T> callable) {
|
||||
Preconditions.checkArgument(delay >= 0, "delay < 0");
|
||||
Preconditions.checkNotNull(unit, "unit");
|
||||
Preconditions.checkNotNull(callable, "callable");
|
||||
return new AsyncFutureImpl<T>(scheduler.schedule(callable, delay, unit));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStop() throws ServiceStopException {
|
||||
scheduler.shutdown();
|
||||
async.shutdown();
|
||||
try {
|
||||
scheduler.awaitTermination(60, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
log.warn("Scheduler thread did not stop in 60 seconds", e);
|
||||
}
|
||||
try {
|
||||
async.awaitTermination(60, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
log.warn("Asynchronous thread did not stop in 60 seconds", e);
|
||||
}
|
||||
scheduler = null;
|
||||
async = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple delegated implementation for {@link AsyncFuture}
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* @param <T>
|
||||
* the return type
|
||||
*/
|
||||
public static class AsyncFutureImpl<T> implements AsyncFuture<T> {
|
||||
/**
|
||||
* The future that is delegated in this implementation
|
||||
*/
|
||||
private final Future<T> future;
|
||||
|
||||
/**
|
||||
* Creates a new instance
|
||||
*
|
||||
* @param future
|
||||
* the future
|
||||
*/
|
||||
private AsyncFutureImpl(Future<T> future) {
|
||||
this.future = future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
return future.cancel(mayInterruptIfRunning);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return future.isCancelled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return future.isDone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get() throws InterruptedException, ExecutionException {
|
||||
return future.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(long timeout, TimeUnit unit) throws InterruptedException,
|
||||
ExecutionException, TimeoutException {
|
||||
return future.get(timeout, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void await() throws InterruptedException {
|
||||
try {
|
||||
this.get();
|
||||
} catch (ExecutionException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void await(long timeout, TimeUnit unit)
|
||||
throws InterruptedException, TimeoutException {
|
||||
try {
|
||||
this.get(timeout, unit);
|
||||
} catch (ExecutionException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean awaitUninterruptibly() {
|
||||
try {
|
||||
this.get();
|
||||
return true;
|
||||
} catch (InterruptedException e) {
|
||||
return false;
|
||||
} catch (ExecutionException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean awaitUninterruptibly(long timeout, TimeUnit unit) {
|
||||
try {
|
||||
this.get(timeout, unit);
|
||||
return true;
|
||||
} catch (InterruptedException e) {
|
||||
return false;
|
||||
} catch (ExecutionException e) {
|
||||
return false;
|
||||
} catch (TimeoutException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ import org.apache.commons.pool.impl.GenericObjectPool;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.model.id.ObjectID;
|
||||
import com.l2jserver.model.id.object.allocator.IDAllocator;
|
||||
@@ -49,8 +50,8 @@ import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
import com.l2jserver.service.cache.CacheService;
|
||||
import com.l2jserver.service.configuration.ConfigurationService;
|
||||
import com.l2jserver.service.core.LoggingService;
|
||||
import com.l2jserver.service.game.template.TemplateService;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.util.ArrayIterator;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
@@ -137,6 +138,7 @@ public class MySQLDatabaseService extends AbstractService implements
|
||||
* @return an instance of <tt>T</tt>
|
||||
*/
|
||||
public <T> T query(Query<T> query) {
|
||||
Preconditions.checkNotNull(query, "query");
|
||||
try {
|
||||
final Connection conn = dataSource.getConnection();
|
||||
try {
|
||||
@@ -155,6 +157,7 @@ public class MySQLDatabaseService extends AbstractService implements
|
||||
|
||||
@Override
|
||||
public Object getCachedObject(Object id) {
|
||||
Preconditions.checkNotNull(id, "id");
|
||||
final Element element = objectCache.get(id);
|
||||
if (element == null)
|
||||
return null;
|
||||
@@ -163,16 +166,20 @@ public class MySQLDatabaseService extends AbstractService implements
|
||||
|
||||
@Override
|
||||
public boolean hasCachedObject(Object id) {
|
||||
Preconditions.checkNotNull(id, "id");
|
||||
return objectCache.get(id) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCache(Object key, Object value) {
|
||||
Preconditions.checkNotNull(key, "key");
|
||||
Preconditions.checkNotNull(value, "value");
|
||||
objectCache.put(new Element(key, value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeCache(Object key) {
|
||||
Preconditions.checkNotNull(key, "key");
|
||||
objectCache.remove(key);
|
||||
}
|
||||
|
||||
@@ -254,6 +261,7 @@ public class MySQLDatabaseService extends AbstractService implements
|
||||
|
||||
@Override
|
||||
public Integer query(Connection conn) throws SQLException {
|
||||
Preconditions.checkNotNull(conn, "conn");
|
||||
int rows = 0;
|
||||
while (iterator.hasNext()) {
|
||||
final T object = iterator.next();
|
||||
@@ -314,6 +322,7 @@ public class MySQLDatabaseService extends AbstractService implements
|
||||
public static abstract class SelectListQuery<T> implements Query<List<T>> {
|
||||
@Override
|
||||
public List<T> query(Connection conn) throws SQLException {
|
||||
Preconditions.checkNotNull(conn, "conn");
|
||||
final PreparedStatement st = conn.prepareStatement(query());
|
||||
parametize(st);
|
||||
st.execute();
|
||||
@@ -368,6 +377,7 @@ public class MySQLDatabaseService extends AbstractService implements
|
||||
public static abstract class SelectSingleQuery<T> implements Query<T> {
|
||||
@Override
|
||||
public T query(Connection conn) throws SQLException {
|
||||
Preconditions.checkNotNull(conn, "conn");
|
||||
final PreparedStatement st = conn.prepareStatement(query());
|
||||
parametize(st);
|
||||
st.execute();
|
||||
@@ -465,6 +475,7 @@ public class MySQLDatabaseService extends AbstractService implements
|
||||
@SuppressWarnings("unchecked")
|
||||
public final T map(ResultSet rs) throws SQLException {
|
||||
final I id = createID(rs);
|
||||
Preconditions.checkNotNull(id, "id");
|
||||
|
||||
if (database.hasCachedObject(id))
|
||||
return (T) database.getCachedObject(id);
|
||||
|
||||
@@ -19,8 +19,12 @@ package com.l2jserver.service.game;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.capability.Actor;
|
||||
import com.l2jserver.service.Service;
|
||||
import com.l2jserver.service.game.SpawnService.AlreadySpawnedServiceException;
|
||||
import com.l2jserver.service.game.SpawnService.NotSpawnedServiceException;
|
||||
import com.l2jserver.service.game.SpawnService.SpawnPointNotFoundServiceException;
|
||||
import com.l2jserver.util.dimensional.Coordinate;
|
||||
import com.l2jserver.util.dimensional.Point;
|
||||
import com.l2jserver.util.exception.L2ChatServiceException;
|
||||
|
||||
/**
|
||||
* This service manages {@link L2Character} instances
|
||||
@@ -33,16 +37,24 @@ public interface CharacterService extends Service {
|
||||
*
|
||||
* @param character
|
||||
* the character
|
||||
* @throws SpawnPointNotFoundServiceException
|
||||
* if the character does not have an spawn point defined
|
||||
* @throws AlreadySpawnedServiceException
|
||||
* if the character is already spawned in the world
|
||||
*/
|
||||
void enterWorld(L2Character character);
|
||||
void enterWorld(L2Character character)
|
||||
throws SpawnPointNotFoundServiceException,
|
||||
AlreadySpawnedServiceException;
|
||||
|
||||
/**
|
||||
* Perform all operations required to this character leave the world
|
||||
*
|
||||
* @param character
|
||||
* the character
|
||||
* @throws NotSpawnedServiceException
|
||||
* if the object is not spawned in the world
|
||||
*/
|
||||
void leaveWorld(L2Character character);
|
||||
void leaveWorld(L2Character character) throws NotSpawnedServiceException;
|
||||
|
||||
/**
|
||||
* Set the target of this <tt>character</tt>
|
||||
@@ -51,8 +63,11 @@ public interface CharacterService extends Service {
|
||||
* the character
|
||||
* @param actor
|
||||
* the targeted actor
|
||||
* @throws CannotSetTargetServiceException
|
||||
* if target cannot be set
|
||||
*/
|
||||
void target(L2Character character, Actor actor);
|
||||
void target(L2Character character, Actor actor)
|
||||
throws CannotSetTargetServiceException;
|
||||
|
||||
/**
|
||||
* Attacks with the given <tt>character</tt> the <tt>target</tt>
|
||||
@@ -61,8 +76,36 @@ public interface CharacterService extends Service {
|
||||
* the character
|
||||
* @param target
|
||||
* the target
|
||||
* @throws CannotSetTargetServiceException
|
||||
* if target cannot be set
|
||||
*/
|
||||
void attack(L2Character character, Actor target);
|
||||
void attack(L2Character character, Actor target)
|
||||
throws CannotSetTargetServiceException;
|
||||
|
||||
/**
|
||||
* Jails the given <tt>character</tt> for <tt>time</tt> seconds.
|
||||
*
|
||||
* @param character
|
||||
* the character
|
||||
* @param time
|
||||
* the jail time, in seconds
|
||||
* @param reason
|
||||
* the jail reason
|
||||
* @throws CharacterInJailServiceException
|
||||
* if the character is already in jail
|
||||
*/
|
||||
void jail(L2Character character, long time, String reason)
|
||||
throws CharacterInJailServiceException;
|
||||
|
||||
/**
|
||||
* Unjails the given <tt>character</tt>
|
||||
*
|
||||
* @param character
|
||||
* the character to be unjailed
|
||||
* @throws CharacterNotInJailServiceException
|
||||
* if character is not in jail
|
||||
*/
|
||||
void unjail(L2Character character) throws CharacterNotInJailServiceException;
|
||||
|
||||
/**
|
||||
* Moves the given <tt>character</tt> to <tt>coordinate</tt>
|
||||
@@ -109,4 +152,32 @@ public interface CharacterService extends Service {
|
||||
* the character
|
||||
*/
|
||||
void run(L2Character character);
|
||||
|
||||
/**
|
||||
* Exception thrown when the target cannot be set
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class CannotSetTargetServiceException extends L2ChatServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown when the character is in jail
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class CharacterInJailServiceException extends L2ChatServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown when the character is <b>not</b> in jail
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class CharacterNotInJailServiceException extends
|
||||
L2ChatServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.l2jserver.service.game;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.db.dao.ItemDAO;
|
||||
import com.l2jserver.game.net.Lineage2Connection;
|
||||
@@ -47,6 +48,9 @@ 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.SpawnService.AlreadySpawnedServiceException;
|
||||
import com.l2jserver.service.game.SpawnService.NotSpawnedServiceException;
|
||||
import com.l2jserver.service.game.SpawnService.SpawnPointNotFoundServiceException;
|
||||
import com.l2jserver.service.game.chat.ChatMessageDestination;
|
||||
import com.l2jserver.service.game.chat.ChatService;
|
||||
import com.l2jserver.service.game.chat.channel.ChatChannel;
|
||||
@@ -114,15 +118,14 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterWorld(final L2Character character) {
|
||||
public void enterWorld(final L2Character character)
|
||||
throws SpawnPointNotFoundServiceException,
|
||||
AlreadySpawnedServiceException {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
final CharacterID id = character.getID();
|
||||
final Lineage2Connection conn = networkService.discover(id);
|
||||
if (conn == null)
|
||||
return;
|
||||
if (!worldService.add(character))
|
||||
// TODO this should throw an exception
|
||||
// character is already in the world!
|
||||
return;
|
||||
|
||||
itemDao.loadInventory(character);
|
||||
|
||||
@@ -224,34 +227,23 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
eventDispatcher.dispatch(new CharacterEnterWorldEvent(character));
|
||||
|
||||
// spawn the player -- this will also dispatch a spawn event
|
||||
// here the object is registered in the world
|
||||
spawnService.spawn(character, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(L2Character character, Coordinate coordinate) {
|
||||
final CharacterID id = character.getID();
|
||||
final Lineage2Connection conn = networkService.discover(id);
|
||||
// we don't set the character coordinate here, this will be done by
|
||||
// validation packets, sent by client
|
||||
|
||||
// for now, let's just write the packet, we don't have much validation
|
||||
// to be done yet. With character validation packet, another packet of
|
||||
// these will be broadcasted.
|
||||
conn.write(new ActorMovementPacket(character, coordinate));
|
||||
// we don't dispatch events here, they will be dispatched by
|
||||
// with the same packet referred up here.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leaveWorld(L2Character character) {
|
||||
if (!worldService.remove(character))
|
||||
return;
|
||||
public void leaveWorld(L2Character character)
|
||||
throws NotSpawnedServiceException {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
spawnService.unspawn(character);
|
||||
eventDispatcher.dispatch(new CharacterLeaveWorldEvent(character));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void target(L2Character character, Actor target) {
|
||||
public void target(L2Character character, Actor target)
|
||||
throws CannotSetTargetServiceException {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
Preconditions.checkNotNull(target, "target");
|
||||
final CharacterID id = character.getID();
|
||||
final Lineage2Connection conn = networkService.discover(id);
|
||||
|
||||
@@ -277,17 +269,19 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
character, target));
|
||||
conn.write(new CharacterTargetSelectedPacket(target));
|
||||
} else {
|
||||
// this indicates an inconsistency, send an action failed and reset
|
||||
// target, i.e. deselect with no target
|
||||
// TODO instead of sending action failed, we should throw an
|
||||
// exception here
|
||||
conn.sendActionFailed();
|
||||
// this indicates an inconsistency: reset target and throws an
|
||||
// exception
|
||||
// this happens if tried deselect with no target
|
||||
character.setTargetID(null);
|
||||
throw new CannotSetTargetServiceException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(L2Character character, Actor target) {
|
||||
public void attack(L2Character character, Actor target)
|
||||
throws CannotSetTargetServiceException {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
Preconditions.checkNotNull(target, "target");
|
||||
final CharacterID id = character.getID();
|
||||
final Lineage2Connection conn = networkService.discover(id);
|
||||
// check if this Actor can be attacked
|
||||
@@ -305,19 +299,59 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jail(L2Character character, long time, String reason)
|
||||
throws CharacterInJailServiceException {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
Preconditions.checkArgument(time > 0, "time <= 0");
|
||||
Preconditions.checkNotNull(reason, "reason");
|
||||
// TODO implement jailing
|
||||
throw new CharacterInJailServiceException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unjail(L2Character character)
|
||||
throws CharacterNotInJailServiceException {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
// TODO implement jailing
|
||||
throw new CharacterNotInJailServiceException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(L2Character character, Coordinate coordinate) {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
Preconditions.checkNotNull(coordinate, "coordinate");
|
||||
final CharacterID id = character.getID();
|
||||
final Lineage2Connection conn = networkService.discover(id);
|
||||
// we don't set the character coordinate here, this will be done by
|
||||
// validation packets, sent by client
|
||||
|
||||
// for now, let's just write the packet, we don't have much validation
|
||||
// to be done yet. With character validation packet, another packet of
|
||||
// these will be broadcasted.
|
||||
conn.write(new ActorMovementPacket(character, coordinate));
|
||||
// we don't dispatch events here, they will be dispatched by
|
||||
// with the same packet referred up here.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(L2Character character, Point point) {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
Preconditions.checkNotNull(point, "point");
|
||||
// TODO implement position validation
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedValidation(L2Character character, Point point) {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
Preconditions.checkNotNull(point, "point");
|
||||
character.setPoint(point);
|
||||
eventDispatcher.dispatch(new CharacterMoveEvent(character, point));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void walk(L2Character character) {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
final CharacterID id = character.getID();
|
||||
final Lineage2Connection conn = networkService.discover(id);
|
||||
// test if character is running
|
||||
@@ -332,6 +366,7 @@ public class CharacterServiceImpl extends AbstractService implements
|
||||
|
||||
@Override
|
||||
public void run(L2Character character) {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
final CharacterID id = character.getID();
|
||||
final Lineage2Connection conn = networkService.discover(id);
|
||||
// test if character is walking
|
||||
|
||||
@@ -24,6 +24,11 @@ import com.l2jserver.service.Service;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface GameTimeService extends Service {
|
||||
/**
|
||||
* The real time length of a day in-game in milliseconds.
|
||||
*/
|
||||
public static final int GAME_DAY = 120 * 60 * 1000;
|
||||
|
||||
/**
|
||||
* Returns the in-game time
|
||||
*
|
||||
|
||||
@@ -27,7 +27,6 @@ public class GameTimeServiceImpl extends AbstractService implements
|
||||
GameTimeService {
|
||||
@Override
|
||||
public int getGameTime() {
|
||||
// TODO implement this!
|
||||
return (int) (System.currentTimeMillis() / 1000);
|
||||
return (int) (System.currentTimeMillis() % GAME_DAY) / 1000;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,16 +14,25 @@
|
||||
* 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.threading;
|
||||
package com.l2jserver.service.game;
|
||||
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.service.Service;
|
||||
|
||||
/**
|
||||
* This service is responsible for scheduling tasks and executing them in
|
||||
* parallel.
|
||||
* This service controls {@link NPC}s
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface ThreadService extends Service {
|
||||
|
||||
public interface MonsterService extends Service {
|
||||
/**
|
||||
* Interacts the given <tt>player</tt> with the given <tt>npc</tt>
|
||||
*
|
||||
* @param npc
|
||||
* the npc
|
||||
* @param character
|
||||
* the character
|
||||
*/
|
||||
void interact(NPC npc, L2Character character);
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import com.l2jserver.model.world.player.event.PlayerTeleportEvent;
|
||||
import com.l2jserver.service.Service;
|
||||
import com.l2jserver.util.dimensional.Coordinate;
|
||||
import com.l2jserver.util.dimensional.Point;
|
||||
import com.l2jserver.util.exception.L2SpawnServiceException;
|
||||
|
||||
/**
|
||||
* This service is responsible for spawning monsters, npcs and players.
|
||||
@@ -41,8 +42,15 @@ public interface SpawnService extends Service {
|
||||
* @param point
|
||||
* the spawning point. If null, will try to use
|
||||
* {@link Spawnable#getPoint()}.
|
||||
* @throws SpawnPointNotFoundServiceException
|
||||
* if could not find an spawn point (i.e <tt>point</tt> and
|
||||
* {@link Spawnable#getPoint()} are null)
|
||||
* @throws AlreadySpawnedServiceException
|
||||
* if the object is already spawned in the world
|
||||
*/
|
||||
void spawn(Spawnable spawnable, Point point);
|
||||
void spawn(Spawnable spawnable, Point point)
|
||||
throws SpawnPointNotFoundServiceException,
|
||||
AlreadySpawnedServiceException;
|
||||
|
||||
/**
|
||||
* Teleports the object to the given <tt>point</tt>.
|
||||
@@ -54,11 +62,16 @@ public interface SpawnService extends Service {
|
||||
* the player object
|
||||
* @param coordinate
|
||||
* the teleportation coordinate
|
||||
* @throws NotSpawnedServiceException
|
||||
* if the object to be teleported is not spawned
|
||||
*/
|
||||
void teleport(Player player, Coordinate coordinate);
|
||||
void teleport(Player player, Coordinate coordinate)
|
||||
throws NotSpawnedServiceException;
|
||||
|
||||
/**
|
||||
* Schedules an {@link Spawnable} object to be respawn in a certain time.
|
||||
* <p>
|
||||
* TODO this is not complete
|
||||
*
|
||||
* @param spawnable
|
||||
* the spawnable object
|
||||
@@ -70,6 +83,37 @@ public interface SpawnService extends Service {
|
||||
*
|
||||
* @param spawnable
|
||||
* the spawnable object
|
||||
* @throws NotSpawnedServiceException
|
||||
* if the object is not spawned
|
||||
*/
|
||||
void unspawn(Spawnable spawnable);
|
||||
void unspawn(Spawnable spawnable) throws NotSpawnedServiceException;
|
||||
|
||||
/**
|
||||
* Exception thrown when the object is already spawned and registered in the
|
||||
* world
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class AlreadySpawnedServiceException extends L2SpawnServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown when the target spawn point is not found
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class SpawnPointNotFoundServiceException extends
|
||||
L2SpawnServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown when trying to unspawn an object that is not spawned
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class NotSpawnedServiceException extends L2SpawnServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.l2jserver.service.game;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.packet.server.CharacterTeleportPacket;
|
||||
@@ -72,16 +73,16 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn(Spawnable spawnable, Point point) {
|
||||
public void spawn(Spawnable spawnable, Point point)
|
||||
throws SpawnPointNotFoundServiceException {
|
||||
Preconditions.checkNotNull(spawnable, "spawnable");
|
||||
// sanitize
|
||||
if (point == null)
|
||||
// retrieving stored point
|
||||
point = spawnable.getPoint();
|
||||
if (point == null) {
|
||||
// not point send and no point stored, aborting
|
||||
// TODO this should throw an exception
|
||||
log.warn("Trying to spawn {} to a null point", spawnable);
|
||||
return;
|
||||
throw new SpawnPointNotFoundServiceException();
|
||||
}
|
||||
|
||||
// set the spawning point
|
||||
@@ -110,6 +111,8 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
|
||||
|
||||
@Override
|
||||
public void teleport(Player player, Coordinate coordinate) {
|
||||
Preconditions.checkNotNull(player, "player");
|
||||
Preconditions.checkNotNull(coordinate, "coordinate");
|
||||
player.setPosition(coordinate);
|
||||
if (player instanceof L2Character) {
|
||||
final Lineage2Connection conn = networkService
|
||||
@@ -127,12 +130,14 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
|
||||
|
||||
@Override
|
||||
public void scheduleRespawn(Spawnable spawnable) {
|
||||
Preconditions.checkNotNull(spawnable, "spawnable");
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unspawn(Spawnable spawnable) {
|
||||
Preconditions.checkNotNull(spawnable, "spawnable");
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@@ -22,11 +22,11 @@ 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.threading.ThreadService;
|
||||
import com.l2jserver.service.game.template.TemplateService;
|
||||
import com.l2jserver.service.game.world.WorldService;
|
||||
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
|
||||
import com.l2jserver.service.network.NetworkService;
|
||||
import com.l2jserver.service.threading.ThreadService;
|
||||
import com.l2jserver.util.dimensional.Coordinate;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,11 @@
|
||||
*/
|
||||
package com.l2jserver.service.game.chat;
|
||||
|
||||
/**
|
||||
* Enumeration of all possible message destinations
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public enum ChatMessageDestination {
|
||||
/**
|
||||
* Everyone
|
||||
@@ -44,9 +49,17 @@ public enum ChatMessageDestination {
|
||||
/**
|
||||
* $
|
||||
*/
|
||||
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);
|
||||
ALLIANCE(9),
|
||||
/**
|
||||
* Announcement
|
||||
*/
|
||||
ANNOUNCEMENT(10),
|
||||
/**
|
||||
* Boat
|
||||
*/
|
||||
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;
|
||||
|
||||
|
||||
@@ -110,16 +110,32 @@ public interface ChatService extends Service {
|
||||
|
||||
// TODO party chat
|
||||
|
||||
/**
|
||||
* Exception thrown when the target of an private chat is not found
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class TargetNotFoundChatServiceException extends
|
||||
L2ChatServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown if the player is trying to chat with itself.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class CannotChatToSelfChatServiceException extends
|
||||
L2ChatServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception thrown if the player trying to send a message is currently
|
||||
* banned.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class ChatBanActiveChatServiceException extends
|
||||
L2ChatServiceException {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.l2jserver.service.game.chat;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.db.dao.CharacterDAO;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
@@ -106,7 +107,12 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
public void send(CharacterID sender, ChatMessageDestination chat,
|
||||
String message, String extra)
|
||||
throws TargetNotFoundChatServiceException,
|
||||
CannotChatToSelfChatServiceException {
|
||||
CannotChatToSelfChatServiceException,
|
||||
ChatBanActiveChatServiceException {
|
||||
Preconditions.checkNotNull(sender, "sender");
|
||||
Preconditions.checkNotNull(message, "message");
|
||||
Preconditions.checkNotNull(extra, "extra");
|
||||
|
||||
final ChatChannel channel;
|
||||
switch (chat) {
|
||||
case ALL:
|
||||
@@ -122,7 +128,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
final L2Character character = charDao.selectByName(extra);
|
||||
if (character == null)
|
||||
throw new TargetNotFoundChatServiceException();
|
||||
if (character.equals(sender))
|
||||
if (character.getID().equals(sender))
|
||||
throw new CannotChatToSelfChatServiceException();
|
||||
channel = getChannel(character.getID());
|
||||
break;
|
||||
@@ -152,6 +158,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
|
||||
@Override
|
||||
public PublicChatChannel getRegionChannel(L2Character character) {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
final Region region = regionService.getRegion(character);
|
||||
RegionChatChannelImpl channel = regionChannels.get(region);
|
||||
if (channel == null) {
|
||||
@@ -163,6 +170,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
|
||||
@Override
|
||||
public PrivateChatChannel getChannel(CharacterID character) {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
if (character == null)
|
||||
return null;
|
||||
PrivateChatChannelImpl channel = privateChannels.get(character);
|
||||
@@ -175,6 +183,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
|
||||
@Override
|
||||
public PublicChatChannel getChannel(ClanID clan) {
|
||||
Preconditions.checkNotNull(clan, "clan");
|
||||
if (clan == null)
|
||||
return null;
|
||||
ClanChatChannelImpl channel = clanChannels.get(clan);
|
||||
@@ -207,6 +216,9 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
|
||||
@Override
|
||||
public void send(CharacterID sender, String message) {
|
||||
Preconditions.checkNotNull(sender, "sender");
|
||||
Preconditions.checkNotNull(message, "message");
|
||||
// TODO throw exception if sender is banned from chat
|
||||
for (final ChatChannelListener listener : listeners) {
|
||||
listener.onMessage(this, sender, message);
|
||||
}
|
||||
@@ -214,11 +226,13 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
|
||||
@Override
|
||||
public void addChatChannelListener(ChatChannelListener listener) {
|
||||
Preconditions.checkNotNull(listener, "listener");
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeChatChannelListener(ChatChannelListener listener) {
|
||||
Preconditions.checkNotNull(listener, "listener");
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
@@ -233,6 +247,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
private final CharacterID character;
|
||||
|
||||
public PrivateChatChannelImpl(CharacterID character) {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
this.character = character;
|
||||
}
|
||||
|
||||
@@ -288,6 +303,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
* @param clanID
|
||||
*/
|
||||
public ClanChatChannelImpl(ClanID clanID) {
|
||||
Preconditions.checkNotNull(clanID, "clanID");
|
||||
this.clanID = clanID;
|
||||
}
|
||||
}
|
||||
@@ -311,6 +327,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
|
||||
* @param clanID
|
||||
*/
|
||||
public RegionChatChannelImpl(Region region) {
|
||||
Preconditions.checkNotNull(region, "region");
|
||||
this.region = region;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.l2jserver.service.game.chat.channel;
|
||||
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.service.game.chat.ChatService.ChatBanActiveChatServiceException;
|
||||
|
||||
/**
|
||||
* The {@link ChatChannel} object is used to send messages to a channel.
|
||||
@@ -35,8 +36,11 @@ public interface ChatChannel {
|
||||
* the character sending the message
|
||||
* @param message
|
||||
* the message to be sent
|
||||
* @throws ChatBanActiveChatServiceException
|
||||
* if <tt>sender</tt> is banned from chatting
|
||||
*/
|
||||
void send(CharacterID sender, String message);
|
||||
void send(CharacterID sender, String message)
|
||||
throws ChatBanActiveChatServiceException;
|
||||
|
||||
/**
|
||||
* Adds a {@link ChatChannelListener} that will be notified once a message
|
||||
|
||||
@@ -28,16 +28,17 @@ import javax.xml.bind.Unmarshaller;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
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.LoggingService;
|
||||
import com.l2jserver.service.game.scripting.impl.ScriptContextImpl;
|
||||
import com.l2jserver.service.game.scripting.scriptmanager.ScriptInfo;
|
||||
import com.l2jserver.service.game.scripting.scriptmanager.ScriptList;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
/**
|
||||
@@ -84,6 +85,7 @@ public class ScriptingServiceImpl extends AbstractService implements
|
||||
@Override
|
||||
public synchronized List<ScriptContext> load(File scriptDescriptor)
|
||||
throws Exception {
|
||||
Preconditions.checkNotNull(scriptDescriptor, "scriptDescriptor");
|
||||
final JAXBContext c = JAXBContext.newInstance(ScriptInfo.class,
|
||||
ScriptList.class);
|
||||
final Unmarshaller u = c.createUnmarshaller();
|
||||
@@ -115,6 +117,9 @@ public class ScriptingServiceImpl extends AbstractService implements
|
||||
*/
|
||||
private ScriptContext createContext(ScriptInfo si, ScriptContext parent)
|
||||
throws Exception {
|
||||
Preconditions.checkNotNull(si, "si");
|
||||
Preconditions.checkNotNull(parent, "parent");
|
||||
|
||||
ScriptContext context = getScriptContext(si.getRoot(), parent);
|
||||
context.setLibraries(si.getLibraries());
|
||||
context.setCompilerClassName(si.getCompilerClass());
|
||||
@@ -153,6 +158,9 @@ public class ScriptingServiceImpl extends AbstractService implements
|
||||
*/
|
||||
private ScriptContext getScriptContext(File root, ScriptContext parent)
|
||||
throws InstantiationException {
|
||||
Preconditions.checkNotNull(root, "root");
|
||||
Preconditions.checkNotNull(parent, "parent");
|
||||
|
||||
ScriptContextImpl ctx;
|
||||
if (parent == null) {
|
||||
ctx = new ScriptContextImpl(injector, root);
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.l2jserver.service.game.template;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.l2jserver.model.id.TemplateID;
|
||||
@@ -27,9 +28,9 @@ import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
import com.l2jserver.service.configuration.ConfigurationService;
|
||||
import com.l2jserver.service.core.LoggingService;
|
||||
import com.l2jserver.service.game.scripting.ScriptContext;
|
||||
import com.l2jserver.service.game.scripting.ScriptingService;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
@Depends({ LoggingService.class, ConfigurationService.class,
|
||||
@@ -73,10 +74,13 @@ public class ScriptTemplateService extends AbstractService implements
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Template<?>> T getTemplate(TemplateID<T> id) {
|
||||
Preconditions.checkNotNull(id, "id");
|
||||
return (T) templates.get(id);
|
||||
}
|
||||
|
||||
public void addTemplate(Class<? extends Template<?>> t) {
|
||||
Preconditions.checkNotNull(t, "t");
|
||||
|
||||
final Template<?> template = injector.getInstance(t);
|
||||
if (templates.containsKey(template.getID()))
|
||||
throw new TemplateException("Template with ID" + template.getID()
|
||||
@@ -88,6 +92,7 @@ public class ScriptTemplateService extends AbstractService implements
|
||||
}
|
||||
|
||||
public void removeTemplate(Template<?> t) {
|
||||
Preconditions.checkNotNull(t, "t");
|
||||
// TODO templates.remove(t);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import net.sf.ehcache.Element;
|
||||
import net.sf.ehcache.config.CacheConfiguration;
|
||||
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.db.dao.CharacterDAO;
|
||||
import com.l2jserver.db.dao.ItemDAO;
|
||||
@@ -114,6 +115,7 @@ public class CachedWorldIDService extends AbstractService implements
|
||||
* an collection of ids
|
||||
*/
|
||||
private void load(Collection<? extends ObjectID<?>> ids) {
|
||||
Preconditions.checkNotNull(ids, "ids");
|
||||
for (final ObjectID<?> id : ids) {
|
||||
allocator.allocate(id.getID());
|
||||
add(id);
|
||||
@@ -123,6 +125,7 @@ public class CachedWorldIDService extends AbstractService implements
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <I extends ObjectID<?>> I resolve(int id) {
|
||||
Preconditions.checkNotNull(id, "id");
|
||||
if (!loaded) {
|
||||
// ignore resolving before all IDs are loaded
|
||||
return null;
|
||||
@@ -136,6 +139,7 @@ public class CachedWorldIDService extends AbstractService implements
|
||||
|
||||
@Override
|
||||
public <I extends ObjectID<?>> void add(I id) {
|
||||
Preconditions.checkNotNull(id, "id");
|
||||
if (id == null)
|
||||
return;
|
||||
cache.put(new Element(id.getID(), id));
|
||||
@@ -143,6 +147,7 @@ public class CachedWorldIDService extends AbstractService implements
|
||||
|
||||
@Override
|
||||
public <I extends ObjectID<?>> void remove(I id) {
|
||||
Preconditions.checkNotNull(id, "id");
|
||||
cache.remove(id.getID());
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Set;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.model.id.ObjectID;
|
||||
import com.l2jserver.model.world.WorldObject;
|
||||
@@ -31,6 +32,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.LoggingService;
|
||||
import com.l2jserver.service.database.DatabaseService;
|
||||
import com.l2jserver.service.game.scripting.ScriptingService;
|
||||
import com.l2jserver.service.game.template.TemplateService;
|
||||
@@ -41,7 +43,6 @@ import com.l2jserver.service.game.world.filter.WorldObjectFilter;
|
||||
import com.l2jserver.service.game.world.filter.impl.IDFilter;
|
||||
import com.l2jserver.service.game.world.filter.impl.InstanceFilter;
|
||||
import com.l2jserver.service.game.world.filter.impl.KnownListFilter;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
/**
|
||||
@@ -87,12 +88,14 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
|
||||
@Override
|
||||
public boolean add(WorldObject object) {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
log.debug("Adding object {} to world", object);
|
||||
return objects.add(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(WorldObject object) {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
log.debug("Removing object {} from world", object);
|
||||
// we also need to remove all listeners for this object
|
||||
dispatcher.clear(object.getID());
|
||||
@@ -101,12 +104,14 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
|
||||
@Override
|
||||
public boolean contains(WorldObject object) {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
return objects.contains(object);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends WorldObject> T find(ObjectID<T> id) {
|
||||
Preconditions.checkNotNull(id, "id");
|
||||
final IDFilter filter = new IDFilter(id);
|
||||
for (final WorldObject object : objects) {
|
||||
if (filter.accept(object))
|
||||
@@ -118,10 +123,8 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
|
||||
@Override
|
||||
public void knownlist(Positionable object, KnownListCallback callback) {
|
||||
if (object == null)
|
||||
return;
|
||||
if (callback == null)
|
||||
return;
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
Preconditions.checkNotNull(callback, "callback");
|
||||
for (Positionable known : iterable(new KnownListFilter(object))) {
|
||||
callback.knownObject(known);
|
||||
}
|
||||
@@ -134,6 +137,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
|
||||
@Override
|
||||
public <T extends WorldObject> List<T> list(WorldObjectFilter<T> filter) {
|
||||
Preconditions.checkNotNull(filter, "filter");
|
||||
log.debug("Listing objects with filter {}", filter);
|
||||
final List<T> list = CollectionFactory.newList();
|
||||
for (final T object : this.iterable(filter)) {
|
||||
@@ -144,6 +148,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
|
||||
@Override
|
||||
public <T extends WorldObject> List<T> list(Class<T> type) {
|
||||
Preconditions.checkNotNull(type, "type");
|
||||
log.debug("Listing of type {}", type);
|
||||
return list(new InstanceFilter<T>(type));
|
||||
}
|
||||
@@ -156,12 +161,14 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
|
||||
@Override
|
||||
public <T extends WorldObject> Iterator<T> iterator(
|
||||
final WorldObjectFilter<T> filter) {
|
||||
Preconditions.checkNotNull(filter, "filter");
|
||||
return new FilterIterator<T>(filter, objects.iterator());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends WorldObject> Iterable<T> iterable(
|
||||
final WorldObjectFilter<T> filter) {
|
||||
Preconditions.checkNotNull(filter, "filter");
|
||||
return new Iterable<T>() {
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.l2jserver.service.game.world.event;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.l2jserver.model.world.WorldObject;
|
||||
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
|
||||
|
||||
@@ -30,6 +31,7 @@ public abstract class FilteredWorldListener<T extends WorldObject> implements
|
||||
private final WorldObjectFilter<T> filter;
|
||||
|
||||
public FilteredWorldListener(WorldObjectFilter<T> filter) {
|
||||
Preconditions.checkNotNull(filter, "filter");
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
*/
|
||||
package com.l2jserver.service.game.world.event;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/**
|
||||
* This listener will filter to only dispatch an certain type events.
|
||||
*
|
||||
@@ -25,6 +27,7 @@ public abstract class TypedWorldListener<T> implements WorldListener {
|
||||
private final Class<T> type;
|
||||
|
||||
public TypedWorldListener(Class<T> type) {
|
||||
Preconditions.checkNotNull(type, "type");
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.concurrent.TimeoutException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.util.concurrent.AbstractFuture;
|
||||
import com.l2jserver.model.id.ObjectID;
|
||||
import com.l2jserver.model.world.WorldObject;
|
||||
@@ -92,6 +93,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
|
||||
|
||||
@Override
|
||||
public <E extends WorldEvent> WorldEventFuture<E> dispatch(E event) {
|
||||
Preconditions.checkNotNull(event, "event");
|
||||
log.debug("Queing dispatch for event {}", event);
|
||||
final WorldEventFutureImpl<E> future = new WorldEventFutureImpl<E>();
|
||||
events.add(new EventContainer(event, future));
|
||||
@@ -119,10 +121,9 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
|
||||
if (!listener.dispatch(event.event))
|
||||
// remove listener if return value is false
|
||||
listeners.remove(listener);
|
||||
} catch (ClassCastException e) {
|
||||
log.debug(
|
||||
"Exception in Listener. This might indicate an implementation issue in {}",
|
||||
listener.getClass());
|
||||
} catch (Throwable t) {
|
||||
log.warn("Exception in listener", t);
|
||||
// always remove any listener that throws an exception
|
||||
listeners.remove(listener);
|
||||
}
|
||||
}
|
||||
@@ -132,33 +133,43 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
|
||||
|
||||
@Override
|
||||
public void addListener(WorldListener listener) {
|
||||
Preconditions.checkNotNull(listener, "listener");
|
||||
log.debug("Adding new listener global {}", listener);
|
||||
globalListeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(WorldObject object, WorldListener listener) {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
Preconditions.checkNotNull(listener, "listener");
|
||||
addListener(object.getID(), listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(ObjectID<?> id, WorldListener listener) {
|
||||
Preconditions.checkNotNull(id, "id");
|
||||
Preconditions.checkNotNull(listener, "listener");
|
||||
log.debug("Adding new listener {} to {}", listener, id);
|
||||
getListeners(id).add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(WorldListener listener) {
|
||||
Preconditions.checkNotNull(listener, "listener");
|
||||
globalListeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(WorldObject object, WorldListener listener) {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
Preconditions.checkNotNull(listener, "listener");
|
||||
removeListener(object.getID(), listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(ObjectID<?> id, WorldListener listener) {
|
||||
Preconditions.checkNotNull(id, "id");
|
||||
Preconditions.checkNotNull(listener, "listener");
|
||||
log.debug("Removing new listener {} from {}", listener, id);
|
||||
getListeners(id).remove(listener);
|
||||
}
|
||||
@@ -170,6 +181,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
|
||||
* the object id
|
||||
*/
|
||||
public void clear(ObjectID<?> id) {
|
||||
Preconditions.checkNotNull(id, "id");
|
||||
listeners.remove(id);
|
||||
}
|
||||
|
||||
@@ -182,6 +194,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
|
||||
* @return the {@link Set}. Never null.
|
||||
*/
|
||||
private Set<WorldListener> getListeners(ObjectID<?> id) {
|
||||
Preconditions.checkNotNull(id, "id");
|
||||
Set<WorldListener> set = listeners.get(id);
|
||||
if (set == null) {
|
||||
set = CollectionFactory.newSet();
|
||||
@@ -189,7 +202,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
|
||||
public void stop() {
|
||||
timer.cancel();
|
||||
timer = null;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.l2jserver.service.game.world.filter.impl;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.l2jserver.model.id.ObjectID;
|
||||
import com.l2jserver.model.world.WorldObject;
|
||||
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
|
||||
@@ -38,6 +39,7 @@ public class IDFilter implements WorldObjectFilter<WorldObject> {
|
||||
* the desired object ID
|
||||
*/
|
||||
public IDFilter(final ObjectID<?> id) {
|
||||
Preconditions.checkNotNull(id, "id");
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.l2jserver.service.game.world.filter.impl;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.l2jserver.model.world.WorldObject;
|
||||
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
|
||||
|
||||
@@ -40,6 +41,7 @@ public class InstanceFilter<T extends WorldObject> implements
|
||||
* the instance type
|
||||
*/
|
||||
public InstanceFilter(Class<?> instance) {
|
||||
Preconditions.checkNotNull(instance, "instance");
|
||||
this.type = instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.l2jserver.service.game.world.filter.impl;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.l2jserver.model.world.capability.Positionable;
|
||||
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
|
||||
|
||||
@@ -43,6 +44,8 @@ public class RangeFilter implements WorldObjectFilter<Positionable> {
|
||||
* the desired maximum distance of the object
|
||||
*/
|
||||
public RangeFilter(final Positionable object, final int range) {
|
||||
Preconditions.checkNotNull(object, "object");
|
||||
Preconditions.checkState(range >= 0, "range < 0");
|
||||
this.object = object;
|
||||
this.range = range;
|
||||
}
|
||||
|
||||
@@ -27,16 +27,18 @@ import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
import org.jboss.netty.logging.Slf4JLoggerFactory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.Lineage2PipelineFactory;
|
||||
import com.l2jserver.game.net.packet.ServerPacket;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.AbstractService.Depends;
|
||||
import com.l2jserver.service.configuration.ConfigurationService;
|
||||
import com.l2jserver.service.core.LoggingService;
|
||||
import com.l2jserver.service.game.world.WorldService;
|
||||
import com.l2jserver.service.logging.LoggingService;
|
||||
import com.l2jserver.service.network.keygen.BlowfishKeygenService;
|
||||
import com.l2jserver.util.factory.CollectionFactory;
|
||||
|
||||
@@ -97,6 +99,7 @@ public class NettyNetworkService extends AbstractService implements
|
||||
|
||||
@Override
|
||||
public void register(final Lineage2Connection client) {
|
||||
Preconditions.checkNotNull(client, "client");
|
||||
clients.add(client);
|
||||
client.getChannel().getCloseFuture()
|
||||
.addListener(new ChannelFutureListener() {
|
||||
@@ -110,11 +113,13 @@ public class NettyNetworkService extends AbstractService implements
|
||||
|
||||
@Override
|
||||
public void unregister(Lineage2Connection client) {
|
||||
Preconditions.checkNotNull(client, "client");
|
||||
clients.remove(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Lineage2Connection discover(CharacterID character) {
|
||||
Preconditions.checkNotNull(character, "character");
|
||||
for (final Lineage2Connection client : clients) {
|
||||
if (character.equals(client.getCharacterID()))
|
||||
return client;
|
||||
@@ -122,6 +127,12 @@ public class NettyNetworkService extends AbstractService implements
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(ServerPacket packet) {
|
||||
Preconditions.checkNotNull(packet, "packet");
|
||||
channel.write(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanup() {
|
||||
// TODO
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.l2jserver.service.network;
|
||||
|
||||
import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.packet.ServerPacket;
|
||||
import com.l2jserver.model.id.object.CharacterID;
|
||||
import com.l2jserver.service.Service;
|
||||
|
||||
@@ -52,6 +53,14 @@ public interface NetworkService extends Service {
|
||||
*/
|
||||
Lineage2Connection discover(CharacterID character);
|
||||
|
||||
/**
|
||||
* Broadcast an given <tt>packet</tt> to all clients connected
|
||||
*
|
||||
* @param packet
|
||||
* the packet
|
||||
*/
|
||||
void broadcast(ServerPacket packet);
|
||||
|
||||
/**
|
||||
* Searches for idle connection and removes them
|
||||
*/
|
||||
|
||||
@@ -18,6 +18,20 @@ package com.l2jserver.service.network.keygen;
|
||||
|
||||
import com.l2jserver.service.Service;
|
||||
|
||||
/**
|
||||
* This service generated cryptography keys used to encrypt and decrypt client
|
||||
* or server packets. Implementations can use an fixed set of keys or generate a
|
||||
* random one. Note that the generated key might not be cryptographically safe,
|
||||
* and this is implementation specific.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface BlowfishKeygenService extends Service {
|
||||
/**
|
||||
* Creates a new 128 bits key. Note that the key is not necessarily random
|
||||
* and can be a fixed key.
|
||||
*
|
||||
* @return the 128 bits key
|
||||
*/
|
||||
byte[] generate();
|
||||
}
|
||||
|
||||
@@ -22,8 +22,17 @@ import com.l2jserver.service.AbstractService;
|
||||
import com.l2jserver.service.ServiceStartException;
|
||||
import com.l2jserver.service.ServiceStopException;
|
||||
|
||||
/**
|
||||
* Generates a new random key using JDK {@link Random}. Keys generated by this
|
||||
* implementation are not completely secure but are very fast to generate.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class PseudoRandomBlowfishKeygenService extends AbstractService
|
||||
implements BlowfishKeygenService {
|
||||
/**
|
||||
* The random number generator
|
||||
*/
|
||||
private Random random;
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user