Compare commits

...
This repository has been archived on 2025-01-04. You can view files and clone it, but cannot push or open issues or pull requests.

93 commits

Author SHA1 Message Date
d246f221f0 Event database access
Added tables that store event access interfaces and event states per
interface, as well as functions which allow events to be retrieved:
 * events.interfaces lists access interfaces,
 * events.unprocessed_events lists events which haven't been processed
for each type of interface, with a "pre-processed" flag
 * events.ep_read() is a set of function variants which will read events
 * events.ep_access() is a set of function variants which read events
then update their states.
2012-07-03 10:32:15 +02:00
d7b14e3de9 Event processing task
Implemented the new ticker task which processes queued events.
2012-07-01 15:48:37 +02:00
af33d44b2a Package for event handling components
Added new Maven module for the server's event handling components.
2012-07-01 15:23:53 +02:00
3a0f5bbb78 Events storage procedure
Added the necessary database code to convert the contents of event
queues into actual event records. The changes include:
 * a new table, events.pending_events, which is automatically filled by
a trigger when events are inserted into queue tables,
 * the game.events.batchSize constant which defines the maximal amount
of events to process in a single transaction,
 * the events.eq_process() stored procedure, which processes the events.
In addition, the "hstore" extension was added as it is the easiest way
to convert events from the queues' table model to the store's
meta-model.
2012-07-01 14:12:22 +02:00
dc9ef2292d Event-related functions split
Because the events management functions are definitely going to be quite
big, I thought it would be better to split them into multiple SQL files.
For now, there's a file for event definition functions and one for
functions that manipulate priority overrides. The old file containing
the old code stays around for now.
2012-07-01 01:04:26 +02:00
9e84f333e7 Events database structure
Added tables allowing event data to be stored on the long term:
 * events.events_v2 (which will need to be renamed) contains the events'
main entry
 * events.field_values stores field values for all events.
2012-06-30 18:47:33 +02:00
cf8dee6ec9 Priority settings update procedures
Added stored procedures which can be used to update customisable event
priorities:
 * events.evcp_set() adds or modifies an override,
 * events.clear() can be used to remove a specific override or all
overrides for a given player.
2012-06-30 16:25:50 +02:00
1dd1da5ae3 Comments in event definition data classes
Some comments were missing in the classes used to load event definitions
from the XML file. They have been added.
2012-06-30 15:43:26 +02:00
75c5245764 Event definition loader
Implemented the ImportEvents command line tool, which allows event
definitions to be imported. In all cases the tool will try to import all
definitions; if an error occurs, the process continues but the
transaction is rolled back. It skips existing definitions rather than
taking the risk of doing something inappropriate (e.g. deletion of
existing events).
2012-06-30 14:52:55 +02:00
c8f19a4c06 Event record creation bugfix
When I18N strings (name and template) were added to the event definition
table, some of the code was not modified.
2012-06-30 14:47:02 +02:00
7e3d8a558a XML event definitions
Added a dummy event definitions file, and more importantly the
associated XML schema.
2012-06-30 14:30:46 +02:00
aaec345957 Event definition stored procedures bugfix
Fixed a bug which caused events.evdef_finalise() to fail with an
exception when the event type identifier was wrong, and to register the
event type event if error had occurred on field definitions.
2012-06-30 12:43:29 +02:00
a6562052d3 Event definitions - missing I18N properties
Added the display name and template I18N properties to event
definitions. Modified events.evdef_start() accordingly.
2012-06-29 17:31:14 +02:00
8f2fd29c71 Player-defined priority storage
Added the events.custom_priorities that ought to store player-defined
priorities for event types which support it.
2012-06-29 17:19:23 +02:00
0c67d1e799 Event definition functions
Added functions that allow new event types to be defined. The functions
are:
 * events.evdef_start() which starts recording a definition,
 * events.evdef_addfld_*(), a set of functions to add fields to
the current definition,
 * events.evdef_finalise() which adds the definition records and creates
the event queue table.

It is not possible to modify or delete event definitions at this time.
They will be added if and when they become necessary.
2012-06-29 15:18:18 +02:00
ff78c6a2d6 Added event definition tables
* New events.event_definitions table
* New events.field_definitions table
* New types for event field type specification
2012-06-28 12:40:47 +02:00
071257786c Renamed technology tables and views
* Removed the _v2 suffix from some tables and views.
2012-04-09 15:01:04 +02:00
ab04752169 Research page - Unlocked buildings
* The research page now includes a list of buildings unlocked by each
technology when that technology is not in the "unknown" state.
2012-04-09 13:08:08 +02:00
96c296e9d5 Removed old research system
* Removed all tables, views and functions

* Removed references to old system in Java code, including old import
tool

* Replaced XML dump code
2012-04-09 11:36:09 +02:00
070d55dc05 "Buildables" depend on tech graph
* Modified buildable definitions and loader to use technologies from the
tech graph as dependencies instead of the old research system

* Modified planet-related views and functions accordingly
2012-04-08 14:30:43 +02:00
76a01cbf1c Fixed research page bug
* In some cases, it was impossible to implement a technology or set its
research priority, due to the JS click handler exiting with a "false"
return value.
2012-04-08 14:29:16 +02:00
6dcd59d7bc New research and technology page
* Added legacyworlds-server-beans-technologies Maven module, including
the player-level DAO and controller.

* Added session classes to carry technology information, modified web
client session façade accordingly

* Various changes to common UI elements (forms, lists, etc...) so the
start and end of some element can be drawn separately

* Added controller, templates and JavaScript for research page
2012-04-07 13:06:03 +02:00
154f215e24 Removed client-side display for old technology system
* Removed data classes and database access that were used to display
technology information

* Removed "Research" tab from Overview page on the web client
2012-04-03 10:35:57 +02:00
9a7bc03171 Improved I18N support:
* GamePageData now includes the selected language's code.
* Added support for multiple fetches in one call to the Translator
service.
2012-04-05 11:25:08 +02:00
c7949e41cc Research update
* Implemented new research update. Old research system no longer
updates.

* Fixed a major bug in the constants registrar

* Added game.research.vacation constant (determines the rate of
research when players are in vacation mode)
2012-04-02 13:29:43 +02:00
a14601df37 Research weight computations
* Added game.research.weightBase constant

* Added view which computes the weights for each in-progress research

* Added view which computes total weights per empire
2012-03-01 12:42:05 +01:00
c9d8a077bd Moved empire research SQL to separate file
* Empire research & technology SQL code was getting dense, so it was
moved to a separate file.
2012-03-01 11:50:40 +01:00
1dcde71dff Research priorities
* Added stored procedures meant to update research priorities.
2012-03-01 10:52:52 +01:00
b15acadc1b Empire technology views
* Added new research-related constants

* Added set of views and functions to list empires' technologies. This
includes a view which determines the visibility of an in-progress
research's details, and a main list view.
2012-03-01 09:50:20 +01:00
e01eab9c09 Technology dependencies view
* Added SQL view that lists dependencies of technologies as
comma-separated lists of identifiers
2012-02-29 11:50:04 +01:00
f4e38e4943 Technology implementation
* A stored procedure which implements technologies has been added. It
will mark a pending technology as implemented and remove the
corresponding quantity of money from the empire, then add any newly
available research items to the empire's research.
2012-02-28 16:15:02 +01:00
8c0b4abd1e Empire research initialisation
* When an empire is created, all technologies that have no dependencies
will be added as ongoing research with default priority and no points in
the empire research table.
2012-02-28 12:34:59 +01:00
1f3c7a9202 Technology definitions loader
* Added "dummy" data file for technologies (for now it simply copies the
old, line-based technologies) and corresponding XML schema

* Added missing SQL stored procedure to clear all dependencies and
reverse dependencies from a technology

* Added import classes, loader and import tool for the technology graph

* Added tech graph import tool to post-build tests
2012-02-27 20:04:02 +01:00
c5464212bc Deleted old "test" buildables and technologies
* These 2 definition files were remnants of B6M1's early tests. They did
not belong in the repo any more.
2012-02-27 14:27:33 +01:00
26fe4b926d Fixed package for resources data tests
* The tests for resource definition import classes were not in the right
package. They have been moved.
2012-02-27 18:18:35 +01:00
af57e7d3b5 Technology definition functions
* Added stored procedures which manipulate technology definitions
themselves (defs.uoc_technology) or their dependencies (defs.techdep_add
and defs.techdep_remove)
2012-02-27 14:14:00 +01:00
3b2ec4bb64 Empire technologies table
* Added table to store empire technologies. The table will store
technologies in all states.

* Note: this table is called "emp.technologies_v2" for now. It will need
to be renamed when the old tech system is gone.

* 030-data/110-empires.sql needs to be executed to create the new table
and a type it uses.
2012-02-17 07:46:51 +01:00
1ae9a15f6e Improvements to developer SQL tests runner
* The script will no longer fail when there are no tests matching the
requested name in either admin/ or user/

* The script will ignore non-SQL files when running with --run-name
2012-02-16 18:32:44 +01:00
4f083830f2 Technology dependencies caching and integrity checks
* Added table that will contain the cached technology dependencies.

* Implemented trigger functions that update the cache and make sure
there are no cycles or redundancies in the technology graph.

* The following SQL files need to be (re-)executed:
  -> 030-data/080-techs.sql (for the defs.techdep_cache table)
  -> 040-functions/026-technology-dependencies.sql (new file)
2012-02-16 18:30:58 +01:00
b90491ca73 Technology definition tables
* Added a pair of tables that will contain graph-like technology
definitions. The first table describes a technology, while the second
table is used to list dependencies between technologies. The new tables
contain the basic checks and foreign keys. However, integrity checks on
the dependency graph are not implemented.

* The following SQL files need to be re-executed:
  -> 030-data/080-techs.sql
2012-02-16 11:07:43 +01:00
cb65a6e643 Empire resources and vacation mode
* Modified the empire resources update to check for vacation mode and
apply the modifier from vacation.cashDivider if necessary.

* Some parts of the database need to be reloaded:
  -> 050-updates/015-empire-resources.sql
2012-02-16 10:22:30 +01:00
96670d45be Resources information on planet list
* Added resource information records to the planet list's response.

* Added a database view and the corresponding row mapper and DAO method
which can be used as the data source for the planet list's resource
information. For now this view always returns 0 for both civilian and
military investments.

* Added new tab to display resource information on the planet list page.
The old version of the economy tab will be kept until the corresponding
data no longer exists.

* The following SQL scripts must be re-executed to upgrade a database:
  -> 040-functions/167-planet-list.sql
2012-02-15 14:45:43 +01:00
bf6bea5a79 Extracted quantities update as soon as possible
* The quantities of resources extracted from mines will now be updated
as soon as they have a reason to. This includes planet assignment,
abandonment, ownership changes, and updates to mining priorities.

* The mining update will now remove the current resource income from the
providers, and only then re-compute all extracted quantities. This is
more logical and corresponds to the way the other game updates work.

* Fixed bug in extraction computation where the size of the planet's
happy population was used instead of the happy/total ratio when
adjusting the mining production for riots.

* The following SQL scripts must be re-executed to upgrade a database:
  -> 040-functions/040-empire.sql
  -> 040-functions/145-resource-providers.sql
  -> 040-functions/147-empire-mining.sql
  -> 050-updates/120-planet-mining.sql
2012-02-09 10:54:00 +01:00
f3aa563758 Planet resources interface fix
* Some text in the English version of the planet page's "natural
resources" tab incorrectly used the term "settings" instead of
"priorities".

* The English version of the planet page's "natural resources" tab did
not display any explanation when the planet was following empire-wide
mining priorities.
2012-02-08 11:54:01 +01:00
afa1224391 Production adjustment fix
* The production adjustment function was completely off (and always has
been). It has been fixed.

* The problem with the adjustment function not being reported means that
no-one ever encountered it. As a consequence, happiness strike threshold
has been increased to 50%

/!\ Full database reset required (or at least much easier than other
options).
2012-02-08 15:38:12 +01:00
c94958a058 Added log files to Git ignore list
* Added both "normal" log files and compressed files created when
full-debug.log is rotated.
2012-02-08 08:56:07 +01:00
cb2553d1e5 Build system and documentation update
* Added tests of the command line tools to the post-build scripts

* Local deployment documentation mentions ImportResources
2012-02-08 08:38:56 +01:00
fd117f6f7b Fixed consequences of Spring config clean-up
* While the server works fine, the tools - which use hardcoded paths to
specific parts of the Spring config - were not updated last time. They
should work now.
2012-02-07 19:40:57 +01:00
e64f847ec3 Planet mining settings interface
* Modified owned planet view to include a field which indicates whether
mining settings are specific to the planet or come from the empire;
modified "simple" game components accordingly

