Ejemplo n.º 1
0
int get_HTTP_headers(int socket_h, SSL *ssl_h, char **headers, int *overflow, int timeout)
{
	int len_in=0, len=4096;
	char *buffer = mymalloc(len, "http header");
	int rc = RC_OK;

	*headers = NULL;

	memset(buffer, 0x00, len);

	for(;;)
	{
		int rrc;
		int now_n = (len - len_in) - 1;

#ifndef NO_SSL
		if (ssl_h)
			rrc = SSL_read(ssl_h, &buffer[len_in], now_n);
		else
#endif
			rrc = read_to(socket_h, &buffer[len_in], now_n, timeout);
		if (rrc == 0 || rrc == RC_SHORTREAD)	/* socket closed before request was read? */
		{
			rc = RC_SHORTREAD;
			break;
		}
		else if (rrc == RC_TIMEOUT)		/* timeout */
		{
			free(buffer);
			return RC_TIMEOUT;
		}

		len_in += rrc;

		buffer[len_in] = 0x00;
		if (strstr(buffer, "\r\n\r\n") != NULL)
			break;

		if (len_in == (len - 1))
		{
			len <<= 1;
			buffer = (char *)myrealloc(buffer, len, "http reply");
		}
	}

	*headers = buffer;

	char *term = strstr(buffer, "\r\n\r\n");
	if (term)
		*overflow = len_in - (term - buffer + 4);
	else
		*overflow = 0;

	return rc;
}
Ejemplo n.º 2
0
void extract_map(std::string const &filename, std::string const &output_dir) {
	std::ifstream ifs;
	ifs.exceptions(std::ios::badbit | std::ios::failbit | std::ios::eofbit);
	ifs.open(filename.c_str(), std::ios::binary);

	map_header header;
	read_to(header, ifs);

	std::vector<char> minimap(header.width * header.height);
	read_to(minimap, ifs);

	std::vector<unsigned short> map_index(header.width * header.height);
	read_to(map_index, ifs);

	unsigned short terrains_count;
	read_to(terrains_count, ifs);

	typedef char tile_gfx[64*64];
	std::vector<tile_gfx> map_gfx(terrains_count);
	read_to(map_gfx, ifs);

	std::vector<char> palette(3 * 256);
	read_to(palette, ifs);

	std::vector<char> tile_types(terrains_count);
	read_to(tile_types, ifs);

	png_encoder encoder;
	CreateDirectoryA(output_dir.c_str(), 0);

	image minimap_img = decode_simple_buffer(header.width, header.height, minimap.data(), palette.data());
	minimap_img.swap_pixels();
	encoder.save_png(output_dir + "/minimap.png", minimap_img);

	for (size_t i = 0; i < terrains_count; ++i) {
		image tile_gfx = decode_simple_buffer(64, 64, map_gfx[i], palette.data());
		tile_gfx.swap_pixels();
		std::ostringstream foss;
		foss << output_dir << "/" << i << ".png";
		encoder.save_png(foss.str(), tile_gfx);
	}

	std::ofstream maptxt(output_dir + "/map.txt");
	maptxt << header.width << " " << header.height << std::endl;

	maptxt << tile_types.size() << std::endl;
	for (int type : tile_types)
		maptxt << type << " ";
	maptxt << std::endl;
	
	maptxt << map_index.size() << std::endl;
	for (int idx : map_index)
		maptxt << idx << " ";
	maptxt << std::endl;
}
Ejemplo n.º 3
0
 void* read(const unsigned char* data)
 {
     void* d = malloc(ctype_length);
     read_to(data, d);
     return d;
 }