#ifndef COMMAND_CLIENT_H
#define COMMAND_CLIENT_H

#include "socketClient.h"
#include "sharedStructures.h"
#include "threads.h"
#include <map>
#include <time.h>
#include "handlerMapper.h"
#include "softProj\ChatWidget\ChatMessage.h"
#include "protocol.h"
#include "softProj\clientServer\ClientSynchronizer.h"
#include "structs.h"
#include "valueReader.h"

class MainWindow;

typedef std::map<std::string, std::string> ValueMap;

/// Main point for high-level client-server communication
/** Main point for high-level client-server communication. All requests and responses go through
CommandClient. It is responsible for sending requests to the server and receiving
responses from the server. 
CommandClient represents high-level communication. For low-level communication, it uses SocketClient. 
High-level communication means that CommandClient processs received messages to game data structures 
any time it receives message from the server. Also, it encodes game data structures to the messages that 
it then sends to the server. It never does any real game work, it only accepts requests and responses and
does the encoding and decoding.
All requests mehods are public, because client uses them to create request messages to the server. On the 
other hand, response messages are private, because client does not call them, they are called by CommandClient 
itself any time it receives message from the server and decides how to process it to game data. For this, it
checks name of the request of the message and decides, what method to call to do the decoding into game data.
CommandClient always works for some time interval that can be set. During this interval, it gets messages from the
received messages queue, one at a time, looks what it request name is and looks up corresponding handler, that is method,
that will do the decoding into game data. After decoding message it calls corresponding method on MainWindow and passes
processd game data. 
CommandClient receives protocol messages from SocketClient, that does low-level communication. So CommandClient does not care
about real sending the message, it just encodes game data and passes them to the SocketClient. Analogously, it receives messages
from SocketClient and processs them into game data.
Semantics of method is following. Update means that client requests for data from server, to synchronize displayed data with server.
Change means, that client changed displayed data and wants server to synchronize itself with client, that means, set server data to 
reflect client changes. Decode means decoding message from server.
*/
class CommandClient {
public:
	/****************************************
	* General command client methods
	*****************************************/

	/** Creates new instance of CommandClient
	@param socketClient Socket client for low-level communication
	@param mainWindow Main application class that works with accepted game data
	*/
	CommandClient(ASocketClient * socketClient, MainWindow * mainWindow);

	/** Destructor */
	~CommandClient();

	/** Connects client to the server with last active configuration */
	void reconnect();

	/** Gets information about current login and connection 
	@return Login and connection information
	*/
	LoginDetails getCurrentLogin();

	/** Sets interval between two pings
	@param milliseconds Interval length in milliseconds
	*/
	void setPingInterval(int milliseconds);

	/** Connects to server 
	@param server Server address where to connect
	@param port Port where to connect
	*/
	void connectToServer(const std::string & server, unsigned long port);

	/** Disconnects from server */
	void disconnectFromServer();

	bool isActive();

	/** Sets time limit in milliseconds for message processing. CommandClient will process received process
	messages only within this time limit. This does not mean that it cannot process longer sometime, because
	CommandClient can start processing within correct interval and finish processing after the interval, but it 
	guarantees, that CommandClient will never start processing of new message if it is not within interval anymore.
	@param milliseconds Time limit in milliseconds
	*/
	void setTimeLimitForProcessing(int milliseconds);
	
	/** Start processing incoming messages. Processing always gets message from queue of received messages, gets it
	request name and finds handler for decoding, depending on request name.
	*/
	void processIncomingMessages();
	
	/** Logs received message in a way that it creates html string and passes it to the MainWindow that displays it
	in IncomingWidget. This is here just for testing purposes and will be removed probably.
	@param protocolMessage Received protocol message to log
	*/

	/** Sends ping to the server. It only delegates ping to SocketClient */
	void pingServer();

	/****************************************
	* Client requests to server
	*****************************************/

	/* NAVIGATION */
	
	/** Request to navigate ship to space object with impulse drive
	@param shipId Id of ship to navigate
	@param spaceObjectId Id of target space object
	@param limit Time limit for how long the engine should run
	*/
	void navigationMoveToSpaceObject(id_t shipId, id_t spaceObjectId, unsigned long limit);

	/** Request to navigate ship to custom location with impulse drive
	@param shipId Id of ship to navigate
	@param positionx X coordinate of target location
	@param positiony Y coordinate of target location
	@param limit Time limit for how long the engine should run
	*/
	void navigationMoveTo(id_t shipId, long long positionx, long long positiony, unsigned long limit);

	/** Request to navigate ship to space object with subspace drive
	@param shipId Id of ship to navigate
	@param spaceObjectId Id of target space object
	*/
	void navigationMoveToSpaceObjectByWarp(id_t shipId, id_t spaceObjectId);

	/** Request to navigate ship to pursuit some other ship, that is, move to it with impulse drive
	@param shipId Id of ship to navigate
	@param spaceObjectId Id of target ship
	@param limit Time limit for how long the engine should run
	*/
	void navigationPursuit(id_t shipId, id_t spaceObjectId, unsigned long limit);

	/** Request to stop ship warp, that means stop subspace drive
	@param shipId Id of ship to navigate
	*/
	void navigationBreakWarp(id_t shipId);

	/** Request to start orbiting with the ship
	@param shipId Id of ship to navigate
	*/
	void navigationOrbit(id_t shipId);

	/** Request to stop ship movement
	@param shipId Id of ship to navigate
	*/
	void navigationStop(id_t shipId);	

	/** Request to move ship with warp drive to custom location
	@param shipId Id of ship to navigate
	@param positionx X coordinate of target location
	@param positiony Y coordinate of target location
	*/
	void navigationWarp(id_t shipId, long long positionx, long long positiony);

	/** Request to get list of planets in solar system
	@param areaId Id of solar system from which we wants planets
	*/
	void navigationPlanetsInStarArea(id_t areaId);

	/** Request to get list of planets in solar system
	@param shipId Id of ship from which to count planet distance
	@param areaId Id of solar system from which we wants planets
	*/
	void navigationPlanetsInStarArea(id_t shipId, id_t areaId);

	/** Request to get complete navigation status of the ship.
	That means list of known solar systems, list of owned ships and bases and
	all ships that are in range of high resolution and long range sensors
	@param shipId Id of ship that we request information about
	*/
	void navigationStatus(unsigned long shipId);

