public class GSONServerProxy extends java.lang.Object implements ServerProxy
Modifier and Type | Field and Description |
---|---|
private int |
gameID |
private java.lang.String |
HTTP_GET |
private java.lang.String |
HTTP_POST |
private java.lang.String |
SERVER_HOST |
private int |
SERVER_PORT |
private java.lang.String |
URL_PREFIX |
private UserCookie |
userCookie |
private int |
userIndex |
private java.lang.String |
userName |
Constructor and Description |
---|
GSONServerProxy()
Default constructor.
|
GSONServerProxy(java.lang.String server_host,
int server_port)
Sets up connection with the server with specified parameters
|
Modifier and Type | Method and Description |
---|---|
GameModel |
acceptTrade(boolean willAccept)
Notifies the server whether this player has decided to accept or reject a trade
|
void |
addAI(AIType aiType)
Adds an AI to the game
|
GameModel |
buildCity(Coordinate location)
Notifies the server that the user has decided to build a city
|
GameModel |
buildRoad(Coordinate start,
Coordinate end,
boolean free)
Notifies the server that the user has decided to build a road
|
GameModel |
buildSettlement(Coordinate location,
boolean free)
Notifies the server that the user has decided to build a settlement
|
GameModel |
buyDevCard()
Notifies the server that the user has bought a development card
|
void |
clearCookies()
FOR DEBUGGING ONLY
TODO make private for distro
Clears all cookies
|
GameInfo |
createGame(boolean randomTiles,
boolean randomNumbers,
boolean randomPorts,
java.lang.String name)
Creates a game on the server
|
GameModel |
discardCards(java.util.List<java.lang.Integer> resourceList)
Notifies the server that the user has discarded cards
|
private java.lang.String |
doJSONGet(java.lang.String urlPath) |
private java.lang.String |
doJSONPost(java.lang.String urlPath,
java.lang.String postData,
boolean getUserCookie,
boolean getGameCookie) |
GameModel |
finishTurn()
Notifies the server that the user has finished his turn
|
GameModel |
getGameModel(int version)
Retrieves the game model from the server
|
UserCookie |
getUserCookie()
Gets the user cookie
|
int |
getUserId()
Gets the player ID
|
int |
getUserIndex()
Getting for current user index
|
java.lang.String |
getUserName()
Gets the current user's name
|
void |
joinGame(int id,
CatanColor color) |
java.util.List<AIType> |
listAI() |
java.util.List<GameInfo> |
listGames()
Fetches a list of ongoing games
|
boolean |
loginUser(java.lang.String username,
java.lang.String password)
Logs the specified user in and returns a User object if the user was
successfully logged in.
|
GameModel |
maritimeTrade(int ratio,
ResourceType inputResource,
ResourceType outputResource)
Notifies the server that the user has decided to initiate a maritime trade
|
GameModel |
monopolyCard(ResourceType resource)
Notifies the server that the user has played a monopoly card
|
GameModel |
monumentCard()
Notifies the server that the user has played a monument card
|
GameModel |
offerTrade(java.util.List<java.lang.Integer> resourceList,
int receiver)
Notifies the server that the user has decided to offer a trade to another player
|
boolean |
registerUser(java.lang.String username,
java.lang.String password)
Registers a user with the specified username and password
|
GameModel |
roadBuildingCard(Coordinate start1,
Coordinate end1,
Coordinate start2,
Coordinate end2)
Notifies the server that the user has played a road building card
|
GameModel |
robPlayer(int victimIndex,
Coordinate location)
Notifies the server that the user has decided to rob another player
|
GameModel |
rollNumber(int roll)
Reports the result of a dice roll to the server
|
GameModel |
sendChat(java.lang.String content)
Sends a chat message from the specified user to the server
|
GameModel |
soldierCard(int victimIndex,
Coordinate location)
Notifies the server that the user has played a soldier card
|
GameModel |
yearOfPlentyCard(ResourceType resource1,
ResourceType resource2)
Notifies the server that the user has played a year of plenty card
|
private UserCookie userCookie
private int gameID
private java.lang.String SERVER_HOST
private int SERVER_PORT
private java.lang.String URL_PREFIX
private final java.lang.String HTTP_GET
private final java.lang.String HTTP_POST
private int userIndex
private java.lang.String userName
public GSONServerProxy()
public GSONServerProxy(java.lang.String server_host, int server_port)
server_host
- this string represents the hostname of the serverserver_port
- this int is the port to send requests to on the serverpublic int getUserIndex()
public int getUserId()
getUserId
in interface ServerProxy
public java.lang.String getUserName() throws ServerProxyException
getUserName
in interface ServerProxy
ServerProxyException
- if not logged inpublic boolean loginUser(java.lang.String username, java.lang.String password) throws ServerProxyException
ServerProxy
loginUser
in interface ServerProxy
username
- The username of the user to log inpassword
- The password of the user to log inServerProxyException
- if the user could not be logged inpublic boolean registerUser(java.lang.String username, java.lang.String password) throws ServerProxyException
ServerProxy
registerUser
in interface ServerProxy
username
- The username of the user to be registeredpassword
- The password of the user to be registeredServerProxyException
- if this user could not be registeredpublic java.util.List<GameInfo> listGames() throws ServerProxyException
ServerProxy
listGames
in interface ServerProxy
ServerProxyException
public GameInfo createGame(boolean randomTiles, boolean randomNumbers, boolean randomPorts, java.lang.String name) throws ServerProxyException
ServerProxy
createGame
in interface ServerProxy
randomTiles
- Whether the server should place random tilesrandomNumbers
- Whether the server should place random number chitsrandomPorts
- Whether the server should place random portsname
- The name of the game to be createdServerProxyException
- if something goes wrongpublic void joinGame(int id, CatanColor color) throws ServerProxyException
joinGame
in interface ServerProxy
color
- the color the user wishes to represent himServerProxyException
- if something goes wrongpublic GameModel getGameModel(int version) throws ServerProxyException
ServerProxy
getGameModel
in interface ServerProxy
version
- the current version of the model in the clientServerProxyException
- if something goes wrongpublic void addAI(AIType aiType) throws ServerProxyException
ServerProxy
addAI
in interface ServerProxy
aiType
- the type of AI the user wishes to addServerProxyException
- if there is no logged in userpublic java.util.List<AIType> listAI() throws ServerProxyException
listAI
in interface ServerProxy
ServerProxyException
- if there is no logged in userpublic GameModel sendChat(java.lang.String content) throws ServerProxyException
ServerProxy
sendChat
in interface ServerProxy
content
- The content of the chat messageServerProxyException
- if there is no logged in userpublic GameModel rollNumber(int roll) throws ServerProxyException
ServerProxy
rollNumber
in interface ServerProxy
roll
- The result of the user's rollServerProxyException
- if there is no logged in userpublic GameModel robPlayer(int victimIndex, Coordinate location) throws ServerProxyException
ServerProxy
robPlayer
in interface ServerProxy
victimIndex
- The index of the victim of the user's robbinglocation
- The new coordinate location of the robberServerProxyException
- if there is no logged in userpublic GameModel finishTurn() throws ServerProxyException
ServerProxy
finishTurn
in interface ServerProxy
ServerProxyException
- if there is no logged in userpublic GameModel buyDevCard() throws ServerProxyException
ServerProxy
buyDevCard
in interface ServerProxy
ServerProxyException
- if there is no logged in userpublic GameModel yearOfPlentyCard(ResourceType resource1, ResourceType resource2) throws ServerProxyException
ServerProxy
yearOfPlentyCard
in interface ServerProxy
resource1
- The first chosen resourceresource2
- The second chosen resourceServerProxyException
- if there is no logged in userpublic GameModel roadBuildingCard(Coordinate start1, Coordinate end1, Coordinate start2, Coordinate end2) throws ServerProxyException
ServerProxy
roadBuildingCard
in interface ServerProxy
start1
- The start coordinate of the first roadend1
- The end coordinate of the first roadstart2
- The start location of the second roadend2
- The end location of the second roadServerProxyException
- if there is no logged in userpublic GameModel soldierCard(int victimIndex, Coordinate location) throws ServerProxyException
ServerProxy
soldierCard
in interface ServerProxy
victimIndex
- The index of the player who is being robbedlocation
- The new location of the robberServerProxyException
- if there is no logged in userpublic GameModel monopolyCard(ResourceType resource) throws ServerProxyException
ServerProxy
monopolyCard
in interface ServerProxy
resource
- The resource that the player has chosen to have a monopoly onServerProxyException
- if there is no logged in userpublic GameModel monumentCard() throws ServerProxyException
ServerProxy
monumentCard
in interface ServerProxy
ServerProxyException
- if there is no logged in userpublic GameModel buildRoad(Coordinate start, Coordinate end, boolean free) throws ServerProxyException
ServerProxy
buildRoad
in interface ServerProxy
start
- the Coordinate where the road startsend
- the Coordinate where the road endsfree
- Whether this road was free (only true during the set up phases)ServerProxyException
- if there is no logged in userpublic GameModel buildSettlement(Coordinate location, boolean free) throws ServerProxyException
ServerProxy
buildSettlement
in interface ServerProxy
location
- The vertex coordinate of the settlementfree
- Whether this settlement was free (only true during the set up phases)ServerProxyException
- if there is no logged in userpublic GameModel buildCity(Coordinate location) throws ServerProxyException
ServerProxy
buildCity
in interface ServerProxy
location
- The vertex location of the cityServerProxyException
- if there is no logged in userpublic GameModel offerTrade(java.util.List<java.lang.Integer> resourceList, int receiver) throws ServerProxyException
ServerProxy
offerTrade
in interface ServerProxy
resourceList
- A list of the resources that the user wishes to trade, in this order: brick, ore, sheep,
wheat, and wood. Negative values denotes that this user will give these resources, and positive values denote
the resources that will be receivedreceiver
- The index of the player who will receive this trade offerServerProxyException
- if there is no logged in userpublic GameModel acceptTrade(boolean willAccept) throws ServerProxyException
ServerProxy
acceptTrade
in interface ServerProxy
willAccept
- true if the user will accept the trade, false if notServerProxyException
- if there is no logged in userpublic GameModel maritimeTrade(int ratio, ResourceType inputResource, ResourceType outputResource) throws ServerProxyException
ServerProxy
maritimeTrade
in interface ServerProxy
ratio
- The ratio of resources demanded by the harborinputResource
- The resources traded awayoutputResource
- The resource receivedServerProxyException
- if there is no logged in userpublic GameModel discardCards(java.util.List<java.lang.Integer> resourceList) throws ServerProxyException
ServerProxy
discardCards
in interface ServerProxy
resourceList
- A list of integers that denotes how many of each resource the user will discard. The
order is brick, ore, sheep, wheat, and woodServerProxyException
- if there is no logged in userprivate java.lang.String doJSONPost(java.lang.String urlPath, java.lang.String postData, boolean getUserCookie, boolean getGameCookie) throws ServerProxyException
ServerProxyException
private java.lang.String doJSONGet(java.lang.String urlPath) throws ServerProxyException
ServerProxyException
public UserCookie getUserCookie()
public void clearCookies()