当前位置: 首页>>代码示例>>C++>>正文


C++ NetworkString类代码示例

本文整理汇总了C++中NetworkString的典型用法代码示例。如果您正苦于以下问题:C++ NetworkString类的具体用法?C++ NetworkString怎么用?C++ NetworkString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NetworkString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getNetworkString

/** Sends a vote for a major vote 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 major Major mode voted for.
 */
void ClientLobbyRoomProtocol::voteMajor(uint8_t player_id, uint32_t major)
{
    NetworkString *request = getNetworkString(6);
    request->addUInt8(LE_VOTE_MAJOR).addUInt8(player_id)
           .addUInt32(major);
    sendToServer(request, true);
    delete request;
}   // voteMajor
开发者ID:Elderme,项目名称:stk-code,代码行数:14,代码来源:client_lobby_room_protocol.cpp

示例2: getNetworkString

// ----------------------------------------------------------------------------
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
开发者ID:devnexen,项目名称:stk-code,代码行数:9,代码来源:game_events_protocol.cpp

示例3: switch

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
开发者ID:Elderme,项目名称:stk-code,代码行数:56,代码来源:client_lobby_room_protocol.cpp

示例4: sendPacket

/** Sends a packet to this host.
 *  \param data The data to send.
 *  \param reliable If the data is sent reliable or not.
 */
void STKPeer::sendPacket(NetworkString const& data, bool reliable)
{
    TransportAddress a(m_enet_peer->address);
    Log::verbose("STKPeer", "sending packet of size %d to %s",
                 data.size(), a.toString().c_str());
         
    ENetPacket* packet = enet_packet_create(data.getBytes(), data.size() + 1,
                                    (reliable ? ENET_PACKET_FLAG_RELIABLE
                                              : ENET_PACKET_FLAG_UNSEQUENCED));
    enet_peer_send(m_enet_peer, 0, packet);
}   // sendPacket
开发者ID:TheDudeWithThreeHands,项目名称:A-StreamKart,代码行数:15,代码来源:stk_peer.cpp

示例5: getNetworkString