	/** Request to get details about current ship journey.
	That means information about ship current action, actual location,
	target location, estimated time and distance to the target, speed,
	accelerance and etc.
	@param shipId Id of ship that we request information about
	*/
	void shipJourneyDetails(unsigned long shipId);

	/** Request to dock down to some base with the ship
	@param shipId Id of ship to dock down
	@param baseId Id of base where to dock down
	*/
	void navigationDockDown(id_t shipId, id_t baseId);

	/** Request to unbound the ship from its base
	@param shipId Id of ship to unbound
	*/
	void navigationUnbound(id_t shipId);

	/* LOGIN */

	/** Request to login to the server
	@param details Information about login and connection
	*/
	void login(const LoginDetails & details);

	/** Request to login to the server
	@param username User login
	@param password User password
	*/
	void login(const std::string & username, const std::string & password);

	/* DEVICE ENERGY STATE */ 

	/** Request to change energy distribution state in fortress 
	@param shipId Id of fortress where to change distribution state
	@param deviceEnergy State of distribution of energy to set
	*/
	void changeDeviceEnergyState(unsigned long shipId, requestDeviceEnergy & deviceEnergy);

	/** Request to get state of energy distribution in fortress 
	@param shipId Id of fortress where to update distribution
	*/
	void updateDeviceEnergyState(unsigned long shipId);

	/* CHAT */

	/** Request to get available buddies to chat with */
	void buddies();

	/** Request to send chat message to the target through server
	@param message Chat message to send
	*/
	void sendChatMessage(ChatMessage * message);

	/* SHIPS AND BASES LIST */

	/** Request to get list of all players ships */
	void playerShips();

	/** Request to get list of all players bases */
	void playerBases();

	/* ATTACK ISSUES */		


	/** Request to update radar data in space map mode for the ship
	@param shipId Id of ship that requests for update
	*/
	void updateRadarData(unsigned long shipId);

	/* RENDER */

	/** Request for location data of given ship 
	@param shipId Id  of ship that we are interested in
	*/
	void shipLocationInfo(id_t shipId);

	/** Request for ship warp informations
	@param shipId Id of ship that we are interested in
	*/
	void getShipWarpInfo(unsigned long shipId);

	/** Request for list of ships that are in area of the ship
	@param shipId Id of ship that defines the ship area
	*/
	void shipsInShipArea(unsigned long shipId);

	/** Request for list of ships that are in area of the sun
	@param shipId Id of sun that defines the sun area
	*/
	void planetsInStarArea(unsigned long areaId);

	/* SCIENCE TREE */

	/** Request to update science tree state */
	void updateScienceTree();

	/** Request to change science tree state
	@param data New state of science tree to set
	*/
	void changeScienceTree(sciencetree_raw_data & data);

	/* CENTRAL INFO WIDGET */
	
	/** Request to update fortress central information
	@param fortressId Id of fortress to update
	*/
	void updateFortressCentralInformation(id_t fortressId);

	/* SHIELDS */

	/** Request to update fortress shields information 
	@param fortressId Id of fortress to update 
	*/
	void updateFortressShieldsInformation(id_t fortressId);

	/* IMPULS DRIVE */

	/** Request to update ship impuls drive information 
	@param fortressId Id of fortress to update 
	*/
	void updateShipImpulsDriveInformation(id_t fortressId);

	/* SUBSPACE DRIVE */

	/** Request to update ship subspace drive information 
	@param fortressId Id of fortress to update 
	*/
	void updateShipSubspaceDriveInformation(id_t fortressId);

	/* MAINFRAME */

	/** Request to update fortress mainframe information 
	@param fortressId Id of fortress to update 
	*/
	void updateFortressMainframeInformation(id_t fortressId);

	/* WEAPONS */

	/** Request to update fortress weapons information 
	@param fortressId Id of fortress to update 
	*/
	void updateFortressWeaponsInformation(id_t fortressId);

	/** Request to change fortress shields state 
	@param fortressId Id of fortress to change
	@param state New state of weapons
	*/
	void changeFortressWeaponsState(id_t fortressId, WeaponsChangeDetails & state);

	/* CREW */

	/** Request to update fortress crew information 
	@param fortressId Id of fortress to update 
	*/
	void updateFortressCrewInformation(id_t fortressId);

	/* MINING */

	/** Request to update fortress quarrying information 
	@param fortressId Id of fortress to update 
	*/
	void updateFortressQuarryInformation(id_t fortressId);
	
	/** Request to change fortress quarrying of quark gluon plasma 
	@param fortressId Id of fortress to update 
	@param isQuarrying If fortress wants to quarry or not
	*/
	void changeQuarkGluonPlasmaQuarryState(id_t fortressId, bool isQuarrying);

	/** Request to change fortress quarrying of heavy water 
	@param fortressId Id of fortress to update 
	@param isQuarrying If fortress wants to quarry or not
	*/
	void changeHeavyWaterQuarryState(id_t fortressId, bool isQuarrying);

	/** Request to change fortress quarrying of zirconium crystals
	@param fortressId Id of fortress to update 
	@param isQuarrying If fortress wants to quarry or not
	*/
	void changeZirconiumCrystalQuarryState(id_t fortressId, bool isQuarrying);

	/** Request to change fortress quarrying of ilmenite
	@param fortressId Id of fortress to update 
	@param isQuarrying If fortress wants to quarry or not
	*/
	void changeIlmeniteQuarryState(id_t fortressId, bool isQuarrying);

	/* ACCOMMODATIONS */

	/** Request to update fortress accommodations information 
	@param fortressId Id of fortress to update 
	*/
	void updateFortressAccommodationsInformation(id_t fortressId);

	/* OTHER EQUIPMENT */

	/** Request to update fortress other equipment information 
	@param fortressId Id of fortress to update 
	*/
	void updateFortressOtherEquipmentInformation(id_t fortressId);

	/* FACTORIES */

	/** Request to update base factories information 
	@param fortressId Id of fortress to update 
	*/
	void updateBaseFactoriesInformation(id_t fortressId);

	/* WAREHOUSES */

	/** Request to update fortress warehouses information 
	@param fortressId Id of fortress to update 
	*/
	void updateFortressWarehousesInformation(id_t fortressId);

	/* ANDROIDS */

	/** Request to update ship androids information 
	@param fortressId Id of fortress to update 
	*/
	void updateShipAndroidsInformation(id_t fortressId);

	/** Request to update base androids information 
	@param fortressId Id of fortress to update 
	*/
	void updateBaseAndroidsInformation(id_t fortressId);

