com.empireclassic.Remote
Class RemoteEmpire

java.lang.Object
  extended by com.empireclassic.Remote.RemoteEmpire

public class RemoteEmpire
extends java.lang.Object

This class provides the abstraction of retrieving all data and passing all commands to the server.

Implemented as a Singleton, so you must use getInstance() to make use of this class.

Two different versions of getInstance() are provided: The version with arguments must be used the first time to set the host name and port number. Following that the version with no arguments should always be used. Also provides cacheing RemoteEmpire is thread safe. All server transactions are atomic per call, and each is synchronized. The server always provides a numeric error code (0 is OK) and an error message string. In general the error code is pretty generic and the error message string is quite specific, so pay more attention to the message string. Occasionally the server returns some small piece of information with an OK. Generally these will be returned in a special error return format.

Author:
chas
See Also:
getInstance(String, int), getInstance(), setCacheStrategy(CacheStrategy), RemoteEmpire.CacheStrategy, LoginResponse

Nested Class Summary
 class RemoteEmpire.AssaultReply
           
 class RemoteEmpire.AssaultTestReply
           
 class RemoteEmpire.AttackReply
           
 class RemoteEmpire.BuildPlanesReply
           
 class RemoteEmpire.CacheData
           
static class RemoteEmpire.CacheStrategy
           
 class RemoteEmpire.LoginReply
           
 class RemoteEmpire.Mail
           
static class RemoteEmpire.MailStatus
           
static class RemoteEmpire.PlaneType
           
 class RemoteEmpire.SpreadTestReply
           
 class RemoteEmpire.UserInfo
          Simple data structure representing currently logged on user info.
 
Field Summary
protected  RemoteEmpire.CacheStrategy cacheStrategy
           
protected  java.net.Socket comSocket
           
protected static RemoteEmpire instance
           
protected  java.util.Map<java.lang.Integer,IslandInfo> islands
           
protected  java.util.LinkedList<RemoteEmpire.CacheData> mruCache
           
protected  int mruCacheLimit
           
protected  EmpireStreamReader reader
           
protected  java.util.Map<java.lang.Integer,RemoteEmpire.CacheData> sectorCache
           
protected  java.lang.String serverName
           
protected  int serverPortNum
           
static java.util.List<ShipType> shipTypeList
          Information from server on types of ships
static EmpireDimension worldSize
          Publicly available info on the size of the world
protected  java.io.BufferedWriter writer
           
 
Method Summary
 EmpireError assignShipToFleet(int shipNum, int fleetNum)
           
 RemoteEmpire.AttackReply attack(int islandNum, IslandCoord from, IslandCoord to, int numAttacking)
           
 RemoteEmpire.AttackReply attackTest(int islandNum, IslandCoord from, IslandCoord to)
           
 RemoteEmpire.BuildPlanesReply BuildPlanes(int islandNum, RemoteEmpire.PlaneType type, int numRequested)
           
 RemoteEmpire.BuildPlanesReply buildPlanesTest(int islandNum, RemoteEmpire.PlaneType type)
           
 void close()
           
 double date()
           
 java.lang.String date(java.lang.String gameDate)
           
 EmpireError enlist(int islandNum, IslandCoord coord, int enlistNum)
           
 EmpireError gatherToShip(int islandNum, int what, int howMuch, int maxTime)
           
 java.util.List<java.lang.String> getAlerts()
           
 RemoteEmpire.CacheStrategy getCacheStrategy()
           
static RemoteEmpire getInstance()
          This version of getInstance() is used for all subsequent calls.
