Skip to content

Commit

Permalink
Merge pull request #16 from JMaNGOS/master
Browse files Browse the repository at this point in the history
Merge from master to storm #6
  • Loading branch information
mAdloVe committed Aug 11, 2012
2 parents 94379c5 + 8c4e01a commit 80bae77
Show file tree
Hide file tree
Showing 86 changed files with 1,604 additions and 2,134 deletions.
12 changes: 9 additions & 3 deletions Auth/src/main/java/org/jmangos/auth/AuthServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
*******************************************************************************/
package org.jmangos.auth;

import javax.inject.Inject;

import org.jmangos.auth.config.Config;
import org.jmangos.auth.module.HandlerDM;
import org.jmangos.auth.service.BanIpService;
import org.jmangos.auth.service.UpdateService;
import org.jmangos.auth.service.WorldListService;
import org.jmangos.auth.utils.ShutdownHook;
import org.jmangos.commons.config.Compatiple;
import org.jmangos.commons.database.DatabaseConfig;
import org.jmangos.commons.database.DatabaseFactory;
import org.jmangos.commons.log4j.LoggingService;
import org.jmangos.commons.network.netty.service.NetworkService;
Expand All @@ -38,6 +41,8 @@
* @author MinimaJack
*/
public class AuthServer {

private static Config config;

/**
* The main method.
Expand All @@ -51,15 +56,16 @@ public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(new HandlerDM());
ServiceContent.setInjector(injector);
injector.getInstance(LoggingService.class).start();
config = injector.getInstance(Config.class);
injector.getInstance(DatabaseConfig.class);
injector.getInstance(DatabaseFactory.class).start();
injector.getInstance(WorldListService.class).start();
injector.getInstance(Config.class).load();
if (Config.COMPATIBLE != Compatiple.MANGOS) {
if (config.COMPATIBLE != Compatiple.MANGOS) {
injector.getInstance(BanIpService.class).start();
}
injector.getInstance(ThreadPoolManager.class).start();

if (Config.COMPATIBLE == Compatiple.MANGOS)
if (config.COMPATIBLE == Compatiple.MANGOS)
injector.getInstance(UpdateService.class).start();

Runtime.getRuntime().addShutdownHook(
Expand Down
36 changes: 11 additions & 25 deletions Auth/src/main/java/org/jmangos/auth/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,42 @@
*******************************************************************************/
package org.jmangos.auth.config;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Properties;

import org.apache.log4j.Logger;
import javax.inject.Singleton;

import org.jmangos.commons.config.Compatiple;
import org.jmangos.commons.configuration.ConfigurableProcessor;
import org.jmangos.commons.configuration.AbstractConfig;
import org.jmangos.commons.configuration.Property;
import org.jmangos.commons.utils.PropertiesUtils;

/**
* The Class Config.
*
* @author MinimaJack
*
*/
public class Config {
/**
* Logger for this class.
*/
protected static final Logger log = Logger.getLogger(Config.class);
@Singleton
public class Config extends AbstractConfig {

/** The Constant CONFIG_FILE. */
public static final String CONFIG_FILE = "conf/network/auth.network.properties";
private static final String CONFIG_FILE = "conf/network/auth.network.properties";

/** Login Server address to client. */
@Property(key = "network.client.address", defaultValue = "*:3724")
public static InetSocketAddress CLIENT_ADDRESS;
public InetSocketAddress CLIENT_ADDRESS;

/** The UPDAT e_ interval. */
@Property(key = "network.service.updateRealmlistInterval", defaultValue = "60")
public static int UPDATE_INTERVAL;
public Integer UPDATE_INTERVAL;

/** The COMPATIBLE. */
@Property(key = "network.compatible", defaultValue = "NONE")
public static Compatiple COMPATIBLE;
public Compatiple COMPATIBLE;

/**
* Load configuration.
*/
public void load() {

Properties p;
try {
p = PropertiesUtils.load(CONFIG_FILE);
} catch (IOException e) {
log.fatal("Can't load network configuration...");
throw new Error("Can't load " + CONFIG_FILE, e);
}

ConfigurableProcessor.process(Config.class, p);
protected Config() {
super(CONFIG_FILE);
}
}
67 changes: 29 additions & 38 deletions Auth/src/main/java/org/jmangos/auth/dao/AccountDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,103 +21,94 @@

/**
* DAO that manages accounts.
*
*
* @author MinimaJack
*
*
*/
public abstract class AccountDAO implements DAO {

public abstract class AccountDAO implements DAO
{

/**
* Returns account by name or null.
*
* @param name
* account name
*
* @param name account name
* @return account object or null
*/
public abstract Account getAccount(String name);

/**
* Retuns account id or -1 in case of error.
*
* @param name
* name of account
*
* @param name name of account
* @return id or -1 in case of error
*/
public abstract int getAccountId(String name);

/**
* Reruns account count If error occured - returns -1.
*
*
* @return account count
*/
public abstract int getAccountCount();

/**
* Update security key.
*
* @param account
* the account
*
* @param account the account
* @return true, if successful
*/
public abstract boolean updateSecurityKey(Account account);

/**
* Updates lastServer field of account.
*
* @param accountId
* account id
* @param lastServer
* last accessed server
*
* @param accountId account id
* @param lastServer last accessed server
* @return was updated successful or not
*/
public abstract boolean updateLastServer(int accountId, byte lastServer);

/**
* Updates last ip that was used to access an account.
*
* @param accountId
* account id
* @param ip
* ip address
*
* @param accountId account id
* @param ip ip address
* @return was update successful or not
*/
public abstract boolean updateLastIp(int accountId, String ip);

/**
* Get last ip that was used to access an account.
*
* @param accountId
* account id
*
* @param accountId account id
* @return ip address
*/
public abstract String getLastIp(int accountId);

/**
* Returns uniquire class name for all implementations.
*
*
* @return uniquire class name for all implementations
*/
@Override
public final String getClassName() {
public final String getClassName()
{
return AccountDAO.class.getName();
}

/**
* Update session key.
*
* @param username
* the username
* @param key
* the key
*
* @param username the username
* @param key the key
* @return true, if successful
*/
public abstract boolean updateSessionKey(String username, String key);

/**
* Gets the session key.
*
* @param username
* the username
*
* @param username the username
* @return the session key
*/
public abstract String getSessionKey(String username);
Expand Down
3 changes: 3 additions & 0 deletions Auth/src/main/java/org/jmangos/auth/module/HandlerDM.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.jmangos.auth.module;

import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jmangos.auth.config.Config;
import org.jmangos.auth.dao.AccountDAO;
import org.jmangos.auth.dao.BanIpDAO;
import org.jmangos.auth.dao.RealmDAO;
Expand All @@ -31,6 +32,8 @@
import org.jmangos.auth.service.AuthNetworkService;
import org.jmangos.auth.service.WorldListService;
import org.jmangos.auth.utils.ShutdownHook;
import org.jmangos.commons.configuration.AbstractConfig;
import org.jmangos.commons.database.DatabaseConfig;
import org.jmangos.commons.database.DatabaseFactory;
import org.jmangos.commons.network.handlers.PacketHandlerFactory;
import org.jmangos.commons.network.model.ConnectHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected Object decode(ChannelHandlerContext ctx, Channel channel,
ByteOrder.LITTLE_ENDIAN, header);
byte opcode = clientHeader.readByte();
int size = clientHeader.readShort();
if ((size < 0) || (size > 10240) || (opcode > 10240)) {
if ((size < 0) || (size > 10240)) {
log.error("PacketFrameDecoder::decode: realm sent malformed packet size = "
+ size + " , opcode = " + opcode);
channel.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*******************************************************************************/
package org.jmangos.auth.network.netty.packet.client;

import java.nio.charset.Charset;

import javax.inject.Inject;

import org.apache.log4j.Logger;
Expand Down Expand Up @@ -76,23 +78,34 @@ public int getMinimumLength() {
/**
* {@inheritDoc}
*/
@SuppressWarnings("unused")
@Override
protected void readImpl() {
int error = readC();
int size = readH();
byte[] gamename = readB(4);
int version1 = readC();
int version2 = readC();
int version3 = readC();
int build = readH();
byte[] platform = readB(4);
byte[] os = readB(4);
byte[] country = readB(4);
int timezone_bias = readD();
int ip = readD();
/** int error = */
readC();
/** int size = */
readH();
/** byte[] gamename = */
readB(4);
/** int version1 = */
readC();
/** int version2 = */
readC();
/** int version3 = */
readC();
/** int build = */
readH();
/** byte[] platform = */
readB(4);
/** byte[] os = */
readB(4);
/** byte[] country = */
readB(4);
/** int timezone_bias = */
readD();
/** int ip = */
readD();
int lenLogin = readC();
login = new String(readB(lenLogin), 0, lenLogin);
login = new String(readB(lenLogin), Charset.forName("UTF-8"));
}

/**
Expand All @@ -102,7 +115,6 @@ protected void readImpl() {
protected void runImpl() {
WoWAuthResponse response = accountService.login(login,
(NettyNetworkChannel) getClient());

switch (response) {
case WOW_FAIL_BANNED:
sender.sendAndClose(this.getClient(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.jmangos.auth.network.netty.packet.client;

import java.math.BigInteger;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
Expand Down Expand Up @@ -68,9 +69,10 @@ public CMD_AUTH_LOGON_PROOF() {
protected void readImpl() {
byte[] a = readB(32);
byte[] m1 = readB(20);
byte[] crc = readB(20);
int numberofKey = readC();
int securityFlag = readC();
/** byte[] crc = */
readB(20);
/**int numberofKey = */readC();
/**int securityFlag = */readC();

logger.debug("a length " + a.length);
logger.debug("a value "
Expand All @@ -95,8 +97,7 @@ protected void readImpl() {
BigNumber A = new BigNumber();
A.setBinary(a);
logger.debug("A:" + A.asHexStr());
BigNumber S = new BigNumber();
S = A.multiply((getAccount().getV_crypto().modPow(u, AccountUtils.N)))
BigNumber S = A.multiply((getAccount().getV_crypto().modPow(u, AccountUtils.N)))
.modPow(getAccount().getB(), AccountUtils.N);

byte[] t = new byte[32];
Expand Down Expand Up @@ -136,7 +137,7 @@ protected void readImpl() {
}

byte[] t4 = new byte[20];
sha.update(getAccount().getName().getBytes());
sha.update(getAccount().getName().getBytes(Charset.forName("UTF-8")));
t4 = sha.digest();

sha.update(hash);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
* The Class LoginNetworkService.
*/
public class AuthNetworkService extends AbstractNetworkService {

@javax.inject.Inject
private Config config;

/** The auth to client pipeline factory. */
@Inject
@Named("AuthToClient")
Expand All @@ -40,7 +44,7 @@ public class AuthNetworkService extends AbstractNetworkService {
*/
@Override
public void start() {
createServerChannel(Config.CLIENT_ADDRESS, authToClientPipelineFactory);
createServerChannel(config.CLIENT_ADDRESS, authToClientPipelineFactory);
}

/**
Expand Down
Loading

0 comments on commit 80bae77

Please sign in to comment.