	/** Request to change ship androids state 
	@param fortressId Id of fortress to change 
	@param state New state of ship androids 
	*/
	void changeShipAndroidsState(id_t fortressId, ship_androids_request_status & state);

	/** Request to change base androids state 
	@param fortressId Id of fortress to change 
	@param state New state of ship androids
	*/
	void changeBaseAndroidsState(id_t fortressId, base_androids_request_status & state);

	/** Request to update base hangars state 
	@param fortressId Id of fortress to update 
	@param hangarId Id of hangar to update 
	@param selectedId Name of item pattern to update 
	*/
	void updateBaseHangarsInformation(id_t fortressId, id_t hangarId, const std::string & patternName);

	/** Request to update base hangars state, asking to update first hangar possible 
	@param fortressId Id of fortress to update 
	*/
	void updateBaseHangarsInformation(id_t fortressId);

	/** Request to update base hangar item state 
	@param patternName Name of item pattern to update 
	*/
	void updateBaseHangarItemInformation(const std::string & patternName);

	/** Request to build item in hangar
	@param fortressId Id of fortress where to buy
	@param data Information data of item to buy
	*/
	void hangarBuildItem(id_t fortressId, const HangarServerInputData & data);

	/** Request to cancel building item in hangar
	@param fortressId Id of fortress where to cancel
	@param hangarId Id of hangar where to cancel
	*/
	void hangarCancelItem(id_t fortressId, id_t hangarId);

	/** Request to unmount device from fortress
	@param data Information about unmounting
	*/
	void unmountFortressDevice(const unmount_device_info & data);

	/** Request to invite trade given trade partner to trade with owned fortress
	@param hostFortressId Id of owned fortress that will be participant of the trade
	@param invitedFortressId Id of partner fortress that will be participant of the trade
	*/
	void sendTradeInvitation(id_t hostFortressId, id_t invitedFortressId);

	/** Request to cancel previously send invitation to invite trade partner
	*/
	void cancelTrade();

	/** Request to get all fortresses that player can trade with in respect to owned fortress
	@param fortressId Id of owned fortress that will be trade participant
	*/
	void tradePartnerFortresses(id_t fortressId);

	/** Request to accept or reject trade invitation for given fortresses
	@param hostFortressId Id of this player fortress that will be trade participant
	@param invitedFortressId Id of this partner player fortress that will be trade participant
	@param acceptInvitation Whether this player wants to accept or reject invitation
	*/
	void decideTradeInvitation(id_t hostFortressId, id_t invitedFortressId, bool acceptInvitation);

	/** Request to recieve stars discovered by player
	*/
	void getPlayerDiscoveredStars(void);
	/** Request to move trade item in trade
	@param tradeData Data about moved item and current trade
	*/
	void moveTradeItem(const trade_client_movement_data & tradeData);

	/** Request to commit current trade
	@param selfFortressId Id of self fortress that participates in trade
	@param selfFortressId Id of partner fortress that participates in trade
	@param selfOffer Trade offer of this player
	@param partnerOffer Trade offer of this partner player
	*/
	void commitTrade(id_t selfFortressId, id_t partnerFortressId, const client_trade_data & selfOffer, const client_trade_data & partnerOffer);

	/** Request to move trade resource in trade
	@param tradeData Data about moved resource and current trade
	*/
	void moveTradeResource(const trade_resource_movement_data & data);

	/** Request to reject commit invitation for given fortresses or to cancel sent commit before partner accepts it
	@param hostFortressId Id of this player fortress that is trade participant
	@param invitedFortressId Id of this partner player fortress that is trade participant
	*/
	void cancelTradeCommit(id_t selfFortressId, id_t partnerFortressId);

	/** Request to mount device from warehouse
	@param data Data about item to mount
	*/
	void mountFortressDevice(const mount_device_info & data);

	/** Request to get all fortresses that are in weapons range of given ship 
	@param fortressId Id of fortress for which to get fortresses in range
	*/
	void fortressInWeaponsRange(id_t fortressId);

	/** Request to attack fortress with given fortress
	@param selfFortressId Id of fortress that should start attack
	@param enemyfortressId Id of fortress that should be attacked
	*/
	void attackFortress(id_t selfFortressId, id_t enemyfortressId);

	/** Request to stop attack with given fortress
	@param selfFortressId Id of fortress that should stop attack
	*/
	void stopAttackFortress(id_t selfFortressId);

	/** Request to get all fortresses that are in conquer range of given ship 
	@param fortressId Id of fortress for which to get fortresses in range
	*/
	void fortressesInConquerRange(id_t fortressId);

	/** Request to build new base shell
	@param fortressId Id of fortress that should start the build
	@param fortressClassId Id of class of builded bases
	@param buildingTitanium Starting titanium to put in build of base
	*/
	void buildNewBaseShell(id_t fortressId, id_t fortressClassId, unsigned long long buildingTitanium);	

	/** Request to get available build classes for given fortress
	@param fortressId Id of fortress that we want available classes for
	*/
	void availableFortressClasses(id_t fortressId);

	/** Request to get fortress class data for give fortress class id
	@param fortressClassId Id of fortress class that we want information about
	*/
	void fortressClassData(id_t fortressClassId);

	/** Request to get player fortresses with build information
	*/
	void playerFortressesWithBuildInformation();

	/** Request to get player fortresses 
	*/
	void playerFortresses();

	/** Request to conquer uncontrollable fortress
	@param selfFortressId Id of player fortress that fshould conquer the other
	@param enemyFortressId Id of uncontrollable fortress that should be conquered
	*/
	void conquerFortress(id_t selfFortressId, id_t enemyFortressId);

	/** Request to register new player
	@param data User registration information
	*/
	void registerPlayer(const RegistrationData & data);

	/** Request to add new rooms to fortress
	@param fortressId Id of player fortress where to add new rooms
	@param count Number of rooms to add
	@param accommodationType Type of rooms to add
	*/
	void fortressAddAccommodations(id_t fortressId, unsigned long count, accommodation_type accommodationType);

	/** Request to add new crew members to fortress
	@param fortressId Id of player fortress where to add new crew members
	@param able Number of able crew members to add
	@param wounded Number of wounded crew members to add
	@param crewType Type of crew members to add
	*/
	void fortressAddCrew(id_t fortressId, unsigned long able, unsigned long wounded, crew_type crewType);

