Update protocol to include server difficulty and mode

This commit is contained in:
Marianne Gagnon 2016-03-10 19:25:55 -05:00
parent 90f0c12393
commit d0499be4b9
4 changed files with 15 additions and 13 deletions

View File

@ -38,10 +38,6 @@ Server::Server(const XMLNode & xml, bool is_lan)
m_current_players = 0;
m_max_players = 0;
m_is_lan = is_lan;
// TODO: get minor mode and difficulty from network protocol
// See STKHost::handleLANRequests
// and this is unpacked in ServersManager operation(
m_minor_mode = RaceManager::MINOR_MODE_NORMAL_RACE;
m_difficulty = RaceManager::DIFFICULTY_HARD;
@ -77,10 +73,6 @@ Server::Server(const core::stringw &name, bool is_lan, int max_players,
m_address.copy(address);
// In case of LAN server, public and private port are the same.
m_private_port = m_address.getPort();
// TODO: get minor mode and difficulty from network protocol
// See STKHost::handleLANRequests
// and this is unpacked in ServersManager operation(
m_minor_mode = RaceManager::MINOR_MODE_NORMAL_RACE;
m_difficulty = RaceManager::DIFFICULTY_HARD;

View File

@ -119,8 +119,12 @@ public:
// ------------------------------------------------------------------------
RaceManager::MinorRaceModeType getRaceMinorMode() const { return m_minor_mode; }
// ------------------------------------------------------------------------
void setRaceMinorMode(RaceManager::MinorRaceModeType m) { m_minor_mode = m; }
// ------------------------------------------------------------------------
RaceManager::Difficulty getDifficulty() const { return m_difficulty; }
// ------------------------------------------------------------------------
void setDifficulty(RaceManager::Difficulty d) { m_difficulty = d; }
// ------------------------------------------------------------------------
/** Compares two servers according to the sort order currently defined.
* \param a The addon to compare this addon to.
*/

View File

@ -178,10 +178,14 @@ Online::XMLRequest* ServersManager::getLANRefreshRequest() const
uint8_t players = s.getUInt8(bytes_read+1);
uint32_t my_ip = s.getUInt32(bytes_read+2);
uint32_t my_port = s.getUInt16(bytes_read+6);
ServersManager::get()
->addServer(new Server(name, /*lan*/true,
max_players, players,
sender) );
uint16_t mode = s.getUInt16(bytes_read+8);
uint8_t difficulty = s.getUInt8(bytes_read+10);
Server* server = new Server(name, /*lan*/true,
max_players, players, sender);
server->setDifficulty((RaceManager::Difficulty)difficulty);
server->setRaceMinorMode((RaceManager::MinorRaceModeType)mode);
ServersManager::get()->addServer(server);
TransportAddress me(my_ip, my_port);
NetworkConfig::get()->setMyAddress(me);
m_success = true;

View File

@ -586,12 +586,14 @@ void STKHost::handleLANRequests()
// current players, and the client's ip address and port
// number (which solves the problem which network interface
// might be the right one if there is more than one).
BareNetworkString s(name.size()+1+8);
BareNetworkString s(name.size()+1+11);
s.encodeString(name);
s.addUInt8(NetworkConfig::get()->getMaxPlayers());
s.addUInt8(0); // FIXME: current number of connected players
s.addUInt32(sender.getIP());
s.addUInt16(sender.getPort());
s.addUInt16((uint16_t)race_manager->getMinorMode());
s.addUInt8((uint8_t)race_manager->getDifficulty());
m_lan_network->sendRawPacket(s, sender);
} // if message is server-requested
else if (command == "connection-request")