Skip to content

Commit

Permalink
Merge pull request #12 from paalgyula/master
Browse files Browse the repository at this point in the history
Merge from branch paalgyula to storm #6
  • Loading branch information
mAdloVe committed Aug 10, 2012
2 parents 06fb317 + 96823a0 commit a82650f
Show file tree
Hide file tree
Showing 107 changed files with 29,700 additions and 2,179 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
*.project
*.settings/
*.classpath
*.iml
*.ipr
*.ids
*.iws
*target/
.idea
24 changes: 14 additions & 10 deletions Auth/conf/packetData/lc-packets.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@
xsi:noNamespaceSchemaLocation="packets.xsd">
<opcodelist direction="DOWNSTREAM"
package="org.jmangos.auth.network.netty.packet.client.">
<packet id="00" name="CMD_AUTH_LOGON_CHALLENGE" state="CONNECTED"/>
<packet id="01" name="CMD_AUTH_LOGON_PROOF" state="CONNECTED"/>
<packet id="10" name="CMD_REALM_LIST" state="AUTHED"/>
<packet id="02" name="CMD_RECONNECT_CHALLENGE" state="CONNECTED" /><packet
name="CMD_RECONNECT_PROOF" id="3" ></packet>
<packet id="00" name="CMD_AUTH_LOGON_CHALLENGE" state="CONNECTED" />
<packet id="01" name="CMD_AUTH_LOGON_PROOF" state="CONNECTED" />
<packet id="02" name="CMD_RECONNECT_CHALLENGE" state="CONNECTED" />
<packet id="03" name="CMD_RECONNECT_PROOF" state="CONNECTED" />
<packet id="10" name="CMD_REALM_LIST" state="AUTHED" />
<packet id="50" name="CMD_AUTH_ENABLE_CRYPT" state="AUTHED" />
<packet id="51" name="CMD_TEST_CRYPT" state="AUTHED" />
</opcodelist>
<opcodelist direction="UPSTREAM"
package="org.jmangos.auth.network.netty.packet.server.">
<packet id="00" name="TCMD_AUTH_LOGON_CHALLENGE"/>
<packet id="01" name="TCMD_AUTH_LOGON_PROOF"/>
<packet id="10" name="TCMD_REALM_LIST"/><packet name="TCMD_RECONNECT_CHALLENGE" id="2" /><packet
name="TCMD_RECONNECT_PROOF" id="3" />
<packet id="00" name="TCMD_AUTH_LOGON_CHALLENGE" />
<packet id="01" name="TCMD_AUTH_LOGON_PROOF" />
<packet id="02" name="TCMD_RECONNECT_CHALLENGE" />
<packet id="03" name="TCMD_RECONNECT_PROOF" />
<packet id="10" name="TCMD_REALM_LIST" />
<packet id="50" name="TCMD_AUTH_ENABLE_CRYPT" />
</opcodelist>
</opcodes>
</opcodes>
Empty file modified Auth/conf/packetData/lr-packets.xml
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion Auth/src/main/java/org/jmangos/auth/AuthServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(new HandlerDM());
ServiceContent.setInjector(injector);
injector.getInstance(LoggingService.class).start();
injector.getInstance(DatabaseFactory.class).start();
//injector.getInstance(DatabaseFactory.class).start();
injector.getInstance(WorldListService.class).start();
injector.getInstance(Config.class).load();
if (Config.COMPATIBLE != Compatiple.MANGOS) {
Expand Down
4 changes: 0 additions & 4 deletions Auth/src/main/java/org/jmangos/auth/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ public class Config {
@Property(key = "network.compatible", defaultValue = "NONE")
public static Compatiple COMPATIBLE;

/** The REAL m_ address. */
@Property(key = "network.realm.address", defaultValue = "*:3740")
public static InetSocketAddress REALM_ADDRESS;

/**
* Load configuration.
*/
Expand Down
167 changes: 156 additions & 11 deletions Auth/src/main/java/org/jmangos/auth/dao/AccountDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
*******************************************************************************/
package org.jmangos.auth.dao;

import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.jmangos.auth.model.Account;
import org.jmangos.commons.database.DatabaseFactory;
import org.jmangos.commons.database.dao.DAO;

/**
Expand All @@ -25,39 +29,75 @@
* @author MinimaJack
*
*/
public abstract class AccountDAO implements DAO
public class AccountDAO implements DAO
{

Logger logger = Logger.getLogger( AccountDAO.class );

/**
* Returns account by name or null.
*
* @param name account name
* @return account object or null
*/
public abstract Account getAccount(String name);
public Account getAccount(String name) {
Session session = DatabaseFactory.getAccountsSessionFactory().openSession();
Query query = session.createQuery("select a from Account a where a.username = :name").setString( "name", name );
Account account = (Account)query.uniqueResult();
session.close();
return account;
}

/**
* Retuns account id or -1 in case of error.
*
* @param name name of account
* @return id or -1 in case of error
*/
public abstract int getAccountId(String name);
public int getAccountId(String name) {
Session session = DatabaseFactory.getAccountsSessionFactory().openSession();
Query query = session.createQuery("select a from Account a where a.username = :name").setString( "name", name );
Account account = (Account)query.uniqueResult();
if ( account == null )
return -1;
session.close();
return account.getId();
}

/**
* Reruns account count If error occured - returns -1.
*
* @return account count
*/
public abstract int getAccountCount();
public int getAccountCount() {
Session session = DatabaseFactory.getAccountsSessionFactory().openSession();
Query query = session.createQuery("select a from Account a");
int accCount = query.list().size();
session.close();
return accCount;
}

/**
* Update security key.
*
* @param account the account
* @return true, if successful
*/
public abstract boolean updateSecurityKey(Account account);
public boolean updateSecurityKey(Account account) {
Session session = DatabaseFactory.getAccountsSessionFactory().openSession();
session.getTransaction().begin();
boolean success = false;
try {
session.saveOrUpdate( account );
session.getTransaction().commit();
success = true;
} finally {
if( session.getTransaction().isActive() )
session.getTransaction().rollback();
session.close();
}

return success;
}

/**
* Updates lastServer field of account.
Expand All @@ -66,7 +106,32 @@ public abstract class AccountDAO implements DAO
* @param lastServer last accessed server
* @return was updated successful or not
*/
public abstract boolean updateLastServer(int accountId, byte lastServer);
public boolean updateLastServer(int accountId, byte lastServer) {
Session session = DatabaseFactory.getAccountsSessionFactory().openSession();
Query query = session.createQuery("select a from Account a where a.id = :id").setInteger( "id", accountId );
Account account = (Account)query.uniqueResult();

if ( account == null ) {
session.close();
logger.warn( "Account with id (" + accountId + ") not found!" );
return false;
}

account.setLastServer( lastServer );
session.getTransaction().begin();
boolean success = false;
try {
session.saveOrUpdate( account );
session.getTransaction().commit();
success = true;
} finally {
if( session.getTransaction().isActive() )
session.getTransaction().rollback();
session.close();
}

return success;
}

/**
* Updates last ip that was used to access an account.
Expand All @@ -75,15 +140,55 @@ public abstract class AccountDAO implements DAO
* @param ip ip address
* @return was update successful or not
*/
public abstract boolean updateLastIp(int accountId, String ip);
public boolean updateLastIp(int accountId, String ip) {
Session session = DatabaseFactory.getAccountsSessionFactory().openSession();
Query query = session.createQuery("select a from Account a where a.id = :id").setInteger( "id", accountId );
Account account = (Account)query.uniqueResult();

if ( account == null ) {
session.close();
logger.warn( "Account with id (" + accountId + ") not found!" );
return false;
}

account.setLastIp( ip );
session.getTransaction().begin();
boolean success = false;
try {
session.saveOrUpdate( account );
session.getTransaction().commit();
success = true;
logger.info( String.format( "Account (#%d) updated. New IP: %s.", accountId, ip ) );
} finally {
if( session.getTransaction().isActive() )
session.getTransaction().rollback();
session.close();
}

return success;
}

/**
* Get last ip that was used to access an account.
*
* @param accountId account id
* @return ip address
*/
public abstract String getLastIp(int accountId);
public String getLastIp(int accountId) {
Session session = DatabaseFactory.getAccountsSessionFactory().openSession();
Query query = session.createQuery("select a from Account a where a.id = :accountid").setInteger("accountid", accountId);
Account account = (Account)query.uniqueResult();

if ( account == null ) {
session.close();
logger.warn( "Account with id (" + accountId + ") not found!" );
return "";
}

String lastIp = account.getLastIp();
session.close();
return lastIp;
}

/**
* Returns uniquire class name for all implementations.
Expand All @@ -103,13 +208,53 @@ public final String getClassName()
* @param key the key
* @return true, if successful
*/
public abstract boolean updateSessionKey(String username, String key);
public boolean updateSessionKey(String username, String key) {
Session session = DatabaseFactory.getAccountsSessionFactory().openSession();
Query query = session.createQuery("select a from Account a where a.username = :username").setString( "username", username );
Account account = (Account)query.uniqueResult();

if ( account == null ) {
session.close();
logger.warn( "Account with id (" + username + ") not found!" );
return false;
}

account.setSessionKey( key );
session.getTransaction().begin();
boolean success = false;
try {
session.saveOrUpdate( account );
session.getTransaction().commit();
success = true;
logger.info( String.format( "Account (%s) updated. New session key: %s.", username, key ) );
} finally {
if( session.getTransaction().isActive() )
session.getTransaction().rollback();
session.close();
}

return success;
}

/**
* Gets the session key.
*
* @param username the username
* @return the session key
*/
public abstract String getSessionKey(String username);
public String getSessionKey(String username) {
Session session = DatabaseFactory.getAccountsSessionFactory().openSession();
Query query = session.createQuery("select a from Account a where a.username = :username").setString( "username", username );
Account account = (Account)query.uniqueResult();

if ( account == null ) {
session.close();
logger.warn( "Account with id (" + username + ") not found!" );
return "";
}

String sessionKey = account.getMsessionKey();
session.close();
return sessionKey;
}
}
31 changes: 26 additions & 5 deletions Auth/src/main/java/org/jmangos/auth/dao/RealmDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@
*******************************************************************************/
package org.jmangos.auth.dao;

import org.hibernate.Query;
import org.hibernate.Session;
import org.jmangos.auth.model.Account;
import org.jmangos.auth.model.Realm;
import org.jmangos.commons.database.DatabaseFactory;
import org.jmangos.commons.database.dao.DAO;

import javolution.util.FastMap;

import java.util.Iterator;

/**
* The Class WorldDAO.
*
* @author MinimaJack
*
*/
public abstract class RealmDAO implements DAO {
public class RealmDAO implements DAO {

/*
* (non-Javadoc)
Expand All @@ -44,16 +50,31 @@ public String getClassName() {
*
* @return the all worlds
*/
public abstract FastMap<Integer, Realm> getAllRealms();
public FastMap<Integer, Realm> getAllRealms() {
Session session = DatabaseFactory.getAccountsSessionFactory().openSession();
Query query = session.createQuery("select r from Realm r");
Iterator<Realm> realmIterator = query.iterate();
FastMap<Integer, Realm> map = new FastMap<Integer, Realm>();

while ( realmIterator.hasNext() ) {
Realm realm = realmIterator.next();
map.put( realm.getId(), realm );
}

session.close();
return map;
}

/**
* Gets the amount characters.
*
* @param id
* the id
* the realm id
* @return the amount characters
*/
public abstract FastMap<Integer, Integer> getAmountCharacters(
final Integer id);
public FastMap<Integer, Integer> getAmountCharacters(final Integer id) {
// TODO:implement
return new FastMap<Integer, Integer>();
}

}
Loading

0 comments on commit a82650f

Please sign in to comment.