* Modified stored procedures to only allow planet-specific mining
settings updates when the planet actually uses planet-specific settings,
and added a stored procedure which toggles the source of a planet's
settings

* Added corresponding parts to mining settings DAO and resources
controller

* Added session commands and server command handlers that toggle the
source of the settings and that upload the settings

* Split planet page template into multiple files for clarity and added
the mining priorities form to the natural resources tab
2012-02-07 17:03:55 +01:00
51b529a09f Removed TODO file
* Since we're now using tasks.legacyworlds.com, the TODO file is no
longer useful.
2012-02-07 09:42:03 +01:00
d38576a5cf Empire mining settings
* Modified mining settings stored procedures to use text identifiers
instead of numeric identifiers

* Added DAO for mining settings and controller for resource operations

* Added UpdateEmpireMiningSettingsCommand and associated command
delegate. The command always returns NullResponse.

* Overview page templates split into multiple files for clarity, added
priority update form to the empire economy view and associated web
server handler
2012-02-05 10:10:43 +01:00
92dd01ffce Fixed project directories
* Because some resources were moved in a previous commit, Git decided to
automatically remove a directory. Re-added that directory with a hidden
file to prevent Git from being such a moron.
2012-02-04 15:32:20 +01:00
b4903d78e4 Object name validator component
* Moved the component from the -user package to the -naming package

* Added a separate interface to the component
2012-02-04 15:26:53 +01:00
35d8891fe3 Spring configuration clean-up
* Regrouped component definitions into one single file per package in
most cases, with a few exceptions

* Added documentation about how the configuration is stored and which
guidelines should be followed when adding or modifying Spring component
configurations.
2012-02-04 12:56:58 +01:00
597429fadf In-game resources views
* Added session records to carry resource information over to the
clients

* Added SQL support code for the various views

* Added interface and implementation of the resource information access
component

* Hooked resources information queries into both the empire and planet
management component

* Added resources display to planet and overview pages
2012-02-04 10:43:12 +01:00
56eddcc4f0 Game updates improvements
* Added a set of tables which define game updates and their targets.
These definitions replace the old enumerate type. Added a set of
triggers which automatically create specific update tables, insert
missing entries, etc... when game update types are being manipulated.

* Removed manual insertion of game updates from empire creation
function and universe generator.

* Added registration of core update targets (i.e. planets and empires),
updated all existing game update processing functions and added type
registrations

* Created Maven project for game updates control components, moved
existing components from the -simple project, rewritten most of what
they contained, added new components for server-side update batch
processing
2012-02-03 16:25:03 +01:00
ba6a1e2b41 SQL unit tests fixes
* Added plan() instead of no_plan() where necessary

* Removed junk from dirty tests system self-check
2012-01-31 12:14:38 +01:00
44b6ec1920 Fixed resource extraction
* Formula was mis-copied from the wiki, the result was multiplied by the
provider's current quantity

* Changed extraction per work unit from 1 to 10
2012-01-30 09:18:20 +01:00
b9bc5e038c Additional Maven projects for unit tests
* Changed names of common packages so they are coherent with the rest

* Added new project for tests on common classes (utilities and session)

* Added new project for tests on the web clients
2012-01-25 09:36:46 +01:00
a4bce68b17 Client/server communications overview
* Added a text file which describes the current client/server protocol,
and the implementation of both the protocol itself and the server-level
support. It also includes a discussion of what is wrong with the current
implementation.
2012-01-24 16:08:30 +01:00
4e27875d87 Maven project & PostgreSQL fix
* Made the PostgreSQL library a compile-time dependency (it used to be
runtime only as it was used as the JDBC driver, however it is now used
directly to access PostgreSQL-specific types; this does not matter, as
the DB code is already 100% specific to PostgreSQL)
2012-01-24 14:51:51 +01:00
775426347a Resource definitions
* Added a few resource definitions and the corresponding strings. While
the descriptions are blank, and resource definitions themselves are
incomplete (relations to e.g. technologies are missing), this should
allow easier testing of the rest of the resources system.
2012-01-24 14:49:23 +01:00
Tim Rosser
f4a16aa431 Resource Definition Loader
* Implemented resource definition loader including tests

* Added resource definition xml file and style definition

* Made a small style change to i18n loader
2012-01-10 22:38:29 +11:00
3637b6e1d1 Mining settings in XML dumps
* Empire mining settings have been included in the empire's resource
information records

* Planet-specific mining settings have been included in the resource
provider information records
2012-01-19 10:28:12 +01:00
9b346a80c2 Empire resources in XML dumps
* Added dump view for empire resources

* Added empire resource information storage class and associated row
mapper

* Integrated empire resource information into the summary generator
2012-01-19 09:35:12 +01:00
ce6d86d344 Planet resources and resource providers in XML dumps
* Dump version bumped up to 2

* Added SQL view that shows resource delta and provider information for
all empire-owned planets

* Added new storage classes for resource providers and resource deltas

* Added row mapper which extracts all planet resources information
(providers and deltas)

* Modified dump generator to include planet resources / resource
providers
2012-01-18 09:28:35 +01:00
95e6019c12 Mock result set class
* Added a mock result set class which can be used to write unit tests
for e.g. RowMapper-based classes. The class is incomplete and should be
extended as necessary.

* Added unit test for BuildingsInformationMapper as a proof of concept
2012-01-17 16:47:05 +01:00
426a1fdfd4 XML dumps code clean-up
* Moved empire summary generator to a separate package, moved all empire
summary data classes to a sub-package of the former

* All row mappers for empire summary contents have been moved to
separate classes with default access

* Added comments to the component and to the mapper classes
2012-01-17 10:50:51 +01:00
2adc754a2c Dependency upgrades
* Spring upgraded from 3.0.3 to 3.1.0 - As a consequence, all code that
used SimpleJdbcTemplate has been modified to use JdbcTemplate, as the
former has been deprecated.

* SLF4J upgraded from 1.5.11 to 1.6.4

* Apache Commons: DBCP upgraded from 1.2.2 to 1.4, Codec upgraded from
1.4 to 1.6

* CGLib upgraded from 2.2 to 2.2.2

* javax.mail upgraded from 1.4.1 to 1.4.4

* XStream upgraded from 1.3.1 to 1.4.2

* JUnit upgraded from 4.7 to 4.10

* FreeMarker upgraded from 2.3.16 to 2.3.18

* PostgreSQL JDBC glue upgraded from 8.4-701 to 9.1-901

* legacyworlds-server-tests no longer considered a dummy package
2012-01-16 18:09:45 +01:00
a981d1653e Universe generator fix
* A function called by the initial universe generator was changed, but
the call wasn't updated accordingly. This problem has been fixed.

* Variable / procedure name errors in some of the old, untested
functions.
2012-01-16 17:42:11 +01:00
30a1080e6e Maven projects fixes and improvements
* Fixed copy of the SQL files to the distribution

* Distribution packages will now execute an automatic clean-up before
assembling. While this will avoid having dirty, old files in the
distribution directory, it also has a negative consequence -
configuration files will be destroyed if they exist.
2012-01-16 16:06:44 +01:00
24f40c5549 Fix for dirty SQL tests
* Fixed an error in the main post-build script which caused dirty SQL
tests to be skipped
2012-01-16 12:50:10 +01:00
74b6f2ab09 Mining computation update
* Added various views and helper functions used by the mining
computation but which may be re-used in other parts.

* Added mining computation update type and associated update function

* New constants: game.resources.weightBase (the value used to compute
weights from mining settings) and game.resources.extraction (the
quantity extracted in a day from a full provider at difficulty 0)
2012-01-16 12:35:20 +01:00
038bba896a Mining computations update
* Added a few that can be used to retrieve mining settings for resource
providers from empire-owned planets from either the empire-wide or
planet-specific settings
2012-01-10 16:28:25 +01:00
c18bdc2d1f Dirty SQL test system
* Added a system that allows "dirty" tests to be written. These tests
actually need to change the database, so a temporary test database must
be created to run them.
2012-01-14 09:02:24 +01:00
04e550709a Empire resources update
* Added a new update that computes the amount of resources possessed and
owed by empires. At the moment this computation ignores fleets, as their
upkeep does not use the resource system.
2012-01-10 13:29:56 +01:00
b49bc1a44f Planet resources
* Added missing table that should store a planet's resources data
(income and upkeep for each type of resource).

* Modified resource definition functions and universe generator to
initialise planet resource records as well

* Heavy clean-up in resource definition function unit tests
2012-01-10 12:30:47 +01:00
37555841ce Empire resources initialisation
* Empire resources will be initialised when an empire is created

* When a new resource is created through the appropriate defs.uoc_...
function, it will be added to all empires as well.
2012-01-10 10:48:56 +01:00
afc66166e0 Mining settings
* Changed the way mining settings work: use a priority value (between 0
and 4) as the weight. Leaving them as they were before would have caused
numerous problems (and a lot of unnecessary code to work around them)

* Empire mining settings will be created along with the empire's own
record. By default all natural resources will have weight = 2.

* Added a set of four stored procedures which can be used to update an
empire's mining settings, including planet-specific settings. The
emp.mset_update_start() function can be used to start an update (on an
empire's settings if there is only one parameter, or on a planet's
settings if there are two parameters); the emp.mset_update_set() and
emp.mset_update_apply() functions are then used to modify the settings
and apply the changes, respectively.
2012-01-10 10:17:47 +01:00
3e109b13bc SQL logging fixes
* Added user mapping on the "remote" logging database for the
administrative user. This allows calls to sys.write_sql_log() to succeed
when they are executed by code with administrative privileges.

* Added test suites for both the link to the database and the function
itself.

* Replaced RAISE NOTICE with actual logging in the universe generator
2012-01-07 11:14:17 +01:00
e50775ec76 Database definition & tests organisation
* The main loader script has been updated to generate the list of files
it needs to load automatically. As a consequence, files that contained
manually-maintained lists of scripts have been removed, and definition
directories have been renamed accordingly.

* PostgreSQL extension loading and configuration has been moved to a
separate script to be loaded automatically in the main transaction.

* Data and function definition scripts that had the -data or -functions
suffix have been renamed (the suffix is unnecessary).

* Unit tests have been reorganised to follow the definition's structure.

* Documentation has been improved
2012-01-06 11:19:19 +01:00
b054a379a9 Universe generator: resource providers
* The universe generator has been modified to generate resource
providers. The code attempts to keep the universe balanced according to
the natural resources definitions.
2012-01-06 10:05:47 +01:00
e7d2072813 SQL privileges fix and unit tests
* Fixed privileges on both variants of defs.uoc_natural_resource()

* Added user unit tests which check execution privileges on all (new)
stored procedures and INSERT/UPDATE/SELECT/DELETE privileges on all
(new) tables
2012-01-03 09:35:57 +01:00
d4945d8e21 Maven project for resources-related component
Added a Maven project that will contain all resources-related
components. Updated list of children in the top-level components
project. Added dependency to the main project.
2012-01-02 15:11:17 +01:00
66c72ef718 Resource provider regeneration
Implemented resource regeneration computation in the
verse.compute_provider_regeneration() function.

Created the PLANET_RES_REGEN update type, and added the corresponding
implementation.

Added resource regeneration constants registration.
2012-01-02 15:10:04 +01:00
d768766214 Main web interface update
* Added the new interface style, including the necessary pictures and page
layout template.

* Updated existing style sheet in order to accommodate the new fluid
layout and to use some more CSS3 goodness.

* Upgraded JQuery from 1.4.2 to 1.7.1.
2012-01-02 08:57:06 +01:00
bed784a8e1 Resource management functions
* Added defs.uoc_resources() set of functions which create or update
basic resources.

 * Added defs.uoc_natural_resources() set of functions which create or
update natural resources.
2011-12-19 16:00:01 +01:00
4e1bb91780 Resource database structures
* Added structures for resource definitions, natural resources
definitions, resource providers, empire resources and empire mining
settings (both empire-wide and planet-specific).

* Added a few common utility functions to the SQL test suite. These
functions allow test initialisation to be a little shorter.

* Added "MINE" production type and an associated building definition.
The production will not be added to the XML dump or to the output of the
planets summary page, as this is extremely temporary.
2011-12-19 11:57:08 +01:00
631f49fb86 Command line tools
* Added base classes for all importable data. These new classes should
be used for all future loaders; all existing loaders that are modified
should be updated.

* I18N loader rewritten to make use of the new base classes. External
strings are now read using the XML data file's path as the base
directory.

* Updated all external I18N definitions and moved the existing files
around in an attempt to make the data directory somewhat more livable.