	/** Request to remove new crew members to fortress
	@param fortressId Id of player fortress where to remove new crew members
	@param able Number of able crew members to remove
	@param wounded Number of wounded crew members to remove
	@param crewType Type of crew members to remove
	*/
	void fortressRemoveCrew(id_t fortressId, unsigned long able, unsigned long wounded, crew_type crewType);

	/** Request to get speed of server game time, that is game seconds in one actual seconds */
	void gameSecondsPerActualSecond();

	/** Request to rename owned fortress to new name 
	@param fortressId Id of fortress to rename
	@param newName New desired name for fortress
	*/
	void renameFortress(id_t fortressId, const std::string & newName);	

	/** Request to get all player fortresses with information about their weapons target */
	void playerFortressesAttackInformation();

	/** Request to build new ship shell
	@param fortressId Id of fortress that should start the build
	@param hangarId Id of hangar that should start the build
	@param fortressClassId Id of class of builded ship
	@param buildingTitanium Starting titanium to put in build of ship
	*/
	void hangarBuildShip(id_t fortressId, id_t hangarId, id_t fortressClassId, unsigned long long buildingTitanium);	\
		
	/** Request to update fortress HR sensors information
	@param fortressId ID of fortress where to update
	*/
	void updateFortressSensorsInformation(id_t fortressId);

	/** Request to update fortress cloaking information
	@param fortressId ID of fortress where to update
	*/
	void updateFortressCloakingInformation(id_t fortressId);
private:
	/****************************************
	* General command client methods
	*****************************************/

	/** Gets next message from received messages queue, finds message handler by request name and passes it the message
	@return True if there is message in a queue that was dequeued and possibly processed. False if queue was empty.
	*/
	bool processNextMessage();

	/** Adds handler as a method for decoding message with given request name 
	@param requestName Request name of the message
	@param handler Method that does decoding of the message
	*/
	void addMessageHandler(const std::string & requestName, TMessageHandler handler);

	/****************************************
	* Server answers to client
	*****************************************/

	/* SERVER UPDATE NOTIFICATION */
	
	/** Decodes server update notification.
	This notification informs client that server updated ship data and client should
	ask server for update to synchronize
	@param protocolMessage
	*/
	void processUpdateShip(message * protocolMessage);

	/* NAVIGATION */

	/** Decodes answer of request to move ship to space object with impuls drive
	Related request is navigationMoveToSpaceObject
	@param protocolMessage Protocol message to decode
	*/
	void processNavigationMoveToSpaceObject(message * protocolMessage);

	/** Decodes answer of request to move ship to space object with warp
	Related request is navigationMoveToSpaceObjectByWarp
	@param protocolMessage Protocol message to decode
	*/
	void processNavigationMoveToSpaceObjectByWarp(message * protocolMessage);

	/** Decodes answer of request to move ship to custom location
	Related request is navigationMoveTo
	@param protocolMessage Protocol message to decode
	*/
	void processNavigationMoveTo(message * protocolMessage);

	/** Decodes answer of request to move ship to pursuit other ships
	Related request is navigationPursuit
	@param protocolMessage Protocol message to decode
	*/
	void processNavigationPursuit(message * protocolMessage);

	/** Decodes answer of request to stop ship warp drice
	Related request is navigationBreakWarp
	@param protocolMessage Protocol message to decode
	*/
	void processNavigationBreakWarp(message * protocolMessage);

	/** Decodes answer of request to start orbiting with ship
	Related request is navigationOrbit
	@param protocolMessage Protocol message to decode
	*/
	void processNavigationOrbit(message * protocolMessage);

	/** Decodes answer of request to stop ship movement
	Related request is navigationStop
	@param protocolMessage Protocol message to decode
	*/
	void processNavigationStop(message * protocolMessage);	

	/** Decodes answer of request to move ship to custom location with warp drive
	Related request is navigationWarp
	@param protocolMessage Protocol message to decode
	*/
	void processNavigationWarp(message * protocolMessage);

	/** Decodes FAIL answer of request to navigate ship
	@param reader ValueReader that holds the message
	*/
	void processNavigationShipFAIL(const ValueReader & reader);

	/** Decodes answer of request to get ship navigation status
	@param protocolMessage Protocol message to decode
	*/
	void processNavigationStatus(message * protocolMessage);

	/** Decodes answer of request to get ship journey information
	@param protocolMessage Protocol message to decode
	*/
	void processShipJourneyDetails(message * protocolMessage);

	/** Decodes FAIL answer of request to get ship journey information
	@param reader ValueReader that holds the message
	*/
	void processShipJourneyDetailsFAIL(const ValueReader & reader);

	/** Decodes answer of request to get ship journey information in case that ship moves
	@param reader ValueReader that holds the message
	*/
	void processShipJourneyDetailsSTANDARD(const ValueReader & reader);

	/** Decodes answer of request to get ship journey information in case that ship pursuits another ship
	@param reader ValueReader that holds the message
	*/
	void processShipJourneyDetailsPURSUIT(const ValueReader & reader);

	/** Decodes answer of request to get ship journey information in case that ship moves to custom location
	@param reader ValueReader that holds the message
	*/
	void processShipJourneyDetailsMOVE_TO(const ValueReader & reader);

	/** Decodes answer of request to get ship journey information in case that ship moves to space object
	@param reader ValueReader that holds the message
	*/
	void processShipJourneyDetailsMOVE_TO_SPACE_OBJECT(const ValueReader & reader);

	/** Decodes answer of request to get ship journey information in case that ship is stopped
	@param reader ValueReader that holds the message
	*/
	void processShipJourneyDetailsSTOP(const ValueReader & reader);

	/** Decodes answer of request to get ship journey information in case that ship orbits
	@param reader ValueReader that holds the message
	*/
	void processShipJourneyDetailsORBIT(const ValueReader & reader);

	/** Decodes answer of request to get ship journey information in case that ship does not do any action
	@param reader ValueReader that holds the message
	*/
	void processShipJourneyDetailsNONE(const ValueReader & reader);

	/** Decodes answer of request to dock ship down to the base
	Related request is navigationDockDown
	@param protocolMessage Protocol message to decode
	*/
	void processNavigationDockDown(message * protocolMessage);

	/** Decodes answer of request to unbound ship from the base
	Related request is navigationUnbound
	@param protocolMessage Protocol message to decode
	*/
	void processNavigationUnbound(message * protocolMessage);

