Importing SVN archives - Trunk
This commit is contained in:
parent
fc4c6bd340
commit
ff53af6668
507 changed files with 8866 additions and 2450 deletions
legacyworlds-server/legacyworlds-server-beans/legacyworlds-server-beans-simple
|
@ -3,11 +3,11 @@
|
|||
<parent>
|
||||
<artifactId>legacyworlds-server-beans</artifactId>
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<version>5.99.1</version>
|
||||
<version>5.99.2</version>
|
||||
</parent>
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<artifactId>legacyworlds-server-beans-simple</artifactId>
|
||||
<version>5.99.1</version>
|
||||
<version>5.99.2</version>
|
||||
<name>Legacy Worlds simple game</name>
|
||||
<description>This module contains code that corresponds to a simple "placeholder" game. This code should become obsolete over time, as it is being replaced with actual LWB6 code, until the module can finally be removed.</description>
|
||||
</project>
|
|
@ -4,9 +4,7 @@ package com.deepclone.lw.beans.empire;
|
|||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
|
@ -20,8 +18,6 @@ import com.deepclone.lw.cmd.player.gdata.NameIdPair;
|
|||
import com.deepclone.lw.cmd.player.gdata.PlanetListData;
|
||||
import com.deepclone.lw.cmd.player.gdata.empire.OverviewData;
|
||||
import com.deepclone.lw.interfaces.game.EmpireDAO;
|
||||
import com.deepclone.lw.sqld.game.EmpireTechLine;
|
||||
import com.deepclone.lw.sqld.game.EmpireTechnology;
|
||||
import com.deepclone.lw.sqld.game.GeneralInformation;
|
||||
import com.deepclone.lw.utils.StoredProc;
|
||||
|
||||
|
@ -31,7 +27,6 @@ public class EmpireDAOBean
|
|||
implements EmpireDAO
|
||||
{
|
||||
private SimpleJdbcTemplate dTemplate;
|
||||
private StoredProc fImplementTech;
|
||||
private StoredProc fAddEmpEnemy;
|
||||
private StoredProc fAddAllEnemy;
|
||||
private StoredProc fRemoveEmpEnemy;
|
||||
|
@ -40,16 +35,36 @@ public class EmpireDAOBean
|
|||
|
||||
private final PlanetListMapper mPlanetList = new PlanetListMapper( );
|
||||
|
||||
private final RowMapper< GeneralInformation > mEmpireInfo;
|
||||
|
||||
|
||||
public EmpireDAOBean( )
|
||||
{
|
||||
this.mEmpireInfo = new RowMapper< GeneralInformation >( ) {
|
||||
@Override
|
||||
public GeneralInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
String st = rs.getString( "status" );
|
||||
Character status = ( st == null ) ? null : st.charAt( 0 );
|
||||
String name = rs.getString( "name" );
|
||||
String tag = rs.getString( "alliance" );
|
||||
String language = rs.getString( "language" );
|
||||
long cash = rs.getLong( "cash" );
|
||||
long nextTick = rs.getLong( "game_time" );
|
||||
int accountId = rs.getInt( "account_id" );
|
||||
return new GeneralInformation( status , name , tag , language , cash , nextTick , accountId );
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dTemplate = new SimpleJdbcTemplate( dataSource );
|
||||
|
||||
this.fImplementTech = new StoredProc( dataSource , "emp" , "implement_tech" );
|
||||
this.fImplementTech.addParameter( "empire_id" , Types.INTEGER );
|
||||
this.fImplementTech.addParameter( "line_id" , Types.INTEGER );
|
||||
|
||||
this.fAddEmpEnemy = new StoredProc( dataSource , "emp" , "add_enemy_empire" );
|
||||
this.fAddEmpEnemy.addParameter( "empire_id" , Types.INTEGER );
|
||||
this.fAddEmpEnemy.addParameter( "enemy_name" , Types.VARCHAR );
|
||||
|
@ -79,19 +94,8 @@ public class EmpireDAOBean
|
|||
public GeneralInformation getInformation( int empireId )
|
||||
{
|
||||
String sql = "SELECT * FROM emp.general_information WHERE id = ?";
|
||||
RowMapper< GeneralInformation > mapper = new RowMapper< GeneralInformation >( ) {
|
||||
@Override
|
||||
public GeneralInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
String st = rs.getString( "status" );
|
||||
Character status = ( st == null ) ? null : st.charAt( 0 );
|
||||
return new GeneralInformation( status , rs.getString( "name" ) , rs.getString( "alliance" ) , rs
|
||||
.getLong( "cash" ) , rs.getLong( "game_time" ) , rs.getInt( "account_id" ) );
|
||||
}
|
||||
};
|
||||
try {
|
||||
return this.dTemplate.queryForObject( sql , mapper , empireId );
|
||||
return this.dTemplate.queryForObject( sql , this.mEmpireInfo , empireId );
|
||||
} catch ( EmptyResultDataAccessException e ) {
|
||||
return null;
|
||||
}
|
||||
|
@ -156,65 +160,6 @@ public class EmpireDAOBean
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List< EmpireTechLine > getTechnology( int empireId )
|
||||
{
|
||||
String sql = "SELECT * FROM emp.tech_lines_view WHERE empire = ?";
|
||||
RowMapper< EmpireTechLine > lineMapper = new RowMapper< EmpireTechLine >( ) {
|
||||
@Override
|
||||
public EmpireTechLine mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
EmpireTechLine etl = new EmpireTechLine( );
|
||||
etl.setId( rs.getInt( "tech_line" ) );
|
||||
etl.setName( rs.getString( "name" ) );
|
||||
etl.setDescription( rs.getString( "description" ) );
|
||||
return etl;
|
||||
}
|
||||
};
|
||||
|
||||
List< EmpireTechLine > lines = this.dTemplate.query( sql , lineMapper , empireId );
|
||||
if ( lines.isEmpty( ) ) {
|
||||
return lines;
|
||||
}
|
||||
|
||||
Map< Integer , EmpireTechLine > linesById = new HashMap< Integer , EmpireTechLine >( );
|
||||
for ( EmpireTechLine etl : lines ) {
|
||||
linesById.put( etl.getId( ) , etl );
|
||||
}
|
||||
|
||||
sql = "SELECT * FROM emp.technologies_view WHERE empire = ?";
|
||||
RowMapper< EmpireTechnology > techMapper = new RowMapper< EmpireTechnology >( ) {
|
||||
@Override
|
||||
public EmpireTechnology mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
EmpireTechnology et = new EmpireTechnology( );
|
||||
et.setLine( rs.getInt( "tech_line" ) );
|
||||
et.setName( rs.getString( "name" ) );
|
||||
et.setDescription( rs.getString( "description" ) );
|
||||
et.setImplemented( rs.getBoolean( "implemented" ) );
|
||||
et.setProgress( (int) rs.getDouble( "progress" ) );
|
||||
et.setCost( rs.getInt( "cost" ) );
|
||||
return et;
|
||||
}
|
||||
};
|
||||
|
||||
for ( EmpireTechnology et : this.dTemplate.query( sql , techMapper , empireId ) ) {
|
||||
linesById.get( et.getLine( ) ).addTechnology( et );
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void implementTechnology( int empireId , int lineId )
|
||||
{
|
||||
this.fImplementTech.execute( empireId , lineId );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List< PlanetListData > getPlanetList( int empireId )
|
||||
{
|
||||
|
|
|
@ -18,19 +18,18 @@ import com.deepclone.lw.cmd.player.gdata.NameIdPair;
|
|||
import com.deepclone.lw.cmd.player.gdata.PlanetListData;
|
||||
import com.deepclone.lw.cmd.player.gdata.battles.BattleListEntry;
|
||||
import com.deepclone.lw.cmd.player.gdata.empire.OverviewData;
|
||||
import com.deepclone.lw.cmd.player.gdata.empire.ResearchLineData;
|
||||
import com.deepclone.lw.cmd.player.gdata.empire.TechnologyData;
|
||||
import com.deepclone.lw.interfaces.acm.UsersDAO;
|
||||
import com.deepclone.lw.interfaces.game.BattlesCache;
|
||||
import com.deepclone.lw.interfaces.game.BattlesDAO;
|
||||
import com.deepclone.lw.interfaces.game.EmpireDAO;
|
||||
import com.deepclone.lw.interfaces.game.EmpireManagement;
|
||||
import com.deepclone.lw.interfaces.i18n.LanguageTranslator;
|
||||
import com.deepclone.lw.interfaces.i18n.Translator;
|
||||
import com.deepclone.lw.interfaces.i18n.UnknownLanguageException;
|
||||
import com.deepclone.lw.interfaces.naming.NamingDAO;
|
||||
import com.deepclone.lw.interfaces.prefs.AccountPreferences;
|
||||
import com.deepclone.lw.interfaces.prefs.PreferencesDAO;
|
||||
import com.deepclone.lw.sqld.accounts.Account;
|
||||
import com.deepclone.lw.sqld.game.EmpireTechLine;
|
||||
import com.deepclone.lw.sqld.game.EmpireTechnology;
|
||||
import com.deepclone.lw.sqld.game.GeneralInformation;
|
||||
import com.deepclone.lw.sqld.game.battle.BattleListRecord;
|
||||
import com.deepclone.lw.utils.EmailAddress;
|
||||
|
@ -46,6 +45,7 @@ public class EmpireManagementBean
|
|||
private EmpireDAO empireDao;
|
||||
private PreferencesDAO prefsDao;
|
||||
private BattlesDAO battlesDao;
|
||||
private Translator translator;
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
|
@ -83,6 +83,13 @@ public class EmpireManagementBean
|
|||
}
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setI18NManager( Translator translator )
|
||||
{
|
||||
this.translator = translator;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Integer getEmpireId( EmailAddress address )
|
||||
{
|
||||
|
@ -108,29 +115,22 @@ public class EmpireManagementBean
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public LanguageTranslator getTranslator( int empireId )
|
||||
{
|
||||
GeneralInformation generalInformation = this.empireDao.getInformation( empireId );
|
||||
try {
|
||||
return this.translator.getLanguageTranslator( generalInformation.getLanguage( ) );
|
||||
} catch ( UnknownLanguageException e ) {
|
||||
throw new RuntimeException( "account for empire " + empireId + " is using an unsupported language" , e );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EmpireResponse getOverview( int empireId )
|
||||
{
|
||||
OverviewData overview = this.empireDao.getOverview( empireId );
|
||||
List< ResearchLineData > research = new LinkedList< ResearchLineData >( );
|
||||
|
||||
for ( EmpireTechLine etl : this.empireDao.getTechnology( empireId ) ) {
|
||||
List< TechnologyData > implemented = new LinkedList< TechnologyData >( );
|
||||
TechnologyData current = null;
|
||||
|
||||
for ( EmpireTechnology et : etl.getTechnologies( ) ) {
|
||||
if ( et.isImplemented( ) ) {
|
||||
implemented.add( new TechnologyData( et.getName( ) , et.getDescription( ) ) );
|
||||
} else if ( et.getProgress( ) == 100 ) {
|
||||
current = new TechnologyData( et.getName( ) , et.getDescription( ) , 100 , et.getCost( ) );
|
||||
} else {
|
||||
current = new TechnologyData( et.getName( ) , et.getDescription( ) , et.getProgress( ) );
|
||||
}
|
||||
}
|
||||
|
||||
research.add( new ResearchLineData( etl.getId( ) , etl.getName( ) , etl.getDescription( ) , implemented ,
|
||||
current ) );
|
||||
}
|
||||
|
||||
List< BattleListEntry > battles = new LinkedList< BattleListEntry >( );
|
||||
for ( BattleListRecord record : this.battlesDao.getBattles( empireId ) ) {
|
||||
|
@ -150,15 +150,7 @@ public class EmpireManagementBean
|
|||
battles.add( entry );
|
||||
}
|
||||
|
||||
return new EmpireResponse( this.getGeneralInformation( empireId ) , overview , research , battles );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public EmpireResponse implementTechnology( int empireId , int techId )
|
||||
{
|
||||
this.empireDao.implementTechnology( empireId , techId );
|
||||
return this.getOverview( empireId );
|
||||
return new EmpireResponse( this.getGeneralInformation( empireId ) , overview , battles );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,138 +0,0 @@
|
|||
package com.deepclone.lw.beans.updates;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import com.deepclone.lw.cmd.admin.logs.LogLevel;
|
||||
import com.deepclone.lw.interfaces.eventlog.Logger;
|
||||
import com.deepclone.lw.interfaces.eventlog.SystemLogger;
|
||||
import com.deepclone.lw.interfaces.game.UpdatesDAO;
|
||||
import com.deepclone.lw.interfaces.sys.MaintenanceStatusException;
|
||||
import com.deepclone.lw.interfaces.sys.SystemStatus;
|
||||
import com.deepclone.lw.interfaces.sys.TickStatusException;
|
||||
import com.deepclone.lw.interfaces.sys.Ticker;
|
||||
import com.deepclone.lw.interfaces.sys.Ticker.Frequency;
|
||||
|
||||
|
||||
|
||||
public class GameUpdateBean
|
||||
implements InitializingBean , Runnable
|
||||
{
|
||||
private Ticker ticker;
|
||||
private SystemStatus systemStatus;
|
||||
private SystemLogger logger;
|
||||
|
||||
private TransactionTemplate tTemplate;
|
||||
private UpdatesDAO updatesDao;
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setTicker( Ticker ticker )
|
||||
{
|
||||
this.ticker = ticker;
|
||||
}
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setSystemStatus( SystemStatus systemStatus )
|
||||
{
|
||||
this.systemStatus = systemStatus;
|
||||
}
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setLogger( Logger logger )
|
||||
{
|
||||
this.logger = logger.getSystemLogger( "GameUpdate" );
|
||||
}
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setTransactionManager( PlatformTransactionManager transactionManager )
|
||||
{
|
||||
this.tTemplate = new TransactionTemplate( transactionManager );
|
||||
}
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setUpdatesDAO( UpdatesDAO updatesDao )
|
||||
{
|
||||
this.updatesDao = updatesDao;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet( )
|
||||
{
|
||||
try {
|
||||
this.endPreviousTick( );
|
||||
} catch ( MaintenanceStatusException e ) {
|
||||
// Do nothing
|
||||
}
|
||||
this.ticker.registerTask( Frequency.MINUTE , "Game update" , this );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run( )
|
||||
{
|
||||
// Attempt to end the previous tick, if e.g. maintenance mode was initiated while it was
|
||||
// being processed
|
||||
try {
|
||||
this.endPreviousTick( );
|
||||
} catch ( MaintenanceStatusException e1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Initiate next tick
|
||||
long tickId;
|
||||
try {
|
||||
tickId = this.systemStatus.startTick( );
|
||||
} catch ( TickStatusException e ) {
|
||||
throw new RuntimeException( "tick initiated while previous tick still being processed" , e );
|
||||
} catch ( MaintenanceStatusException e ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Execute tick
|
||||
this.logger.log( LogLevel.DEBUG , "Tick " + tickId + " started" ).flush( );
|
||||
this.executeTick( tickId );
|
||||
}
|
||||
|
||||
|
||||
private void endPreviousTick( )
|
||||
throws MaintenanceStatusException
|
||||
{
|
||||
Long currentTick = this.systemStatus.checkStuckTick( );
|
||||
if ( currentTick == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.logger.log( LogLevel.WARNING , "Tick " + currentTick + " restarted" ).flush( );
|
||||
this.executeTick( currentTick.longValue( ) );
|
||||
}
|
||||
|
||||
|
||||
private void executeTick( final long tickId )
|
||||
{
|
||||
boolean hasMore;
|
||||
do {
|
||||
hasMore = this.tTemplate.execute( new TransactionCallback< Boolean >( ) {
|
||||
|
||||
@Override
|
||||
public Boolean doInTransaction( TransactionStatus status )
|
||||
{
|
||||
return updatesDao.processUpdates( tickId );
|
||||
}
|
||||
|
||||
} );
|
||||
} while ( hasMore );
|
||||
this.logger.log( LogLevel.TRACE , "Tick " + tickId + " completed" ).flush( );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package com.deepclone.lw.beans.updates;
|
||||
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.SqlOutParameter;
|
||||
import org.springframework.jdbc.core.SqlParameter;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcCall;
|
||||
|
||||
import com.deepclone.lw.interfaces.game.UpdatesDAO;
|
||||
|
||||
|
||||
|
||||
public class UpdatesDAOBean
|
||||
implements UpdatesDAO
|
||||
{
|
||||
|
||||
private SimpleJdbcCall process;
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.process = new SimpleJdbcCall( dataSource );
|
||||
this.process.withCatalogName( "sys" ).withFunctionName( "process_updates" );
|
||||
this.process.withoutProcedureColumnMetaDataAccess( );
|
||||
this.process.addDeclaredParameter( new SqlParameter( "tick_id" , Types.BIGINT ) );
|
||||
this.process.addDeclaredParameter( new SqlOutParameter( "has_more" , Types.BOOLEAN ) );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean processUpdates( long tickId )
|
||||
{
|
||||
Map< String , Object > m = this.process.execute( tickId );
|
||||
return (Boolean) m.get( "has_more" );
|
||||
}
|
||||
|
||||
}
|
|
@ -10,13 +10,11 @@
|
|||
<import resource="simple/empire-management-bean.xml" />
|
||||
<import resource="simple/fleet-management-bean.xml" />
|
||||
<import resource="simple/fleets-dao-bean.xml" />
|
||||
<import resource="simple/game-update-bean.xml" />
|
||||
<import resource="simple/map-viewer-bean.xml" />
|
||||
<import resource="simple/message-beans.xml" />
|
||||
<import resource="simple/planet-dao-bean.xml" />
|
||||
<import resource="simple/planets-management-bean.xml" />
|
||||
<import resource="simple/universe-dao-bean.xml" />
|
||||
<import resource="simple/universe-generator-bean.xml" />
|
||||
<import resource="simple/updates-dao-bean.xml" />
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
<!-- Game update bean -->
|
||||
<bean id="gameUpdate" class="com.deepclone.lw.beans.updates.GameUpdateBean" />
|
||||
|
||||
</beans>
|
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
<bean id="updatesDAO" class="com.deepclone.lw.beans.updates.UpdatesDAOBean" />
|
||||
|
||||
</beans>
|
Reference in a new issue