Exemplo n.º 1
0
//
// readSnapshot()
//
//
void NetDemo::readSnapshot(const netdemo_index_entry_t *snap)
{
    if (!isPlaying() || !snap)
        return;

    gametic = snap->ticnum;
    int file_offset = snap->offset;
    fseek(demofp, file_offset, SEEK_SET);

    // read the values for length, gametic, and message type
    netdemo_message_t type;
    uint32_t len = 0, tic = 0;
    readMessageHeader(type, len, tic);

    if (len > NetDemo::MAX_SNAPSHOT_SIZE)
    {
        error("Snapshot too large to read");
        return;
    }

    size_t cnt = fread(snapbuf, 1, len, demofp);
    if (cnt < len)
    {
        error("Unable to read snapshot from data file");
        return;
    }

    readSnapshotData(snapbuf, len);
    netdemotic = snap->ticnum - header.starting_gametic;
}
Exemplo n.º 2
0
void NetDemo::readMessages(buf_t* netbuffer)
{
    if (!isPlaying())
    {
        return;
    }

    uint32_t len, tic;

    readMessageHeader(len, tic);
    gametic = tic;
    readMessageBody(netbuffer, len);
}
Exemplo n.º 3
0
void NetDemo::readMessages(buf_t* netbuffer)
{
    if (!isPlaying())
    {
        return;
    }

    netdemo_message_t type;
    uint32_t len = 0, tic = 0;

    // get the values for type, len and tic
    readMessageHeader(type, len, tic);

    while (type == NetDemo::msg_snapshot)
    {
        // skip over snapshots and read the next message instead
        fseek(demofp, len, SEEK_CUR);
        readMessageHeader(type, len, tic);
    }

    // read from the input file and put the data into netbuffer
    gametic = tic;
    readMessageBody(netbuffer, len);
}
Exemplo n.º 4
0
void Server::handlePacket(const enet_uint8 *data, size_t size, size_t channel, ENetPeer *peer) {
	LOG_TRACE(logger) << "Received message of length " << size;

	MessageType type;
	if (readMessageHeader((const char *) data, size, &type)) {
		LOG_WARNING(logger) << "Received malformed message";
		return;
	}

	int id = ((PeerData *) peer->data)->id;
	LOG_TRACE(logger) << "Message type: " << (int) type << ", client id: " << (int) id;
	switch (clientInfos[id].status) {
	case CONNECTING:
		if (type == PLAYER_INFO) {
			PlayerInfo info;
			if (readMessageBody((const char *) data, size, &info)) {
				LOG_WARNING(logger) << "Received malformed message";
				break;
			}
			clientInfos[id].status = PLAYING;
			gameServer->onPlayerJoin(id, info);
		} else
			LOG_WARNING(logger) << "Received message of type " << type << " from client without player info";
		break;
	case DISCONNECTING:
		LOG_WARNING(logger) << "Received message from disconnecting client";
		break;
	case PLAYING:
		switch (type) {
		case PLAYER_INPUT:
			{
				PlayerInput input;
				if (readMessageBody((const char *) data, size, &input)) {
					LOG_WARNING(logger) << "Received malformed message";
					break;
				}
				gameServer->onPlayerInput(id, input);
			}
			break;
		case CHUNK_REQUEST:
			{
				ChunkRequest request;
				if (readMessageBody((const char *) data, size, &request)) {
					LOG_WARNING(logger) << "Received malformed message";
					break;
				}
				chunkServer->onChunkRequest(request, id);
			}
			break;
		case CHUNK_ANCHOR_SET:
			{
				ChunkAnchorSet anchorSet;
				if (readMessageBody((const char *) data, size, &anchorSet)) {
					LOG_WARNING(logger) << "Received malformed message";
					break;
				}
				chunkServer->onAnchorSet(anchorSet, id);
			}
			break;
		default:
			LOG_WARNING(logger) << "Received message of unknown type " << type;
			break;
		}
		break;
	default:
		break;
	}
}