	/** Decodes part of a message that contains information about object that is in range of
	long range sensors and stores it to given game date structure. It decodes object with given index.
	@param reader ValueReader that holds the message
	@param index Index of object information in a message
	@param details Game data structure where to store information
	*/
	void navigationReadLongRangeDetails(const ValueReader & reader, int index, NavigationLongRangeDetails & details);

	/** Decodes part of a message that contains information about object that is in range of
	high resolution sensors and stores it to given game date structure. It decodes object with given index.
	@param reader ValueReader that holds the message
	@param index Index of object information in a message
	@param details Game data structure where to store information
	*/
	void navigationReadHighResolutionDetails(const ValueReader & reader, int index, NavigationHighResolutionDetails & details);

	/** Decodes part of a message that contains information about owned ship that is in range of
	high resolution sensors and stores it to given game date structure. It decodes object with given index.
	@param reader ValueReader that holds the message
	@param index Index of object information in a message
	@param details Game data structure where to store information
	*/
	void navigationReadHighResolutionOwnShipDetails(const ValueReader & reader, int index, PlayerShipDetails & details);

	/** Decodes part of a message that contains information about ship. It decodes object with given index.
	@param reader ValueReader that holds the message
	@param index Index of object information in a message
	@param details Game data structure where to store information
	*/
	void navigationReadShip(const ValueReader & reader, int index, NavigationObject & details);

	/** Decodes part of a message that contains information about base. It decodes object with given index.
	@param reader ValueReader that holds the message
	@param index Index of object information in a message
	@param details Game data structure where to store information
	*/
	void navigationReadBase(const ValueReader & reader, int index, NavigationBaseObject & details);

	/** Decodes part of a message that contains information about star. It decodes object with given index.
	@param reader ValueReader that holds the message
	@param index Index of object information in a message
	@param details Game data structure where to store information
	*/
	void navigationReadStar(const ValueReader & reader, int index, NavigationObject & details);	

	/* LOGIN */

	/** Decodes answer of request to login to server
	Related request is login.
	@param protocolMessage Protocol message to decode
	*/
	void processLogin(message * protocolMessage);

	/* DEVICE ENERGY STATE */ 

	/** Decodes answer of request to change fortress energy distribution
	Related request is changeDeviceEnergyState.
	@param protocolMessage Protocol message to decode
	*/
	void processChangeDeviceEnergyState(message * protocolMessage);

	/** Decodes FAIL answer of request to change fortress energy distribution
	Related request is changeDeviceEnergyState.
	@param reader ValueReader that holds the message
	*/
	void processChangeDeviceEnergyStateFAIL(const ValueReader & reader);

	/** Decodes answer of request to update fortress energy distribution
	Related request is updateDeviceEnergyState.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateDeviceEnergyState(message * protocolMessage);

	/** Decodes answer of request to update fortress energy distribution
	Related request is updateDeviceEnergyState.
	@param reader ValueReader that holds the message
	*/
	void processUpdateDeviceEnergyStateFAIL(const ValueReader & reader);
	
	/** Decodes part of message that constains information about device energy state
	@param reader ValueReader that holds the message
	@param deviceName Name of the device to which state is related
	@param state Game data structure where to store information
	*/
	void readEnergyState(const ValueReader & reader, const char* deviceName, answerDeviceEnergyState & state);

	/* CHAT */

	/** Decodes answer of request to get list of available buddies
	Related request is  buddies.
	@param protocolMessage Protocol message to decode
	*/
	void processBuddies(message * protocolMessage);

	/** Decodes message containing received message from some buddy
	@param protocolMessage Protocol message to decode
	*/
	void processChatMessage(message * protocolMessage);

	/* SHIPS AND BASES LIST */

	/** Decodes answer of request to get list of players ships
	Related request is playerShips.
	@param protocolMessage Protocol message to decode
	*/
	void processPlayerShips(message * protocolMessage);	

	/** Decodes answer of request to get list of players bases
	Related request is playerBases.
	@param protocolMessage Protocol message to decode
	*/
	void processPlayerBases(message * protocolMessage);
	
	/* RENDER */

	// TODO MARTIN BY STEPAN - doplnit dokumentaci
	void processShipLocationInfo( message * protocolMessage );

	/** Decodes answer of request to get ships in area of some ship
	Related request is shipsInArea.
	@param protocolMessage Protocol message to decode
	*/
	void processShipsInShipArea(message * protocolMessage);

	/** Decodes FAIL answer of request to get ships in area of some ship
	Related request is shipsInArea.
	@param reader ValueReader that holds the message
	*/
	void processShipsInAreaFAIL(const ValueReader & reader);
	
	/** Decodes answer of request to get planets in area of some sun
	Related request is planetsInStarArea.
	@param protocolMessage Protocol message to decode
	*/
	void processPlanetsInStarArea(message * protocolMessage);

	/** Decodes answer of request to get planets in area of some sun
	Related request is planetsInStarArea.
	@param reader ValueReader that holds the message
	*/
	void processPlanetsInStarAreaFAIL(const ValueReader & reader);
	
	/** Decodes part of a message that contains information about planet. It decodes object with given index.
	@param reader ValueReader that holds the message
	@param index Index of object information in a message
	@param details Game data structure where to store information
	*/
	void readPlanetDetails(const ValueReader & reader, int index, PlanetDetails & details);

	/** Decodes part of a message that contains information about planet for navigation. It decodes object with given index.
	@param reader ValueReader that holds the message
	@param index Index of object information in a message
	@param details Game data structure where to store information
	*/
	void readPlanetDetails(const ValueReader & reader, int index, NavigationPlanetDetails & details);

	/** Decodes part of a message that contains information about objects in long range sensors.
	It decodes object with given index.
	@param reader ValueReader that holds the message
	@param index Index of object information in a message
	@param details Game data structure where to store information
	*/
	void readLongRangeDetails(const ValueReader & reader, int index, LongRangeDetails & details);

	/** Decodes part of a message that contains information about object in high resolution sensors.
	It decodes object with given index.
	@param reader ValueReader that holds the message
	@param index Index of object information in a message
	@param details Game data structure where to store information
	*/
	void readHighResolutionDetails(const ValueReader & reader, int index, HighResolutionDetails & details);
	
	// TODO MARTIN BY STEPAN - doplnit dokumentaci
	void synchronizeModelPlanet(PlanetDetails & details);

	// TODO MARTIN BY STEPAN - doplnit dokumentaci
	void synchronizeShipWithHighResolution(HighResolutionDetails & details);