* Added dependency management entry for the server's main package to the
root project, updated server distribution package accordingly. Added
dependency on the server's main package to the server's testing package.
2011-12-17 12:37:01 +01:00
be3106c463 Database management changes
* Added in-base logging through a foreign data wrapper, which is only
possible using PostgreSQL 9.1
* Renamed database-related configuration files to indicate that they are
samples, and added the "real" names to the Git ignore list. Server
distribution modified accordingly.
* Removed PL/PgSQL registration (it was only necessary on 8.4)
* Added pgTAP SQL definitions and a script which will (hopefully) be
executed by the build system after the main Java build in order to
execute database unit tests. The script supports both admin- and user-
level testing. I also added a few tests to make sure the testing framework
actually runs them.
* Added documentation about the database definitions structure
2011-12-15 15:38:46 +01:00
f682594cbd Finished migration to Git and the build system
* Added web interface packaging
* Added documentation about the development workflow
2011-12-15 13:41:27 +01:00
0665a760de Project: * Clean-up (Eclipse cruft, unused files, etc...) * Git-specific changes * Maven POMs clean-up and changes for the build system * Version set to 1.0.0-0 in the development branches * Maven plug-ins updated to latest versions * Very partial dev. documentation added 2011-12-09 08:07:33 +01:00
c74e30d5ba
Manually import single change from old staging repo 2025-01-04 15:28:26 +01:00
1905 changed files with 50725 additions and 7261 deletions

8
.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
target
.settings
.classpath
.project
legacyworlds-server-main/data-source.xml
legacyworlds-server-data/db-structure/db-config.txt
*.log
full-debug*.zip

View file

@ -1,17 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>legacyworlds</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
</natures>
</projectDescription>

View file

@ -1,51 +0,0 @@
#!/bin/sh
cd `dirname $0`/..
SRCDIR=`pwd`
if [ "x$1" = "x" ]; then
OUTDIR="$SRCDIR";
else
OUTDIR="$1";
fi
echo "Building Legacy Worlds..."
mvn clean || { echo "Maven clean-up failed"; exit 1; };
mvn package || { echo "Maven build failed"; exit 1; };
echo "Copying files..."
TEMPDIR=`mktemp -d`
mkdir $TEMPDIR/legacyworlds
mkdir $TEMPDIR/legacyworlds/server
mkdir $TEMPDIR/legacyworlds/server/data
mkdir $TEMPDIR/legacyworlds/web
mkdir $TEMPDIR/legacyworlds/sql
# Database and initial data
cp -Rapv legacyworlds-server/legacyworlds-server-data/db-structure/database.sql $TEMPDIR/legacyworlds/sql
cp -Rapv legacyworlds-server/legacyworlds-server-data/db-structure/db-config.txt $TEMPDIR/legacyworlds/sql/db-config-example.txt
cp -Rapv legacyworlds-server/legacyworlds-server-data/db-structure/parts $TEMPDIR/legacyworlds/sql
cp -Rapv legacyworlds-server/legacyworlds-server-main/data/* $TEMPDIR/legacyworlds/server/data
# Server
cp -Rapv legacyworlds-server/legacyworlds-server-main/target/*.jar $TEMPDIR/legacyworlds/server
cp -Rapv legacyworlds-server/legacyworlds-server-main/target/lib $TEMPDIR/legacyworlds/server
cp -Rapv legacyworlds-server/legacyworlds-server-main/data-source.xml $TEMPDIR/legacyworlds/server/data-source-example.xml
# Tools
cp -Rapv build-tools/server-config-example.sh $TEMPDIR/legacyworlds
cp -Rapv build-tools/start-server.sh $TEMPDIR/legacyworlds
cp -Rapv build-tools/stop-server.sh $TEMPDIR/legacyworlds
cp -Rapv build-tools/execute-clit.sh $TEMPDIR/legacyworlds
cp -Rapv build-tools/deploy.sh $TEMPDIR/legacyworlds
# Web sites
cp -Rapv legacyworlds-web/legacyworlds-web-*/target/*.war $TEMPDIR/legacyworlds/web
echo "Preparing archive..."
cd $TEMPDIR
find $TEMPDIR/legacyworlds -type d -name .svn | xargs rm -rf
tar cvjf $OUTDIR/legacyworlds.tar.bz2 legacyworlds || { echo "Archive generation failed"; exit 1; };
echo "Removing temporary directory..."
cd $SRCDIR
rm -rf $TEMPDIR
echo "All done. Legacy Worlds archive: $OUTDIR/legacyworlds.tar.bz2"

View file

@ -1,34 +0,0 @@
#!/bin/sh
COREDIR="$1"
if [ "x$COREDIR" = "x" ] || ! [ -d "$COREDIR" ]; then
echo "Syntax: $0 main_dir tomcat_dir web_dir"
exit 1;
fi
TOMCATDIR="$2"
if [ "x$TOMCATDIR" = "x" ] || ! [ -d "$TOMCATDIR" ]; then
echo "Syntax: $0 main_dir tomcat_dir web_dir"
exit 1;
fi
WEBDIR="$3"
if [ "x$WEBDIR" = "x" ] || ! [ -d "$WEBDIR" ]; then
echo "Syntax: $0 main_dir tomcat_dir web_dir"
exit 1;
fi
cd `dirname $0`
SRCDIR=`pwd`
cp -Rap server web *-*.sh $COREDIR
cd "$TOMCATDIR"
if [ -L "lwmain.war" ]; then
rm -f lwmain.war lwadmin.war
fi
ln -s "$COREDIR/web/legacyworlds-web-main-"*.war lwmain.war
ln -s "$COREDIR/web/legacyworlds-web-admin-"*.war lwadmin.war
cd $WEBDIR
unzip -o $COREDIR/web/legacyworlds-web-main-*.war "css/*" "js/*" "pjirc/*" "img/*"

View file

@ -0,0 +1,58 @@
#!/bin/bash
cd legacyworlds-server-data/db-structure
if ! [ -f db-config.txt ]; then
cat > db-config.txt <<EOF
admin=$USER
db=tests
user=tests
password=tests
EOF
fi
export TEST_DATABASE="`grep ^db= db-config.txt | sed -e s/.*=//`"
export TEST_USER="`grep ^user= db-config.txt | sed -e s/.*=//`"
echo
echo
echo "======================================================================"
echo "LOADING DATABASE DEFINITION ..."
echo "======================================================================"
echo
echo
psql -vQUIET=1 -vON_ERROR_STOP=1 -e --file database.sql || exit 1
if ! [ -d tests/admin ] && ! [ -d tests/user ]; then
echo
echo
echo "WARNING: no unit tests to run"
echo
echo
exit 0
fi
echo
echo
echo "======================================================================"
echo "LOADING TEST FRAMEWORK ..."
echo "======================================================================"
echo
echo
psql -vQUIET=1 -f tests/pgtap.sql $TEST_DATABASE || exit 1
echo
echo
echo "======================================================================"
echo "RUNNING DATABASE TESTS ..."
echo "======================================================================"
echo
echo
cd tests
if [ -d admin ]; then
pg_prove -d $TEST_DATABASE `find admin/ -type f -name '*.sql'` || exit 1
fi
if [ -d user ]; then
pg_prove -U $TEST_USER -d $TEST_DATABASE `find user/ -type f -name '*.sql'` || exit 1
fi
if [ -x dirty/run-dirty-tests.sh ]; then
( cd dirty; exec ./run-dirty-tests.sh ) || exit 1
fi

View file

@ -0,0 +1,51 @@
#!/bin/bash
TESTDIR=`mktemp -d`
cp -Rapv legacyworlds-server-DIST/target/legacyworlds/legacyworlds-server-* $TESTDIR
cd $TESTDIR/legacyworlds-server-*/sql
cat > db-config.txt <<EOF
admin=$USER
db=tests
user=tests
password=tests
EOF
psql -vQUIET=1 -vON_ERROR_STOP=1 -e --file database.sql || exit 1
cd ..
cat > data-source.xml <<EOF
<?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 name="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql:tests" />
<property name="username" value="tests" />
<property name="password" value="tests" />
</bean>
</beans>
EOF
java legacyworlds-server-main-*.jar --run-tool ImportText data/i18n-text.xml || exit 1
java legacyworlds-server-main-*.jar --run-tool ImportEvents data/event-definitions.xml || exit 1
java legacyworlds-server-main-*.jar --run-tool ImportResources data/resources.xml || exit 1
java legacyworlds-server-main-*.jar --run-tool ImportTechs data/techs.xml || exit 1
java legacyworlds-server-main-*.jar --run-tool ImportTechGraph data/tech-graph.xml || exit 1
java legacyworlds-server-main-*.jar --run-tool ImportBuildables data/buildables.xml || exit 1
java legacyworlds-server-main-*.jar &
sleep 10
if ! ps ux | grep -q 'java -jar legacyworlds-server-main'; then
exit 1;
fi
java legacyworlds-server-main-*.jar --run-tool Stop || {
killall java
exit 1;
}
java -jar legacyworlds-server-main-1.0.0-0.jar --run-tool CreateUser 'test@example.org 12blah34bleh en' || exit 1
java -jar legacyworlds-server-main-1.0.0-0.jar --run-tool CreateSuperuser 'test@example.org Turlututu' || exit 1

View file

