Пример #1
0
void NetServer::localLogin( ClientPtr clt, Packet &p )
{
    if (!clt) return;
    NetBuffer netbuf( p.getData(), p.getDataLength() );
    clt->callsign = netbuf.getString();
    string    passwd = netbuf.getString();
    if (!this->server_password.empty() && passwd != this->server_password) {
        this->sendLoginError( clt );
        return;
    }
    for (unsigned int i = 0; i < _Universe->numPlayers(); i++) {
        Cockpit *cp = _Universe->AccessCockpit( i );
        if (cp->savegame && cp->savegame->GetCallsign() == clt->callsign) {
            COUT<<"Cannot login player "<<clt->callsign<<": already exists on this server!";
            sendLoginAlready( clt );
            return;
        }
    }
    netbuf.Reset();
    vector< string >ships;
    getShipList( ships );
    netbuf.addShort( ships.size() );
    for (vector< string >::const_iterator iter = ships.begin(); iter != ships.end(); ++iter)
        netbuf.addString( *iter );
    Packet p1;
    p1.send( CMD_CHOOSESHIP, 0, netbuf.getData(),
            netbuf.getDataLength(), SENDRELIABLE, &clt->cltadr, clt->tcp_sock, __FILE__, PSEUDO__LINE__( 202 ) );
}
Пример #2
0
void NetDemo::writeMessages()
{
    if (!isRecording())
    {
        return;
    }

    if (connected && gamestate == GS_LEVEL)
    {
        // Write the player's ticcmd
        buf_t netbuf_localcmd(128);
        writeLocalCmd(&netbuf_localcmd);
        captured.push_back(netbuf_localcmd);

        if ((gametic - header.first_gametic) % header.snapshot_spacing == 0
                && (unsigned)gametic > header.first_gametic)
        {
            buf_t netbuf_snapshot(NetDemo::MAX_SNAPSHOT_SIZE);
            writeSnapshot(&netbuf_snapshot);
            captured.push_front(netbuf_snapshot);
        }
    }


    byte *output_buf = new byte[captured.size() * MAX_UDP_PACKET];

    uint32_t output_len = 0;
    while (!captured.empty())
    {
        buf_t netbuf(captured.front());
        uint32_t len = netbuf.BytesLeftToRead();

        byte *chunk = netbuf.ReadChunk(len);
        memcpy(output_buf + output_len, chunk, len);
        output_len += len;

        captured.pop_front();
    }

    uint32_t le_output_len = LONG(output_len);
    uint32_t le_gametic = LONG(gametic);

    // write a blank message even if there is no data in order to preserve
    // timing of the netdemo
    if (header.first_gametic == 0)
        header.first_gametic = gametic;

    size_t cnt = 0;
    cnt += sizeof(le_output_len) * fwrite(&le_output_len, sizeof(le_output_len), 1, demofp);
    cnt += sizeof(le_gametic) * fwrite(&le_gametic, sizeof(le_gametic), 1, demofp);

    cnt += fwrite(output_buf, 1, output_len, demofp);

    delete [] output_buf;
}
Пример #3
0
void NetDemo::writeMessages()
{
    if (!isRecording())
        return;

    static buf_t netbuf_localcmd(1024);

    if (atSnapshotInterval())
    {
        size_t length;
        writeSnapshotData(snapbuf, length);
        writeSnapshotIndexEntry();

        writeChunk(snapbuf, length, NetDemo::msg_snapshot);
    }

    if (connected)
    {
        // Write the console player's game data
        SZ_Clear(&netbuf_localcmd);
        writeLocalCmd(&netbuf_localcmd);
        captured.push_back(netbuf_localcmd);
    }

    byte *output_buf = new byte[captured.size() * MAX_UDP_PACKET];

    uint32_t output_len = 0;
    while (!captured.empty())
    {
        buf_t netbuf(captured.front());
        uint32_t len = netbuf.BytesLeftToRead();

        byte *chunk = netbuf.ReadChunk(len);
        memcpy(output_buf + output_len, chunk, len);
        output_len += len;

        captured.pop_front();
    }

    writeChunk(output_buf, output_len, NetDemo::msg_packet);

    delete [] output_buf;
}
Пример #4
0
void NetServer::chooseShip( ClientPtr clt, Packet &p )
{
    if (!clt) return;
    if ( clt->callsign.empty() ) {
        sendLoginError( clt );
        return;
    }
    vector< string >ships;
    getShipList( ships );

    NetBuffer netbuf( p.getData(), p.getDataLength() );
    unsigned short selection = netbuf.getShort();
    string    shipname = netbuf.getString();
    if ( selection >= ships.size() ) {
        sendLoginError( clt );
        return;
    }
    string   fighter = ships[selection];
    Cockpit *cp = loadCockpit( clt );
    if (cp)
        if ( loadFromNewGame( clt, cp, fighter ) )
            sendLoginAccept( clt, cp );
}