コード例 #1
0
ファイル: packet_handshake.c プロジェクト: Justasic/bedrock
int packet_handshake(struct client *client, bedrock_packet *p)
{
	int32_t proto;
	char server_address[BEDROCK_MAX_STRING_LENGTH];
	uint16_t server_port;
	int32_t state;

	packet_read_varint(p, &proto);
	packet_read_string(p, server_address, sizeof(server_address));
	packet_read_int(p, &server_port, sizeof(server_port));
	packet_read_varint(p, &state);

	if (p->error)
		return p->error;

	if (proto != BEDROCK_PROTOCOL_VERSION)
	{
		packet_send_disconnect(client, "Incorrect version");
		return ERROR_OK;
	}

	switch (state)
	{
		case STATUS:
			client->state = STATE_STATUS;
			break;
		case LOGIN:
			client->state = STATE_LOGIN;
			break;
		default:
			packet_send_disconnect(client, "Unknown state");
			return ERROR_UNEXPECTED;
	}

	return ERROR_OK;
}
コード例 #2
0
ファイル: packet_position.c プロジェクト: Adam-/bedrock
int packet_position(struct client *client, bedrock_packet *p)
{
	double x, y, z;
	bool on_ground;

	packet_read_double(p, &x);
	packet_read_double(p, &y);
	packet_read_double(p, &z);
	packet_read_bool(p, &on_ground);

	if (p->error)
		return p->error;

	if (!(client->state & STATE_BURSTING) && (abs(x - client->x) > 100 || abs(z - client->z) > 100))
	{
		packet_send_disconnect(client, "Moving too fast");
		return ERROR_OK;
	}

	client_update_position(client, x, y, z, client->yaw, client->pitch, y + 1.62, on_ground); // XXX?

	return ERROR_OK;
}