@ -0,0 +1,67 @@
<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</artifactId>
<groupId>com.deepclone.lw</groupId>
<version>1.0.0</version>
<relativePath>../legacyworlds-server/pom.xml</relativePath>
</parent>
<artifactId>legacyworlds-server-DIST</artifactId>
<version>${legacyworlds.version.main}.${legacyworlds.version.release}-${legacyworlds.version.build}</version>
<packaging>pom</packaging>
<name>Legacy Worlds - Server - Packaging</name>
<description>This Maven module is responsible for creating the Legacy Worlds server's packaging.</description>
<!-- Depend solely on the server's JAR, other dependencies will update automatically -->
<dependencies>
<dependency>
<groupId>com.deepclone.lw</groupId>
<artifactId>legacyworlds-server-main</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Clean the target directory before generating the distribution -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<executions>
<execution>
<id>clean-before-assembly</id>
<phase>initialize</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Use the assembly plug-in to generate the distribution -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>distribution-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<attach>false</attach>
<finalName>legacyworlds-server-${project.version}</finalName>
<descriptors>
<descriptor>src/server.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View file

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<!-- Legacy Worlds server assembly -->
<id>legacyworlds-server</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<!-- The server's main archive -->
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>.</outputDirectory>
<unpack>false</unpack>
<includes>
<include>com.deepclone.lw:legacyworlds-server-main:jar</include>
</includes>
</dependencySet>
<!-- Libraries - both internal and external dependencies -->
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
<includes>
<include>*:jar</include>
</includes>
<excludes>
<exclude>com.deepclone.lw:legacyworlds-server-main:jar</exclude>
</excludes>
</dependencySet>
</dependencySets>
<fileSets>
<!-- Database definitions -->
<fileSet>
<directory>../legacyworlds-server-data/db-structure</directory>
<outputDirectory>sql</outputDirectory>
<includes>
<include>*.sql</include>
<include>parts/**</include>
<include>db-config.sample.txt</include>
</includes>
</fileSet>
<!-- Default data -->
<fileSet>
<directory>../legacyworlds-server-main/data</directory>
<outputDirectory>data</outputDirectory>
<includes>
<include>i18n/**</include>
<include>**.xml</include>
</includes>
</fileSet>
</fileSets>
<files>
<!-- Data source configuration -->
<file>
<source>../legacyworlds-server-main/data-source.sample.xml</source>
<fileMode>0600</fileMode>
<outputDirectory>.</outputDirectory>
</file>
</files>
</assembly>

View file

@ -4,12 +4,12 @@
<parent>
<artifactId>legacyworlds-server-beans</artifactId>
<groupId>com.deepclone.lw</groupId>
<version>5.99.1</version>
<version>1.0.0</version>
<relativePath>../legacyworlds-server-beans/pom.xml</relativePath>
</parent>
<groupId>com.deepclone.lw</groupId>
<artifactId>legacyworlds-server-beans-accounts</artifactId>
<name>Legacy Worlds account management</name>
<version>5.99.1</version>
<name>Legacy Worlds - Server - Components - Accounts</name>
<version>${legacyworlds.version.main}.${legacyworlds.version.release}-${legacyworlds.version.build}</version>
<description>This package contains the beans responsible for managing accounts, including registration, inactivity checks, bans and authentication.</description>
</project>

View file

@ -11,8 +11,8 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import com.deepclone.lw.cmd.admin.users.SessionTerminationType;
import com.deepclone.lw.cmd.admin.users.UserSession;
@ -25,7 +25,7 @@ public class UserSessionDAOBean
implements UserSessionDAO , InitializingBean
{
private SimpleJdbcTemplate dTemplate;
private JdbcTemplate dTemplate;
private final RowMapper< UserSession > mSession;
@ -66,7 +66,7 @@ public class UserSessionDAOBean
@Autowired( required = true )
public void setDataSource( DataSource dataSource )
{
this.dTemplate = new SimpleJdbcTemplate( dataSource );
this.dTemplate = new JdbcTemplate( dataSource );
this.fSessionStart = new StoredProc( dataSource , "users" , "sessions_login" );
this.fSessionStart.addParameter( "credentials_id" , Types.INTEGER );
@ -84,7 +84,7 @@ public class UserSessionDAOBean
@Override
public void afterPropertiesSet( )
{
this.dTemplate.getJdbcOperations( ).execute( "SELECT users.sessions_server_restart()" );
this.dTemplate.execute( "SELECT users.sessions_server_restart()" );
}

View file

@ -11,8 +11,8 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import com.deepclone.lw.cmd.admin.users.AccountBanEntry;
import com.deepclone.lw.cmd.admin.users.AccountListEntry;
@ -55,7 +55,7 @@ public class UsersDAOBean
private final AccountListMapper< AccountListEntry > mAccountList;
private final AccountListMapper< AccountViewEntry > mAccountView;
private SimpleJdbcTemplate dTemplate;
private JdbcTemplate dTemplate;
private StoredProc fCreateAccount;
private StoredProc fMailFailure;
@ -181,7 +181,7 @@ public class UsersDAOBean
@Autowired( required = true )
public void setDataSource( DataSource dataSource )
{
this.dTemplate = new SimpleJdbcTemplate( dataSource );
this.dTemplate = new JdbcTemplate( dataSource );
this.fCreateAccount = new StoredProc( dataSource , "users" , "create_credentials" );
this.fCreateAccount.addParameter( "address" , Types.VARCHAR );
@ -426,7 +426,7 @@ public class UsersDAOBean
@Override
public void expireRequests( )
{
this.dTemplate.getJdbcOperations( ).execute( "SELECT users.expire_requests( )" );
this.dTemplate.execute( "SELECT users.expire_requests( )" );
}
@ -469,7 +469,7 @@ public class UsersDAOBean
@Override
public void processVacations( )
{
this.dTemplate.getJdbcOperations( ).execute( "SELECT users.process_vacations( )" );
this.dTemplate.execute( "SELECT users.process_vacations( )" );
}
@ -529,7 +529,7 @@ public class UsersDAOBean
@Override
public void deleteOldAccounts( )
{
this.dTemplate.getJdbcOperations( ).execute( "SELECT users.delete_old_accounts( )" );
this.dTemplate.execute( "SELECT users.delete_old_accounts( )" );
}

View file

@ -13,8 +13,8 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import com.deepclone.lw.cmd.admin.adata.AdminOverview;
import com.deepclone.lw.interfaces.admin.AdminDAO;
@ -34,7 +34,7 @@ public class AdminDAOBean
private static final String sGetAdminByName = "SELECT * FROM admin.admins_view WHERE lower( name ) = ?";
private static final String sListAdministrators = "SELECT * FROM admin.admins_view ORDER BY active DESC , name";
private SimpleJdbcTemplate dTemplate;
private JdbcTemplate dTemplate;
private final RowMapper< AdminRecord > mAdminRecord;
private final RowMapper< AdminOverview > mAdminOverview;
@ -89,7 +89,7 @@ public class AdminDAOBean
@Autowired( required = true )
public void setDataSource( DataSource dataSource )
{
this.dTemplate = new SimpleJdbcTemplate( dataSource );
this.dTemplate = new JdbcTemplate( dataSource );
this.fCreateAdmin = new StoredProc( dataSource , "admin" , "create_admin" );
this.fCreateAdmin.addParameter( "address" , Types.VARCHAR );

View file

@ -12,8 +12,8 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import com.deepclone.lw.cmd.admin.bans.ArchivedBanRequest;
import com.deepclone.lw.cmd.admin.bans.BanRequest;
@ -51,7 +51,7 @@ public class BansDAOBean
}
}
private SimpleJdbcTemplate dTemplate;
private JdbcTemplate dTemplate;
private final BanRequestMapper< BanRequest > mPending;
private final BanRequestMapper< BanRequest > mArchived;
@ -122,7 +122,7 @@ public class BansDAOBean
@Autowired( required = true )
public void setDataSource( DataSource dataSource )
{
this.dTemplate = new SimpleJdbcTemplate( dataSource );
this.dTemplate = new JdbcTemplate( dataSource );
this.fRequestBanAddress = new StoredProc( dataSource , "admin" , "request_ban_on_address" );
this.fRequestBanAddress.addParameter( "admin_id" , Types.INTEGER );
@ -251,14 +251,14 @@ public class BansDAOBean
@Override
public void expireBanRequests( )
{
this.dTemplate.getJdbcOperations( ).execute( "SELECT admin.expire_ban_requests( )" );
this.dTemplate.execute( "SELECT admin.expire_ban_requests( )" );
}
@Override
public void expireWarnings( )
{
this.dTemplate.getJdbcOperations( ).execute( "SELECT admin.expire_warnings( )" );
this.dTemplate.execute( "SELECT admin.expire_warnings( )" );
}

View file

@ -12,8 +12,8 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
@ -70,7 +70,7 @@ public class PreferenceDefinitionsBean
private SystemLogger logger;
private Translator translator;
private SimpleJdbcTemplate dTemplate;
private JdbcTemplate dTemplate;
private StoredProc uocGroup;
private StoredProc uocDef;
@ -95,7 +95,7 @@ public class PreferenceDefinitionsBean
@Autowired( required = true )
public void setDataSource( DataSource dataSource )
{
this.dTemplate = new SimpleJdbcTemplate( dataSource );
this.dTemplate = new JdbcTemplate( dataSource );
this.uocGroup = new StoredProc( dataSource , "defs" , "uoc_preference_group" );
this.uocGroup.addParameter( "name" , Types.VARCHAR );

View file

@ -12,8 +12,8 @@ import java.util.Map;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import com.deepclone.lw.interfaces.prefs.AccountPreferences;
import com.deepclone.lw.interfaces.prefs.Preference;
@ -30,7 +30,7 @@ public class PreferencesDAOBean
implements PreferencesDAO
{
private SimpleJdbcTemplate dTemplate;
private JdbcTemplate dTemplate;
private PreferenceTypesRegistry registry;
private StoredProc fReset;
private StoredProc fSetPref;
@ -39,7 +39,7 @@ public class PreferencesDAOBean
@Autowired( required = true )
public void setDataSource( DataSource dataSource )
{
this.dTemplate = new SimpleJdbcTemplate( dataSource );
this.dTemplate = new JdbcTemplate( dataSource );
this.fReset = new StoredProc( dataSource , "users" , "reset_preferences" );
this.fReset.addParameter( "a_id" , Types.INTEGER );

View file

@ -0,0 +1,26 @@
<?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.1.xsd">
<bean id="accountCleanup" class="com.deepclone.lw.beans.acm.AccountCleanupBean" />
<bean id="accountManagement" class="com.deepclone.lw.beans.acm.AccountManagementBean" />
<bean id="adminDao" class="com.deepclone.lw.beans.admin.AdminDAOBean" />
<bean id="administration" class="com.deepclone.lw.beans.admin.AdministrationBean" />
<bean id="adminRecap" class="com.deepclone.lw.beans.admin.AdminRecapBean" />
<bean id="bansDao" class="com.deepclone.lw.beans.admin.BansDAOBean" />
<bean id="bansProcessor" class="com.deepclone.lw.beans.admin.BansProcessorBean" />
<bean id="defaultPreferences" class="com.deepclone.lw.beans.prefs.DefaultPreferencesBean" />
<bean id="ipBan" class="com.deepclone.lw.beans.admin.IpBanBean" />
<bean id="preferenceDefinitions" class="com.deepclone.lw.beans.prefs.PreferenceDefinitionsBean" />
<bean id="preferencesDAO" class="com.deepclone.lw.beans.prefs.PreferencesDAOBean" />
<bean id="preferenceTypesRegistry"
class="com.deepclone.lw.beans.prefs.PreferenceTypesRegistryBean" />
<bean id="quitProcessor" class="com.deepclone.lw.beans.acm.QuitProcessorBean" />
<bean id="requestsExpiration" class="com.deepclone.lw.beans.acm.RequestsExpirationBean" />
<bean id="usersDAO" class="com.deepclone.lw.beans.acm.UsersDAOBean" />
<bean id="userSessionDao" class="com.deepclone.lw.beans.acm.UserSessionDAOBean" />
<bean id="vacationProcessor" class="com.deepclone.lw.beans.acm.VacationProcessorBean" />
</beans>

View file

@ -4,7 +4,8 @@
<parent>
<artifactId>legacyworlds-server-beans</artifactId>
<groupId>com.deepclone.lw</groupId>
<version>5.99.1</version>
<version>1.0.0</version>
<relativePath>../legacyworlds-server-beans/pom.xml</relativePath>
</parent>
<dependencies>
@ -12,14 +13,16 @@
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>${com.thoughtworks.xstream.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
</dependencies>
<groupId>com.deepclone.lw</groupId>
<artifactId>legacyworlds-server-beans-bt</artifactId>
<version>5.99.1</version>
<name>Legacy Worlds bug tracking system</name>
<name>Legacy Worlds - Server - Components - Bug tracking system</name>
<version>${legacyworlds.version.main}.${legacyworlds.version.release}-${legacyworlds.version.build}</version>
</project>

View file

@ -11,9 +11,8 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import com.deepclone.lw.cmd.admin.adata.Administrator;
import com.deepclone.lw.cmd.bt.data.*;
import com.deepclone.lw.interfaces.bt.BugsDAO;
@ -25,7 +24,7 @@ public class BugsDAOBean
implements BugsDAO
{
private SimpleJdbcTemplate dTemplate;
private JdbcTemplate dTemplate;
private final RowMapper< BugReport > mBugReport;
private final RowMapper< BugEvent > mBugEvent;
@ -129,7 +128,7 @@ public class BugsDAOBean
@Autowired( required = true )
public void setDataSource( DataSource dataSource )
{
this.dTemplate = new SimpleJdbcTemplate( dataSource );
this.dTemplate = new JdbcTemplate( dataSource );
this.fPostUserReport = new StoredProc( dataSource , "bugs" , "post_player_report" );
this.fPostUserReport.addParameter( "empire_id" , Types.INTEGER );

View file

@ -0,0 +1,44 @@
package com.deepclone.lw.beans.bt.es;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.deepclone.lw.beans.bt.es.data.BuildingsInformation;
/**
* Building information row mapper
*
* <p>
* Map rows from <code>bugs.dump_buildings_view</code> into {@link BuildingsInformation} instances.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*
*/
final class BuildingsInformationMapper
implements RowMapper< BuildingsInformation >
{
/**
* Map a row from <code>bugs.dump_buildings_view</code>
*
* <p>
* Generate and initialise a {@link BuildingsInformation} instance using the row's fields.
*/
@Override
public BuildingsInformation mapRow( ResultSet rs , int rowNum )
throws SQLException
{
BuildingsInformation bi = new BuildingsInformation( );
bi.setPlanetId( rs.getInt( "planet_id" ) );
bi.setId( rs.getInt( "building_id" ) );
bi.setName( rs.getString( "building_name" ) );
bi.setAmount( rs.getInt( "amount" ) );
bi.setDamage( rs.getDouble( "damage" ) );
return bi;
}
}

View file

@ -0,0 +1,65 @@
package com.deepclone.lw.beans.bt.es;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.deepclone.lw.beans.bt.es.data.AllianceInformation;
import com.deepclone.lw.beans.bt.es.data.DebugInformation;
/**
* Top-level empire summary row mapper
*
* <p>
* This class maps an entry from the database's main empire summary view,
* <code>bugs.dump_main_view</code>, into a top-level {@link DebugInformation} instance.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*
*/
final class DebugInformationMapper
implements RowMapper< DebugInformation >
{
/**
* Map a row from <code>bugs.dump_main_view</code> into a {@link DebugInformation} instance
*
* <p>
* Converts the row into a {@link DebugInformation} instance containing system information,
* account information and empire information. If the row contains alliance information, add an
* {@link AllianceInformation} record to the empire information.
*/
@Override
public DebugInformation mapRow( ResultSet rs , int rowNum )
throws SQLException
{
DebugInformation di = new DebugInformation( );
di.getSystem( ).setNextTick( rs.getLong( "next_tick" ) );
di.getSystem( ).setCurrentTick( (Long) rs.getObject( "current_tick" ) );
di.getAccount( ).setId( rs.getInt( "account_id" ) );
di.getAccount( ).setAddress( rs.getString( "account_address" ) );
di.getAccount( ).setGameCredits( rs.getInt( "game_credits" ) );
di.getAccount( ).setStatus( rs.getString( "account_status" ) );
di.getAccount( ).setLanguage( rs.getString( "account_language" ) );
di.getEmpire( ).setId( rs.getInt( "empire_id" ) );
di.getEmpire( ).setName( rs.getString( "empire_name" ) );
di.getEmpire( ).setCash( rs.getDouble( "cash" ) );
String allianceTag = rs.getString( "alliance_tag" );
if ( allianceTag != null ) {
AllianceInformation alliance = new AllianceInformation( );
alliance.setId( rs.getInt( "alliance_id" ) );
alliance.setTag( allianceTag );
alliance.setPending( rs.getBoolean( "alliance_pending" ) );
di.getEmpire( ).setAlliance( alliance );
}
return di;
}
}