	// TODO MARTIN BY STEPAN - doplnit dokumentaci
	void synchronizePlayerShipDetails( PlayerShipDetails & details);

	// TODO MARTIN BY STEPAN - doplnit dokumentaci
	void synchronizeShipWithLongRange( LongRangeDetails &lrDetails);

	/* SCIENCE TREE */

	/** Decodes answer of request to update science tree state
	Related request is updateScienceTree.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateScienceTree(message * protocolMessage);

	/* CENTRAL INFO WIDGET */

	/** Decodes answer of request to update fortress central information
	Related request is updateFortressCentralInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateFortressCentralInformation(message * protocolMessage);

	/* SHIELDS */

	/** Decodes answer of request to update fortress shields information
	Related request is updateFortressShieldsInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateFortressShieldsInformation(message * protocolMessage);

	/* IMPULS DRIVE */

	/** Decodes answer of request to update fortress impuls drive information
	Related request is updateShipImpulsDriveInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateShipImpulsDriveInformation(message * protocolMessage);

	/* SUBSPACE DRIVE */

	/** Decodes answer of request to update fortress subspace drive information
	Related request is updateShipSubspaceDriveInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateShipSubspaceDriveInformation(message * protocolMessage);

	/* MAINFRAME */

	/** Decodes answer of request to update fortress mainframe information
	Related request is updateFortressMainframeInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateFortressMainframeInformation(message * protocolMessage);

	/* WEAPONS */

	/** Decodes answer of request to update fortress weapons information
	Related request is updateFortressWeaponsInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateFortressWeaponsInformation(message * protocolMessage);

	/** Decodes part of a message that contains information about drone missile launcher.
	It decodes object with given index.
	@param reader ValueReader that holds the message
	@param index Index of object information in a message
	@param details Game data structure where to store information
	*/
	void readDroneMissileLauncher(ValueReader & reader, int index, drone_missile_launcher_status & details);

	/** Decodes part of a message that contains information about laser gun.
	It decodes object with given index.
	@param reader ValueReader that holds the message
	@param index Index of object information in a message
	@param details Game data structure where to store information
	*/
	void readLaserGun(ValueReader & reader, int index, laser_gun_status & details);

	/** Decodes FAIL answer of request to change fortress weapons state
	Related request is changeFortressWeaponsState.
	@param reader ValueReader that holds the message
	*/
	void processChangeFortressWeaponsStateFAIL(ValueReader & reader);

	/* CREW */

	/** Decodes answer of request to update fortress crew information
	Related request is updateFortressCrewInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateFortressCrewInformation(message * protocolMessage);

	/* MINING */

	/** Decodes answer of request to update fortress quarry information
	Related request is updateFortressQuarryInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateFortressQuarryInformation(message * protocolMessage);

	/** Decodes FAIL answer of request to update fortress quarry information
	Related request is updateFortressQuarryInformation.
	@param reader ValueReader that holds the message
	*/
	void processUpdateFortressQuarryInformationFAIL(ValueReader & reader);

	/** Decodes FAIL answer of request to change fortress quarry state
	Related request is changeFortressQuarryState.
	@param reader ValueReader that holds the message
	*/
	void processChangeFortressQuarryStateFAIL(ValueReader & reader);

	/* ACCOMMODATIONS */

	/** Decodes answer of request to update fortress accommodations information
	Related request is updateFortressAccommodationsInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateFortressAccommodationsInformation(message * protocolMessage);

	/** Decodes FAIL answer of request to update fortress accommodations information
	Related request is updateFortressAccommodationsInformation.
	@param reader ValueReader that holds the message
	*/
	void processUpdateFortressAccommodationsInformationFAIL(ValueReader & reader);

	/* OTHER EQUIPMENT */

	/** Decodes answer of request to update fortress other equipment information
	Related request is updateFortressOtherEquipmentInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateFortressOtherEquipmentInformation(message * protocolMessage);

	/** Decodes FAIL answer of request to update fortress other equipment information
	Related request is updateFortressOtherEquipmentInformation.
	@param reader ValueReader that holds the message
	*/
	void processUpdateFortressOtherEquipmentInformationFAIL(ValueReader& reader);

	/* FACTORIES */

	/** Decodes answer of request to update base factories information
	Related request is updateBaseFactoriesInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateBaseFactoriesInformation(message * protocolMessage);

	/** Decodes FAIL answer of request to update base factories information
	Related request is updateBaseFactoriesInformation.
	@param reader ValueReader that holds the message
	*/
	void processUpdateBaseFactoriesInformationFAIL(ValueReader& reader);

	/* WAREHOUSES */

	/** Decodes answer of request to update fortress warehouses information
	Related request is updateFortressWarehousesInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateFortressWarehousesInformation(message * protocolMessage);

	/** Decodes FAIL answer of request to update fortress warehouses information
	Related request is updateFortressWarehousesInformation.
	@param reader ValueReader that holds the message
	*/
	void processUpdateFortressWarehousesInformationFAIL(ValueReader & reader);

	/** Decodes part of a message that contains information about warehouse item.
	It decodes object with given index.
	@param reader ValueReader that holds the message
	@param prefix Prefix of data writen in a message
	@param index Index of object information in a message
	@param details Game data structure where to store information
	*/
	void readWarehouseItem(ValueReader& reader, const std::string & prefix, int index, warehouse_item_status& details) ;

	/** Decodes part of a message that contains information about warehouse items list
	@param reader ValueReader that holds the message
	@param prefix Prefix of data writen in a message
	@param itemsList Output list that will be filled
	*/
	void readWarehouseItemsList(ValueReader & reader, const std::string & prefix, warehouses_status::items_list_t & itemsList);

	/* ANDROIDS */

	/** Decodes answer of request to update ship androids information
	Related request is updateShipAndroidsInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateShipAndroidsInformation(message * protocolMessage);

	/** Decodes answer of request to update ship androids information
	Related request is updateShipAndroidsInformation.
	@param reader ValueReader that holds the message
	*/
	void processUpdateShipAndroidsInformationFAIL(ValueReader & reader);

	/** Decodes answer of request to update base androids information
	Related request is updateBaseAndroidsInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateBaseAndroidsInformation(message * protocolMessage);

	/** Decodes FAIL answer of request to update base androids information
	Related request is updateBaseAndroidsInformation.
	@param reader ValueReader that holds the message
	*/
	void processUpdateBaseAndroidsInformationFAIL(ValueReader & reader);