static RemoteEmpire getInstance(java.lang.String serverName, int portNum)
          This version of getInstance() must always be called first in order to provide the host/port to connect to.
 IslandInfo getIsland(int islandNumber)
           
 java.util.Map<java.lang.Integer,IslandInfo> getIslandList()
          Return a list of islands of which we have some knowledge.
 EmpireError getMail(int id)
           
 java.util.List<RemoteEmpire.Mail> getMailList()
           
 int getMruCacheLimit()
           
 NationInfo getNation(int nationNumber)
           
 java.util.Map<java.lang.Integer,NationInfo> getNationList()
          Get the list of nations in the game.
 ParamInfo getParams()
           
 java.util.Map<IslandCoord,Sector> getSectors(int islandNum)
          Get information about every sector on an island.
 java.lang.String getServerName()
           
 int getServerPortNum()
           
 MyShip getShip(int shipNum)
           
 java.util.Map<java.lang.Integer,MyShip> getShipList()
           
 java.util.List<ShipType> getShipTypeList()
           
 java.util.List<RemoteEmpire.UserInfo> getUserList()
          Return the list of currently logged on players
 EmpireDimension getWorldSize()
           
 EmpireError islandUpdate(int islandNum, int updateTime)
           
 EmpireError launch(int islandNum, IslandCoord coord, java.lang.String shipType)
           
 RemoteEmpire.LoginReply login(java.lang.String nationName, java.lang.String password)
          Log into an empire game.
 EmpireError move(int islandNum, char thing, java.lang.String from, java.lang.String to, int quantity, boolean test)
           
 RemoteEmpire.LoginReply newNation(java.lang.String nationName, java.lang.String password)
           
 java.util.Map<java.lang.Integer,YourShip> radar()
           
 EmpireError radioSend(java.lang.String message)
           
 EmpireError sendMail(int to, java.lang.String subject, java.lang.String message)
           
 void setCacheStrategy(RemoteEmpire.CacheStrategy cacheStrategy)
           
 EmpireError setDes(int islandNumber, IslandCoord coord, int selection)
           
 EmpireError setFleetCourse(int nationNum, int fleetNum, WorldCoord dest)
           
 EmpireError setIslandName(int islandNum, java.lang.String newName)
           
 void setMruCacheLimit(int mruCacheLimit)
           
 void setWorldSize(EmpireDimension worldSize)
           
 RemoteEmpire.AssaultReply shipAssault(int shipNum, int numAttacking)
           
 RemoteEmpire.AssaultTestReply shipAssaultTest(int shipNum)
           
 EmpireError shipEmerge(int shipNum)
           
 EmpireError shipLoadUnload(int shipNum, java.lang.String what, int quantity)
           
 EmpireError shipMine(int shipNum, int numMines)
           
 EmpireError shipMove(int shipNum, double direction, double distance)
           
 EmpireError shipSetCourse(int shipNum, WorldCoord dest, double speed)
           
 EmpireError shipSubmerge(int shipNum)
           
 EmpireError shipUndock(int shipNum)
           
 EmpireError spread(int islandNum, java.awt.Rectangle area, IslandCoord fromCoord, boolean mountains, boolean own, int civsPerSec, IslandCoord dumpCoord)
           
 RemoteEmpire.SpreadTestReply spreadTest(int islandNum, java.awt.Rectangle area, IslandCoord fromCoord, boolean mountains, boolean own)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

comSocket

protected java.net.Socket comSocket

writer

protected java.io.BufferedWriter writer

reader

protected EmpireStreamReader reader

instance

protected static RemoteEmpire instance

serverName

protected java.lang.String serverName

serverPortNum

protected int serverPortNum

cacheStrategy

protected RemoteEmpire.CacheStrategy cacheStrategy

mruCacheLimit

protected int mruCacheLimit

islands

protected java.util.Map<java.lang.Integer,IslandInfo> islands

sectorCache

protected java.util.Map<java.lang.Integer,RemoteEmpire.CacheData> sectorCache

mruCache

protected java.util.LinkedList<RemoteEmpire.CacheData> mruCache

shipTypeList

public static java.util.List<ShipType> shipTypeList
Information from server on types of ships


worldSize

public static EmpireDimension worldSize
Publicly available info on the size of the world

Method Detail

getInstance

public static RemoteEmpire getInstance(java.lang.String serverName,
                                       int portNum)
                                throws java.net.UnknownHostException,
                                       java.io.IOException
This version of getInstance() must always be called first in order to provide the host/port to connect to.

Parameters:
serverName - Host name of an empire server
portNum - Port the empire server is listening on
Returns:
The instance of RemoteEmpire5
Throws:
java.net.UnknownHostException
java.io.IOException

getInstance

public static RemoteEmpire getInstance()
This version of getInstance() is used for all subsequent calls.

Returns:
The instance of RemoteEmpire5
Throws:
java.lang.Error - If the argument version of getInstance() wasn't called first.

login

public RemoteEmpire.LoginReply login(java.lang.String nationName,
                                     java.lang.String password)
Log into an empire game. Note the server and port number came via the constructor.

Parameters:
nationName - A name or number of an existing nation.
password - A password
Returns:
Specialized return construct

getUserList

public java.util.List<RemoteEmpire.UserInfo> getUserList()
Return the list of currently logged on players

Returns:
List of UserInfo

getIslandList

public java.util.Map<java.lang.Integer,IslandInfo> getIslandList()
Return a list of islands of which we have some knowledge.

Returns:
Map of IslandInfo
See Also:
IslandInfo

getSectors

public java.util.Map<IslandCoord,Sector> getSectors(int islandNum)
Get information about every sector on an island. Note that varying amounts of information are returned based on your presence on the island This implements the CacheStrategy set at the beginning. Sector is the main thing we are interested in cacheing. We check the IslandInfo to see if the version has changed. If not, we can return what's in the cache.

Parameters:
islandNum -
Returns:
A Map of Sector
See Also:
Sector, RemoteEmpire.CacheStrategy, setCacheStrategy(CacheStrategy)