View file

@ -0,0 +1,52 @@
package com.deepclone.lw.beans.bt.es;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.deepclone.lw.beans.bt.es.data.EmpireResourceInformation;
/**
* Empire resource row mapper
*
* <p>
* This class is responsible for transforming rows from <code>bugs.dump_emp_resources_view</code>
* into {@link EmpireResourceInformation} instances.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
final class EmpireResourceInformationMapper
implements RowMapper< EmpireResourceInformation >
{
/**
* Map a row from <code>bugs.dump_emp_resources_view</code>
*
* <p>
* Create a new {@link EmpireResourceInformation} instance and set its fields using the row's
* contents. If a mining priority is present, set it, otherwise leave the field to its default
* <code>null</code> value.
*/
@Override
public EmpireResourceInformation mapRow( ResultSet rs , int rowNum )
throws SQLException
{
EmpireResourceInformation empRes = new EmpireResourceInformation( );
empRes.setResource( rs.getString( "resource_name" ) );
empRes.setOwed( rs.getDouble( "empres_owed" ) );
empRes.setPossessed( rs.getDouble( "empres_possessed" ) );
int priority = rs.getInt( "mining_priority" );
if ( !rs.wasNull( ) ) {
empRes.setMiningPriority( priority );
}
return empRes;
}
}

View file

@ -0,0 +1,359 @@
package com.deepclone.lw.beans.bt.es;
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.JdbcTemplate;
import com.deepclone.lw.beans.bt.es.data.AccountInformation;
import com.deepclone.lw.beans.bt.es.data.AllianceInformation;
import com.deepclone.lw.beans.bt.es.data.BuildingsInformation;
import com.deepclone.lw.beans.bt.es.data.DebugInformation;
import com.deepclone.lw.beans.bt.es.data.EmpireInformation;
import com.deepclone.lw.beans.bt.es.data.EmpireResourceInformation;
import com.deepclone.lw.beans.bt.es.data.FleetInformation;
import com.deepclone.lw.beans.bt.es.data.MovementInformation;
import com.deepclone.lw.beans.bt.es.data.PlanetInformation;
import com.deepclone.lw.beans.bt.es.data.QueueInformation;
import com.deepclone.lw.beans.bt.es.data.QueueItemInformation;
import com.deepclone.lw.beans.bt.es.data.ResearchGraphInformation;
import com.deepclone.lw.beans.bt.es.data.ResearchInformation;
import com.deepclone.lw.beans.bt.es.data.ResearchLineInformation;
import com.deepclone.lw.beans.bt.es.data.ResourceDeltaInformation;
import com.deepclone.lw.beans.bt.es.data.ResourceProviderInformation;
import com.deepclone.lw.beans.bt.es.data.ShipsInformation;
import com.deepclone.lw.beans.bt.es.data.SystemInformation;
import com.deepclone.lw.interfaces.bt.EmpireSummary;
import com.thoughtworks.xstream.XStream;
/**
* Empire XML summary generator
*
* <p>
* This component is used by the bug tracking system to generate XML dumps of an empire's state. It
* reads the necessary data from the database, convert it to XML dump record classes then serialises
* the whole thing through XStream.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
public class EmpireSummaryBean
implements EmpireSummary
{
/** Beginning of all dump SQL queries */
private static final String SQL_START = "SELECT * FROM bugs.dump_";
/** Ending of (almost) all dump SQL queries */
private static final String SQL_END = "_view WHERE empire_id = ?";
/** SQL query that accesses the main empire dump view */
private static final String Q_EMPIRE = SQL_START + "main" + SQL_END;
/** SQL query that accesses the resources dump view */
private static final String Q_RESOURCES = SQL_START + "emp_resources" + SQL_END;
/** SQL query that accesses the research dump view */
private static final String Q_RESEARCH = SQL_START + "research" + SQL_END;
/** SQL query that accesses the empire's planets dump view */
private static final String Q_PLANETS = SQL_START + "planets" + SQL_END;
/** SQL query that accesses the planetary resources dump view */
private static final String Q_PLANET_RESOURCES = SQL_START + "planet_resources" + SQL_END;
/** SQL query that accesses the build queues dump view */
private static final String Q_BUILD_QUEUES = SQL_START + "queues" + SQL_END + " ORDER BY queue_order";
/** SQL query that accesses the buildings dump view */
private static final String Q_BUILDINGS = SQL_START + "buildings" + SQL_END;
/** SQL query that accesses the fleets dump view */
private static final String Q_FLEETS = SQL_START + "fleets" + SQL_END;
/** SQL query that accesses the ships dump view */
private static final String Q_SHIPS = SQL_START + "ships" + SQL_END;
/** JDBC access interface */
private JdbcTemplate dTemplate;
/** XStream instance used to serialise XML dumps */
private final XStream xStream;
/** Top-level row mapper */
private final DebugInformationMapper mMainInfo;
/** Empire resources row mapper */
private final EmpireResourceInformationMapper mResources;
/** Empire research row mapper */
private final ResearchInformationMapper mResearch;
/** Empire-owned planet row mapper */
private final PlanetInformationMapper mPlanet;
/** Planet resources row mapper */
private final ResourceRowMapper mPlanetResources;
/** Planet construction queue item row mapper */
private final QueueItemInformationMapper mQueueItem;
/** Planet buildings information mapper */
private final BuildingsInformationMapper mBuildings;
/** Fleet information row mapper */
private final FleetInformationMapper mFleet;
/** Fleet ships row mapper */
private final ShipsInformationMapper mShips;
/**
* Set up the {@link XStream} instance that generates the dumps as well as the necessary row
* mappers.
*/
public EmpireSummaryBean( )
{
this.xStream = new XStream( );
this.xStream.processAnnotations( new Class< ? >[] {
AccountInformation.class , AllianceInformation.class , BuildingsInformation.class ,
DebugInformation.class , EmpireInformation.class , FleetInformation.class , MovementInformation.class ,
PlanetInformation.class , QueueInformation.class , QueueItemInformation.class ,
ResearchLineInformation.class , ResearchGraphInformation.class , ResourceDeltaInformation.class ,
ResourceProviderInformation.class , ShipsInformation.class , SystemInformation.class
} );
this.mMainInfo = new DebugInformationMapper( );
this.mResources = new EmpireResourceInformationMapper( );
this.mResearch = new ResearchInformationMapper( );
this.mPlanet = new PlanetInformationMapper( );
this.mPlanetResources = new ResourceRowMapper( );
this.mQueueItem = new QueueItemInformationMapper( );
this.mBuildings = new BuildingsInformationMapper( );
this.mFleet = new FleetInformationMapper( );
this.mShips = new ShipsInformationMapper( );
}
/**
* Dependency injector that sets the data source
*
* @param dataSource
* the data source
*/
@Autowired( required = true )
public void setDataSource( DataSource dataSource )
{
this.dTemplate = new JdbcTemplate( dataSource );
}
/**
* Generate an empire's XML summary
*
* <p>
* Retrieve all information from the database, convert that information into XML dump record
* instances through row mappers, then convert the top-level record into XML using the
* component's {@link XStream} instance.
*/
@Override
public String getSummary( int empireId )
{
DebugInformation empireDump = this.dTemplate.queryForObject( Q_EMPIRE , this.mMainInfo , empireId );
this.getResources( empireId , empireDump );
this.getResearch( empireId , empireDump );
this.getPlanets( empireId , empireDump );
this.getFleets( empireId , empireDump );
return this.xStream.toXML( empireDump );
}
/**
* Extract resources information
*
* <p>
* Read the list of empire resources from the appropriate view and add the extracted entries to
* the empire's list of resources.
*
* @param empireId
* the empire's identifier
* @param empireDump
* the top-level instance
*/
private void getResources( int empireId , DebugInformation empireDump )
{
List< EmpireResourceInformation > resources = empireDump.getEmpire( ).getResources( );
for ( EmpireResourceInformation empRes : this.dTemplate.query( Q_RESOURCES , this.mResources , empireId ) ) {
resources.add( empRes );
}
}
/**
* Get research information
*
* <p>
* Read all research-related information from the appropriate dump view, and add corresponding
* entries to the top-level instance.
*
* @param empireId
* the empire's identifier
* @param empireDump
* the top-level instance
*/
private void getResearch( int empireId , DebugInformation empireDump )
{
for ( ResearchInformation ri : this.dTemplate.query( Q_RESEARCH , this.mResearch , empireId ) ) {
empireDump.getResearch( ).add( ri );
}
}
/**
* Get empire planets and related information
*
* <p>
* Read the planet list and basic planet information from the appropriate dump view, then read
* all extra information (resources, build queues, buildings).
*
* @param empireId
* the empire's identifier
* @param empireDump
* the top-level instance
*/
private void getPlanets( int empireId , DebugInformation empireDump )
{
HashMap< Integer , PlanetInformation > planets = new HashMap< Integer , PlanetInformation >( );
for ( PlanetInformation planet : this.dTemplate.query( Q_PLANETS , this.mPlanet , empireId ) ) {
empireDump.getPlanets( ).add( planet );
planets.put( planet.getId( ) , planet );
}
this.getPlanetResources( empireId , planets );
this.getBuildQueues( empireId , planets );
this.getBuildings( empireId , planets );
}
/**
* Add resources information to planets
*
* <p>
* Access resources information for the empire's planets and add the records to each planet.
*
* @param empireId
* the empire's identifier
* @param planets
* a map associating planet records with their identifier
*/
private void getPlanetResources( int empireId , Map< Integer , PlanetInformation > planets )
{
for ( PlanetResourceRow resRow : this.dTemplate.query( Q_PLANET_RESOURCES , this.mPlanetResources , empireId ) ) {
PlanetInformation planet = planets.get( resRow.getPlanetId( ) );
planet.getResourceDeltas( ).add( resRow.getDelta( ) );
ResourceProviderInformation resProv = resRow.getProvider( );
if ( resProv != null ) {
planet.getResourceProviders( ).add( resProv );
}
}
}
/**
* Add build queue information to planet records
*
* <p>
* Access the contents of build queues and add the records to the corresponding planets.
*
* @param empireId
* the empire's identifier
* @param planets
* the map of planets by identifier
*/
private void getBuildQueues( int empireId , Map< Integer , PlanetInformation > planets )
{
for ( QueueItemInformation queueItem : this.dTemplate.query( Q_BUILD_QUEUES , this.mQueueItem , empireId ) ) {
PlanetInformation planet = planets.get( queueItem.getPlanetId( ) );
QueueInformation queue;
if ( queueItem.isMilitary( ) ) {
queue = planet.getMilitaryQueue( );
} else {
queue = planet.getCivilianQueue( );
}
queue.getItems( ).add( queueItem );
}
}
/**
* Add buildings information to planet records
*
* <p>
* Access the contents of the buildings dump view and add the building records to the
* corresponding planets.
*
* @param empireId
* the empire's identifier
* @param planets
* the map of planets by identifier
*/
private void getBuildings( int empireId , Map< Integer , PlanetInformation > planets )
{
for ( BuildingsInformation bi : this.dTemplate.query( Q_BUILDINGS , this.mBuildings , empireId ) ) {
planets.get( bi.getPlanetId( ) ).getBuildings( ).add( bi );
}
}
/**
* Retrieve information about the empire's fleets
*
* <p>
* Access the list of fleets, add the records to the top-level instance, then retrieve all
* necessary information.
*
* @param empireId
* the empire's identifier
* @param empireDump
* the top-level empire dump
*/
private void getFleets( int empireId , DebugInformation empireDump )
{
Map< Long , FleetInformation > fleets = new HashMap< Long , FleetInformation >( );
for ( FleetInformation fi : this.dTemplate.query( Q_FLEETS , this.mFleet , empireId ) ) {
empireDump.getFleets( ).add( fi );
fleets.put( fi.getId( ) , fi );
}
this.getShips( empireId , fleets );
}
/**
* Add ships information to fleet records
*
* <p>
* Retrieve information about ships and add the records to the corresponding fleets.
*
* @param empireId
* the empire's identifier
* @param fleets
* the map of fleets by identifier
*/
private void getShips( int empireId , Map< Long , FleetInformation > fleets )
{
for ( ShipsInformation si : this.dTemplate.query( Q_SHIPS , this.mShips , empireId ) ) {
fleets.get( si.getFleetId( ) ).getShips( ).add( si );
}
}
}

