本文整理汇总了C++中NetworkString::addUInt8方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkString::addUInt8方法的具体用法?C++ NetworkString::addUInt8怎么用?C++ NetworkString::addUInt8使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkString
的用法示例。
在下文中一共展示了NetworkString::addUInt8方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: kartSelectionRequested
/*! \brief Called when a player asks to select a kart.
* \param event : Event providing the information.
*
* Format of the data :
* Byte 0 1 2
* ----------------------------------------------
* Size | 1 | 1 | N |
* Data |player id | N (kart name size) | kart name |
* ----------------------------------------------
*/
void ServerLobbyRoomProtocol::kartSelectionRequested(Event* event)
{
if(m_state!=SELECTING)
{
Log::warn("Server", "Received kart selection while in state %d.",
m_state);
return;
}
if (!checkDataSize(event, 1)) return;
const NetworkString &data = event->data();
STKPeer* peer = event->getPeer();
uint8_t player_id = data.getUInt8();
std::string kart_name;
data.decodeString(&kart_name);
// check if selection is possible
if (!m_selection_enabled)
{
NetworkString *answer = getNetworkString(2);
// selection still not started
answer->addUInt8(LE_KART_SELECTION_REFUSED).addUInt8(2);
peer->sendPacket(answer);
delete answer;
return;
}
// check if somebody picked that kart
if (!m_setup->isKartAvailable(kart_name))
{
NetworkString *answer = getNetworkString(2);
// kart is already taken
answer->addUInt8(LE_KART_SELECTION_REFUSED).addUInt8(0);
peer->sendPacket(answer);
delete answer;
return;
}
// check if this kart is authorized
if (!m_setup->isKartAllowed(kart_name))
{
NetworkString *answer = getNetworkString(2);
// kart is not authorized
answer->addUInt8(LE_KART_SELECTION_REFUSED).addUInt8(1);
peer->sendPacket(answer);
delete answer;
return;
}
// send a kart update to everyone
NetworkString *answer = getNetworkString(3+kart_name.size());
// This message must be handled synchronously on the client.
answer->setSynchronous(true);
// kart update (3), 1, race id
answer->addUInt8(LE_KART_SELECTION_UPDATE).addUInt8(player_id)
.encodeString(kart_name);
sendMessageToPeersChangingToken(answer);
delete answer;
m_setup->setPlayerKart(player_id, kart_name);
} // kartSelectionRequested
示例2: voteRaceCount
/** Sends a vote for the number of tracks from a client to the server. Note
* that even this client will only store the vote when it is received back
* from the server.
* \param player_id The global player id of the voting player.
* \param count NUmber of tracks to play.
*/
void ClientLobbyRoomProtocol::voteRaceCount(uint8_t player_id, uint8_t count)
{
NetworkString *request = getNetworkString(3);
request->addUInt8(LE_VOTE_RACE_COUNT).addUInt8(player_id).addUInt8(count);
sendToServer(request, true);
delete request;
} // voteRaceCount
示例3: doneWithResults
/** Called from the gui when a client clicked on 'continue' on the race result
* screen. It notifies the server that this client has exited the screen and
* is back at the lobby.
*/
void ClientLobbyRoomProtocol::doneWithResults()
{
NetworkString *done = getNetworkString(1);
done->addUInt8(LE_RACE_FINISHED_ACK);
sendToServer(done, /*reliable*/true);
delete done;
} // doneWithResults
示例4: voteMinor
/** Sends a vote for the minor game mode from a client to the server. Note that
* even this client will only store the vote when it is received back from the
* server.
* \param player_id The global player id of the voting player.
* \param minor Voted minor mode.
*/
void ClientLobbyRoomProtocol::voteMinor(uint8_t player_id, uint32_t minor)
{
NetworkString *request = getNetworkString(6);
request->addUInt8(LE_VOTE_MINOR).addUInt8(player_id).addUInt32(minor);
sendToServer(request, true);
delete request;
} // voteMinor
示例5: sendStartupBoost
// ----------------------------------------------------------------------------
void GameEventsProtocol::sendStartupBoost(uint8_t kart_id)
{
NetworkString *ns = getNetworkString();
ns->setSynchronous(true);
ns->addUInt8(GE_STARTUP_BOOST).addUInt8(kart_id);
sendToServer(ns, /*reliable*/true);
delete ns;
} // sendStartupBoost
示例6: checkRaceFinished
/** Checks if the race is finished, and if so informs the clients and switches
* to state RESULT_DISPLAY, during which the race result gui is shown and all
* clients can click on 'continue'.
*/
void ServerLobbyRoomProtocol::checkRaceFinished()
{
assert(RaceEventManager::getInstance()->isRunning());
assert(World::getWorld());
if(!RaceEventManager::getInstance()->isRaceOver()) return;
m_player_ready_counter = 0;
// Set the delay before the server forces all clients to exit the race
// result screen and go back to the lobby
m_timeout = (float)(StkTime::getRealTime()+15.0f);
m_state = RESULT_DISPLAY;
// calculate karts ranks :
int num_karts = race_manager->getNumberOfKarts();
std::vector<int> karts_results;
std::vector<float> karts_times;
for (int j = 0; j < num_karts; j++)
{
float kart_time = race_manager->getKartRaceTime(j);
for (unsigned int i = 0; i < karts_times.size(); i++)
{
if (kart_time < karts_times[i])
{
karts_times.insert(karts_times.begin() + i, kart_time);
karts_results.insert(karts_results.begin() + i, j);
break;
}
}
}
const std::vector<STKPeer*> &peers = STKHost::get()->getPeers();
NetworkString *total = getNetworkString(1 + karts_results.size());
total->setSynchronous(true);
total->addUInt8(LE_RACE_FINISHED);
for (unsigned int i = 0; i < karts_results.size(); i++)
{
total->addUInt8(karts_results[i]); // kart pos = i+1
Log::info("ServerLobbyRoomProtocol", "Kart %d finished #%d",
karts_results[i], i + 1);
}
sendMessageToPeersChangingToken(total, /*reliable*/ true);
delete total;
Log::info("ServerLobbyRoomProtocol", "End of game message sent");
} // checkRaceFinished
示例7: requestKartSelection
/** Sends the selection of a kart from this client to the server.
* \param player_id The global player id of the voting player.
* \param kart_name Name of the selected kart.
*/
void ClientLobbyRoomProtocol::requestKartSelection(uint8_t player_id,
const std::string &kart_name)
{
NetworkString *request = getNetworkString(3+kart_name.size());
request->addUInt8(LE_KART_SELECTION).addUInt8(player_id)
.encodeString(kart_name);
sendToServer(request, /*reliable*/ true);
delete request;
} // requestKartSelection
示例8: voteReversed
/** Sends a vote if a track at a specified place in the list of all tracks
* should be played in reverse or not. Note that even this client will only
* store the vote when it is received back from the server.
* \param player_id Global player id of the voting player.
* \param reversed True if the track should be played in reverse.
* \param track_nb Index for the track to be voted on in the list of all
* tracks.
*/
void ClientLobbyRoomProtocol::voteReversed(uint8_t player_id, bool reversed,
uint8_t track_nb)
{
NetworkString *request = getNetworkString(9);
request->addUInt8(LE_VOTE_REVERSE).addUInt8(player_id).addUInt8(reversed)
.addUInt8(track_nb);
sendToServer(request, true);
delete request;
} // voteReversed
示例9: kartFinishedRace
/** This function is called from the server when a kart finishes a race. It
* sends a notification to all clients about this event.
* \param kart The kart that finished the race.
* \param time The time at which the kart finished.
*/
void GameEventsProtocol::kartFinishedRace(AbstractKart *kart, float time)
{
NetworkString *ns = getNetworkString(20);
ns->setSynchronous(true);
ns->addUInt8(GE_KART_FINISHED_RACE).addUInt8(kart->getWorldKartId())
.addFloat(time);
sendMessageToPeers(ns, /*reliable*/true);
delete ns;
} // kartFinishedRace
示例10: voteLaps
/** Vote for the number of laps of the specified track. Note that even this
* client will only store the vote when it is received back from the server.
* \param player_id Global player id of the voting player.
* \param laps Number of laps for the specified track.
* \param track_nb Index of the track in the list of all tracks.
*/
void ClientLobbyRoomProtocol::voteLaps(uint8_t player_id, uint8_t laps,
uint8_t track_nb)
{
NetworkString *request = getNetworkString(10);
request->addUInt8(LE_VOTE_LAPS).addUInt8(player_id).addUInt8(laps)
.addUInt8(track_nb);
sendToServer(request, true);
delete request;
} // voteLaps
示例11: update
void ClientLobbyRoomProtocol::update(float dt)
{
switch (m_state)
{
case NONE:
if (STKHost::get()->isConnectedTo(m_server_address))
{
m_state = LINKED;
}
break;
case LINKED:
{
core::stringw name;
if(PlayerManager::getCurrentOnlineState()==PlayerProfile::OS_SIGNED_IN)
name = PlayerManager::getCurrentOnlineUserName();
else
name = PlayerManager::getCurrentPlayer()->getName();
std::string name_u8 = StringUtils::wideToUtf8(name);
const std::string &password = NetworkConfig::get()->getPassword();
NetworkString *ns = getNetworkString(6+1+name_u8.size()
+1+password.size());
// 4 (size of id), global id
ns->addUInt8(LE_CONNECTION_REQUESTED).encodeString(name)
.encodeString(NetworkConfig::get()->getPassword());
sendToServer(ns);
delete ns;
m_state = REQUESTING_CONNECTION;
}
break;
case REQUESTING_CONNECTION:
break;
case CONNECTED:
break;
case KART_SELECTION:
{
NetworkKartSelectionScreen* screen =
NetworkKartSelectionScreen::getInstance();
screen->push();
m_state = SELECTING_KARTS;
}
break;
case SELECTING_KARTS:
break;
case PLAYING:
break;
case RACE_FINISHED:
break;
case DONE:
m_state = EXITING;
ProtocolManager::getInstance()->requestTerminate(this);
break;
case EXITING:
break;
}
} // update
示例12: voteTrack
/** Sends the vote about which track to play at which place in the list of
* tracks (like a custom GP definition). Note that even this client will only
* store the vote when it is received back from the server.
* \param player_id The global player id of the voting player.
* \param track Name of the track.
* \param At which place in the list of tracks this track should be played.
*/
void ClientLobbyRoomProtocol::voteTrack(uint8_t player_id,
const std::string &track,
uint8_t track_nb)
{
NetworkString *request = getNetworkString(2+1+track.size());
request->addUInt8(LE_VOTE_TRACK).addUInt8(player_id).addUInt8(track_nb)
.encodeString(track);
sendToServer(request, true);
delete request;
} // voteTrack
示例13: startGame
/** This function informs each client to start the race, and then starts the
* StartGameProtocol.
*/
void ServerLobbyRoomProtocol::startGame()
{
const std::vector<STKPeer*> &peers = STKHost::get()->getPeers();
NetworkString *ns = getNetworkString(1);
ns->addUInt8(LE_START_RACE);
sendMessageToPeersChangingToken(ns, /*reliable*/true);
delete ns;
Protocol *p = new StartGameProtocol(m_setup);
p->requestStart();
m_state = RACING;
} // startGame
示例14: handleLANRequests
// ----------------------------------------------------------------------------
void STKHost::handleLANRequests()
{
const int LEN=2048;
char buffer[LEN];
TransportAddress sender;
int len = m_lan_network->receiveRawPacket(buffer, LEN, &sender, 1);
if(len<=0) return;
if (std::string(buffer, len) == "stk-server")
{
Log::verbose("STKHost", "Received LAN server query");
std::string name =
StringUtils::wideToUtf8(NetworkConfig::get()->getServerName());
// Avoid buffer overflows
if (name.size() > 255)
name = name.substr(0, 255);
// Send the answer, consisting of server name, max players,
// 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).
NetworkString s;
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());
m_lan_network->sendRawPacket(s.getBytes(), s.size(), sender);
} // if message is server-requested
else if (std::string(buffer, len) == "connection-request")
{
Protocol *c = new ConnectToPeer(sender);
c->requestStart();
}
else
Log::info("STKHost", "Received unknown command '%s'",
std::string(buffer, len).c_str());
} // handleLANRequests
示例15: clientDisconnected
/** Called when a client disconnects.
* \param event The disconnect event.
*/
void ServerLobbyRoomProtocol::clientDisconnected(Event* event)
{
std::vector<NetworkPlayerProfile*> players_on_host =
event->getPeer()->getAllPlayerProfiles();
NetworkString *msg = getNetworkString(2);
msg->addUInt8(LE_PLAYER_DISCONNECTED);
for(unsigned int i=0; i<players_on_host.size(); i++)
{
msg->addUInt8(players_on_host[i]->getGlobalPlayerId());
Log::info("ServerLobbyRoomProtocol", "Player disconnected : id %d",
players_on_host[i]->getGlobalPlayerId());
m_setup->removePlayer(players_on_host[i]);
}
sendMessageToPeersChangingToken(msg, /*reliable*/true);
// Remove the profile from the peer (to avoid double free)
STKHost::get()->removePeer(event->getPeer());
delete msg;
} // clientDisconnected