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-accounts
legacyworlds-server-beans-bt
pom.xml
src/main/java/com/deepclone/lw/beans/bt
legacyworlds-server-beans-eventlog
legacyworlds-server-beans-events
legacyworlds-server-beans-i18n
legacyworlds-server-beans-mailer
legacyworlds-server-beans-naming
legacyworlds-server-beans-simple
legacyworlds-server-beans-system
pom.xml
src/main/java/com/deepclone/lw/beans/sys
legacyworlds-server-beans-techs
.classpath.project
.settings
pom.xmlsrc/main
java/com/deepclone/lw/beans/techs
EmpireTechnologyDAOBean.javaEmpireTechnologyManagerBean.javaEmpireUpdate.javaResearchResponseBuilder.javaResearchUpdateBean.javaResearchUpdateDAOBean.javaTechnologyGraphDAOBean.javaTechnologyGraphManagerBean.java
resources/configuration
legacyworlds-server-beans-updates
.classpath.project
.settings
pom.xmlsrc/main
java/com/deepclone/lw/beans/updates
resources/configuration
legacyworlds-server-beans-user
pom.xml
pom.xmlsrc/main
java/com/deepclone/lw/beans/user
admin/main/techs
player/game/techs
resources/configuration/user
|
@ -4,12 +4,12 @@
|
|||
<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-accounts</artifactId>
|
||||
<name>Legacy Worlds account management</name>
|
||||
<version>5.99.1</version>
|
||||
<version>5.99.2</version>
|
||||
<description>This package contains the beans responsible for managing accounts, including registration, inactivity checks, bans and authentication.</description>
|
||||
</project>
|
|
@ -4,7 +4,7 @@
|
|||
<parent>
|
||||
<artifactId>legacyworlds-server-beans</artifactId>
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<version>5.99.1</version>
|
||||
<version>5.99.2</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@ -20,6 +20,6 @@
|
|||
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<artifactId>legacyworlds-server-beans-bt</artifactId>
|
||||
<version>5.99.1</version>
|
||||
<version>5.99.2</version>
|
||||
<name>Legacy Worlds bug tracking system</name>
|
||||
</project>
|
|
@ -28,6 +28,7 @@ public class EmpireSummaryBean
|
|||
|
||||
private final RowMapper< DebugInformation > mMainInfo;
|
||||
private final RowMapper< ResearchInformation > mResearch;
|
||||
private final RowMapper< TechnologyInformation > mTechnology;
|
||||
private final RowMapper< PlanetInformation > mPlanet;
|
||||
private final RowMapper< QueueItemInformation > mQueueItem;
|
||||
private final RowMapper< BuildingsInformation > mBuildings;
|
||||
|
@ -42,7 +43,8 @@ public class EmpireSummaryBean
|
|||
AccountInformation.class , AllianceInformation.class , BuildingsInformation.class ,
|
||||
DebugInformation.class , EmpireInformation.class , FleetInformation.class , MovementInformation.class ,
|
||||
PlanetInformation.class , QueueInformation.class , QueueItemInformation.class ,
|
||||
ResearchInformation.class , ShipsInformation.class , SystemInformation.class
|
||||
ResearchInformation.class , TechnologyInformation.class , ShipsInformation.class ,
|
||||
SystemInformation.class
|
||||
} );
|
||||
|
||||
this.mMainInfo = new RowMapper< DebugInformation >( ) {
|
||||
|
@ -83,13 +85,23 @@ public class EmpireSummaryBean
|
|||
throws SQLException
|
||||
{
|
||||
ResearchInformation ri = new ResearchInformation( );
|
||||
ri.setId( rs.getInt( "line_id" ) );
|
||||
ri.setCurrentLevel( rs.getInt( "level" ) );
|
||||
ri.setLevelName( rs.getString( "name" ) );
|
||||
ri.setName( rs.getString( "name" ) );
|
||||
ri.setAccumulated( rs.getDouble( "accumulated" ) );
|
||||
ri.setPriority( rs.getInt( "priority" ) );
|
||||
return ri;
|
||||
}
|
||||
};
|
||||
this.mTechnology = new RowMapper< TechnologyInformation >( ) {
|
||||
@Override
|
||||
public TechnologyInformation mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
TechnologyInformation ti = new TechnologyInformation( );
|
||||
ti.setName( rs.getString( "name" ) );
|
||||
ti.setImplemented( rs.getBoolean( "implemented" ) );
|
||||
return ti;
|
||||
}
|
||||
};
|
||||
this.mPlanet = new RowMapper< PlanetInformation >( ) {
|
||||
@Override
|
||||
public PlanetInformation mapRow( ResultSet rs , int rowNum )
|
||||
|
@ -199,9 +211,10 @@ public class EmpireSummaryBean
|
|||
DebugInformation di = this.dTemplate.queryForObject( sql , this.mMainInfo , empireId );
|
||||
|
||||
sql = "SELECT * FROM bugs.dump_research_view WHERE empire_id = ?";
|
||||
for ( ResearchInformation ri : this.dTemplate.query( sql , this.mResearch , empireId ) ) {
|
||||
di.getResearch( ).add( ri );
|
||||
}
|
||||
di.getResearch( ).addAll( this.dTemplate.query( sql , this.mResearch , empireId ) );
|
||||
|
||||
sql = "SELECT * FROM bugs.dump_technologies_view WHERE empire_id = ?";
|
||||
di.getTechnologies( ).addAll( this.dTemplate.query( sql , this.mTechnology , empireId ) );
|
||||
|
||||
sql = "SELECT * FROM bugs.dump_planets_view WHERE empire_id = ?";
|
||||
Map< Integer , PlanetInformation > planets = new HashMap< Integer , PlanetInformation >( );
|
||||
|
|
|
@ -15,26 +15,29 @@ public class DebugInformation
|
|||
implements Serializable
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 2L;
|
||||
|
||||
@XStreamAsAttribute
|
||||
@XStreamAlias( "dump-version" )
|
||||
private int version = 1;
|
||||
private final int version = 2;
|
||||
|
||||
private SystemInformation system = new SystemInformation( );
|
||||
private final SystemInformation system = new SystemInformation( );
|
||||
|
||||
private AccountInformation account = new AccountInformation( );
|
||||
private final AccountInformation account = new AccountInformation( );
|
||||
|
||||
private EmpireInformation empire = new EmpireInformation( );
|
||||
private final EmpireInformation empire = new EmpireInformation( );
|
||||
|
||||
@XStreamAlias( "research" )
|
||||
private List< ResearchInformation > research = new LinkedList< ResearchInformation >( );
|
||||
private final List< ResearchInformation > research = new LinkedList< ResearchInformation >( );
|
||||
|
||||
@XStreamAlias( "technologies" )
|
||||
private final List< TechnologyInformation > technologies = new LinkedList< TechnologyInformation >( );
|
||||
|
||||
@XStreamAlias( "planets" )
|
||||
private List< PlanetInformation > planets = new LinkedList< PlanetInformation >( );
|
||||
private final List< PlanetInformation > planets = new LinkedList< PlanetInformation >( );
|
||||
|
||||
@XStreamAlias( "fleets" )
|
||||
private List< FleetInformation > fleets = new LinkedList< FleetInformation >( );
|
||||
private final List< FleetInformation > fleets = new LinkedList< FleetInformation >( );
|
||||
|
||||
|
||||
public int getVersion( )
|
||||
|
@ -67,6 +70,12 @@ public class DebugInformation
|
|||
}
|
||||
|
||||
|
||||
public List< TechnologyInformation > getTechnologies( )
|
||||
{
|
||||
return technologies;
|
||||
}
|
||||
|
||||
|
||||
public List< PlanetInformation > getPlanets( )
|
||||
{
|
||||
return planets;
|
||||
|
@ -78,4 +87,4 @@ public class DebugInformation
|
|||
return fleets;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -8,64 +8,34 @@ import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
|
|||
|
||||
|
||||
|
||||
@XStreamAlias( "research-line" )
|
||||
@XStreamAlias( "research-topic" )
|
||||
public class ResearchInformation
|
||||
implements Serializable
|
||||
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 2L;
|
||||
|
||||
@XStreamAsAttribute
|
||||
@XStreamAlias( "line")
|
||||
private int id;
|
||||
|
||||
@XStreamAsAttribute
|
||||
@XStreamAlias( "level")
|
||||
private int currentLevel;
|
||||
private String name;
|
||||
|
||||
@XStreamAsAttribute
|
||||
@XStreamAlias( "name")
|
||||
private String levelName;
|
||||
|
||||
@XStreamAsAttribute
|
||||
@XStreamAlias( "accumulated-points")
|
||||
@XStreamAlias( "accumulated-points" )
|
||||
private double accumulated;
|
||||
|
||||
@XStreamAsAttribute
|
||||
private int priority;
|
||||
|
||||
public int getId( )
|
||||
|
||||
public String getName( )
|
||||
{
|
||||
return id;
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setId( int id )
|
||||
public void setName( String name )
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
|
||||
public int getCurrentLevel( )
|
||||
{
|
||||
return currentLevel;
|
||||
}
|
||||
|
||||
|
||||
public void setCurrentLevel( int currentLevel )
|
||||
{
|
||||
this.currentLevel = currentLevel;
|
||||
}
|
||||
|
||||
|
||||
public String getLevelName( )
|
||||
{
|
||||
return levelName;
|
||||
}
|
||||
|
||||
|
||||
public void setLevelName( String levelName )
|
||||
{
|
||||
this.levelName = levelName;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
|
@ -80,4 +50,16 @@ public class ResearchInformation
|
|||
this.accumulated = accumulated;
|
||||
}
|
||||
|
||||
|
||||
public int getPriority( )
|
||||
{
|
||||
return priority;
|
||||
}
|
||||
|
||||
|
||||
public void setPriority( int priority )
|
||||
{
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package com.deepclone.lw.beans.bt.esdata;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
|
||||
|
||||
|
||||
|
||||
@XStreamAlias( "technology" )
|
||||
public class TechnologyInformation
|
||||
implements Serializable
|
||||
{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@XStreamAsAttribute
|
||||
private String name;
|
||||
|
||||
@XStreamAsAttribute
|
||||
private boolean implemented;
|
||||
|
||||
|
||||
public String getName( )
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
public void setName( String name )
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public boolean isImplemented( )
|
||||
{
|
||||
return implemented;
|
||||
}
|
||||
|
||||
|
||||
public void setImplemented( boolean implemented )
|
||||
{
|
||||
this.implemented = implemented;
|
||||
}
|
||||
|
||||
}
|
|
@ -4,12 +4,12 @@
|
|||
<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-eventlog</artifactId>
|
||||
<version>5.99.1</version>
|
||||
<version>5.99.2</version>
|
||||
<name>Legacy Worlds event log</name>
|
||||
<description>This package is responsible for all logging in Legacy Worlds through three different beans (system event logger, admin event logger and user event logger).</description>
|
||||
</project>
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>legacyworlds-server-beans-events</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,6 @@
|
|||
#Sun Apr 03 09:36:59 CEST 2011
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
|
@ -0,0 +1,9 @@
|
|||
#Sun Apr 03 09:36:59 CEST 2011
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
fullBuildGoals=process-test-resources
|
||||
includeModules=false
|
||||
resolveWorkspaceProjects=true
|
||||
resourceFilterGoals=process-resources resources\:testResources
|
||||
skipCompilerPlugin=true
|
||||
version=1
|
|
@ -0,0 +1,13 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>legacyworlds-server-beans</artifactId>
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<version>5.99.2</version>
|
||||
</parent>
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<artifactId>legacyworlds-server-beans-events</artifactId>
|
||||
<version>5.99.2</version>
|
||||
<name>Game events</name>
|
||||
<description>This module contains components which manage game events.</description>
|
||||
</project>
|
|
@ -4,13 +4,13 @@
|
|||
<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-i18n</artifactId>
|
||||
<name>Legacy Worlds internationalisation</name>
|
||||
<version>5.99.1</version>
|
||||
<version>5.99.2</version>
|
||||
<description>This package defines the two beans which control server-side internationalised text management.</description>
|
||||
|
||||
</project>
|
|
@ -6,6 +6,7 @@ import java.util.Set;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
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.i18n.UnknownStringException;
|
||||
|
@ -21,6 +22,67 @@ import com.deepclone.lw.interfaces.i18n.UnknownStringException;
|
|||
public class TranslatorBean
|
||||
implements Translator
|
||||
{
|
||||
|
||||
/**
|
||||
* Implementation of a language-specific translator.
|
||||
*/
|
||||
private static class LanguageTranslatorImpl
|
||||
implements LanguageTranslator
|
||||
{
|
||||
/** Language used by the translator */
|
||||
private final String language;
|
||||
|
||||
/** Translations store */
|
||||
private final I18NData data;
|
||||
|
||||
|
||||
LanguageTranslatorImpl( String language , TranslatorBean translator )
|
||||
{
|
||||
this.language = language;
|
||||
this.data = translator.data;
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in LanguageTranslator interface */
|
||||
@Override
|
||||
public String getLanguage( )
|
||||
{
|
||||
return this.language;
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in LanguageTranslator interface */
|
||||
@Override
|
||||
public String getLanguageName( )
|
||||
{
|
||||
this.data.readLock( ).lock( );
|
||||
try {
|
||||
return this.data.getLanguageName( language );
|
||||
} finally {
|
||||
this.data.readLock( ).unlock( );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in LanguageTranslator interface */
|
||||
@Override
|
||||
public String translate( String string )
|
||||
throws UnknownStringException
|
||||
{
|
||||
this.data.readLock( ).lock( );
|
||||
try {
|
||||
if ( !this.data.hasString( string ) ) {
|
||||
throw new UnknownStringException( string );
|
||||
}
|
||||
return this.data.getTranslation( language , string );
|
||||
} finally {
|
||||
this.data.readLock( ).unlock( );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Translations store */
|
||||
private I18NData data;
|
||||
|
||||
|
||||
|
@ -119,4 +181,21 @@ public class TranslatorBean
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in Translator interface */
|
||||
@Override
|
||||
public LanguageTranslator getLanguageTranslator( String language )
|
||||
throws UnknownLanguageException
|
||||
{
|
||||
this.data.readLock( ).lock( );
|
||||
try {
|
||||
if ( !this.data.isLanguageComplete( language ) ) {
|
||||
throw new UnknownLanguageException( language );
|
||||
}
|
||||
return new LanguageTranslatorImpl( language , this );
|
||||
} finally {
|
||||
this.data.readLock( ).unlock( );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
<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-mailer</artifactId>
|
||||
<version>5.99.1</version>
|
||||
<version>5.99.2</version>
|
||||
<name>Legacy Worlds mailer</name>
|
||||
<description>
|
||||
This package contains the mailer component, which uses LW's i18n system and Spring's mail sending interfaces.
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
<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-naming</artifactId>
|
||||
<version>5.99.1</version>
|
||||
<version>5.99.2</version>
|
||||
<name>Legacy Worlds object naming system</name>
|
||||
<description>This module contains the beans responsible for managing the names of the various objects (players and planets).</description>
|
||||
</project>
|
|
@ -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>
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
<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-system</artifactId>
|
||||
<version>5.99.1</version>
|
||||
<version>5.99.2</version>
|
||||
<name>Legacy Worlds system management</name>
|
||||
<description>This module regroups system management beans such as the constants manager.</description>
|
||||
</project>
|
|
@ -93,7 +93,7 @@ class ConstantsData
|
|||
this.uocConstantNoBounds.addDeclaredParameter( new SqlParameter( "cname" , Types.VARCHAR ) );
|
||||
this.uocConstantNoBounds.addDeclaredParameter( new SqlParameter( "cdesc" , Types.VARCHAR ) );
|
||||
this.uocConstantNoBounds.addDeclaredParameter( new SqlParameter( "catname" , Types.VARCHAR ) );
|
||||
this.uocConstantNoBounds.addDeclaredParameter( new SqlParameter( "value" , Types.REAL ) );
|
||||
this.uocConstantNoBounds.addDeclaredParameter( new SqlParameter( "value" , Types.DOUBLE ) );
|
||||
|
||||
this.uocConstantSingleBound = new SimpleJdbcCall( dataSource );
|
||||
this.uocConstantSingleBound.withCatalogName( "sys" ).withFunctionName( "uoc_constant" );
|
||||
|
@ -101,8 +101,8 @@ class ConstantsData
|
|||
this.uocConstantSingleBound.addDeclaredParameter( new SqlParameter( "cname" , Types.VARCHAR ) );
|
||||
this.uocConstantSingleBound.addDeclaredParameter( new SqlParameter( "cdesc" , Types.VARCHAR ) );
|
||||
this.uocConstantSingleBound.addDeclaredParameter( new SqlParameter( "catname" , Types.VARCHAR ) );
|
||||
this.uocConstantSingleBound.addDeclaredParameter( new SqlParameter( "value" , Types.REAL ) );
|
||||
this.uocConstantSingleBound.addDeclaredParameter( new SqlParameter( "boundary" , Types.REAL ) );
|
||||
this.uocConstantSingleBound.addDeclaredParameter( new SqlParameter( "value" , Types.DOUBLE ) );
|
||||
this.uocConstantSingleBound.addDeclaredParameter( new SqlParameter( "boundary" , Types.DOUBLE ) );
|
||||
this.uocConstantSingleBound.addDeclaredParameter( new SqlParameter( "is_min" , Types.BOOLEAN ) );
|
||||
|
||||
this.uocConstantTwoBounds = new SimpleJdbcCall( dataSource );
|
||||
|
@ -111,13 +111,13 @@ class ConstantsData
|
|||
this.uocConstantTwoBounds.addDeclaredParameter( new SqlParameter( "cname" , Types.VARCHAR ) );
|
||||
this.uocConstantTwoBounds.addDeclaredParameter( new SqlParameter( "cdesc" , Types.VARCHAR ) );
|
||||
this.uocConstantTwoBounds.addDeclaredParameter( new SqlParameter( "catname" , Types.VARCHAR ) );
|
||||
this.uocConstantTwoBounds.addDeclaredParameter( new SqlParameter( "value" , Types.REAL ) );
|
||||
this.uocConstantTwoBounds.addDeclaredParameter( new SqlParameter( "min" , Types.REAL ) );
|
||||
this.uocConstantTwoBounds.addDeclaredParameter( new SqlParameter( "max" , Types.REAL ) );
|
||||
this.uocConstantTwoBounds.addDeclaredParameter( new SqlParameter( "value" , Types.DOUBLE ) );
|
||||
this.uocConstantTwoBounds.addDeclaredParameter( new SqlParameter( "min" , Types.DOUBLE ) );
|
||||
this.uocConstantTwoBounds.addDeclaredParameter( new SqlParameter( "max" , Types.DOUBLE ) );
|
||||
|
||||
this.fSetConstant = new StoredProc( dataSource , "sys" , "set_constant" );
|
||||
this.fSetConstant.addParameter( "cname" , Types.VARCHAR );
|
||||
this.fSetConstant.addParameter( "value" , Types.REAL );
|
||||
this.fSetConstant.addParameter( "value" , Types.DOUBLE );
|
||||
this.fSetConstant.addParameter( "admin" , Types.INTEGER );
|
||||
|
||||
this.tTemplate = tTemplate;
|
||||
|
@ -149,8 +149,8 @@ class ConstantsData
|
|||
c.setName( rs.getString( "name" ) );
|
||||
c.setDescription( rs.getString( "description" ) );
|
||||
c.setValue( rs.getDouble( "value" ) );
|
||||
c.setMinValue( (Float) rs.getObject( "min" ) );
|
||||
c.setMaxValue( (Float) rs.getObject( "max" ) );
|
||||
c.setMinValue( (Double) rs.getObject( "min" ) );
|
||||
c.setMaxValue( (Double) rs.getObject( "max" ) );
|
||||
return c;
|
||||
}
|
||||
|
||||
|
@ -609,7 +609,7 @@ class ConstantsData
|
|||
@Override
|
||||
protected void doInTransactionWithoutResult( TransactionStatus status )
|
||||
{
|
||||
fSetConstant.execute( name , value.floatValue( ) , admin );
|
||||
fSetConstant.execute( name , value , admin );
|
||||
}
|
||||
|
||||
} );
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package com.deepclone.lw.beans.sys;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
|
@ -92,9 +93,10 @@ public class ConstantsManagerBean
|
|||
|
||||
/* Documented in ConstantsManager interface */
|
||||
@Override
|
||||
public void registerUser( ConstantsUser user , Set< String > constants )
|
||||
public void registerUser( ConstantsUser user , String... constants )
|
||||
{
|
||||
this.data.registerUser( user , constants );
|
||||
HashSet< String > cSet = new HashSet< String >( Arrays.asList( constants ) );
|
||||
this.data.registerUser( user , cSet );
|
||||
}
|
||||
|
||||
|
||||
|
@ -112,4 +114,5 @@ public class ConstantsManagerBean
|
|||
{
|
||||
return new ConstantsAdministrationImpl( this.data , admin );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ public class ConstantsRegistrarBean
|
|||
// Work and income
|
||||
String[] wcNames = {
|
||||
"population" , "factory" , "strikeEffect" , "wuPerPopUnit" , "destructionRecovery" , "destructionWork" ,
|
||||
"rpPerPopUnit" , "cancelRecovery"
|
||||
"cancelRecovery"
|
||||
};
|
||||
for ( int i = 0 ; i < wcNames.length ; i++ ) {
|
||||
wcNames[ i ] = "game.work." + wcNames[ i ];
|
||||
|
@ -107,10 +107,8 @@ public class ConstantsRegistrarBean
|
|||
defs.add( new ConstantDefinition( wcNames[ 4 ] , cat , cDesc , 0.1 , 0.01 , 0.99 ) );
|
||||
cDesc = "Proportion of a building's construction work units required to destroy it";
|
||||
defs.add( new ConstantDefinition( wcNames[ 5 ] , cat , cDesc , 0.25 , 0.01 , 1.0 ) );
|
||||
cDesc = "Research points per population unit.";
|
||||
defs.add( new ConstantDefinition( wcNames[ 6 ] , cat , cDesc , 0.50 , 0.01 , true ) );
|
||||
cDesc = "Proportion of queue investments that is recovered when flushing the queue.";
|
||||
defs.add( new ConstantDefinition( wcNames[ 7 ] , cat , cDesc , 0.1 , 0.01 , 1.0 ) );
|
||||
defs.add( new ConstantDefinition( wcNames[ 6 ] , cat , cDesc , 0.1 , 0.01 , 1.0 ) );
|
||||
|
||||
// Vacation mode
|
||||
cDesc = "Initial vacation credits.";
|
||||
|
@ -155,7 +153,7 @@ public class ConstantsRegistrarBean
|
|||
// Ticker
|
||||
cDesc = "Interval between ticks with the highest frequency, in milliseconds.";
|
||||
defs.add( new ConstantDefinition( "ticker.interval" , "Ticker" , cDesc , 5000.0 , 1000.0 , true ) );
|
||||
|
||||
|
||||
// Accounts
|
||||
cDesc = "Minimal interval between address change requests (seconds)";
|
||||
defs.add( new ConstantDefinition( "accounts.acrDelay" , "Accounts" , cDesc , 14400.0 , 1.0 , true ) );
|
||||
|
@ -169,32 +167,43 @@ public class ConstantsRegistrarBean
|
|||
defs.add( new ConstantDefinition( "accounts.banDelay" , "Accounts" , cDesc , 178000.0 , 3600.0 , true ) );
|
||||
cDesc = "Delay before a ban request expires (seconds)";
|
||||
defs.add( new ConstantDefinition( "accounts.banExpiration" , "Accounts" , cDesc , oneWeek , 3600.0 , true ) );
|
||||
|
||||
|
||||
// Accounts - warnings
|
||||
cDesc = "Amount of warnings that triggers an automatic ban request.";
|
||||
defs.add( new ConstantDefinition( "accounts.warnings.autoBan" , "Accounts - Warnings" , cDesc , 3.0 , 1.0 , true ) );
|
||||
defs.add( new ConstantDefinition( "accounts.warnings.autoBan" , "Accounts - Warnings" , cDesc , 3.0 , 1.0 ,
|
||||
true ) );
|
||||
cDesc = "Period after a warning is received during which additional warnings will be ignored (seconds).";
|
||||
defs.add( new ConstantDefinition( "accounts.warnings.grace" , "Accounts - Warnings" , cDesc , 7200.0 , 60.0 , true ) );
|
||||
defs.add( new ConstantDefinition( "accounts.warnings.grace" , "Accounts - Warnings" , cDesc , 7200.0 , 60.0 ,
|
||||
true ) );
|
||||
cDesc = "Time after which warnings are decreased (expressed in units as defined by a.w.expiration.units).";
|
||||
defs.add( new ConstantDefinition( "accounts.warnings.expiration" , "Accounts - Warnings" , cDesc , 60.0 , 1.0 , true ) );
|
||||
defs.add( new ConstantDefinition( "accounts.warnings.expiration" , "Accounts - Warnings" , cDesc , 60.0 , 1.0 ,
|
||||
true ) );
|
||||
cDesc = "Units used to express warning expiration time (seconds).";
|
||||
defs.add( new ConstantDefinition( "accounts.warnings.expiration.units" , "Accounts - Warnings" , cDesc , 86400.0 , 1.0 , true ) );
|
||||
|
||||
defs.add( new ConstantDefinition( "accounts.warnings.expiration.units" , "Accounts - Warnings" , cDesc ,
|
||||
86400.0 , 1.0 , true ) );
|
||||
|
||||
// Account inactivity
|
||||
cDesc = "Time units (seconds)";
|
||||
defs.add( new ConstantDefinition( "accounts.inactivity.units" , "Accounts - Inactivity" , cDesc , oneWeek , 3600.0 , true ) );
|
||||
defs.add( new ConstantDefinition( "accounts.inactivity.units" , "Accounts - Inactivity" , cDesc , oneWeek ,
|
||||
3600.0 , true ) );
|
||||
cDesc = "Time after which the inactivity warning e-mail is to be sent, expressed using units defined by a.i.units.";
|
||||
defs.add( new ConstantDefinition( "accounts.inactivity.warningMail" , "Accounts - Inactivity" , cDesc , 3.0 , 1.0 , true ) );
|
||||
defs.add( new ConstantDefinition( "accounts.inactivity.warningMail" , "Accounts - Inactivity" , cDesc , 3.0 ,
|
||||
1.0 , true ) );
|
||||
cDesc = "Time between the inactivity warning e-mail and actual account deletion, expressed using units defined by a.i.units.";
|
||||
defs.add( new ConstantDefinition( "accounts.inactivity.deletion" , "Accounts - Inactivity" , cDesc , 1.0 , 1.0 , true ) );
|
||||
|
||||
defs.add( new ConstantDefinition( "accounts.inactivity.deletion" , "Accounts - Inactivity" , cDesc , 1.0 , 1.0 ,
|
||||
true ) );
|
||||
|
||||
// Bug reports
|
||||
cDesc = "Amount of credits granted for low priority bug reports.";
|
||||
defs.add( new ConstantDefinition( "bugtracker.lowCredits" , "Bug tracking system" , cDesc , 1.0 , 1.0 , true ) );
|
||||
cDesc = "Amount of credits granted for normal bug reports.";
|
||||
defs.add( new ConstantDefinition( "bugtracker.mediumCredits" , "Bug tracking system" , cDesc , 2.0 , 1.0 , true ) );
|
||||
defs
|
||||
.add( new ConstantDefinition( "bugtracker.mediumCredits" , "Bug tracking system" , cDesc , 2.0 , 1.0 ,
|
||||
true ) );
|
||||
cDesc = "Amount of credits granted for critical bug reports.";
|
||||
defs.add( new ConstantDefinition( "bugtracker.highCredits" , "Bug tracking system" , cDesc , 3.0 , 1.0 , true ) );
|
||||
defs
|
||||
.add( new ConstantDefinition( "bugtracker.highCredits" , "Bug tracking system" , cDesc , 3.0 , 1.0 ,
|
||||
true ) );
|
||||
|
||||
cm.registerConstants( defs );
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@ import javax.sql.DataSource;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.SqlOutParameter;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcCall;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
|
@ -44,13 +42,14 @@ public class SystemStatusBean
|
|||
/** Current maintenance mode record */
|
||||
private MaintenanceData maintenance = null;
|
||||
|
||||
private SimpleJdbcCall doStartTick;
|
||||
private SimpleJdbcCall doCheckTick;
|
||||
|
||||
private StoredProc fEnterMaintenanceMode;
|
||||
private StoredProc fExtendMaintenanceMode;
|
||||
private StoredProc fExitMaintenanceMode;
|
||||
|
||||
private StoredProc fCheckTick;
|
||||
private StoredProc fStartTick;
|
||||
private StoredProc fEndTick;
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
|
@ -72,16 +71,14 @@ public class SystemStatusBean
|
|||
this.fExitMaintenanceMode.addParameter( "admin_id" , Types.INTEGER );
|
||||
this.fExitMaintenanceMode.addOutput( "success" , Types.BOOLEAN );
|
||||
|
||||
this.doStartTick = new SimpleJdbcCall( dataSource );
|
||||
this.doStartTick.withCatalogName( "sys" ).withFunctionName( "start_tick" );
|
||||
this.doStartTick.withoutProcedureColumnMetaDataAccess( );
|
||||
this.doStartTick.addDeclaredParameter( new SqlOutParameter( "tick_id" , Types.BIGINT ) );
|
||||
this.fCheckTick = new StoredProc( dataSource , "sys" , "check_stuck_tick" );
|
||||
this.fCheckTick.addOutput( "tick_id" , Types.BIGINT );
|
||||
|
||||
this.doCheckTick = new SimpleJdbcCall( dataSource );
|
||||
this.doCheckTick.withCatalogName( "sys" ).withFunctionName( "check_stuck_tick" );
|
||||
this.doCheckTick.withoutProcedureColumnMetaDataAccess( );
|
||||
this.doCheckTick.addDeclaredParameter( new SqlOutParameter( "tick_id" , Types.BIGINT ) );
|
||||
this.fStartTick = new StoredProc( dataSource , "sys" , "start_tick" );
|
||||
this.fStartTick.addOutput( "tick_id" , Types.BIGINT );
|
||||
|
||||
this.fEndTick = new StoredProc( dataSource , "sys" , "end_tick" );
|
||||
this.fEndTick.addParameter( "tick_id" , Types.BIGINT );
|
||||
}
|
||||
|
||||
|
||||
|
@ -246,6 +243,31 @@ public class SystemStatusBean
|
|||
}
|
||||
|
||||
|
||||
/* Documented in interface */
|
||||
@Override
|
||||
public Long checkStuckTick( )
|
||||
throws MaintenanceStatusException
|
||||
{
|
||||
Long tid = this.tTemplate.execute( new TransactionCallback< Long >( ) {
|
||||
|
||||
@Override
|
||||
public Long doInTransaction( TransactionStatus status )
|
||||
{
|
||||
Map< String , Object > m = fCheckTick.execute( );
|
||||
loadStatus( );
|
||||
return (Long) m.get( "tick_id" );
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
if ( tid == null && this.maintenance != null ) {
|
||||
throw new MaintenanceStatusException( this.maintenance );
|
||||
}
|
||||
|
||||
return tid;
|
||||
}
|
||||
|
||||
|
||||
/* Documented in interface */
|
||||
@Override
|
||||
synchronized public long startTick( )
|
||||
|
@ -256,7 +278,7 @@ public class SystemStatusBean
|
|||
@Override
|
||||
public Long doInTransaction( TransactionStatus status )
|
||||
{
|
||||
Map< String , Object > m = doStartTick.execute( );
|
||||
Map< String , Object > m = fStartTick.execute( );
|
||||
loadStatus( );
|
||||
return (Long) m.get( "tick_id" );
|
||||
}
|
||||
|
@ -277,26 +299,28 @@ public class SystemStatusBean
|
|||
|
||||
/* Documented in interface */
|
||||
@Override
|
||||
public Long checkStuckTick( )
|
||||
throws MaintenanceStatusException
|
||||
public void endTick( )
|
||||
throws TickStatusException , MaintenanceStatusException
|
||||
{
|
||||
Long tid = this.tTemplate.execute( new TransactionCallback< Long >( ) {
|
||||
|
||||
@Override
|
||||
public Long doInTransaction( TransactionStatus status )
|
||||
{
|
||||
Map< String , Object > m = doCheckTick.execute( );
|
||||
loadStatus( );
|
||||
return (Long) m.get( "tick_id" );
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
if ( tid == null && this.maintenance != null ) {
|
||||
if ( this.maintenance != null ) {
|
||||
throw new MaintenanceStatusException( this.maintenance );
|
||||
}
|
||||
|
||||
return tid;
|
||||
final Long tid = this.status.getCurrentTick( );
|
||||
if ( tid == null ) {
|
||||
throw new TickStatusException( );
|
||||
}
|
||||
|
||||
this.tTemplate.execute( new TransactionCallbackWithoutResult( ) {
|
||||
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult( TransactionStatus status )
|
||||
{
|
||||
fEndTick.execute( tid );
|
||||
loadStatus( );
|
||||
}
|
||||
|
||||
} );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package com.deepclone.lw.beans.sys;
|
||||
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -101,9 +98,7 @@ public class TickerBean
|
|||
this.mainThread = new TickerThread( this.logger , this.tickerManager );
|
||||
|
||||
// Register thread as a constants user
|
||||
Set< String > use = new HashSet< String >( );
|
||||
use.add( "ticker.interval" );
|
||||
this.constantsManager.registerUser( this.mainThread , use );
|
||||
this.constantsManager.registerUser( this.mainThread , "ticker.interval" );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>legacyworlds-server-beans-techs</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,6 @@
|
|||
#Mon Mar 28 09:14:01 CEST 2011
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
|
@ -0,0 +1,9 @@
|
|||
#Mon Mar 28 09:13:56 CEST 2011
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
fullBuildGoals=process-test-resources
|
||||
includeModules=false
|
||||
resolveWorkspaceProjects=true
|
||||
resourceFilterGoals=process-resources resources\:testResources
|
||||
skipCompilerPlugin=true
|
||||
version=1
|
|
@ -0,0 +1,15 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>legacyworlds-server-beans</artifactId>
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<version>5.99.2</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<artifactId>legacyworlds-server-beans-techs</artifactId>
|
||||
<version>5.99.2</version>
|
||||
<name>Legacy Worlds technology management</name>
|
||||
<description>This package contains components which are used to manage technologies in LW games.</description>
|
||||
</project>
|
|
@ -0,0 +1,160 @@
|
|||
package com.deepclone.lw.beans.techs;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Types;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
|
||||
import com.deepclone.lw.interfaces.game.techs.EmpireTechnologyDAO;
|
||||
import com.deepclone.lw.sqld.game.techs.EmpireTechnology;
|
||||
import com.deepclone.lw.utils.StoredProc;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Implementation the empire technology and research data access component.
|
||||
*
|
||||
* @author tseeker
|
||||
*/
|
||||
public class EmpireTechnologyDAOBean
|
||||
implements EmpireTechnologyDAO
|
||||
{
|
||||
/** SQL query that reads the list of an empire's technologies */
|
||||
private static final String qGetTechnologies = "SELECT * FROM emp.technologies_view WHERE empire = ?";
|
||||
|
||||
/** SQL query that executes the priorities update preparation function */
|
||||
private static final String qStartPrioritiesUpdate = "SELECT emp.prepare_research_priorities_update( )";
|
||||
|
||||
/** SQL query that inserts research priority changes into the temporary table */
|
||||
private static final String qUploadPriorities = "INSERT INTO research_priorities_updates ( technology , priority ) "
|
||||
+ "VALUES ( ? , ? )";
|
||||
|
||||
/** Data source access component */
|
||||
private SimpleJdbcTemplate dTemplate;
|
||||
|
||||
/** Row mapper for empire technologies */
|
||||
private RowMapper< EmpireTechnology > mEmpireTechnology;
|
||||
|
||||
/** Wrapper for the stored procedure that implements technologies */
|
||||
private StoredProc fImplementTech;
|
||||
|
||||
/** Wrapper for the stored procedure to apply research priority updates */
|
||||
private StoredProc fApplyResearchPriorities;
|
||||
|
||||
|
||||
/** Initialise the row mapper */
|
||||
public EmpireTechnologyDAOBean( )
|
||||
{
|
||||
this.mEmpireTechnology = new RowMapper< EmpireTechnology >( ) {
|
||||
|
||||
@Override
|
||||
public EmpireTechnology mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
int techId = rs.getInt( "technology_id" );
|
||||
String techName = rs.getString( "technology" );
|
||||
boolean detailed = rs.getBoolean( "detailed" );
|
||||
Integer completion = (Integer) rs.getObject( "completion" );
|
||||
Integer cost = (Integer) rs.getObject( "cost" );
|
||||
Integer priority = (Integer) rs.getObject( "priority" );
|
||||
|
||||
EmpireTechnology result;
|
||||
if ( !detailed ) {
|
||||
result = new EmpireTechnology( techId * rs.getInt( "empire" ) , techName , completion , priority );
|
||||
} else if ( completion != null ) {
|
||||
result = new EmpireTechnology( techName , completion , priority );
|
||||
} else if ( cost != null ) {
|
||||
result = new EmpireTechnology( techName , cost );
|
||||
} else {
|
||||
result = new EmpireTechnology( techName );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector that initialises the database access component and stored procedure
|
||||
* wrappers.
|
||||
*
|
||||
* @param dataSource
|
||||
* the data source
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dTemplate = new SimpleJdbcTemplate( dataSource );
|
||||
|
||||
// Stored procedure for technology implementation
|
||||
this.fImplementTech = new StoredProc( dataSource , "emp" , "implement_tech" );
|
||||
this.fImplementTech.addParameter( "empire_id" , Types.INTEGER );
|
||||
this.fImplementTech.addParameter( "technology" , Types.VARCHAR );
|
||||
this.fImplementTech.addOutput( "error_code" , Types.INTEGER );
|
||||
|
||||
// Stored procedure to apply research priority updates
|
||||
this.fApplyResearchPriorities = new StoredProc( dataSource , "emp" , "apply_research_priorities" );
|
||||
this.fApplyResearchPriorities.addParameter( "empire_id" , Types.INTEGER );
|
||||
this.fApplyResearchPriorities.addOutput( "error_code" , Types.INTEGER );
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in EmpireTechnologyDAO interface */
|
||||
@Override
|
||||
public List< EmpireTechnology > getTechnologies( int empireId )
|
||||
{
|
||||
return this.dTemplate.query( qGetTechnologies , this.mEmpireTechnology , empireId );
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in EmpireTechnologyDAO interface */
|
||||
@Override
|
||||
public int implementTechnology( int empireId , String technology )
|
||||
{
|
||||
return (Integer) this.fImplementTech.execute( empireId , technology ).get( "error_code" );
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in EmpireTechnologyDAO interface */
|
||||
@Override
|
||||
public void startPrioritiesUpdate( )
|
||||
{
|
||||
this.dTemplate.queryForList( qStartPrioritiesUpdate );
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in EmpireTechnologyDAO interface */
|
||||
@Override
|
||||
public void uploadPriorities( Map< String , Integer > priorities )
|
||||
{
|
||||
List< Object[] > batch = new ArrayList< Object[] >( priorities.size( ) );
|
||||
int counter = 0;
|
||||
for ( Entry< String , Integer > entry : priorities.entrySet( ) ) {
|
||||
Object[] values = new Object[] {
|
||||
entry.getKey( ) , entry.getValue( )
|
||||
};
|
||||
batch.add( counter++ , values );
|
||||
}
|
||||
this.dTemplate.batchUpdate( qUploadPriorities , batch );
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in EmpireTechnologyDAO interface */
|
||||
@Override
|
||||
public int finishPrioritiesUpdate( int empireId )
|
||||
{
|
||||
return (Integer) this.fApplyResearchPriorities.execute( empireId ).get( "error_code" );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,181 @@
|
|||
package com.deepclone.lw.beans.techs;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.deepclone.lw.cmd.player.research.ResearchOperationResponse;
|
||||
import com.deepclone.lw.cmd.player.research.ViewResearchResponse;
|
||||
import com.deepclone.lw.interfaces.game.EmpireManagement;
|
||||
import com.deepclone.lw.interfaces.game.techs.EmpireTechnologyDAO;
|
||||
import com.deepclone.lw.interfaces.game.techs.EmpireTechnologyManager;
|
||||
import com.deepclone.lw.interfaces.game.techs.TechnologyGraphManager;
|
||||
import com.deepclone.lw.interfaces.sys.ConstantDefinition;
|
||||
import com.deepclone.lw.interfaces.sys.ConstantsManager;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of the empire technology and research management component.
|
||||
*
|
||||
* @author tseeker
|
||||
*/
|
||||
@Transactional
|
||||
public class EmpireTechnologyManagerBean
|
||||
implements EmpireTechnologyManager
|
||||
{
|
||||
/** Empire management component */
|
||||
private EmpireManagement empireManager;
|
||||
|
||||
/** Data access component for empire technologies and research */
|
||||
private EmpireTechnologyDAO empireTechnologyDAO;
|
||||
|
||||
/** Technology graph management component */
|
||||
private TechnologyGraphManager techGraphManager;
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector for the empire management component.
|
||||
*
|
||||
* @param empireManager
|
||||
* the empire management component
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setEmpireManager( EmpireManagement empireManager )
|
||||
{
|
||||
this.empireManager = empireManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector for the data access component for empire technologies and research
|
||||
*
|
||||
* @param empireTechnologyDAO
|
||||
* data access component for empire technologies and research
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setEmpireTechnologyDAO( EmpireTechnologyDAO empireTechnologyDAO )
|
||||
{
|
||||
this.empireTechnologyDAO = empireTechnologyDAO;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector for the technology graph management component.
|
||||
*
|
||||
* @param techGraphManager
|
||||
* the technology graph management component
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setTechnologyGraphManager( TechnologyGraphManager techGraphManager )
|
||||
{
|
||||
this.techGraphManager = techGraphManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector which registers research-related constants into the constants manager.
|
||||
*
|
||||
* @param constantsManager
|
||||
* the constants manager component
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setConstantsManager( ConstantsManager constantsManager )
|
||||
{
|
||||
ConstantDefinition[] definitions = new ConstantDefinition[] {
|
||||
new ConstantDefinition( "game.research.minPoints" , "Research" ,
|
||||
"Minimal research points before a technology being researched is identified" , 50000.0 , 1.0 ,
|
||||
true ) ,
|
||||
new ConstantDefinition( "game.research.minRatio" , "Research" ,
|
||||
"Minimal ratio before a technology being researched is identified" , 0.75 , 0.01 , 0.99 ) ,
|
||||
new ConstantDefinition( "game.research.perPopUnit" , "Research" ,
|
||||
"Research points per population unit." , 0.50 , 0.01 , true )
|
||||
};
|
||||
constantsManager.registerConstants( Arrays.asList( definitions ) );
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in EmpireTechnologyManager interface */
|
||||
@Override
|
||||
public ViewResearchResponse getResearchData( int empireId )
|
||||
{
|
||||
return new ResearchResponseBuilder( empireId , this.empireManager , this.empireTechnologyDAO ,
|
||||
this.techGraphManager ).getResponse( );
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in EmpireTechnologyManager interface */
|
||||
@Override
|
||||
public ResearchOperationResponse implementTechnology( int empireId , String technology )
|
||||
{
|
||||
int result = this.empireTechnologyDAO.implementTechnology( empireId , technology );
|
||||
ResearchOperationResponse response;
|
||||
|
||||
if ( result == 0 ) {
|
||||
response = new ResearchOperationResponse( );
|
||||
} else {
|
||||
ResearchResponseBuilder builder = new ResearchResponseBuilder( empireId , this.empireManager ,
|
||||
this.empireTechnologyDAO , this.techGraphManager );
|
||||
switch ( result ) {
|
||||
|
||||
case 1:
|
||||
response = builder.getResponse( ResearchOperationResponse.Result.ERR_RESOURCES );
|
||||
break;
|
||||
|
||||
case 2:
|
||||
response = builder.getResponse( ResearchOperationResponse.Result.ERR_STATE_CHANGED );
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new RuntimeException( "unsupported return value " + result );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in EmpireTechnologyManager interface */
|
||||
@Override
|
||||
public ResearchOperationResponse setResearchPriorities( int empireId , Map< String , Integer > priorities )
|
||||
{
|
||||
int result;
|
||||
if ( priorities.size( ) < 2 ) {
|
||||
result = 2;
|
||||
} else {
|
||||
this.empireTechnologyDAO.startPrioritiesUpdate( );
|
||||
this.empireTechnologyDAO.uploadPriorities( priorities );
|
||||
result = this.empireTechnologyDAO.finishPrioritiesUpdate( empireId );
|
||||
}
|
||||
|
||||
ResearchOperationResponse response;
|
||||
if ( result == 0 ) {
|
||||
response = new ResearchOperationResponse( );
|
||||
} else {
|
||||
ResearchResponseBuilder builder = new ResearchResponseBuilder( empireId , this.empireManager ,
|
||||
this.empireTechnologyDAO , this.techGraphManager );
|
||||
|
||||
switch ( result ) {
|
||||
|
||||
case 1:
|
||||
response = builder.getResponse( ResearchOperationResponse.Result.ERR_STATE_CHANGED );
|
||||
break;
|
||||
|
||||
case 2:
|
||||
response = builder.getResponse( ResearchOperationResponse.Result.ERR_INVALID );
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new RuntimeException( "unsupported return value " + result );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,293 @@
|
|||
package com.deepclone.lw.beans.techs;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.deepclone.lw.cmd.admin.logs.LogLevel;
|
||||
import com.deepclone.lw.interfaces.eventlog.SystemLogger;
|
||||
import com.deepclone.lw.sqld.game.techs.ResearchStatus;
|
||||
import com.deepclone.lw.sqld.game.techs.ResearchUpdateInput;
|
||||
import com.deepclone.lw.sqld.game.techs.ResearchUpdateOutput;
|
||||
import com.deepclone.lw.sqld.game.techs.TechGraph;
|
||||
import com.deepclone.lw.sqld.game.techs.TechGraphException;
|
||||
import com.deepclone.lw.sqld.game.techs.Technology;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Research update implementation for a single empire.
|
||||
*
|
||||
* @author tseeker
|
||||
*/
|
||||
class EmpireUpdate
|
||||
{
|
||||
/** Empire identifier */
|
||||
private final int id;
|
||||
|
||||
/** Research points produced */
|
||||
private double production;
|
||||
|
||||
/** All technologies (known or being researched) */
|
||||
private final Map< String , ResearchUpdateInput > byName;
|
||||
|
||||
/** Technology names by status */
|
||||
private final Map< ResearchStatus , Set< String >> byStatus;
|
||||
|
||||
/** Output records by name */
|
||||
private final Map< String , ResearchUpdateOutput > output;
|
||||
|
||||
/** Sum of the current research priorities */
|
||||
private double totalPriority;
|
||||
|
||||
/** Amount of active research topics */
|
||||
private int activeTopics;
|
||||
|
||||
/** Parent component's logging interface */
|
||||
private SystemLogger logger;
|
||||
|
||||
|
||||
/**
|
||||
* Initialise the empire updater using the global lists of production points and research
|
||||
* statuses.
|
||||
*
|
||||
* @param logger
|
||||
* the component's logging system
|
||||
* @param empireId
|
||||
* the empire for whom the research update is to be computed
|
||||
* @param production
|
||||
* the map of production points for all empires in the batch
|
||||
* @param status
|
||||
* the list of statuses for all empires in the batch
|
||||
*/
|
||||
EmpireUpdate( SystemLogger logger , int empireId , Map< Integer , Double > production ,
|
||||
HashMap< Integer , List< ResearchUpdateInput >> status )
|
||||
{
|
||||
this.id = empireId;
|
||||
this.production = production.get( this.id );
|
||||
this.logger = logger;
|
||||
|
||||
this.byName = new HashMap< String , ResearchUpdateInput >( );
|
||||
this.output = new HashMap< String , ResearchUpdateOutput >( );
|
||||
|
||||
this.byStatus = new EnumMap< ResearchStatus , Set< String > >( ResearchStatus.class );
|
||||
this.byStatus.put( ResearchStatus.IN_PROGRESS , new HashSet< String >( ) );
|
||||
this.byStatus.put( ResearchStatus.RESEARCHED , new HashSet< String >( ) );
|
||||
this.byStatus.put( ResearchStatus.IMPLEMENTED , new HashSet< String >( ) );
|
||||
|
||||
// Initialise sets and maps
|
||||
List< ResearchUpdateInput > empStatus = status.get( this.id );
|
||||
if ( empStatus != null ) {
|
||||
for ( ResearchUpdateInput entry : status.get( this.id ) ) {
|
||||
this.byName.put( entry.getTechnology( ) , entry );
|
||||
this.byStatus.get( entry.getStatus( ) ).add( entry.getTechnology( ) );
|
||||
}
|
||||
this.logger.flush( );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform the research update, filling the {@link #output} map.
|
||||
*
|
||||
* @param techGraph
|
||||
* the technology graph
|
||||
* @throws TechGraphException
|
||||
* indicates an internal error
|
||||
*/
|
||||
void compute( TechGraph techGraph )
|
||||
throws TechGraphException
|
||||
{
|
||||
if ( this.production == 0 ) {
|
||||
return;
|
||||
}
|
||||
this.prepareOutput( );
|
||||
|
||||
List< Technology > newResearch = this.findNewTechnologies( techGraph );
|
||||
if ( !newResearch.isEmpty( ) ) {
|
||||
this.addResearch( newResearch );
|
||||
}
|
||||
if ( this.output.isEmpty( ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
List< String > inProgress = new LinkedList< String >( this.output.keySet( ) );
|
||||
for ( String resName : inProgress ) {
|
||||
this.researchProgress( techGraph.getTechnology( resName ) , resName );
|
||||
}
|
||||
|
||||
this.updatePriorities( );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Copy information from the list of research to the output map.
|
||||
*/
|
||||
private void prepareOutput( )
|
||||
{
|
||||
this.totalPriority = 0;
|
||||
for ( ResearchUpdateInput entry : this.byName.values( ) ) {
|
||||
if ( entry.getStatus( ) != ResearchStatus.IN_PROGRESS ) {
|
||||
continue;
|
||||
}
|
||||
this.output.put( entry.getTechnology( ) , new ResearchUpdateOutput( this.id , entry.getTechnology( ) ,
|
||||
false , entry.getPoints( ) , entry.getPriority( ) ) );
|
||||
this.totalPriority += entry.getPriority( );
|
||||
}
|
||||
this.activeTopics = this.byStatus.get( ResearchStatus.IN_PROGRESS ).size( );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find new technologies to research
|
||||
*
|
||||
* XXX: we shouldn't be doing that at every update; it's only required if the techs were added
|
||||
* or deleted, if dependencies were changed or if the empire implemented a technology.
|
||||
*
|
||||
* @param techGraph
|
||||
* the technology graph
|
||||
* @return the list of technologies on which research can start
|
||||
* @throws TechGraphException
|
||||
* indicates an internal error
|
||||
*/
|
||||
private List< Technology > findNewTechnologies( TechGraph techGraph )
|
||||
throws TechGraphException
|
||||
{
|
||||
LinkedList< Technology > newResearch = new LinkedList< Technology >( );
|
||||
Set< String > implemented = this.byStatus.get( ResearchStatus.IMPLEMENTED );
|
||||
if ( implemented == null ) {
|
||||
throw new RuntimeException( "wtf?!" );
|
||||
}
|
||||
for ( String catName : techGraph.getCategories( ) ) {
|
||||
for ( String techName : techGraph.getCategory( catName ).getTechnologies( ) ) {
|
||||
// Check if the empire "knows" of the tech
|
||||
if ( this.byName.containsKey( techName ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check dependencies
|
||||
Technology tech = techGraph.getTechnology( techName );
|
||||
boolean mayStart = true;
|
||||
for ( String depName : tech.getDependencies( ) ) {
|
||||
if ( !implemented.contains( depName ) ) {
|
||||
mayStart = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( mayStart ) {
|
||||
newResearch.add( tech );
|
||||
}
|
||||
}
|
||||
}
|
||||
return newResearch;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add new entries to the list of current research topics and updates the total priority
|
||||
* accordingly.
|
||||
*
|
||||
* @param newResearch
|
||||
* the list of research topics to add
|
||||
*/
|
||||
private void addResearch( List< Technology > newResearch )
|
||||
{
|
||||
int increment;
|
||||
if ( this.totalPriority == 0 ) {
|
||||
increment = 1;
|
||||
} else {
|
||||
increment = (int) Math.ceil( this.totalPriority / this.activeTopics );
|
||||
}
|
||||
|
||||
for ( Technology tech : newResearch ) {
|
||||
this.output.put( tech.getName( ) , new ResearchUpdateOutput( this.id , tech.getName( ) , true , 0 ,
|
||||
increment ) );
|
||||
this.totalPriority += increment;
|
||||
}
|
||||
this.activeTopics += newResearch.size( );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update the progress on a research topic.
|
||||
*
|
||||
* @param technology
|
||||
* the technology's definition
|
||||
* @param name
|
||||
* the name of the research topic
|
||||
*/
|
||||
private void researchProgress( Technology technology , String name )
|
||||
{
|
||||
ResearchUpdateOutput entry = this.output.get( name );
|
||||
if ( entry.getPriority( ) == 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
double points = this.production * entry.getPriority( ) / this.totalPriority;
|
||||
double total = points + entry.getPoints( );
|
||||
|
||||
if ( total >= technology.getPoints( ) ) {
|
||||
this.totalPriority -= entry.getPriority( );
|
||||
this.production = this.production + total - entry.getPoints( );
|
||||
this.output.put( name , new ResearchUpdateOutput( this.id , name ) );
|
||||
this.activeTopics--;
|
||||
} else {
|
||||
entry.addPoints( points );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update priorities of active research topics in the output map.
|
||||
*/
|
||||
private void updatePriorities( )
|
||||
{
|
||||
if ( this.activeTopics == 0 || this.totalPriority == 100 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
List< ResearchUpdateOutput > progress = new LinkedList< ResearchUpdateOutput >( );
|
||||
int newTotal = 0;
|
||||
for ( ResearchUpdateOutput update : this.output.values( ) ) {
|
||||
Integer prio = update.getPriority( );
|
||||
if ( prio == null ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int newValue = (int) Math.floor( 100.0 * prio / this.totalPriority );
|
||||
progress.add( update );
|
||||
update.setPriority( newValue );
|
||||
newTotal += newValue;
|
||||
}
|
||||
|
||||
// Distribute the rest of the points
|
||||
while ( newTotal < 100 ) {
|
||||
for ( ResearchUpdateOutput update : progress ) {
|
||||
update.setPriority( update.getPriority( ) + 1 );
|
||||
newTotal++;
|
||||
if ( newTotal == 100 ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
this.logger.flush( );
|
||||
}
|
||||
|
||||
|
||||
/** @return the update output records */
|
||||
Collection< ResearchUpdateOutput > getOutput( )
|
||||
{
|
||||
if ( !this.output.isEmpty( ) ) {
|
||||
this.logger.log( LogLevel.TRACE , "Empire " + this.id + " - " + this.output.size( ) + " update(s)" )
|
||||
.flush( );
|
||||
}
|
||||
return this.output.values( );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,280 @@
|
|||
package com.deepclone.lw.beans.techs;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.deepclone.lw.cmd.player.gdata.GamePageData;
|
||||
import com.deepclone.lw.cmd.player.gdata.empire.ResearchData;
|
||||
import com.deepclone.lw.cmd.player.gdata.empire.TechnologyCategoryData;
|
||||
import com.deepclone.lw.cmd.player.gdata.empire.TechnologyData;
|
||||
import com.deepclone.lw.cmd.player.research.ResearchOperationResponse;
|
||||
import com.deepclone.lw.cmd.player.research.ViewResearchResponse;
|
||||
import com.deepclone.lw.cmd.player.research.ResearchOperationResponse.Result;
|
||||
import com.deepclone.lw.interfaces.game.EmpireManagement;
|
||||
import com.deepclone.lw.interfaces.game.techs.EmpireTechnologyDAO;
|
||||
import com.deepclone.lw.interfaces.game.techs.TechnologyGraphManager;
|
||||
import com.deepclone.lw.interfaces.i18n.LanguageTranslator;
|
||||
import com.deepclone.lw.interfaces.i18n.UnknownStringException;
|
||||
import com.deepclone.lw.sqld.game.techs.Category;
|
||||
import com.deepclone.lw.sqld.game.techs.EmpireTechnology;
|
||||
import com.deepclone.lw.sqld.game.techs.ResearchStatus;
|
||||
import com.deepclone.lw.sqld.game.techs.TechGraph;
|
||||
import com.deepclone.lw.sqld.game.techs.TechGraphException;
|
||||
import com.deepclone.lw.sqld.game.techs.Technology;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Class that builds {@link ViewResearchResponse} or {@link ResearchOperationResponse} instances.
|
||||
*
|
||||
* @author tseeker
|
||||
*/
|
||||
class ResearchResponseBuilder
|
||||
{
|
||||
|
||||
/** Empire identifier */
|
||||
private final int empireId;
|
||||
|
||||
/** Empire management component */
|
||||
private final EmpireManagement empireManager;
|
||||
|
||||
/** Technology and research data access component */
|
||||
private final EmpireTechnologyDAO empireTechnologyDAO;
|
||||
|
||||
/** Technology graph management component */
|
||||
private final TechnologyGraphManager techGraphManager;
|
||||
|
||||
/** Game page data */
|
||||
private GamePageData pageData;
|
||||
|
||||
/** List of current research topics */
|
||||
private List< ResearchData > research;
|
||||
|
||||
/** Lists of implemented technologies by category */
|
||||
private Map< String , List< TechnologyData > > implementedMap;
|
||||
|
||||
/** Final list of implemented technologies */
|
||||
private List< TechnologyCategoryData > implementedLists;
|
||||
|
||||
/** All implemented technologies by identifier */
|
||||
private Map< String , TechnologyData > implementedById;
|
||||
|
||||
|
||||
/**
|
||||
* Initialise the response builder by setting the empire identifier and the various components
|
||||
* that may be required to generate the response.
|
||||
*
|
||||
* @param empireId
|
||||
* the empire identifier
|
||||
* @param empireManager
|
||||
* the empire management component
|
||||
* @param empireTechnologyDAO
|
||||
* the technology and research data access component
|
||||
* @param techGraphManager
|
||||
* the technology graph management component
|
||||
*/
|
||||
ResearchResponseBuilder( int empireId , EmpireManagement empireManager , EmpireTechnologyDAO empireTechnologyDAO ,
|
||||
TechnologyGraphManager techGraphManager )
|
||||
{
|
||||
this.empireId = empireId;
|
||||
this.empireManager = empireManager;
|
||||
this.empireTechnologyDAO = empireTechnologyDAO;
|
||||
this.techGraphManager = techGraphManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build a basic research view response.
|
||||
*
|
||||
* @return the research view response.
|
||||
*/
|
||||
ViewResearchResponse getResponse( )
|
||||
{
|
||||
try {
|
||||
this.buildResponseContents( );
|
||||
} catch ( Exception e ) {
|
||||
throw new RuntimeException( "internal error while processing research data" , e );
|
||||
}
|
||||
return new ViewResearchResponse( this.pageData , this.research , this.implementedLists );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build a research operation response.
|
||||
*
|
||||
* @param errorCode
|
||||
* the operation's error code (should not be
|
||||
* {@link ResearchOperationResponse.Result#OK}).
|
||||
* @return the research operation response.
|
||||
*/
|
||||
ResearchOperationResponse getResponse( Result errorCode )
|
||||
{
|
||||
try {
|
||||
this.buildResponseContents( );
|
||||
} catch ( Exception e ) {
|
||||
throw new RuntimeException( "internal error while processing research data" , e );
|
||||
}
|
||||
return new ResearchOperationResponse( this.pageData , this.research , this.implementedLists , errorCode );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build the lists and records required by research view or operation responses. This includes
|
||||
* the list of current research topics as well as the list of implemented technologies.
|
||||
*
|
||||
* @throws UnknownStringException
|
||||
* if there is an incoherence between the tech graph and the translations database.
|
||||
* @throws TechGraphException
|
||||
* if there is an incoherence between the empire research records and the tech
|
||||
* graph.
|
||||
*/
|
||||
private void buildResponseContents( )
|
||||
throws UnknownStringException , TechGraphException
|
||||
{
|
||||
LanguageTranslator translator = this.empireManager.getTranslator( this.empireId );
|
||||
TechGraph techGraph = this.techGraphManager.getGraph( );
|
||||
|
||||
this.research = new LinkedList< ResearchData >( );
|
||||
this.implementedMap = new HashMap< String , List< TechnologyData > >( );
|
||||
this.implementedById = new HashMap< String , TechnologyData >( );
|
||||
|
||||
for ( EmpireTechnology record : this.empireTechnologyDAO.getTechnologies( this.empireId ) ) {
|
||||
if ( record.getStatus( ) == ResearchStatus.IMPLEMENTED ) {
|
||||
this.addImplemented( record , translator , techGraph );
|
||||
} else {
|
||||
this.addResearchData( record , translator , techGraph );
|
||||
}
|
||||
}
|
||||
|
||||
this.pageData = this.empireManager.getGeneralInformation( this.empireId );
|
||||
Collections.sort( this.research );
|
||||
this.postProcessImplemented( translator , techGraph );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add an implemented technology record.
|
||||
*
|
||||
* @param record
|
||||
* the original record as returned by the {@link EmpireTechnologyDAO}.
|
||||
* @param translator
|
||||
* the translator for the empire's language
|
||||
* @param techGraph
|
||||
* the technology graph
|
||||
*
|
||||
* @throws TechGraphException
|
||||
* if there is an incoherence between the empire research records and the tech
|
||||
* graph.
|
||||
* @throws UnknownStringException
|
||||
* if there is an incoherence between the tech graph and the translations database.
|
||||
*/
|
||||
private void addImplemented( EmpireTechnology record , LanguageTranslator translator , TechGraph techGraph )
|
||||
throws TechGraphException , UnknownStringException
|
||||
{
|
||||
String techId = record.getIdentifier( );
|
||||
Technology tech = techGraph.getTechnology( techId );
|
||||
Category category = tech.getCategory( );
|
||||
|
||||
List< TechnologyData > catTechs = this.implementedMap.get( category.getName( ) );
|
||||
if ( catTechs == null ) {
|
||||
catTechs = new LinkedList< TechnologyData >( );
|
||||
this.implementedMap.put( category.getName( ) , catTechs );
|
||||
}
|
||||
|
||||
TechnologyData tData;
|
||||
String name = translator.translate( techId );
|
||||
String description = translator.translate( tech.getDescription( ) );
|
||||
tData = new TechnologyData( techId , name , description , tech.getDependencies( ) , new LinkedList< String >( ) );
|
||||
|
||||
catTechs.add( tData );
|
||||
this.implementedById.put( techId , tData );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a research topic record.
|
||||
*
|
||||
* @param record
|
||||
* the original record as returned by the {@link EmpireTechnologyDAO}.
|
||||
* @param translator
|
||||
* the translator for the empire's language
|
||||
* @param techGraph
|
||||
* the technology graph
|
||||
*
|
||||
* @throws TechGraphException
|
||||
* if there is an incoherence between the empire research records and the tech
|
||||
* graph.
|
||||
* @throws UnknownStringException
|
||||
* if there is an incoherence between the tech graph and the translations database.
|
||||
*/
|
||||
private void addResearchData( EmpireTechnology record , LanguageTranslator translator , TechGraph techGraph )
|
||||
throws TechGraphException , UnknownStringException
|
||||
{
|
||||
String techId = record.getIdentifier( );
|
||||
Technology tech = techGraph.getTechnology( techId );
|
||||
String category = translator.translate( tech.getCategory( ).getName( ) );
|
||||
|
||||
ResearchData rData;
|
||||
|
||||
if ( !record.isDetailed( ) ) {
|
||||
rData = new ResearchData( record.getNumericId( ) , category , record.getPercentage( ) , record
|
||||
.getPriority( ) );
|
||||
} else {
|
||||
String name = translator.translate( techId );
|
||||
String description = translator.translate( tech.getDescription( ) );
|
||||
String[] dependencies = tech.getDependencies( ).toArray( new String[] { } );
|
||||
if ( record.getStatus( ) == ResearchStatus.RESEARCHED ) {
|
||||
rData = new ResearchData( techId , category , name , description , dependencies , (int) tech.getCost( ) );
|
||||
} else {
|
||||
rData = new ResearchData( techId , category , name , description , dependencies , record
|
||||
.getPercentage( ) , record.getPriority( ) );
|
||||
}
|
||||
}
|
||||
|
||||
this.research.add( rData );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Post-process implemented technologies by adding reverse dependencies, sorting each list, and
|
||||
* generating the sorted list of technology categories.
|
||||
*
|
||||
* @param translator
|
||||
* the translator for the empire's language
|
||||
* @param techGraph
|
||||
* the technology graph
|
||||
*
|
||||
* @throws TechGraphException
|
||||
* if there is an incoherence between the empire research records and the tech
|
||||
* graph.
|
||||
* @throws UnknownStringException
|
||||
* if there is an incoherence between the tech graph and the translations database.
|
||||
*/
|
||||
private void postProcessImplemented( LanguageTranslator translator , TechGraph techGraph )
|
||||
throws UnknownStringException , TechGraphException
|
||||
{
|
||||
this.implementedLists = new LinkedList< TechnologyCategoryData >( );
|
||||
for ( String catId : this.implementedMap.keySet( ) ) {
|
||||
|
||||
List< TechnologyData > techs = this.implementedMap.get( catId );
|
||||
for ( TechnologyData tData : techs ) {
|
||||
for ( String dependency : tData.getDependsOn( ) ) {
|
||||
TechnologyData depData = this.implementedById.get( dependency );
|
||||
if ( depData != null ) {
|
||||
depData.getDependencyOf( ).add( tData.getIdentifier( ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort( techs );
|
||||
|
||||
String catName = translator.translate( catId );
|
||||
String catDesc = translator.translate( techGraph.getCategory( catId ).getDescription( ) );
|
||||
this.implementedLists.add( new TechnologyCategoryData( catName , catDesc , techs ) );
|
||||
}
|
||||
Collections.sort( this.implementedLists );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,180 @@
|
|||
package com.deepclone.lw.beans.techs;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.deepclone.lw.interfaces.eventlog.Logger;
|
||||
import com.deepclone.lw.interfaces.eventlog.SystemLogger;
|
||||
import com.deepclone.lw.interfaces.game.techs.ResearchUpdateDAO;
|
||||
import com.deepclone.lw.interfaces.game.techs.TechnologyGraphManager;
|
||||
import com.deepclone.lw.interfaces.game.updates.GameUpdate;
|
||||
import com.deepclone.lw.interfaces.game.updates.GameUpdatePhase;
|
||||
import com.deepclone.lw.interfaces.game.updates.GameUpdatePhaseHandler;
|
||||
import com.deepclone.lw.interfaces.game.updates.UpdatesDAO;
|
||||
import com.deepclone.lw.sqld.game.techs.ResearchUpdateInput;
|
||||
import com.deepclone.lw.sqld.game.techs.ResearchUpdateOutput;
|
||||
import com.deepclone.lw.sqld.game.techs.TechGraph;
|
||||
import com.deepclone.lw.sqld.game.techs.TechGraphException;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Component responsible for updating empires' research status.
|
||||
*
|
||||
* @author tseeker
|
||||
*/
|
||||
public class ResearchUpdateBean
|
||||
implements GameUpdatePhaseHandler
|
||||
{
|
||||
/** The component's logging interface */
|
||||
private SystemLogger logger;
|
||||
|
||||
/** The technology graph management component */
|
||||
private TechnologyGraphManager techGraphManager;
|
||||
|
||||
/** The current technology graph */
|
||||
private TechGraph techGraph;
|
||||
|
||||
/** The main game update data access component */
|
||||
private UpdatesDAO updatesDAO;
|
||||
|
||||
/** The research updates data access component */
|
||||
private ResearchUpdateDAO researchUpdateDAO;
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector that initialises the component's logging interface.
|
||||
*
|
||||
* @param logger
|
||||
* the system logger
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setLogger( Logger logger )
|
||||
{
|
||||
this.logger = logger.getSystemLogger( "ResearchUpdate" );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector for the technology graph management component.
|
||||
*
|
||||
* @param techGraphManager
|
||||
* the technology graph management component
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setTechGraphManager( TechnologyGraphManager techGraphManager )
|
||||
{
|
||||
this.techGraphManager = techGraphManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector that sets the main game update data access component.
|
||||
*
|
||||
* @param updatesDAO
|
||||
* the main game update data access component
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setUpdatesDAO( UpdatesDAO updatesDAO )
|
||||
{
|
||||
this.updatesDAO = updatesDAO;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector that sets the research updates data access component
|
||||
*
|
||||
* @param researchUpdateDAO
|
||||
* the research updates data access component
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setResearchUpdateDAO( ResearchUpdateDAO researchUpdateDAO )
|
||||
{
|
||||
this.researchUpdateDAO = researchUpdateDAO;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector that registers the handler with the main game update manager
|
||||
*
|
||||
* @param updateManager
|
||||
* the game update manager
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setUpdateManager( GameUpdate updateManager )
|
||||
{
|
||||
updateManager.registerHandler( this );
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in GameUpdatePhaseHandler interface */
|
||||
@Override
|
||||
public GameUpdatePhase getPhase( )
|
||||
{
|
||||
return GameUpdatePhase.EMPIRE_RESEARCH;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a copy of the technology graph when the update phase starts.
|
||||
*/
|
||||
@Override
|
||||
public void onPhaseStart( long updateId )
|
||||
{
|
||||
this.techGraph = this.techGraphManager.getGraph( );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* If there are research updates left to process, lock the records, then obtain all relevant
|
||||
* data, process each empire using {@link EmpireUpdate}, and send the updates to the database.
|
||||
*/
|
||||
@Override
|
||||
public boolean updateGame( long updateId )
|
||||
{
|
||||
// Look for records to update
|
||||
if ( !this.updatesDAO.prepareUpdates( updateId , this.getPhase( ) ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Map< Integer , Double > production;
|
||||
HashMap< Integer , List< ResearchUpdateInput >> status;
|
||||
status = new HashMap< Integer , List< ResearchUpdateInput > >( );
|
||||
|
||||
// Prepare update and load input
|
||||
this.researchUpdateDAO.prepareUpdate( updateId );
|
||||
production = this.researchUpdateDAO.getResearchPoints( updateId );
|
||||
for ( ResearchUpdateInput input : this.researchUpdateDAO.getUpdateData( updateId ) ) {
|
||||
List< ResearchUpdateInput > eStatus = status.get( input.getEmpireId( ) );
|
||||
if ( eStatus == null ) {
|
||||
eStatus = new LinkedList< ResearchUpdateInput >( );
|
||||
status.put( input.getEmpireId( ) , eStatus );
|
||||
}
|
||||
eStatus.add( input );
|
||||
}
|
||||
|
||||
// Handle the update for each empire
|
||||
List< ResearchUpdateOutput > output = new LinkedList< ResearchUpdateOutput >( );
|
||||
for ( int empireId : production.keySet( ) ) {
|
||||
EmpireUpdate update = new EmpireUpdate( this.logger , empireId , production , status );
|
||||
try {
|
||||
update.compute( this.techGraph );
|
||||
} catch ( TechGraphException e ) {
|
||||
throw new RuntimeException( "incoherent technology graph" , e );
|
||||
}
|
||||
output.addAll( update.getOutput( ) );
|
||||
}
|
||||
|
||||
// Send and validate updates
|
||||
this.researchUpdateDAO.submitUpdateData( output );
|
||||
this.updatesDAO.validateUpdatedRecords( updateId , GameUpdatePhase.EMPIRE_RESEARCH );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
package com.deepclone.lw.beans.techs;
|
||||
|
||||
|
||||
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;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
|
||||
|
||||
import com.deepclone.lw.interfaces.game.techs.ResearchUpdateDAO;
|
||||
import com.deepclone.lw.sqld.game.techs.ResearchUpdateInput;
|
||||
import com.deepclone.lw.sqld.game.techs.ResearchUpdateOutput;
|
||||
import com.deepclone.lw.utils.StoredProc;
|
||||
|
||||
|
||||
|
||||
public class ResearchUpdateDAOBean
|
||||
implements ResearchUpdateDAO
|
||||
{
|
||||
/** Query that reads research update input */
|
||||
private static final String qGetInput = "SELECT * FROM emp.research_update_input_view WHERE update_id = ?";
|
||||
|
||||
/** Query that reads empire research points production */
|
||||
private static final String qGetPoints = "SELECT * FROM emp.research_points_production WHERE update_id = ?";
|
||||
|
||||
/** Query that adds a record to the output */
|
||||
private static final String qAddOutput = "INSERT INTO research_update_output "
|
||||
+ "(empire_id , technology , creation , points , priority) "
|
||||
+ "VALUES ( :empireId , :technology , :creation , :points , :priority )";
|
||||
|
||||
/** Query that submits the update */
|
||||
private static final String qSubmitUpdate = "SELECT emp.submit_research_update( )";
|
||||
|
||||
/** Data source access */
|
||||
private SimpleJdbcTemplate dTemplate;
|
||||
|
||||
/** Wrapper for the stored procedure that prepares the database for update */
|
||||
private StoredProc fPrepareUpdate;
|
||||
|
||||
/** Row mapper for research update input */
|
||||
RowMapper< ResearchUpdateInput > ruiMapper;
|
||||
|
||||
|
||||
/**
|
||||
* Initialise the component's row mapper.
|
||||
*/
|
||||
public ResearchUpdateDAOBean( )
|
||||
{
|
||||
this.ruiMapper = new RowMapper< ResearchUpdateInput >( ) {
|
||||
@Override
|
||||
public ResearchUpdateInput mapRow( ResultSet rs , int rowNum )
|
||||
throws SQLException
|
||||
{
|
||||
int empireId = rs.getInt( "empire_id" );
|
||||
String technology = rs.getString( "technology" );
|
||||
|
||||
Boolean implemented = (Boolean) rs.getObject( "implemented" );
|
||||
if ( implemented == null ) {
|
||||
double points = rs.getDouble( "points" );
|
||||
int priority = rs.getInt( "priority" );
|
||||
return new ResearchUpdateInput( empireId , technology , points , priority );
|
||||
}
|
||||
|
||||
return new ResearchUpdateInput( empireId , technology , implemented );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector that initialises the component's database access and stored procedure
|
||||
* wrappers.
|
||||
*
|
||||
* @param dataSource
|
||||
* the data source
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dTemplate = new SimpleJdbcTemplate( dataSource );
|
||||
|
||||
// Stored procedure that prepares the database for update
|
||||
this.fPrepareUpdate = new StoredProc( dataSource , "emp" , "prepare_research_update" );
|
||||
this.fPrepareUpdate.addParameter( "update_id" , Types.BIGINT );
|
||||
}
|
||||
|
||||
|
||||
/* Documented in ResearchUpdateDAO interface */
|
||||
@Override
|
||||
public void prepareUpdate( long updateId )
|
||||
{
|
||||
this.fPrepareUpdate.execute( updateId );
|
||||
}
|
||||
|
||||
|
||||
/* Documented in ResearchUpdateDAO interface */
|
||||
@Override
|
||||
public List< ResearchUpdateInput > getUpdateData( long updateId )
|
||||
{
|
||||
return this.dTemplate.query( qGetInput , this.ruiMapper , updateId );
|
||||
}
|
||||
|
||||
|
||||
/* Documented in ResearchUpdateDAO interface */
|
||||
@Override
|
||||
public Map< Integer , Double > getResearchPoints( long updateId )
|
||||
{
|
||||
Map< Integer , Double > result = new HashMap< Integer , Double >( );
|
||||
|
||||
for ( Map< String , Object > row : this.dTemplate.queryForList( qGetPoints , updateId ) ) {
|
||||
result.put( (Integer) row.get( "empire_id" ) , (Double) row.get( "points" ) );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* Documented in ResearchUpdateDAO interface */
|
||||
@Override
|
||||
public void submitUpdateData( List< ResearchUpdateOutput > output )
|
||||
{
|
||||
if ( !output.isEmpty( ) ) {
|
||||
SqlParameterSource[] batch = SqlParameterSourceUtils.createBatch( output.toArray( ) );
|
||||
this.dTemplate.batchUpdate( qAddOutput , batch );
|
||||
}
|
||||
this.dTemplate.queryForList( qSubmitUpdate );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
package com.deepclone.lw.beans.techs;
|
||||
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowCallbackHandler;
|
||||
|
||||
import com.deepclone.lw.interfaces.game.techs.TechnologyGraphDAO;
|
||||
import com.deepclone.lw.sqld.game.techs.TechGraph;
|
||||
import com.deepclone.lw.sqld.game.techs.TechGraphException;
|
||||
|
||||
|
||||
|
||||
public class TechnologyGraphDAOBean
|
||||
implements TechnologyGraphDAO
|
||||
{
|
||||
private static final String qGetCategories = "SELECT name , description FROM tech.categories_view";
|
||||
private static final String qGetTechnologies = "SELECT category , name , description , points , cost FROM tech.technologies_view";
|
||||
private static final String qGetDependencies = "SELECT technology , dependency FROM tech.dependencies_view";
|
||||
|
||||
private static abstract class TechGraphDBHandler
|
||||
implements RowCallbackHandler
|
||||
{
|
||||
TechGraph graph;
|
||||
TechGraphException error;
|
||||
|
||||
|
||||
public TechGraphDBHandler( )
|
||||
{
|
||||
// EMPTY
|
||||
}
|
||||
|
||||
|
||||
public final void setGraph( TechGraph graph )
|
||||
{
|
||||
this.graph = graph;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final void processRow( ResultSet rs )
|
||||
throws SQLException
|
||||
{
|
||||
if ( this.error != null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.extractData( rs );
|
||||
} catch ( TechGraphException e ) {
|
||||
this.error = e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected abstract void extractData( ResultSet rs )
|
||||
throws TechGraphException , SQLException;
|
||||
|
||||
}
|
||||
|
||||
private static class CategoryExtractor
|
||||
extends TechGraphDBHandler
|
||||
{
|
||||
@Override
|
||||
protected void extractData( ResultSet rs )
|
||||
throws TechGraphException , SQLException
|
||||
{
|
||||
this.graph.addCategory( rs.getString( "name" ) , rs.getString( "description" ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class TechnologyExtractor
|
||||
extends TechGraphDBHandler
|
||||
{
|
||||
@Override
|
||||
protected void extractData( ResultSet rs )
|
||||
throws TechGraphException , SQLException
|
||||
{
|
||||
this.graph.addTechnology( rs.getString( "category" ) , rs.getString( "name" ) , rs
|
||||
.getString( "description" ) , rs.getInt( "points" ) , rs.getInt( "cost" ) );
|
||||
}
|
||||
}
|
||||
|
||||
private static class DependencyExtractor
|
||||
extends TechGraphDBHandler
|
||||
{
|
||||
@Override
|
||||
protected void extractData( ResultSet rs )
|
||||
throws TechGraphException , SQLException
|
||||
{
|
||||
this.graph.addDependency( rs.getString( "technology" ) , rs.getString( "dependency" ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private JdbcTemplate dTemplate;
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
this.dTemplate = new JdbcTemplate( dataSource );
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TechGraph loadGraph( )
|
||||
throws TechGraphException
|
||||
{
|
||||
TechGraph result = new TechGraph( );
|
||||
this.extractGraphData( result , new CategoryExtractor( ) , qGetCategories );
|
||||
this.extractGraphData( result , new TechnologyExtractor( ) , qGetTechnologies );
|
||||
this.extractGraphData( result , new DependencyExtractor( ) , qGetDependencies );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private void extractGraphData( TechGraph graph , TechGraphDBHandler extractor , String query )
|
||||
throws TechGraphException
|
||||
{
|
||||
extractor.setGraph( graph );
|
||||
this.dTemplate.query( query , extractor );
|
||||
if ( extractor.error != null ) {
|
||||
throw extractor.error;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.deepclone.lw.beans.techs;
|
||||
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.deepclone.lw.cmd.admin.techs.TechCategory;
|
||||
import com.deepclone.lw.interfaces.game.techs.TechnologyGraphDAO;
|
||||
import com.deepclone.lw.interfaces.game.techs.TechnologyGraphManager;
|
||||
import com.deepclone.lw.sqld.game.techs.Category;
|
||||
import com.deepclone.lw.sqld.game.techs.TechGraph;
|
||||
import com.deepclone.lw.sqld.game.techs.TechGraphException;
|
||||
|
||||
|
||||
|
||||
@Transactional
|
||||
public class TechnologyGraphManagerBean
|
||||
implements TechnologyGraphManager
|
||||
{
|
||||
private TechGraph graph;
|
||||
private TechnologyGraphDAO technologyGraphDAO;
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setTechGraphDAO( TechnologyGraphDAO technologyGraphDAO )
|
||||
{
|
||||
this.technologyGraphDAO = technologyGraphDAO;
|
||||
}
|
||||
|
||||
|
||||
private void loadGraph( )
|
||||
throws TechGraphException
|
||||
{
|
||||
if ( this.graph == null ) {
|
||||
this.graph = this.technologyGraphDAO.loadGraph( );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Documented in TechnologyGraphManager interface */
|
||||
@Override
|
||||
public TechGraph getGraph( )
|
||||
{
|
||||
try {
|
||||
this.loadGraph( );
|
||||
} catch ( TechGraphException e ) {
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
return new TechGraph( this.graph );
|
||||
}
|
||||
|
||||
|
||||
/* Documented in TechnologyGraphManager interface */
|
||||
@Override
|
||||
public List< TechCategory > listCategories( )
|
||||
{
|
||||
try {
|
||||
this.loadGraph( );
|
||||
|
||||
List< TechCategory > result = new LinkedList< TechCategory >( );
|
||||
for ( String catName : this.graph.getCategories( ) ) {
|
||||
Category cat = this.graph.getCategory( catName );
|
||||
result.add( new TechCategory( catName , cat.getDescription( ) , cat.getTechnologies( ) ) );
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch ( TechGraphException e ) {
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?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">
|
||||
|
||||
<import resource="techs/empire-technology-dao-bean.xml" />
|
||||
<import resource="techs/empire-technology-manager-bean.xml" />
|
||||
<import resource="techs/research-update-bean.xml" />
|
||||
<import resource="techs/research-update-dao-bean.xml" />
|
||||
<import resource="techs/technology-graph-dao-bean.xml" />
|
||||
<import resource="techs/technology-graph-manager-bean.xml" />
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,8 @@
|
|||
<?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="empireTechnologyDAO" class="com.deepclone.lw.beans.techs.EmpireTechnologyDAOBean" />
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,8 @@
|
|||
<?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="empireTechnologyManager" class="com.deepclone.lw.beans.techs.EmpireTechnologyManagerBean" />
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,8 @@
|
|||
<?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="researchUpdate" class="com.deepclone.lw.beans.techs.ResearchUpdateBean" />
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,8 @@
|
|||
<?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="researchUpdateDAO" class="com.deepclone.lw.beans.techs.ResearchUpdateDAOBean" />
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,8 @@
|
|||
<?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="technologyGraphDAO" class="com.deepclone.lw.beans.techs.TechnologyGraphDAOBean" />
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,8 @@
|
|||
<?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="technologyGraphManager" class="com.deepclone.lw.beans.techs.TechnologyGraphManagerBean" />
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>legacyworlds-server-beans-updates</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.maven.ide.eclipse.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,6 @@
|
|||
#Tue Mar 29 13:49:47 CEST 2011
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
|
@ -0,0 +1,9 @@
|
|||
#Tue Mar 29 13:49:47 CEST 2011
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
fullBuildGoals=process-test-resources
|
||||
includeModules=false
|
||||
resolveWorkspaceProjects=true
|
||||
resourceFilterGoals=process-resources resources\:testResources
|
||||
skipCompilerPlugin=true
|
||||
version=1
|
|
@ -0,0 +1,13 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>legacyworlds-server-beans</artifactId>
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<version>5.99.2</version>
|
||||
</parent>
|
||||
<groupId>com.deepclone.lw</groupId>
|
||||
<artifactId>legacyworlds-server-beans-updates</artifactId>
|
||||
<version>5.99.2</version>
|
||||
<name>Legacy Worlds updates and pre-computation management</name>
|
||||
<description>This Maven module contains the components which implement both the game's "standard", per-minute update system as well as the pre-computation manager.</description>
|
||||
</project>
|
|
@ -0,0 +1,367 @@
|
|||
package com.deepclone.lw.beans.updates;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
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.updates.DuplicateUpdateHandler;
|
||||
import com.deepclone.lw.interfaces.game.updates.GameUpdate;
|
||||
import com.deepclone.lw.interfaces.game.updates.GameUpdatePhase;
|
||||
import com.deepclone.lw.interfaces.game.updates.GameUpdatePhaseHandler;
|
||||
import com.deepclone.lw.interfaces.game.updates.UpdatesDAO;
|
||||
import com.deepclone.lw.interfaces.sys.ConstantDefinition;
|
||||
import com.deepclone.lw.interfaces.sys.ConstantsManager;
|
||||
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;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of the game update management component.
|
||||
*
|
||||
* @author tseeker
|
||||
*/
|
||||
public class GameUpdateBean
|
||||
implements GameUpdate , InitializingBean , Runnable , ApplicationContextAware
|
||||
{
|
||||
/** The event scheduling component */
|
||||
private Ticker ticker;
|
||||
|
||||
/** The system status access and update component */
|
||||
private SystemStatus systemStatus;
|
||||
|
||||
/** The game update component's logger */
|
||||
private SystemLogger logger;
|
||||
|
||||
/** Transaction template */
|
||||
private TransactionTemplate tTemplate;
|
||||
|
||||
/** Game updates data access component */
|
||||
private UpdatesDAO updatesDao;
|
||||
|
||||
/** Amount of registered, non-default handlers */
|
||||
private int nRegisteredHandlers = 0;
|
||||
|
||||
/** Amount of handler components */
|
||||
private int nHandlerComponents = -1;
|
||||
|
||||
/** Registered game update phase handlers */
|
||||
private final EnumMap< GameUpdatePhase , GameUpdatePhaseHandler > handlers;
|
||||
|
||||
|
||||
public GameUpdateBean( )
|
||||
{
|
||||
this.handlers = new EnumMap< GameUpdatePhase , GameUpdatePhaseHandler >( GameUpdatePhase.class );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector for the event scheduling component
|
||||
*
|
||||
* @param ticker
|
||||
* the event scheduling component
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setTicker( Ticker ticker )
|
||||
{
|
||||
this.ticker = ticker;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector for the system status access component
|
||||
*
|
||||
* @param systemStatus
|
||||
* the system status access component
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setSystemStatus( SystemStatus systemStatus )
|
||||
{
|
||||
this.systemStatus = systemStatus;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector that initialises the game update component's logger.
|
||||
*
|
||||
* @param logger
|
||||
* the system logging component
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setLogger( Logger logger )
|
||||
{
|
||||
this.logger = logger.getSystemLogger( "GameUpdate" );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector that initialises the transaction template.
|
||||
*
|
||||
* @param transactionManager
|
||||
* the application's transaction manager
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setTransactionManager( PlatformTransactionManager transactionManager )
|
||||
{
|
||||
this.tTemplate = new TransactionTemplate( transactionManager );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector for the game updates data access component
|
||||
*
|
||||
* @param updatesDao
|
||||
* the game updates data access component
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setUpdatesDAO( UpdatesDAO updatesDao )
|
||||
{
|
||||
this.updatesDao = updatesDao;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector which registers the game.updatesPerDay constant.
|
||||
*
|
||||
* @param constantsManager
|
||||
* the constants manager
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setConstantsManager( ConstantsManager constantsManager )
|
||||
{
|
||||
List< ConstantDefinition > definitions;
|
||||
ConstantDefinition constant;
|
||||
definitions = new ArrayList< ConstantDefinition >( 1 );
|
||||
constant = new ConstantDefinition(
|
||||
"game.updatesPerDay" ,
|
||||
"Game (misc)" ,
|
||||
"Game updates per day from the computations's point of view. "
|
||||
+ "This does not affect the actual amount of updates, but changes the computations. "
|
||||
+ "Can be used to speed things up or slow them down without actually changing ticker.interval." ,
|
||||
1440.0 , 0.05 , 5760.0 );
|
||||
definitions.add( 0 , constant );
|
||||
constantsManager.registerConstants( definitions );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read the amount of update phase handlers from the application context.
|
||||
*
|
||||
* @param context
|
||||
* the application context
|
||||
*/
|
||||
@Override
|
||||
public void setApplicationContext( ApplicationContext context )
|
||||
throws BeansException
|
||||
{
|
||||
this.nHandlerComponents = context.getBeansOfType( GameUpdatePhaseHandler.class ).size( );
|
||||
if ( this.nRegisteredHandlers == this.nHandlerComponents ) {
|
||||
this.initialise( );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in GameUpdate interface */
|
||||
@Override
|
||||
public void registerHandler( GameUpdatePhaseHandler handler )
|
||||
throws DuplicateUpdateHandler
|
||||
{
|
||||
GameUpdatePhase phase = handler.getPhase( );
|
||||
synchronized ( this.handlers ) {
|
||||
if ( this.handlers.containsKey( phase ) ) {
|
||||
throw new DuplicateUpdateHandler( phase );
|
||||
}
|
||||
this.handlers.put( phase , handler );
|
||||
}
|
||||
this.logger.log( LogLevel.DEBUG , "Registered game update handler for phase " + phase.toString( ) ).flush( );
|
||||
|
||||
this.nRegisteredHandlers++;
|
||||
if ( this.nRegisteredHandlers == this.nHandlerComponents ) {
|
||||
this.initialise( );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialise the component if it is ready.
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet( )
|
||||
{
|
||||
if ( this.nRegisteredHandlers == this.nHandlerComponents ) {
|
||||
this.initialise( );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Finish any pending computations (unless maintenance mode is active), then register the game
|
||||
* update task into the {@link #ticker}.
|
||||
*/
|
||||
private void initialise( )
|
||||
{
|
||||
// Finish previous tick if possible
|
||||
try {
|
||||
this.endPreviousTick( );
|
||||
} catch ( MaintenanceStatusException e ) {
|
||||
// EMPTY
|
||||
}
|
||||
|
||||
// Register ticker task
|
||||
this.ticker.registerTask( Frequency.MINUTE , "Game update" , this );
|
||||
|
||||
// Make sure initialisation only occurs once
|
||||
this.nHandlerComponents = -1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* When the game update event is triggered by the system's scheduling component, attempt to run
|
||||
* a game update.
|
||||
*
|
||||
* First, check if there is already a game update in progress, and attempt to finish running it
|
||||
* if necessary. Otherwise start a new update though the system status manager, and execute it.
|
||||
*/
|
||||
@Override
|
||||
public void run( )
|
||||
{
|
||||
// Attempt to end the previous tick, if e.g. maintenance mode was initiated while it was
|
||||
// being processed
|
||||
try {
|
||||
if ( this.endPreviousTick( ) ) {
|
||||
return;
|
||||
}
|
||||
} catch ( MaintenanceStatusException e ) {
|
||||
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.executeUpdate( tickId );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if a game update was in progress and finish running it if necessary.
|
||||
*
|
||||
* @return <code>true</code> if a game update was already being executed, <code>false</code>
|
||||
* otherwise.
|
||||
*
|
||||
* @throws MaintenanceStatusException
|
||||
* if the game is under maintenance.
|
||||
*/
|
||||
private boolean endPreviousTick( )
|
||||
throws MaintenanceStatusException
|
||||
{
|
||||
Long currentTick = this.systemStatus.checkStuckTick( );
|
||||
if ( currentTick == null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.logger.log( LogLevel.WARNING , "Tick " + currentTick + " restarted" ).flush( );
|
||||
this.executeUpdate( currentTick.longValue( ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute all phase handlers for a game update, then mark the update as completed.
|
||||
*
|
||||
* @param updateId
|
||||
* the identifier of the current update
|
||||
*/
|
||||
private void executeUpdate( long updateId )
|
||||
{
|
||||
for ( GameUpdatePhase phase : GameUpdatePhase.values( ) ) {
|
||||
this.executeUpdatePhase( updateId , phase );
|
||||
}
|
||||
|
||||
try {
|
||||
this.systemStatus.endTick( );
|
||||
} catch ( TickStatusException e ) {
|
||||
throw new RuntimeException( "Game update completed but status error reported" , e );
|
||||
} catch ( MaintenanceStatusException e ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.logger.log( LogLevel.TRACE , "Tick " + updateId + " completed" ).flush( );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute a phase of the game update.
|
||||
*
|
||||
* @param updateId
|
||||
* the identifier of the current update
|
||||
* @param phase
|
||||
* the phase of the update to execute
|
||||
*/
|
||||
private void executeUpdatePhase( final long updateId , GameUpdatePhase phase )
|
||||
{
|
||||
final GameUpdatePhaseHandler handler = this.getHandlerForPhase( phase );
|
||||
handler.onPhaseStart( updateId );
|
||||
|
||||
boolean hasMore;
|
||||
do {
|
||||
hasMore = this.tTemplate.execute( new TransactionCallback< Boolean >( ) {
|
||||
@Override
|
||||
public Boolean doInTransaction( TransactionStatus status )
|
||||
{
|
||||
return handler.updateGame( updateId );
|
||||
}
|
||||
} );
|
||||
} while ( hasMore );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Access the handler for an update phase. If no handler has been registered, create a default
|
||||
* {@link ProceduralGameUpdate} handler.
|
||||
*
|
||||
* @param phase
|
||||
* the update phase whose handler is to be retrieved
|
||||
* @return the game update handler
|
||||
*/
|
||||
private GameUpdatePhaseHandler getHandlerForPhase( GameUpdatePhase phase )
|
||||
{
|
||||
GameUpdatePhaseHandler handler;
|
||||
synchronized ( this.handlers ) {
|
||||
handler = this.handlers.get( phase );
|
||||
if ( handler == null ) {
|
||||
this.logger.log( LogLevel.DEBUG , "Creating default handler for phase " + phase.toString( ) ).flush( );
|
||||
handler = new ProceduralGameUpdate( this.updatesDao , phase );
|
||||
this.handlers.put( phase , handler );
|
||||
}
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.deepclone.lw.beans.updates;
|
||||
|
||||
|
||||
import com.deepclone.lw.interfaces.game.updates.GameUpdatePhase;
|
||||
import com.deepclone.lw.interfaces.game.updates.GameUpdatePhaseHandler;
|
||||
import com.deepclone.lw.interfaces.game.updates.UpdatesDAO;
|
||||
|
||||
|
||||
|
||||
class ProceduralGameUpdate
|
||||
implements GameUpdatePhaseHandler
|
||||
{
|
||||
|
||||
private final GameUpdatePhase phase;
|
||||
private final UpdatesDAO updatesDao;
|
||||
|
||||
|
||||
ProceduralGameUpdate( UpdatesDAO updatesDao , GameUpdatePhase phase )
|
||||
{
|
||||
this.updatesDao = updatesDao;
|
||||
this.phase = phase;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public GameUpdatePhase getPhase( )
|
||||
{
|
||||
return this.phase;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean updateGame( long updateId )
|
||||
{
|
||||
if ( !this.updatesDao.prepareUpdates( updateId , this.phase ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this.updatesDao.executeProceduralUpdate( updateId , this.phase );
|
||||
this.updatesDao.validateUpdatedRecords( updateId , this.phase );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPhaseStart( long updateId )
|
||||
{
|
||||
// EMPTY
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package com.deepclone.lw.beans.updates;
|
||||
|
||||
|
||||
import java.sql.Types;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.deepclone.lw.interfaces.game.updates.GameUpdatePhase;
|
||||
import com.deepclone.lw.interfaces.game.updates.UpdatesDAO;
|
||||
import com.deepclone.lw.utils.StoredProc;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of the game update data access component.
|
||||
*
|
||||
* @author tseeker
|
||||
*/
|
||||
public class UpdatesDAOBean
|
||||
implements UpdatesDAO
|
||||
{
|
||||
|
||||
/** Wrapper for the stored procedure that prepares updates */
|
||||
private StoredProc fPrepareUpdates;
|
||||
|
||||
/** Wrapper for the stored procedure that executes a procedural game update */
|
||||
private StoredProc fExecuteProcedural;
|
||||
|
||||
/** Wrapper for the stored procedure that marks update records as processed */
|
||||
private StoredProc fUpdatesProcessed;
|
||||
|
||||
|
||||
/**
|
||||
* Dependency injector that initialises stored procedure call handlers.
|
||||
*
|
||||
* @param dataSource
|
||||
* the data source
|
||||
*/
|
||||
@Autowired( required = true )
|
||||
public void setDataSource( DataSource dataSource )
|
||||
{
|
||||
// Stored procedure that prepares updates
|
||||
this.fPrepareUpdates = new StoredProc( dataSource , "sys" , "prepare_updates" );
|
||||
this.fPrepareUpdates.addParameter( "u_id" , Types.BIGINT );
|
||||
this.fPrepareUpdates.addParameter( "u_type" , "update_type" );
|
||||
this.fPrepareUpdates.addOutput( "has_more" , Types.BOOLEAN );
|
||||
|
||||
// Stored procedure that executes a procedural game update
|
||||
this.fExecuteProcedural = new StoredProc( dataSource , "sys" , "exec_update_proc" );
|
||||
this.fExecuteProcedural.addParameter( "u_id" , Types.BIGINT );
|
||||
this.fExecuteProcedural.addParameter( "u_type" , "update_type" );
|
||||
|
||||
// Stored procedure that marks update records as processed
|
||||
this.fUpdatesProcessed = new StoredProc( dataSource , "sys" , "updates_processed" );
|
||||
this.fUpdatesProcessed.addParameter( "u_id" , Types.BIGINT );
|
||||
this.fUpdatesProcessed.addParameter( "u_type" , "update_type" );
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in UpdatesDAO interface */
|
||||
@Override
|
||||
public boolean prepareUpdates( long updateId , GameUpdatePhase phase )
|
||||
{
|
||||
return (Boolean) this.fPrepareUpdates.execute( updateId , phase.toString( ) ).get( "has_more" );
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in UpdatesDAO interface */
|
||||
@Override
|
||||
public void executeProceduralUpdate( long updateId , GameUpdatePhase phase )
|
||||
{
|
||||
this.fExecuteProcedural.execute( updateId , phase.toString( ) );
|
||||
}
|
||||
|
||||
|
||||
/* Documentation in UpdatesDAO interface */
|
||||
@Override
|
||||
public void validateUpdatedRecords( long updateId , GameUpdatePhase phase )
|
||||
{
|
||||
this.fUpdatesProcessed.execute( updateId , phase );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
<?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">
|
||||
|
||||
<import resource="updates/game-update-bean.xml" />
|
||||
<import resource="updates/updates-dao-bean.xml" />
|
||||
|
||||
</beans>
|
|
@ -4,12 +4,12 @@
|
|||
<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-user</artifactId>
|
||||
<version>5.99.1</version>
|
||||
<version>5.99.2</version>
|
||||
<name>Legacy Worlds server - user actions</name>
|
||||
<description>This module defines beans and classes that handle user actions.</description>
|
||||
</project>
|
|
@ -0,0 +1,59 @@
|
|||
package com.deepclone.lw.beans.user.admin.main.techs;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.deepclone.lw.beans.user.abst.AutowiredCommandDelegate;
|
||||
import com.deepclone.lw.beans.user.abst.SessionCommandHandler;
|
||||
import com.deepclone.lw.beans.user.admin.common.AdminOperation;
|
||||
import com.deepclone.lw.beans.user.admin.main.AdminCommandsBean;
|
||||
import com.deepclone.lw.cmd.admin.adata.Administrator;
|
||||
import com.deepclone.lw.cmd.admin.adata.Privileges;
|
||||
import com.deepclone.lw.cmd.admin.techs.ListCategoriesCommand;
|
||||
import com.deepclone.lw.cmd.admin.techs.ListCategoriesResponse;
|
||||
import com.deepclone.lw.interfaces.game.techs.TechnologyGraphManager;
|
||||
import com.deepclone.lw.interfaces.session.ServerSession;
|
||||
import com.deepclone.lw.session.Command;
|
||||
import com.deepclone.lw.session.CommandResponse;
|
||||
|
||||
|
||||
|
||||
public class ListCategoriesCommandDelegateBean
|
||||
extends AdminOperation
|
||||
implements AutowiredCommandDelegate
|
||||
{
|
||||
private TechnologyGraphManager manager;
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setManager( TechnologyGraphManager manager )
|
||||
{
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class< ? extends SessionCommandHandler > getCommandHandler( )
|
||||
{
|
||||
return AdminCommandsBean.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class< ? extends Command > getType( )
|
||||
{
|
||||
return ListCategoriesCommand.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CommandResponse execute( ServerSession session , Command command )
|
||||
{
|
||||
Administrator admin = this.getAdministrator( session );
|
||||
if ( !admin.hasPrivilege( Privileges.GDAT ) ) {
|
||||
return new ListCategoriesResponse( admin );
|
||||
}
|
||||
return new ListCategoriesResponse( admin , this.manager.listCategories( ) );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.deepclone.lw.beans.user.player.game;
|
||||
package com.deepclone.lw.beans.user.player.game.techs;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -6,8 +6,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import com.deepclone.lw.beans.user.abst.AutowiredCommandDelegate;
|
||||
import com.deepclone.lw.beans.user.abst.SessionCommandHandler;
|
||||
import com.deepclone.lw.beans.user.player.GameSubTypeBean;
|
||||
import com.deepclone.lw.cmd.player.ImplementTechCommand;
|
||||
import com.deepclone.lw.interfaces.game.EmpireManagement;
|
||||
import com.deepclone.lw.cmd.player.research.ImplementTechCommand;
|
||||
import com.deepclone.lw.cmd.player.research.ResearchOperationResponse;
|
||||
import com.deepclone.lw.interfaces.game.techs.EmpireTechnologyManager;
|
||||
import com.deepclone.lw.interfaces.session.ServerSession;
|
||||
import com.deepclone.lw.session.Command;
|
||||
import com.deepclone.lw.session.CommandResponse;
|
||||
|
@ -19,13 +20,13 @@ public class ImplementTechCommandDelegateBean
|
|||
|
||||
{
|
||||
|
||||
private EmpireManagement empireManagement;
|
||||
private EmpireTechnologyManager techManagement;
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setEmpireManager( EmpireManagement manager )
|
||||
public void setEmpireManager( EmpireTechnologyManager manager )
|
||||
{
|
||||
this.empireManagement = manager;
|
||||
this.techManagement = manager;
|
||||
}
|
||||
|
||||
|
||||
|
@ -49,8 +50,8 @@ public class ImplementTechCommandDelegateBean
|
|||
ImplementTechCommand command = (ImplementTechCommand) cParam;
|
||||
int empireId = session.get( "empireId" , Integer.class );
|
||||
if ( session.get( "vacation" , Boolean.class ) ) {
|
||||
return this.empireManagement.getOverview( empireId );
|
||||
return new ResearchOperationResponse( );
|
||||
}
|
||||
return this.empireManagement.implementTechnology( empireId , command.getTech( ) );
|
||||
return this.techManagement.implementTechnology( empireId , command.getTech( ) );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.deepclone.lw.beans.user.player.game.techs;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.deepclone.lw.beans.user.abst.AutowiredCommandDelegate;
|
||||
import com.deepclone.lw.beans.user.abst.SessionCommandHandler;
|
||||
import com.deepclone.lw.beans.user.player.GameSubTypeBean;
|
||||
import com.deepclone.lw.cmd.player.research.ResearchOperationResponse;
|
||||
import com.deepclone.lw.cmd.player.research.SetResearchPrioritiesCommand;
|
||||
import com.deepclone.lw.interfaces.game.techs.EmpireTechnologyManager;
|
||||
import com.deepclone.lw.interfaces.session.ServerSession;
|
||||
import com.deepclone.lw.session.Command;
|
||||
import com.deepclone.lw.session.CommandResponse;
|
||||
|
||||
|
||||
|
||||
public class SetResearchPrioritiesCommandDelegateBean
|
||||
implements AutowiredCommandDelegate
|
||||
{
|
||||
|
||||
private EmpireTechnologyManager techManagement;
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setEmpireManager( EmpireTechnologyManager manager )
|
||||
{
|
||||
this.techManagement = manager;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class< ? extends Command > getType( )
|
||||
{
|
||||
return SetResearchPrioritiesCommand.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class< ? extends SessionCommandHandler > getCommandHandler( )
|
||||
{
|
||||
return GameSubTypeBean.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CommandResponse execute( ServerSession session , Command cParam )
|
||||
{
|
||||
SetResearchPrioritiesCommand command = (SetResearchPrioritiesCommand) cParam;
|
||||
int empireId = session.get( "empireId" , Integer.class );
|
||||
if ( session.get( "vacation" , Boolean.class ) ) {
|
||||
return new ResearchOperationResponse( );
|
||||
}
|
||||
return this.techManagement.setResearchPriorities( empireId , command.getPriorities( ) );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.deepclone.lw.beans.user.player.game.techs;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.deepclone.lw.beans.user.abst.AutowiredCommandDelegate;
|
||||
import com.deepclone.lw.beans.user.abst.SessionCommandHandler;
|
||||
import com.deepclone.lw.beans.user.player.GameSubTypeBean;
|
||||
import com.deepclone.lw.cmd.player.research.ViewResearchCommand;
|
||||
import com.deepclone.lw.interfaces.game.techs.EmpireTechnologyManager;
|
||||
import com.deepclone.lw.interfaces.session.ServerSession;
|
||||
import com.deepclone.lw.session.Command;
|
||||
import com.deepclone.lw.session.CommandResponse;
|
||||
|
||||
|
||||
|
||||
public class ViewResearchCommandDelegateBean
|
||||
implements AutowiredCommandDelegate
|
||||
{
|
||||
|
||||
private EmpireTechnologyManager techManagement;
|
||||
|
||||
|
||||
@Autowired( required = true )
|
||||
public void setEmpireManager( EmpireTechnologyManager manager )
|
||||
{
|
||||
this.techManagement = manager;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class< ? extends Command > getType( )
|
||||
{
|
||||
return ViewResearchCommand.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class< ? extends SessionCommandHandler > getCommandHandler( )
|
||||
{
|
||||
return GameSubTypeBean.class;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CommandResponse execute( ServerSession session , Command cParam )
|
||||
{
|
||||
int empireId = session.get( "empireId" , Integer.class );
|
||||
return this.techManagement.getResearchData( empireId );
|
||||
}
|
||||
|
||||
}
|
|
@ -93,5 +93,8 @@
|
|||
<bean class="com.deepclone.lw.beans.user.admin.main.mntm.EnableMaintenanceCommandDelegateBean" />
|
||||
<bean class="com.deepclone.lw.beans.user.admin.main.mntm.EndMaintenanceCommandDelegateBean" />
|
||||
<bean class="com.deepclone.lw.beans.user.admin.main.mntm.ExtendMaintenanceCommandDelegateBean" />
|
||||
|
||||
<!-- Technology graph -->
|
||||
<bean class="com.deepclone.lw.beans.user.admin.main.techs.ListCategoriesCommandDelegateBean" />
|
||||
|
||||
</beans>
|
||||
|
|
|
@ -44,8 +44,12 @@
|
|||
|
||||
<!-- Game: empire -->
|
||||
<bean class="com.deepclone.lw.beans.user.player.game.OverviewCommandDelegateBean" />
|
||||
<bean class="com.deepclone.lw.beans.user.player.game.ImplementTechCommandDelegateBean" />
|
||||
<bean class="com.deepclone.lw.beans.user.player.game.GetNewPlanetCommandDelegateBean" />
|
||||
|
||||
<!-- Game: technologies -->
|
||||
<bean class="com.deepclone.lw.beans.user.player.game.techs.ViewResearchCommandDelegateBean" />
|
||||
<bean class="com.deepclone.lw.beans.user.player.game.techs.ImplementTechCommandDelegateBean" />
|
||||
<bean class="com.deepclone.lw.beans.user.player.game.techs.SetResearchPrioritiesCommandDelegateBean" />
|
||||
|
||||
<!-- Game: planet list -->
|
||||
<bean class="com.deepclone.lw.beans.user.player.game.ListPlanetsCommandDelegateBean" />
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
<parent>
|
||||
<artifactId>legacyworlds-server</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</artifactId>
|
||||
<name>Legacy Worlds server beans</name>
|
||||
<version>5.99.1</version>
|
||||
<version>5.99.2</version>
|
||||
<packaging>pom</packaging>
|
||||
<description>This metapackage regroups all packages which define beans for the Legacy Worlds server.</description>
|
||||
|
||||
|
@ -32,5 +32,8 @@
|
|||
<module>legacyworlds-server-beans-bt</module>
|
||||
<module>legacyworlds-server-beans-user</module>
|
||||
<module>legacyworlds-server-beans-simple</module>
|
||||
<module>legacyworlds-server-beans-techs</module>
|
||||
<module>legacyworlds-server-beans-updates</module>
|
||||
<module>legacyworlds-server-beans-events</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
|
Reference in a new issue