本文整理汇总了C++中NetworkString::gs方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkString::gs方法的具体用法?C++ NetworkString::gs怎么用?C++ NetworkString::gs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkString
的用法示例。
在下文中一共展示了NetworkString::gs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 5 6 N+6
* ---------------------------------------------------
* Size | 1 | 4 | 1 | N |
* Data | 4 | priv token | N (kart name size) | kart name |
* ---------------------------------------------------
*/
void ServerLobbyRoomProtocol::kartSelectionRequested(Event* event)
{
NetworkString data = event->data();
STKPeer* peer = *(event->peer);
if (!checkDataSizeAndToken(event, 6))
return;
uint8_t kart_name_size = data.gui8(5);
std::string kart_name = data.gs(6, kart_name_size);
if (kart_name.size() != kart_name_size)
{
Log::error("ServerLobbyRoomProtocol", "Kart names sizes differ: told:"
"%d, real: %d.", kart_name_size, kart_name.size());
return;
}
// check if selection is possible
if (!m_selection_enabled)
{
NetworkString answer;
answer.ai8(0x82).ai8(1).ai8(2); // selection still not started
m_listener->sendMessage(this, peer, answer);
return;
}
// check if somebody picked that kart
if (!m_setup->isKartAvailable(kart_name))
{
NetworkString answer;
answer.ai8(0x82).ai8(1).ai8(0); // kart is already taken
m_listener->sendMessage(this, peer, answer);
return;
}
// check if this kart is authorized
if (!m_setup->isKartAllowed(kart_name))
{
NetworkString answer;
answer.ai8(0x82).ai8(1).ai8(1); // kart is not authorized
m_listener->sendMessage(this, peer, answer);
return;
}
// send a kart update to everyone
NetworkString answer;
// kart update (3), 1, race id
answer.ai8(0x03).ai8(1).ai8(peer->getPlayerProfile()->race_id);
// kart name size, kart name
answer.ai8(kart_name.size()).as(kart_name);
m_listener->sendMessage(this, answer);
m_setup->setPlayerKart(peer->getPlayerProfile()->race_id, kart_name);
}
示例2: playerTrackVote
/*! \brief Called when a player votes for a track.
* \param event : Event providing the information.
*
* Format of the data :
* Byte 0 1 5 6 N+6 N+7 N+8
* -----------------------------------------------------------
* Size | 1 | 4 | 1 | N | 1 | 1 |
* Data | 4 | priv token | N | track name | 1 | track number (gp) |
* -----------------------------------------------------------
*/
void ServerLobbyRoomProtocol::playerTrackVote(Event* event)
{
NetworkString data = event->data();
STKPeer* peer = *(event->peer);
if (!checkDataSizeAndToken(event, 8))
return;
int N = data[5];
std::string track_name = data.gs(5, N);
if (!isByteCorrect(event, N+6, 1))
return;
uint8_t player_id = peer->getPlayerProfile()->race_id;
m_setup->getRaceConfig()->setPlayerTrackVote(player_id, track_name, data[N+7]);
// Send the vote to everybody (including the sender)
NetworkString other;
other.ai8(1).ai8(player_id); // add the player id
data.removeFront(5); // remove the token
other += data; // add the data
NetworkString prefix;
prefix.ai8(0xc3); // prefix the token with the ype
sendMessageToPeersChangingToken(prefix, other);
}