View file

@ -0,0 +1,66 @@
package com.deepclone.lw.beans.bt.es;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.deepclone.lw.beans.bt.es.data.FleetInformation;
import com.deepclone.lw.beans.bt.es.data.MovementInformation;
/**
* Fleet information row mapper
*
* <p>
* This class is responsible for mapping rows from <code>bugs.dump_fleets_view</code> into
* {@link FleetInformation} instances.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*
*/
final class FleetInformationMapper
implements RowMapper< FleetInformation >
{
/**
* Map a row from <code>bugs.dump_fleets_view</code>
*
* <p>
* Generate a {@link FleetInformation} instance from the row's contents. If the row indicates
* that the fleet is moving, add a {@link MovementInformation} instance to the fleet information
* record.
*/
@Override
public FleetInformation mapRow( ResultSet rs , int rowNum )
throws SQLException
{
FleetInformation fi = new FleetInformation( );
fi.setId( rs.getLong( "fleet_id" ) );
fi.setName( rs.getString( "fleet_name" ) );
fi.setStatus( rs.getString( "status" ) );
fi.setAttacking( rs.getBoolean( "attacking" ) );
fi.setLocationId( rs.getInt( "location_id" ) );
fi.setLocationName( rs.getString( "location_name" ) );
Integer sourceId = (Integer) rs.getObject( "source_id" );
if ( sourceId != null ) {
MovementInformation mi = new MovementInformation( );
mi.setSourceId( sourceId );
mi.setSourceName( rs.getString( "source_name" ) );
mi.setTimeLeft( rs.getInt( "time_left" ) );
mi.setStateTimeLeft( rs.getInt( "state_time_left" ) );
mi.setNearId( (Integer) rs.getObject( "ref_point_id" ) );
mi.setNearName( rs.getString( "ref_point_name" ) );
mi.setOutwards( (Boolean) rs.getObject( "outwards" ) );
mi.setPastRefPoint( (Boolean) rs.getObject( "past_ref_point" ) );
mi.setStartX( (Float) rs.getObject( "start_x" ) );
mi.setStartY( (Float) rs.getObject( "start_y" ) );
fi.setMovement( mi );
}
return fi;
}
}

View file

@ -0,0 +1,50 @@
package com.deepclone.lw.beans.bt.es;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.deepclone.lw.beans.bt.es.data.PlanetInformation;
/**
* Top-level planet information row mapper
*
* <p>
* This class maps rows from <code>bugs.dump_planets_view</code> into {@link PlanetInformation}
* instances.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*
*/
final class PlanetInformationMapper
implements RowMapper< PlanetInformation >
{
/**
* Map a row from <code>bugs.dump_planets_view</code>
*
* <p>
* Create a new {@link PlanetInformation} instance from the row's contents. The instance's
* civilian and military construction queues, while left mostly uninitialised, will have their
* money and work accumulators set.
*/
@Override
public PlanetInformation mapRow( ResultSet rs , int rowNum )
throws SQLException
{
PlanetInformation pi = new PlanetInformation( );
pi.setId( rs.getInt( "planet_id" ) );
pi.setPopulation( rs.getDouble( "population" ) );
pi.setCurrentHappiness( rs.getDouble( "current_happiness" ) );
pi.setTargetHappiness( rs.getDouble( "target_happiness" ) );
pi.getCivilianQueue( ).setAccMoney( rs.getDouble( "civ_money" ) );
pi.getCivilianQueue( ).setAccWork( rs.getDouble( "civ_work" ) );
pi.getMilitaryQueue( ).setAccMoney( rs.getDouble( "mil_money" ) );
pi.getMilitaryQueue( ).setAccWork( rs.getDouble( "mil_work" ) );
return pi;
}
}

View file

@ -0,0 +1,96 @@
package com.deepclone.lw.beans.bt.es;
import com.deepclone.lw.beans.bt.es.data.ResourceDeltaInformation;
import com.deepclone.lw.beans.bt.es.data.ResourceProviderInformation;
/**
* Planet resource row information
*
* <p>
* Planet resources and resource providers are both extracted from the same
* <code>bugs.planet_resources_view</code> rows. Because of that, this class is used to transmit the
* information (as a {@link ResourceDeltaInformation} instance and an optional
* {@link ResourceProviderInformation} instance) from the row mapper to the summary creation
* component.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
class PlanetResourceRow
{
/** Identifier of the planet */
private final int planetId;
/** Resource delta information */
private final ResourceDeltaInformation delta = new ResourceDeltaInformation( );
/** Resource provider information */
private ResourceProviderInformation provider;
/**
* Initialise the instance by setting the planet identifier
*
* @param planetId
* the planet's identifier
*/
public PlanetResourceRow( int planetId )
{
this.planetId = planetId;
}
/** @return the planet's identifier */
public int getPlanetId( )
{
return this.planetId;
}
/** @return the resource delta information record */
public ResourceDeltaInformation getDelta( )
{
return this.delta;
}
/** @return the resource provider information record */
public ResourceProviderInformation getProvider( )
{
return this.provider;
}
/**
* Set the resource provider information record
*
* @param provider
* the resource provider information record
*/
public void setProvider( ResourceProviderInformation provider )
{
this.provider = provider;
}
/**
* Set the name of the resource
*
* <p>
* This method should be called once the rest of the record(s) has been initialised. It will set
* the resource name on both the delta and the provider (if the latter exists).
*
* @param resource
* the name of the resource
*/
public void setResource( String resource )
{
this.delta.setResource( resource );
if ( this.provider != null ) {
this.provider.setResource( resource );
}
}
}

View file

@ -0,0 +1,46 @@
package com.deepclone.lw.beans.bt.es;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.deepclone.lw.beans.bt.es.data.QueueItemInformation;
/**
* Generic row mapper for construction queue items
*
* <p>
* This class is responsible for mapping rows from <code>bugs.dump_queues_view</code> into
* {@link QueueItemInformation} instances. These instances will be added to the right queue later.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*
*/
final class QueueItemInformationMapper
implements RowMapper< QueueItemInformation >
{
/**
* Map a row from <code>bugs.dump_queues_view</code>
*
* <p>
* Create a {@link QueueItemInformation} instance from the row's contents.
*/
@Override
public QueueItemInformation mapRow( ResultSet rs , int rowNum )
throws SQLException
{
QueueItemInformation qii = new QueueItemInformation( );
qii.setPlanetId( rs.getInt( "planet_id" ) );
qii.setMilitary( rs.getBoolean( "military" ) );
qii.setId( rs.getInt( "item_id" ) );
qii.setName( rs.getString( "item_name" ) );
qii.setDestroy( rs.getBoolean( "destroy" ) );
qii.setAmount( rs.getInt( "amount" ) );
return qii;
}
}

View file

@ -0,0 +1,49 @@
package com.deepclone.lw.beans.bt.es;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.postgresql.util.PGobject;
import org.springframework.jdbc.core.RowMapper;
import com.deepclone.lw.beans.bt.es.data.ResearchGraphInformation;
import com.deepclone.lw.beans.bt.es.data.ResearchInformation;
import com.deepclone.lw.beans.bt.es.data.TechnologyState;
/**
* Research information row mapper
*
* <p>
* This class maps rows from <code>bugs.dump_research_view</code> into
* {@link ResearchGraphInformation} instances.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*
*/
final class ResearchInformationMapper
implements RowMapper< ResearchInformation >
{
/**
* Map a <code>bugs.dump_research_view</code> row
*
* <p>
* Create a {@link ResearchGraphInformation} instance from the row's contents.
*/
@Override
public ResearchInformation mapRow( ResultSet rs , int rowNum )
throws SQLException
{
ResearchGraphInformation ri = new ResearchGraphInformation( );
ri.setName( rs.getString( "name" ) );
ri.setState( TechnologyState.valueOf( ( (PGobject) rs.getObject( "state" ) ).toString( ) ) );
if ( ri.getState( ) == TechnologyState.RESEARCH ) {
ri.setPoints( rs.getDouble( "points" ) );
ri.setPriority( rs.getInt( "priority" ) );
}
return ri;
}
}

View file

@ -0,0 +1,65 @@
package com.deepclone.lw.beans.bt.es;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.deepclone.lw.beans.bt.es.data.ResourceProviderInformation;
/**
* Mapper which extract planet resources and resource providers information
*
* <p>
* This class maps rows from <code>bugs.dump_planet_resources_view</code> into
* {@link PlanetResourceRow} instances.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*
*/
class ResourceRowMapper
implements RowMapper< PlanetResourceRow >
{
/**
* Map a row from <code>bugs.dump_planet_resources_view</code>
*
* <p>
* Generate the {@link PlanetResourceRow} instance with the correct planet identifier, resource
* name, income and upkeep. If there is also a resource provider, attach a
* {@link ResourceProviderInformation} instance to the result, and set its mining priority if
* one exists.
*/
@Override
public PlanetResourceRow mapRow( ResultSet rs , int rowNum )
throws SQLException
{
PlanetResourceRow row = new PlanetResourceRow( rs.getInt( "planet_id" ) );
row.getDelta( ).setIncome( rs.getDouble( "pres_income" ) );
row.getDelta( ).setUpkeep( rs.getDouble( "pres_upkeep" ) );
double pCapacity = rs.getDouble( "resprov_quantity_max" );
if ( !rs.wasNull( ) ) {
ResourceProviderInformation rpi = new ResourceProviderInformation( );
rpi.setMaximalQuantity( pCapacity );
rpi.setCurrentQuantity( rs.getDouble( "resprov_quantity" ) );
rpi.setDifficulty( rs.getDouble( "resprov_difficulty" ) );
rpi.setRecovery( rs.getDouble( "resprov_recovery" ) );
int miningPriority = rs.getInt( "mining_priority" );
if ( !rs.wasNull( ) ) {
rpi.setMiningPriority( miningPriority );
}
row.setProvider( rpi );
}
row.setResource( rs.getString( "resource_name" ) );
return row;
}
}

View file

@ -0,0 +1,46 @@
package com.deepclone.lw.beans.bt.es;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;
import com.deepclone.lw.beans.bt.es.data.ShipsInformation;
/**
* Fleet ships information row mapper
*
* <p>
* This class is responsible for creating {@link ShipsInformation} instances from the contents of
* <code>bugs.dump_ships_view</code>.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*
*/
final class ShipsInformationMapper
implements RowMapper< ShipsInformation >
{
/**
* Map a row from <code>bugs.dump_ships_view</code>
*
* <p>
* Generate a {@link ShipsInformation} instance and initialise its fields based on the row's
* contents.
*/
@Override
public ShipsInformation mapRow( ResultSet rs , int rowNum )
throws SQLException
{
ShipsInformation si = new ShipsInformation( );
si.setFleetId( rs.getLong( "fleet_id" ) );
si.setId( rs.getInt( "ship_id" ) );
si.setName( rs.getString( "ship_name" ) );
si.setAmount( rs.getInt( "amount" ) );
si.setDamage( rs.getDouble( "damage" ) );
return si;
}
}

View file

@ -1,8 +1,8 @@
package com.deepclone.lw.beans.bt.esdata;
package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.ArrayList;
import java.util.List;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@ -19,7 +19,7 @@ public class DebugInformation
@XStreamAsAttribute
@XStreamAlias( "dump-version" )
private int version = 1;
private int version = 2;
private SystemInformation system = new SystemInformation( );
@ -28,13 +28,13 @@ public class DebugInformation
private EmpireInformation empire = new EmpireInformation( );
@XStreamAlias( "research" )
private List< ResearchInformation > research = new LinkedList< ResearchInformation >( );
private List< ResearchInformation > research = new ArrayList< ResearchInformation >( );
@XStreamAlias( "planets" )
private List< PlanetInformation > planets = new LinkedList< PlanetInformation >( );
private List< PlanetInformation > planets = new ArrayList< PlanetInformation >( );
@XStreamAlias( "fleets" )
private List< FleetInformation > fleets = new LinkedList< FleetInformation >( );
private List< FleetInformation > fleets = new ArrayList< FleetInformation >( );
public int getVersion( )

View file