/** 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
开发者ID:GreenLunar,项目名称:stk-code-fix_1797,代码行数:14,代码来源:server_lobby_room_protocol.cpp

示例6: startSelection

void ServerLobbyRoomProtocol::startSelection()
{
    std::vector<STKPeer*> peers = NetworkManager::getInstance()->getPeers();
    for (unsigned int i = 0; i < peers.size(); i++)
    {
        NetworkString ns;
        ns.ai8(0x05).ai8(4).ai32(peers[i]->getClientServerToken()); // start selection
        m_listener->sendMessage(this, peers[i], ns, true); // reliably
    }
    m_selection_enabled = true;
}
开发者ID:Charence,项目名称:stk-code,代码行数:11,代码来源:server_lobby_room_protocol.cpp

示例7: startGame

void ServerLobbyRoomProtocol::startGame()
{
    std::vector<STKPeer*> peers = NetworkManager::getInstance()->getPeers();
    for (unsigned int i = 0; i < peers.size(); i++)
    {
        NetworkString ns;
        ns.ai8(0x04).ai8(4).ai32(peers[i]->getClientServerToken()); // start game
        m_listener->sendMessage(this, peers[i], ns, true); // reliably
    }
    m_listener->requestStart(new StartGameProtocol(m_setup));
    m_in_race = true;
}
开发者ID:Charence,项目名称:stk-code,代码行数:12,代码来源:server_lobby_room_protocol.cpp

示例8: KartUpdateProtocol

void SynchronizationProtocol::asynchronousUpdate()
{
    static double timer = StkTime::getRealTime();
    double current_time = StkTime::getRealTime();
    if (m_countdown_activated)
    {
        m_countdown -= (current_time - m_last_countdown_update);
        m_last_countdown_update = current_time;
        Log::debug("SynchronizationProtocol", "Update! Countdown remaining : %f", m_countdown);
        if (m_countdown < 0.0 && !m_has_quit)
        {
            m_has_quit = true;
            Log::info("SynchronizationProtocol", "Countdown finished. Starting now.");
            m_listener->requestStart(new KartUpdateProtocol());
            m_listener->requestStart(new ControllerEventsProtocol());
            m_listener->requestStart(new GameEventsProtocol());
            m_listener->requestTerminate(this);
            return;
        }
        static int seconds = -1;
        if (seconds == -1)
        {
            seconds = (int)(ceil(m_countdown));
        }
        else if (seconds != (int)(ceil(m_countdown)))
        {
            seconds = (int)(ceil(m_countdown));
            Log::info("SynchronizationProtocol", "Starting in %d seconds.", seconds);
        }
    }
    if (current_time > timer+0.1)
    {
        std::vector<STKPeer*> peers = NetworkManager::getInstance()->getPeers();
        for (unsigned int i = 0; i < peers.size(); i++)
        {
            NetworkString ns;
            ns.ai8(i).addUInt32(peers[i]->getClientServerToken()).addUInt8(1).addUInt32(m_pings[i].size());
            // now add the countdown if necessary
            if (m_countdown_activated && m_listener->isServer())
            {
                ns.addUInt32((int)(m_countdown*1000.0));
                Log::debug("SynchronizationProtocol", "CNTActivated: Countdown value : %f", m_countdown);
            }
            Log::verbose("SynchronizationProtocol", "Added sequence number %u for peer %d", m_pings[i].size(), i);
            timer = current_time;
            m_pings[i].insert(std::pair<int,double>(m_pings_count[i], timer));
            m_listener->sendMessage(this, peers[i], ns, false);
            m_pings_count[i]++;
        }
    }

}
开发者ID:kmangame0,项目名称:stk,代码行数:52,代码来源:synchronization_protocol.cpp

示例9: saveState

/** Saves a state on the client. Used to save an initial state at t=0 for each
 *  client in case that we receive an event from another client (which will
 *  trigger a rewind) before a state from the server.
 */
void RewindManager::saveLocalState()
{
    int ticks = World::getWorld()->getTimeTicks();

    saveState(/*local_state*/true);
    NetworkString *state = GameProtocol::lock()->getState();

    // Copy the data to a new string, making the buffer in
    // GameProtocol availble for again.
    BareNetworkString *bns =
        new BareNetworkString(state->getCurrentData(),
                              state->size()           );
    m_rewind_queue.addLocalState(bns, /*confirmed*/true, ticks);
}   // saveLocalState
开发者ID:toymak3r,项目名称:Beyond-The-Mirror---Weird-Rancing-Game,代码行数:18,代码来源:rewind_manager.cpp

示例10: kartDisconnected

void ServerLobbyRoomProtocol::kartDisconnected(Event* event)
{
    STKPeer* peer = *(event->peer);
    if (peer->getPlayerProfile() != NULL) // others knew him
    {
        NetworkString msg;
        msg.ai8(0x02).ai8(1).ai8(peer->getPlayerProfile()->race_id);
        m_listener->sendMessage(this, msg);
        Log::info("ServerLobbyRoomProtocol", "Player disconnected : id %d",
                  peer->getPlayerProfile()->race_id);
        m_setup->removePlayer(peer->getPlayerProfile()->race_id);
        NetworkManager::getInstance()->removePeer(peer);
    }
    else
        Log::info("ServerLobbyRoomProtocol", "The DC peer wasn't registered.");
}
开发者ID:Charence,项目名称:stk-code,代码行数:16,代码来源:server_lobby_room_protocol.cpp

示例11: assert