	/** Decodes part of a message that contains androids status.
	@param reader ValueReader that holds the message
	@param status Game data structure where to store information
	*/
	void readAndroidsStatus(ValueReader& reader, androids_status& status);

	/** Decodes part of a message that contains androids v for given section.
	@param reader ValueReader that holds the message
	@param section Name of the relevant section for which to read assignment
	@param assignment Game data structure where to store information
	*/
	void readAndroidsAssignment(ValueReader& reader, const std::string & section, androids_assignment & assignment);

	/** Decodes answer of request to change ship androids state
	Related request is changeShipAndroidsState.
	@param protocolMessage Protocol message to decode
	*/
	void processChangeShipAndroidsState(message * protocolMessage);

	/** Decodes FAIL answer of request to change ship androids state
	Related request is changeShipAndroidsState.
	@param reader ValueReader that holds the message
	*/
	void processChangeShipAndroidsStateFAIL(ValueReader & reader);

	/** Decodes answer of request to change base androids state
	Related request is changeBaseAndroidsState.
	@param protocolMessage Protocol message to decode
	*/
	void processChangeBaseAndroidsState(message * protocolMessage);	

	/** Decodes FAIL answer of request to change base androids state
	Related request is changeBaseAndroidsState.
	@param reader ValueReader that holds the message
	*/
	void processChangeBaseAndroidsStateFAIL(ValueReader & reader);

	/** Processes ping answer from server
	@param protocolMessage Protocol message to decode
	*/
	void processPing(message * protocolMessage);

	/** Decodes answer of request to update base hangars item information
	Related request is updateHangarItemInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateBaseHangarItemInformation(message * protocolMessage);

	/** Decodes answer of request to update base hangars information
	Related request is updateHangarInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateBaseHangarsInformation(message * protocolMessage);

	/** Decodes answer of request to unmount fortress device
	Related request is updateHangarInformation.
	@param protocolMessage Protocol message to decode
	*/
	void processUnmountFortressDevice(message * protocolMessage);

	/** Decodes FAIL answer of request to unmount fortress device
	Related request is updateHangarInformation.
	@param reader ValueReader that holds the message
	*/
	void processUnmountFortressDevice(ValueReader & reader);

	/** Decodes answer of request to invite trade partner
	Related request is sendTradeInvitation.
	@param protocolMessage Protocol message to decode
	*/
	void processSendTradeInvitation(message * protocolMessage);

	/** Decodes FAIL answer of request to invite trade partner
	Related request is sendTradeInvitation.
	@param reader ValueReader that holds the message
	*/
	void processSendTradeInvitationFAIL(ValueReader & reader);

	/** Decodes answer of request to get partner fortresses
	Related request is tradePartnerFortresses.
	@param protocolMessage Protocol message to decode
	*/
	void processTradePartnerFortresses(message * protocolMessage);

	/** Decodes received trade invitation
	@param protocolMessage Protocol message to decode
	*/
	void processReceiveTradeInvitation(message * protocolMessage);

	/** Decodes decision of trade invitation
	@param protocolMessage Protocol message to decode
	*/
	void processDecideTradeInvitation(message * protocolMessage);

	/** Decodes received decision of trade invitation
	@param protocolMessage Protocol message to decode
	*/
	void processReceiveTradeInvitationDecision(message * protocolMessage);

	/** Decodes received trade invitation
	@param reader Value reader that encapsulates protocol message
	@param invitation Trade invitation data to be filled
	*/
	void readInvitation(ValueReader & reader, trade_invitation_data & invitation);

	/** Decodes answer of request to cancel trade
	@param protocolMessage Protocol message to decode
	*/
	void processCancelTrade(message * protocolMessage);

	/** Decodes trade cancelation, that is not caused by this player.
	That means other player canceled trade or server did.
	@param protocolMessage Protocol message to decode
	*/
	void processReceiveTradeCancelation(message * protocolMessage);	

	/** Decodes received trade start data
	@param reader Value reader that encapsulates protocol message
	@param prefix Prefix for all read values
	@param tradeData Trade data data to be filled
	*/
	void readTradeData(ValueReader & reader, const std::string & prefix, trade_data & tradeData);

	/** Decodes answer of request to move trade item
	@param protocolMessage Protocol message to decode
	*/
	void processMoveTradeItem(message * protocolMessage);

	/** Decodes received trade item movement data
	@param reader Value reader that encapsulates protocol message
	@param tradeData Trade data data to be filled
	*/
	void readTradeMovementData(ValueReader & reader, trade_movement_data & tradeData);

	/** Decodes answer of request to commit trade
	Related request is commitTrade
	@param protocolMessage Protocol message to decode
	*/
	void processCommitTrade(message * protocolMessage);

	/** Decodes FAIL answer of request to commit trade
	Related request is commitTrade
	@param reader ValueReader that holds the message
	*/
	void processCommitTradeFAIL(message * protocolMessage);

	/** Decodes message to prepare commit trade
	@param protocolMessage Protocol message to decode
	*/
	void processPrepareCommitTrade(message * protocolMessage);

	/** Decodes answer of request to move trade resource
	@param protocolMessage Protocol message to decode
	*/
	void processMoveTradeResource(message * protocolMessage);

	/** Decodes received trade resource movement data
	@param reader Value reader that encapsulates protocol message
	@param tradeData Trade data data to be filled
	*/
	void readTradeResourceMovementData(ValueReader & reader, trade_resource_movement_data & tradeData);

	/** Decodes received trade commit cancelation
	@param protocolMessage Protocol message to decode
	*/
	void processCancelTradeCommit(message * protocolMessage);

	/** Decodes received discovered stars data
	@param reader Value reader that encapsulates protocol message
	*/
	void processPlayerDiscoveredStars(message * protocolMessage);

	/** Decodes answer of request to mount item from warehouse
	@param protocolMessage Protocol message to decode
	*/
	void processMountFortressDevice(message * protocolMessage);

	/** Decodes answer of request to get fortresses in weapons range
	Related request is fortressesInWeaponsRange
	@param protocolMessage Protocol message to decode
	*/
	void processFortressesInWeaponsRange(message * protocolMessage);

	/** Decodes answer of request to attack fortress
	Related request is attackFortress
	@param protocolMessage Protocol message to decode
	*/
	void processAttackFortress(message * protocolMessage);