@ -0,0 +1,141 @@
package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
/**
* Empire information record for XML dumps
*
* <p>
* This class regroups all "main" empire information in XML dumps. This includes the empire's name
* and identifier, details about the alliance, and the list of resources.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
@SuppressWarnings( "serial" )
public class EmpireInformation
implements Serializable
{
/** The empire's numeric identifier */
@XStreamAsAttribute
private Integer id;
/** The empire's name */
@XStreamAsAttribute
private String name;
/** The empire's cash */
@XStreamAsAttribute
private Double cash;
/**
* The alliance the empire belongs to or has requested membership of (or <code>null</code> if
* the empire is neither in an alliance nor requesting to join one)
*/
private AllianceInformation alliance;
/** The empire's resources */
private final ArrayList< EmpireResourceInformation > resources = new ArrayList< EmpireResourceInformation >( );
/** @return the empire's numeric identifier */
public Integer getId( )
{
return this.id;
}
/**
* Set the empire's numeric identifier
*
* @param id
* the empire's numeric identifier
*/
public void setId( int id )
{
this.id = id;
}
/** @return the empire's name */
public String getName( )
{
return this.name;
}
/**
* Set the empire's name
*
* @param name
* the empire's name
*/
public void setName( String name )
{
this.name = name;
}
/** @return the amount of cash possessed by the empire */
public Double getCash( )
{
return this.cash;
}
/**
* Set the amount of cash possessed by the empire
*
* @param cash
* the amount of cash possessed by the empire
*/
public void setCash( double cash )
{
this.cash = cash;
}
/**
* @return the alliance the empire belongs to or has requested membership of, or
* <code>null</code> if the empire is neither in an alliance nor requesting to join one
*/
public AllianceInformation getAlliance( )
{
return this.alliance;
}
/**
* Set the information about the alliance
*
* @param alliance
* the information about the alliance
*/
public void setAlliance( AllianceInformation alliance )
{
this.alliance = alliance;
}
/**
* Access the list of resources
*
* @return the list of resources, even if none was set in the file the instance was loaded from.
*/
public List< EmpireResourceInformation > getResources( )
{
if ( this.resources == null ) {
return Collections.emptyList( );
}
return this.resources;
}
}

View file

@ -0,0 +1,134 @@
package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
/**
* Empire resources XML dump record
*
* <p>
* This class is used to store information about an empire's resources in debugging XML dumps. Each
* instance indicates the amount possessed or owed for a given type of resources, as well as the
* mining priority if it is a natural resource.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
@XStreamAlias( "resource" )
@SuppressWarnings( "serial" )
public class EmpireResourceInformation
implements Serializable
{
/** The type of resources */
@XStreamAlias( "id" )
@XStreamAsAttribute
private String resource;
/** The amount of resources possessed */
@XStreamAsAttribute
private Double possessed;
/** The amount of resources owed */
@XStreamAsAttribute
private Double owed;
/**
* The mining priority for this type of resource, or <code>null</code> if it is not a natural
* resource
*/
@XStreamAlias( "mining-priority" )
@XStreamAsAttribute
private Integer miningPriority;
/** @return the type of resources */
public String getResource( )
{
return this.resource;
}
/**
* Set the type of resources
*
* @param resource
* the type of resources
*
* @throws InvalidDumpContentsException
* if the specified resource type is <code>null</code>
*/
public void setResource( String resource )
throws InvalidDumpContentsException
{
if ( resource == null ) {
throw new InvalidDumpContentsException( this.getClass( ) , "resource" );
}
this.resource = resource;
}
/** @return the amount of resources possessed */
public Double getPossessed( )
{
return this.possessed;
}
/**
* Set the amount of resources possessed
*
* @param possessed
* the amount of resources possessed
*/
public void setPossessed( Double possessed )
{
this.possessed = possessed;
}
/** @return the amount of resources owed */
public Double getOwed( )
{
return this.owed;
}
/**
* Set the amount of resources owed
*
* @param owed
* the amount of resources owed
*/
public void setOwed( Double owed )
{
this.owed = owed;
}
/**
* @return the mining priority for this type of resource, or <code>null</code> if it is not a
* natural resource
*/
public Integer getMiningPriority( )
{
return this.miningPriority;
}
/**
* Set the mining priority for this type of resource
*
* @param miningPriority
* the mining priority for this type of resource
*/
public void setMiningPriority( int miningPriority )
{
this.miningPriority = miningPriority;
}
}

View file

@ -0,0 +1,60 @@
package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
/**
* Invalid dump contents exception
*
* <p>
* This runtime exception is thrown by the debugging data record classes when one of the fields is
* set to an incorrect value.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*
*/
public final class InvalidDumpContentsException
extends RuntimeException
{
/** Serialisation identifier */
private static final long serialVersionUID = 1L;
/** Class in which the error was caused */
private final Class< ? extends Serializable > recordType;
/** Name of the field to which invalid contents were assigned */
private final String field;
/**
* Initialise the exception by setting the record and field
*
* @param type
* the type of the XML dump record
* @param field
* the field to which invalid contents were assigned
*/
InvalidDumpContentsException( Class< ? extends Serializable > type , String field )
{
super( "Invalid contents for field " + field + " of record " + type.getSimpleName( ) );
this.recordType = type;
this.field = field;
}
/** @return the type of the XML dump record */
public Class< ? extends Serializable > getRecordType( )
{
return this.recordType;
}
/** @return the field to which invalid contents were assigned */
public String getField( )
{
return this.field;
}
}

View file

@ -0,0 +1,210 @@
package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
/**
* Planet XML record
*
* <p>
* This class is used in XML dumps to represent the information about a planet. It includes a few
* basic values, as well as information about buildings, queues and resources.
*
* <p>
* This record exists since version 1 (B6M1) of XML dumps. However, the following changes were made
* later.
* <ul>
* <li>Version 2 (B6M2):
* <ul>
* <li>resource providers added,
* </ul>
* </ul>
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*
*/
@XStreamAlias( "planet" )
@SuppressWarnings( "serial" )
public class PlanetInformation
implements Serializable
{
/** Planet identifier */
@XStreamAsAttribute
private Integer id;
/** Planet name */
@XStreamAsAttribute
private String name;
/** Current population of the planet */
@XStreamAlias( "population" )
private Double population;
/** Current happiness of the planet's population */
@XStreamAlias( "current-happiness" )
private Double currentHappiness;
/** Target happiness of the planet's population */
@XStreamAlias( "target-happiness" )
private double targetHappiness;
/** List of buildings */
@XStreamAlias( "buildings" )
private final List< BuildingsInformation > buildings = new ArrayList< BuildingsInformation >( );
/** Civilian construction queue */
@XStreamAlias( "civ-queue" )
private final QueueInformation civilianQueue = new QueueInformation( );
/** Military construction queue */
@XStreamAlias( "mil-queue" )
private final QueueInformation militaryQueue = new QueueInformation( );
/** Planet resource deltas */
@XStreamImplicit
private final ArrayList< ResourceDeltaInformation > resourceDeltas = new ArrayList< ResourceDeltaInformation >( );
/** List of resource providers */
@XStreamImplicit( itemFieldName = "resource-provider" )
private final ArrayList< ResourceProviderInformation > resourceProviders = new ArrayList< ResourceProviderInformation >( );
/** @return the planet's identifier */
public Integer getId( )
{
return this.id;
}
/**
* Set the planet's identifier
*
* @param id
* the planet's identifier
*/
public void setId( int id )
{
this.id = id;
}
/** @return the planet's name */
public String getName( )
{
return this.name;
}
/**
* Set the planet's name
*
* @param name
* the planet's name
*/
public void setName( String name )
{
this.name = name;
}
/** @return the planet's current population */
public Double getPopulation( )
{
return this.population;
}
/**
* Set the planet's current population
*
* @param population
* the planet's current population
*/
public void setPopulation( double population )
{
this.population = population;
}
/** @return the current happiness of the planet's population */
public Double getCurrentHappiness( )
{
return this.currentHappiness;
}
/**
* Set the current happiness of the planet's population
*
* @param currentHappiness
* the current happiness of the planet's population
*/
public void setCurrentHappiness( double currentHappiness )
{
this.currentHappiness = currentHappiness;
}
/** @return the target happiness of the planet's population */
public Double getTargetHappiness( )
{
return this.targetHappiness;
}
/**
* Set the target happiness of the planet's population
*
* @param targetHappiness
* the target happiness of the planet's population
*/
public void setTargetHappiness( double targetHappiness )
{
this.targetHappiness = targetHappiness;
}
/** @return the list of buildings constructed on the planet */
public List< BuildingsInformation > getBuildings( )
{
return this.buildings;
}
/** @return the civilian construction queue */
public QueueInformation getCivilianQueue( )
{
return this.civilianQueue;
}
/** @return the military construction queue */
public QueueInformation getMilitaryQueue( )
{
return this.militaryQueue;
}
/** @return the list of resource delta records */
public ArrayList< ResourceDeltaInformation > getResourceDeltas( )
{
return this.resourceDeltas;
}
/** @return the list of resource provider records */
public ArrayList< ResourceProviderInformation > getResourceProviders( )
{
return this.resourceProviders;
}
}

View file

@ -0,0 +1,136 @@
package com.deepclone.lw.beans.bt.es.data;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
/**
* Technology from the technology graph and associated state information
*
* <p>
* This class represents the state of a technology from the B6M2+ technology graph for the empire
* being dumped.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
@SuppressWarnings( "serial" )
@XStreamAlias( "technology" )
public class ResearchGraphInformation
extends ResearchInformation
{
/** The technology's name */
@XStreamAsAttribute
private String name;
/** The technology's state */
@XStreamAsAttribute
private TechnologyState state;
/**
* The amount of accumulated research points, or <code>null</code> if the technology has been
* researched
*/
@XStreamAsAttribute
private Double points;
/** The research priority, or <code>null</code> if the technology has been researched */
@XStreamAsAttribute
private Integer priority;
/**
* Gets the technology's name.
*
* @return the technology's name
*/
public String getName( )
{
return this.name;
}
/**
* Sets the technology's name.
*
* @param name
* the technology's new name
*/
public void setName( String name )
{
this.name = name;
}
/**
* Gets the technology's state.
*
* @return the technology's state
*/
public TechnologyState getState( )
{
return this.state;
}
/**
* Sets the technology's state.
*
* @param state
* the technology's new state
*/
public void setState( TechnologyState state )
{
this.state = state;
}
/**
* Gets the amount of accumulated research points
*
* @return the amount of accumulated research points, or <code>null</code> if the technology has
* been researched
*/
public Double getPoints( )
{
return this.points;
}
/**
* Sets the amount of accumulated research points
*
* @param points
* the amount of accumulated research points
*/
public void setPoints( Double points )
{
this.points = points;
}
/**
* Gets the research priority
*
* @return the research priority, or <code>null</code> if the technology has been researched
*/
public Integer getPriority( )
{
return this.priority;
}
/**
* Sets the research priority
*
* @param priority
* the new research priority
*/
public void setPriority( Integer priority )
{
this.priority = priority;
}
}

View file

@ -0,0 +1,25 @@
package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
/**
* Empty, base research record
*
* <p>
* This class used to contain B6M1 research line entries; however, in order to support B6M2
* technologies while maintaining XML compatibility, it has been replaced with an empty class which
* servces as the base class for both old and new records.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*
*/
@SuppressWarnings( "serial" )
public abstract class ResearchInformation
implements Serializable
{
// EMPTY
}

View file

@ -0,0 +1,137 @@
package com.deepclone.lw.beans.bt.es.data;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
/**
* Research line information
*
* <p>
* This class defines data stored in the dumps for B6M1 research lines. It is no longer actively
* used as of B6M2, but is kept around so the XML files can still be used if necessary.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
@XStreamAlias( "research-line" )
public class ResearchLineInformation
extends ResearchInformation
{
private static final long serialVersionUID = 1L;
/** Identifier of the technology line */
@XStreamAsAttribute
@XStreamAlias( "line" )
private int id;
/** Current level for that line */
@XStreamAsAttribute
@XStreamAlias( "level" )
private int currentLevel;
/** Name of the last level */
@XStreamAsAttribute
@XStreamAlias( "name" )
private String levelName;
/** Accumulated points towards the next level */
@XStreamAsAttribute
@XStreamAlias( "accumulated-points" )
private double accumulated;
/**
* Gets the identifier of the technology line.
*
* @return the identifier of the technology line
*/
public int getId( )
{
return this.id;
}
/**
* Sets the identifier of the technology line.
*
* @param id
* the new identifier of the technology line
*/
public void setId( int id )
{
this.id = id;
}
/**
* Gets the current level for that line.
*
* @return the current level for that line
*/
public int getCurrentLevel( )
{
return this.currentLevel;
}
/**
* Sets the current level for that line.
*
* @param currentLevel
* the new level for that line
*/
public void setCurrentLevel( int currentLevel )
{
this.currentLevel = currentLevel;
}
/**
* Gets the name of the last level.
*
* @return the name of the last level
*/
public String getLevelName( )
{
return this.levelName;
}
/**
* Sets the name of the last level.
*
* @param levelName
* the new name of the last level
*/
public void setLevelName( String levelName )
{
this.levelName = levelName;
}
/**
* Gets the accumulated points towards the next level.
*
* @return the accumulated points towards the next level
*/
public double getAccumulated( )
{
return this.accumulated;
}
/**
* Sets the accumulated points towards the next level.
*
* @param accumulated
* the new accumulated points towards the next level
*/
public void setAccumulated( double accumulated )
{
this.accumulated = accumulated;
}
}