void StartGameProtocol::ready() // on clients, means the loading is finished
{
    if (!m_listener->isServer()) // if we're a client
    {
        assert(NetworkManager::getInstance()->getPeerCount() == 1);
        NetworkString ns;
        ns.ai32(NetworkManager::getInstance()->getPeers()[0]->getClientServerToken()).ai8(1);
        Log::info("StartGameProtocol", "Player ready, notifying server.");
        m_listener->sendMessage(this, ns, true);
        m_state = READY;
        m_ready = true;
        return;
    }
    else // on the server
    {
    }
}
开发者ID:Shreesha-S,项目名称:stk-code,代码行数:17,代码来源:start_game_protocol.cpp

示例12: assert

/** 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
开发者ID:GreenLunar,项目名称:stk-code-fix_1797,代码行数:50,代码来源:server_lobby_room_protocol.cpp

示例13: sendPacket

void STKPeer::sendPacket(NetworkString const& data, bool reliable)
{
    TransportAddress a(m_peer->address);
    Log::verbose("STKPeer", "sending packet of size %d to %s",
                 a.toString().c_str());

    ENetPacket* packet = enet_packet_create(data.getBytes(), data.size() + 1,
                                            (reliable ? ENET_PACKET_FLAG_RELIABLE : ENET_PACKET_FLAG_UNSEQUENCED));
    /* to debug the packet output
    printf("STKPeer: ");
    for (unsigned int i = 0; i < data.size(); i++)
    {
        printf("%d ", (uint8_t)(data[i]));
    }
    printf("\n");
    */
    enet_peer_send(m_peer, 0, packet);
}
开发者ID:jubalh,项目名称:stk-code,代码行数:18,代码来源:stk_peer.cpp

示例14: kartFinishedRace

/** This function is called on a client when it receives a kartFinishedRace
 *  event from the server. It updates the game with this information.
 *  \param ns The message from the server.
 */
void GameEventsProtocol::kartFinishedRace(const NetworkString &ns)
{
    if (ns.size() < 5)
    {
        Log::warn("GameEventsProtocol", "kartFinisheRace: Too short message.");
        return;
    }

    uint8_t kart_id = ns.getUInt8();
    float time      = ns.getFloat();
    if (race_manager->modeHasLaps())
    {
        World::getWorld()->getKart(kart_id)
            ->setPosition(m_last_finished_position++);
    }
    World::getWorld()->getKart(kart_id)->finishedRace(time,
                                                      /*from_server*/true);
}   // kartFinishedRace
开发者ID:devnexen,项目名称:stk-code,代码行数:22,代码来源:game_events_protocol.cpp

示例15: notifyEventAsynchronous

bool StartGameProtocol::notifyEventAsynchronous(Event* event)
{
    NetworkString data = event->data();
    if (data.size() < 5)
    {
        Log::error("StartGameProtocol", "Too short message.");
        return true;
    }
    uint32_t token = data.gui32();
    uint8_t ready = data.gui8(4);
    STKPeer* peer = (*(event->peer));
    if (peer->getClientServerToken() != token)
    {
        Log::error("StartGameProtocol", "Bad token received.");
        return true;
    }
    if (m_listener->isServer() && ready) // on server, player is ready
    {
        Log::info("StartGameProtocol", "One of the players is ready.");
        m_player_states[peer->getPlayerProfile()] = READY;
        m_ready_count++;
        if (m_ready_count == m_game_setup->getPlayerCount())
        {
            // everybody ready, synchronize
            SynchronizationProtocol* protocol = static_cast<SynchronizationProtocol*>(m_listener->getProtocol(PROTOCOL_SYNCHRONIZATION));
            if (protocol)
            {
                protocol->startCountdown(5000); // 5 seconds countdown
                Log::info("StartGameProtocol", "All players ready, starting countdown.");
                m_ready = true;
                return true;
            }
            else
                Log::error("StartGameProtocol", "The Synchronization protocol hasn't been started.");
        }
    }
    else // on the client, we shouldn't even receive messages.
    {
        Log::error("StartGameProtocol", "Received a message with bad format.");
    }
    return true;
}
开发者ID:Shreesha-S,项目名称:stk-code,代码行数:42,代码来源:start_game_protocol.cpp


注:本文中的NetworkString类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。