	/** Decodes answer of request to stop attack fortress
	Related request is stopAttackFortress
	@param protocolMessage Protocol message to decode
	*/
	void processStopAttackFortress(message * protocolMessage);

	/** Decodes report about fight action
	@param protocolMessage Protocol message to decode
	*/
	void processFightActionReport(message * protocolMessage);

	/** Decodes answer of request to get planets in system
	Related request is navigationPlanets
	@param protocolMessage Protocol message to decode
	*/
	void processNavigationPlanets(message * protocolMessage);

	/** Decodes answer of request to get uncontrollable fortresses
	Related request is uncontrollableFortresses
	@param protocolMessage Protocol message to decode
	*/
	void processUncontrollableFortresses(message * protocolMessage);

	/** Decodes answer of request to build new base shell
	Related request is buildNewBaseShell
	@param protocolMessage Protocol message to decode
	*/
	void processBuildNewBaseShell(message * protocolMessage);	

	/** Decodes answer of request to get available build classes
	Related request is availableBuildClasses
	@param protocolMessage Protocol message to decode
	*/
	void processAvailableFortressClasses(message * protocolMessage);

	/** Decodes answer of request to get fortress class data
	Related request is fortressClassData
	@param protocolMessage Protocol message to decode
	*/
	void processFortressClassData(message * protocolMessage);

	/** Decodes answer of request to get fortresses with build information
	Related request is playerFortressesWithBuildInformation
	@param protocolMessage Protocol message to decode
	*/
	void processPlayerFortressesWithBuildInformation(message * protocolMessage);	

	/** Decodes answer of request to get fortresses 
	Related request is playerFortresses
	@param protocolMessage Protocol message to decode
	*/
	void processPlayerFortresses(message * protocolMessage);	

	/** Decodes answer of request to conquer uncontrollable fotress
	Related request is conquerFortress 
	@param protocolMessage Protocol message to decode
	*/
	void processConquerFortress(message * protocolMessage);

	/** Decodes answer of request to add fortress accommodation
	Related request is fortressAddAccommodation 
	@param protocolMessage Protocol message to decode
	*/
	void processFortressAddAccommodations(message * protocolMessage);

	/** Decodes answer of request to add fortress crew
	Related request is fortressAddCrew 
	@param protocolMessage Protocol message to decode
	*/
	void processFortressAddCrew(message * protocolMessage);

	/** Decodes answer of request to remove fortress crew
	Related request is fortressRemoveCrew 
	@param protocolMessage Protocol message to decode
	*/
	void processFortressRemoveCrew(message * protocolMessage);

	/** Decodes update fortress notifications
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateFortress(message * protocolMessage);

	/** Decodes answer of request to register player
	Related request is fortressRemoveCrew 
	@param protocolMessage Protocol message to decode
	*/
	void processRegisterPlayer(message * protocolMessage);

	/** Decodes answer of request to get game time speed 
	Related request is gameSecondsPerActualSecond 
	@param protocolMessage Protocol message to decode
	*/
	void processGameSecondsPerActualSecond(message * protocolMessage);

	/** Decodes answer of request to rename owned fortress
	Related request is renameFortress 
	@param protocolMessage Protocol message to decode
	*/
	void processRenameFortress(message * protocolMessage);

	/** Decodes answer of request to get all player fortresses with attack information
	Related request is playerFortressesAttackInformation
	@param protocolMessage Protocol message to decode
	*/
	void processPlayerFortressesAttackInformation(message * protocolMessage);

	/** Decodes answer of request to build item in hangar 
	Related request is hangarBuildItem
	@param protocolMessage Protocol message to decode
	*/
	void processHangarBuildItem(message * protocolMessage);

	/** Decodes answer of request to cancel build of item in hangar
	Related request is hangarCancelItem
	@param protocolMessage Protocol message to decode
	*/
	void processHangarCancelItem(message * protocolMessage);

	/** Decodes answer of request to build ship in hangar 
	Related request is hangarBuildItem
	@param protocolMessage Protocol message to decode
	*/
	void processHangarBuildShip(message * protocolMessage);

	/** Decodes answer of request to update fortress HR sensors
	Related request is updateFortressSensorsInformation
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateFortressSensorsInformation(message * protocolMessage);

	/** Decodes answer of request to build ship in hangar 
	Related request is updateFortressCloakingInformation
	@param protocolMessage Protocol message to decode
	*/
	void processUpdateFortressCloakingInformation(message * protocolMessage);

	/** Decodes part of a message that contains sensors data
	@param reader ValueReader that holds the message
	@param prefix Prefix to read data
	@param data Sensors data to be filled
	*/
	void readSensorsData(ValueReader & reader, const std::string & prefix, sensors_data & data);

	/** Decodes ship warp informations
	@param protocolMessage Protocol message to decode
	*/
	void processShipWarpInfo(message * protocolMessage);

	/** Decodes message with information about fight progress
	@param protocolMessage Protocol message to decode
	*/
	void processFightProgressReport(message * protocolMessage);

	/** Decodes part of a message with information about fortress fight data
	@param reader ValueReader that holds the message
	@param data Fortress fight data to be filled
	@param index Index of fortress in a message
	*/
	void readFortressFightData(ValueReader & reader, fortress_detailed_fight_data & data, unsigned long index);
private:	
	/** Socket client to use for low-level communication */
	ASocketClient * socketClient_;

	/** Contains handlers for decoding messages received from server, indexed by request name */
	HandlerWrapper * messageMapper_;

	/** Time limit for processing, guarantees that processing of a message does not start after time limit */
	int timeLimitForProcessing_;

	/** MainWindow that gets decoded data and works them after decoding phase */
	MainWindow * mainWindow_;

	/** Last time when client did ping to server */
	clock_t lastPingAcknowledgementTime_;

	/** Interval between two pings, after interval elapses client tries to ping server again */
	int pingInterval_;

	/** Last login and connection configuration */
	LoginDetails currentLoginInformation_;
};

/// Static singleton that holds CommandClient instance. 
/** Static singleton that holds CommandClient instance. This is not true singleton, 
because it only holds CommandClient as a static field, because it is used only when
client wants to start processing of received messages and needs to get reference to
CommandClient from the methods that is not bound to any object.
*/
class CommandClientHolder {
	static CommandClient * commandClient_;
public:
	static void setCommandClient(CommandClient * commandClient);
	static CommandClient * getCommandClient();
};

#endif