getNationList

public java.util.Map<java.lang.Integer,NationInfo> getNationList()
Get the list of nations in the game.

Returns:
A Map of Nation
See Also:
NationInfo

newNation

public RemoteEmpire.LoginReply newNation(java.lang.String nationName,
                                         java.lang.String password)

getIsland

public IslandInfo getIsland(int islandNumber)

getNation

public NationInfo getNation(int nationNumber)

getParams

public ParamInfo getParams()

date

public double date()

date

public java.lang.String date(java.lang.String gameDate)

getShipTypeList

public java.util.List<ShipType> getShipTypeList()

getShipList

public java.util.Map<java.lang.Integer,MyShip> getShipList()

getShip

public MyShip getShip(int shipNum)

getAlerts

public java.util.List<java.lang.String> getAlerts()

radar

public java.util.Map<java.lang.Integer,YourShip> radar()

setDes

public EmpireError setDes(int islandNumber,
                          IslandCoord coord,
                          int selection)

move

public EmpireError move(int islandNum,
                        char thing,
                        java.lang.String from,
                        java.lang.String to,
                        int quantity,
                        boolean test)

islandUpdate

public EmpireError islandUpdate(int islandNum,
                                int updateTime)

spreadTest

public RemoteEmpire.SpreadTestReply spreadTest(int islandNum,
                                               java.awt.Rectangle area,
                                               IslandCoord fromCoord,
                                               boolean mountains,
                                               boolean own)

spread

public EmpireError spread(int islandNum,
                          java.awt.Rectangle area,
                          IslandCoord fromCoord,
                          boolean mountains,
                          boolean own,
                          int civsPerSec,
                          IslandCoord dumpCoord)

setIslandName

public EmpireError setIslandName(int islandNum,
                                 java.lang.String newName)

launch

public EmpireError launch(int islandNum,
                          IslandCoord coord,
                          java.lang.String shipType)

enlist

public EmpireError enlist(int islandNum,
                          IslandCoord coord,
                          int enlistNum)

radioSend

public EmpireError radioSend(java.lang.String message)

buildPlanesTest

public RemoteEmpire.BuildPlanesReply buildPlanesTest(int islandNum,
                                                     RemoteEmpire.PlaneType type)

BuildPlanes

public RemoteEmpire.BuildPlanesReply BuildPlanes(int islandNum,
                                                 RemoteEmpire.PlaneType type,
                                                 int numRequested)

assignShipToFleet

public EmpireError assignShipToFleet(int shipNum,
                                     int fleetNum)

gatherToShip

public EmpireError gatherToShip(int islandNum,
                                int what,
                                int howMuch,
                                int maxTime)

setFleetCourse

public EmpireError setFleetCourse(int nationNum,
                                  int fleetNum,
                                  WorldCoord dest)

attackTest

public RemoteEmpire.AttackReply attackTest(int islandNum,
                                           IslandCoord from,
                                           IslandCoord to)

attack

public RemoteEmpire.AttackReply attack(int islandNum,
                                       IslandCoord from,
                                       IslandCoord to,
                                       int numAttacking)

shipUndock

public EmpireError shipUndock(int shipNum)

shipLoadUnload

public EmpireError shipLoadUnload(int shipNum,
                                  java.lang.String what,
                                  int quantity)

shipAssaultTest

public RemoteEmpire.AssaultTestReply shipAssaultTest(int shipNum)

shipAssault

public RemoteEmpire.AssaultReply shipAssault(int shipNum,
                                             int numAttacking)

shipSubmerge

public EmpireError shipSubmerge(int shipNum)

shipEmerge

public EmpireError shipEmerge(int shipNum)

shipMine

public EmpireError shipMine(int shipNum,
                            int numMines)

shipMove

public EmpireError shipMove(int shipNum,
                            double direction,
                            double distance)

shipSetCourse

public EmpireError shipSetCourse(int shipNum,
                                 WorldCoord dest,
                                 double speed)

getServerName

public java.lang.String getServerName()

getServerPortNum

public int getServerPortNum()

close

public void close()

getWorldSize

public EmpireDimension getWorldSize()

setWorldSize

public void setWorldSize(EmpireDimension worldSize)

getMailList

public java.util.List<RemoteEmpire.Mail> getMailList()

getMail

public EmpireError getMail(int id)

sendMail

public EmpireError sendMail(int to,
                            java.lang.String subject,
                            java.lang.String message)

getCacheStrategy

public RemoteEmpire.CacheStrategy getCacheStrategy()

setCacheStrategy

public void setCacheStrategy(RemoteEmpire.CacheStrategy cacheStrategy)

getMruCacheLimit

public int getMruCacheLimit()

setMruCacheLimit

public void setMruCacheLimit(int mruCacheLimit)