View file

@ -0,0 +1,109 @@
package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
/**
* Resource delta information
*
* <p>
* This class represents records which contain a resource's delta - that is, the income and upkeep
* for some type of resource.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
@SuppressWarnings( "serial" )
@XStreamAlias( "resource-delta" )
public class ResourceDeltaInformation
implements Serializable
{
/** Identifier of the resource */
@XStreamAlias( "id" )
@XStreamAsAttribute
private String resource;
/** Income for that type of resource */
@XStreamAsAttribute
private Double income;
/** Upkeep for that type of resource */
@XStreamAsAttribute
private Double upkeep;
/** @return the resource's identifier */
public String getResource( )
{
return this.resource;
}
/**
* Set the resource's identifier
*
* @param resource
* the resource's identifier
*
* @throws InvalidDumpContentsException
* if the specified resource type is <code>null</code>
*/
public void setResource( String resource )
throws InvalidDumpContentsException
{
if ( resource == null ) {
throw new InvalidDumpContentsException( this.getClass( ) , "resource" );
}
this.resource = resource;
}
/**
* @return the income for that type of resource, or <code>null</code> if no income information
* is available
*/
public Double getIncome( )
{
return this.income;
}
/**
* Set the income for that type of resource
*
* @param income
* the income for that type of resource
*/
public void setIncome( double income )
{
this.income = income;
}
/**
* @return the upkeep for that type of resource, or <code>null</code> if no upkeep information
* is available
*/
public Double getUpkeep( )
{
return this.upkeep;
}
/**
* Set the upkeep for that type of resource
*
* @param upkeep
* the upkeep for that type of resource
*/
public void setUpkeep( double upkeep )
{
this.upkeep = upkeep;
}
}

View file

@ -0,0 +1,179 @@
package com.deepclone.lw.beans.bt.es.data;
import java.io.Serializable;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
/**
* Resource provider XML record
*
* <p>
* This class represents the information about a resource provider that will be serialised to the
* debugging XML dump when a player posts a bug report.
*
* <p>
* This record exists since version 2 (B6M2) of XML dumps.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
@SuppressWarnings( "serial" )
public class ResourceProviderInformation
implements Serializable
{
/** Identifier of the resource */
@XStreamAsAttribute
private String resource;
/** Maximal quantity in the provider */
@XStreamAsAttribute
@XStreamAlias( "max" )
private Double maximalQuantity;
/** Current quantity in the provider */
@XStreamAsAttribute
@XStreamAlias( "current" )
private Double currentQuantity;
/** Extraction difficulty */
@XStreamAsAttribute
private Double difficulty;
/** Recovery rate */
@XStreamAsAttribute
private Double recovery;
/** Planet-specific mining priority */
@XStreamAlias( "mining-priority" )
@XStreamAsAttribute
private Integer miningPriority;
/** @return the resource's identifier */
public String getResource( )
{
return this.resource;
}
/**
* Set the resource's identifier
*
* @param resource
* the resource's identifier
*
* @throws InvalidDumpContentsException
* if the resource's identifier is <code>null</code>
*/
public void setResource( String resource )
throws InvalidDumpContentsException
{
if ( resource == null ) {
throw new InvalidDumpContentsException( this.getClass( ) , "resource" );
}
this.resource = resource;
}
/** @return the provider's total capacity */
public Double getMaximalQuantity( )
{
return this.maximalQuantity;
}
/**
* Set the maximal quantity of resources in the provider
*
* @param maximalQuantity
* the provider's total capacity
*/
public void setMaximalQuantity( double maximalQuantity )
{
this.maximalQuantity = maximalQuantity;
}
/** @return the current quantity of resources in the provider */
public Double getCurrentQuantity( )
{
return this.currentQuantity;
}
/**
* Set the current quantity of resources in the provider
*
* @param currentQuantity
* the current quantity of resources in the provider
*/
public void setCurrentQuantity( double currentQuantity )
{
this.currentQuantity = currentQuantity;
}
/** @return the provider's extraction difficulty */
public Double getDifficulty( )
{
return this.difficulty;
}
/**
* Set the provider's extraction difficulty
*
* @param difficulty
* the provider's extraction difficulty
*/
public void setDifficulty( double difficulty )
{
this.difficulty = difficulty;
}
/** @return the provider's recovery rate */
public Double getRecovery( )
{
return this.recovery;
}
/**
* Set the provider's recovery rate
*
* @param recovery
* the provider's recovery rate
*/
public void setRecovery( double recovery )
{
this.recovery = recovery;
}
/**
* @return the planet-specific mining priority, or <code>null</code> if the empire's global
* settings are in used
*/
public Integer getMiningPriority( )
{
return this.miningPriority;
}
/**
* Set the planet-specific mining priority
*
* @param miningPriority
* the planet-specific mining priority
*/
public void setMiningPriority( int miningPriority )
{
this.miningPriority = miningPriority;
}
}

View file

@ -0,0 +1,20 @@
package com.deepclone.lw.beans.bt.es.data;
/**
* State of a (B6M2+) technology
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
public enum TechnologyState {
/** The technology is being researched */
RESEARCH ,
/** The technology needs to be implemented */
PENDING ,
/** The technology has been researched and implemented */
KNOWN
}

View file

@ -2,8 +2,11 @@
<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">
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="adminBugs" class="com.deepclone.lw.beans.bt.AdminBugsBean" />
<bean id="bugsDAO" class="com.deepclone.lw.beans.bt.BugsDAOBean" />
<bean id="empireSummary" class="com.deepclone.lw.beans.bt.es.EmpireSummaryBean" />
<bean id="playerBugs" class="com.deepclone.lw.beans.bt.PlayerBugsBean" />
</beans>

View file

@ -4,12 +4,12 @@
<parent>
<artifactId>legacyworlds-server-beans</artifactId>
<groupId>com.deepclone.lw</groupId>
<version>5.99.1</version>
<version>1.0.0</version>
<relativePath>../legacyworlds-server-beans/pom.xml</relativePath>
</parent>
<groupId>com.deepclone.lw</groupId>
<artifactId>legacyworlds-server-beans-eventlog</artifactId>
<version>5.99.1</version>
<name>Legacy Worlds event log</name>
<name>Legacy Worlds - Server - Components - Logging</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>
<version>${legacyworlds.version.main}.${legacyworlds.version.release}-${legacyworlds.version.build}</version>
</project>

View file

@ -13,8 +13,8 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
@ -39,7 +39,7 @@ public class LogReaderBean
implements LogReader
{
private SimpleJdbcTemplate dTemplate;
private JdbcTemplate dTemplate;
private TransactionTemplate tTemplate;
private final RowMapper< LogEntry > mLogEntry;
@ -88,7 +88,7 @@ public class LogReaderBean
@Autowired( required = true )
public void setDataSource( DataSource dataSource )
{
this.dTemplate = new SimpleJdbcTemplate( dataSource );
this.dTemplate = new JdbcTemplate( dataSource );
}

View file

@ -0,0 +1,13 @@
<?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.1.xsd">
<bean id="adminErrorMail" class="com.deepclone.lw.beans.eventlog.AdminErrorMailBean" />
<bean id="logCleaner" class="com.deepclone.lw.beans.eventlog.LogCleanerBean" />
<bean id="logger" class="com.deepclone.lw.beans.eventlog.LoggerBean" />
<bean id="logReader" class="com.deepclone.lw.beans.eventlog.LogReaderBean" />
<bean id="logWriter" class="com.deepclone.lw.beans.eventlog.LogWriterBean" />
</beans>

View file

@ -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>1.0.0</version>
<relativePath>../legacyworlds-server-beans/pom.xml</relativePath>
</parent>
<artifactId>legacyworlds-server-beans-events</artifactId>
<version>${legacyworlds.version.main}.${legacyworlds.version.release}-${legacyworlds.version.build}</version>
<name>Legacy Worlds - Server - Components - Events</name>
<description>This package defines the components used to process and handle game events.</description>
</project>

View file

@ -0,0 +1,113 @@
package com.deepclone.lw.beans.events;
import javax.sql.DataSource;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.support.TransactionTemplate;
import com.deepclone.lw.interfaces.sys.Ticker;
import com.deepclone.lw.interfaces.sys.Ticker.Frequency;
/**
* Events processor component
*
* <p>
* This component acquires the necessary dependencies to create an {@link EventProcessorTask}, does
* so, and registers it with the ticker. It clears the reference to the task when destroyed.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*
*/
class EventProcessorBean
implements InitializingBean , DisposableBean
{
/** The ticker */
private Ticker ticker;
/** The Spring transaction template */
private TransactionTemplate tTemplate;
/** The database interface */
private DataSource dataSource;
/** The task */
private Runnable task;
/**
* Dependency injector that sets the ticker component
*
* @param ticker
* the ticker component
*/
@Autowired( required = true )
public void setTicker( Ticker ticker )
{
this.ticker = ticker;
}
/**
* Dependency injector that sets the transaction manager
*
* <p>
* Creates the transaction template from the transaction manager
*
* @param tManager
* the Spring transaction manager
*/
@Autowired( required = true )
public void setTransactionManager( PlatformTransactionManager tManager )
{
this.tTemplate = new TransactionTemplate( tManager );
}
/**
* Dependency injector that sets the database interface
*
* @param dataSource
* the database interface
*/
@Autowired( required = true )
public void setDataSource( DataSource dataSource )
{
this.dataSource = dataSource;
}
/**
* Initialise and register the event processing task
*
* <p>
* When the component's dependencies have been injected, this method creates the
* {@link EventProcessorTask} instance and registers it to the ticker.
*/
@Override
public void afterPropertiesSet( )
{
this.task = new EventProcessorTask( this.tTemplate , this.dataSource );
this.ticker.registerTask( Frequency.HIGH , "Events processor" , this.task );
}
/**
* Clear the task reference
*
* <p>
* Remove the reference to the {@link EventProcessorTask} instance, allowing the ticker to clean
* up.
*/
@Override
public void destroy( )
{
this.task = null;
}
}

View file

@ -0,0 +1,86 @@
package com.deepclone.lw.beans.events;
import javax.sql.DataSource;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;
import com.deepclone.lw.utils.StoredProc;
/**
* Event processing task
*
* <p>
* This class implements the task responsible for regular database event processing calls. It is
* registered as a high-frequency ticker task by {@link EventProcessorBean}.
*
* @author <a href="mailto:tseeker@legacyworlds.com">E. Benoît</a>
*/
class EventProcessorTask
implements Runnable
{
/** The Spring transaction template */
private final TransactionTemplate tTemplate;
/** The stored procedure that implements event processing */
private final StoredProc eqProcess;
/**
* Initialise the transaction template and stored procedure interface
*
* @param tTemplate
* the transaction template
* @param dataSource
* the database interface
*/
public EventProcessorTask( TransactionTemplate tTemplate , DataSource dataSource )
{
this.tTemplate = tTemplate;
this.eqProcess = new StoredProc( dataSource , "events" , "eq_process" );
this.eqProcess.addOutput( "_result" , java.sql.Types.BOOLEAN );
}
/**
* When the task executes, it will call <code>events.eq_process()</code> repeatedly until the
* stored procedure returns <code>false</code>. Each call is made in a separate transaction.
*/
@Override
public void run( )
{
boolean hasMore;
do {
hasMore = this.processBatch( );
} while ( hasMore );
}
/**
* Process a batch of events
*
* <p>
* This method spawns a transaction in which the <code>events.eq_process()</code> stored
* procedure is called.
*
* @return <code>true</code> if events were processed, <code>false</code> if the queues were
* empty.
*/
private boolean processBatch( )
{
return this.tTemplate.execute( new TransactionCallback< Boolean >( ) {
@Override
public Boolean doInTransaction( TransactionStatus status )
{
return (Boolean) EventProcessorTask.this.eqProcess.execute( ).get( "_result" );
}
} );
}
}

View file

@ -2,8 +2,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">
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<bean id="bansDao" class="com.deepclone.lw.beans.admin.BansDAOBean" />
<bean id="eventProcessor" class="com.deepclone.lw.beans.events.EventProcessorBean" />
</beans>

Some files were not shown because too many files have changed in this diff Show more