Class API

Class Documentation

class API

Public Functions

API()
~API() = default
void WriteMessage(const std::string &msg)

Write a message to the network pipe.

Parameters:

msg – Contain the message to send

inline int GetInFd() const

Retrieves the input file descriptor for the network pipe.

Returns:

The file descriptor associated with the input end of the network pipe

inline int GetEventsInFd() const

Retrieves the file descriptor used for relaying events from the network.

This method returns the read end of the pipe that is used to receive events from the network layer. The returned file descriptor can be monitored for incoming events.

Returns:

The file descriptor associated with network event relaying.

inline std::map<std::string, std::vector<Trantor>> GetTeams()

Get the Teams.

Returns:

std::map<std::string, std::vector<Trantor>>

Tilemap GetTilemap()

Get the tilemap.

inline std::map<int, std::pair<int, int>> GetEggList()

Get the Egg List.

Returns:

std::map<int, std::pair<int, int>>

std::vector<std::string> GetTeamsName()

Get the teams name.

Returns:

std::string

void AddEgg(int id, int x, int y)

Create an egg to store it into _eggList.

Parameters:
  • id – Contain the id of the new egg

  • x – Contain the position in x of the new egg

  • y – Contain the position in y of the new egg

void DeleteEgg(int id)

Delete an egg from _eggList.

Parameters:

id – Contain the id of the deleted egg

void ClearCommand()

Clear the command list.

void AskMapSize()

Send a message to ask the map size.

void AskAllTileContent()

Send a message to ask the content of all tile.

void AskTileContent(int x, int y)

Send a message to ask the content of one tile.

Parameters:
  • x – Contain the position in x of tile

  • y – Contain the position in y of tile

void AskAllTeamName()

Ask all team name.

void AskAllPlayerPos()

Send a message to ask the position of all player.

void AskPlayerPos(int id)

Send a message to ask the position of one player.

Parameters:

id – Contain the id of the player

void AskAllPlayerLevel()

Send a message to ask the level of all player.

void AskPlayerLevel(int id)

Send a message to ask the lever of one player.

Parameters:

id – Contain the id of the player

void AskAllPlayerInventory()

Send a message to ask the inventory of all player.

void AskPlayerInventory(int id)

Send a message to ask the inventory of one player.

Parameters:

id – Contain the id of the player

void ParseManageCommand(std::string &command)

Parse and manage the command received from the server.

Parameters:

command – Contain the full string command from the server

void AddPlayer(int id, int x, int y, int orientation, int level, std::string teamsName)

Add a new player to a team.

Parameters:
  • id – Contain the id of the new player

  • x – Contain the position in x of the player

  • y – Contain the position in y of the player

  • orientation – Contain the orientation of the player

  • level – Contain the level of the player

  • teamsName – Contain the name of the team of the player

void HandleMSZ(std::stringstream &ss)

Handle the map size from the server.

Parameters:

ss – Contain the stringstream with map width (X) and height (Y)

void HandleBCT(std::stringstream &ss)

Handle the tile content from the server.

Parameters:

ss – Contain the stringstream with tile position and resources (X Y q0-q6)

void HandleTNA(std::stringstream &ss)

Handle a team name from the server.

Parameters:

ss – Contain the stringstream with the team name (N)

void HandlePNW(std::stringstream &ss)

Handle a new player connection from the server.

Parameters:

ss – Contain the stringstream with the player’s info (#n X Y O L N)

void HandlePPO(std::stringstream &ss)

Handle the position of a player.

Parameters:

ss – Contain the stringstream with the player’s position (#n X Y O)

void HandlePLV(std::stringstream &ss)

Handle the level of a player.

Parameters:

ss – Contain the stringstream with the player’s level (#n L)

void HandlePIN(std::stringstream &ss)

Handle the inventory of a player.

Parameters:

ss – Contain the stringstream with the inventory data (#n X Y q0-q6)

void HandlePEX(std::stringstream &ss)

Handle the expulsion of a player.

Parameters:

ss – Contain the stringstream with the id of the player (#n)

void HandlePBC(std::stringstream &ss)

Handle a broadcast message sent by a player.

Parameters:

ss – Contain the stringstream with the message (#n M)

void HandlePIC(std::stringstream &ss)

Handle the start of an incantation.

Parameters:

ss – Contain the stringstream with the incantation data (X Y L #n …)

void HandlePIE(std::stringstream &ss)

Handle the result of an incantation.

Parameters:

ss – Contain the stringstream with the result (X Y R)

void HandlePFK(std::stringstream &ss)

Handle the egg laying action of a player.

Parameters:

ss – Contain the stringstream with the id of the player (#n)

void HandlePDR(std::stringstream &ss)

Handle the drop of a resource by a player.

Parameters:

ss – Contain the stringstream with the player id and resource number (#n i)

void HandlePGT(std::stringstream &ss)

Handle the pickup of a resource by a player.

Parameters:

ss – Contain the stringstream with the player id and resource number (#n i)

void HandlePDI(std::stringstream &ss)

Handle the death of a player.

Parameters:

ss – Contain the stringstream with the id of the player (#n)

void HandleENW(std::stringstream &ss)

Handle the creation of a new egg.

Parameters:

ss – Contain the stringstream with egg and player data (#e #n X Y)

void HandleEBO(std::stringstream &ss)

Handle the connection of a player from an egg.

Parameters:

ss – Contain the stringstream with the egg id (#e)

void HandleEDI(std::stringstream &ss)

Handle the death of an egg.

Parameters:

ss – Contain the stringstream with the egg id (#e)

void HandleSGT(std::stringstream &ss)

Handle the current time unit from the server.

Parameters:

ss – Contain the stringstream with the time unit (T)

void HandleSST(std::stringstream &ss)

Handle the modification of the time unit.

Parameters:

ss – Contain the stringstream with the new time unit value (T)

void HandleSEG(std::stringstream &ss)

Handle the end of the game and store the winner’s name.

Parameters:

ss – Contain the stringstream with the team name (N)

void HandleSMG(std::stringstream &ss)

Handle a general message from the server.

Parameters:

ss – Contain the stringstream with the message (M)

Public Static Functions

static void HandleMCT()

Handle all tile contents from the server.

static void HandleSUC()

Handle an unknown command from the server.

static void HandleSBP()

Handle a command with bad parameters from the server.