Пример #1
0
static bool IsValidFileForTransfer_d( const char *filepath )
{
	if( filepath == nullptr )
	{
		DebugWarning( "[ServerSecure] Invalid file to download (string pointer was NULL)\n" );
		return false;
	}

	size_t len = std::strlen( filepath );
	if( len == 0 )
	{
		DebugWarning( "[ServerSecure] Invalid file to download (path length was 0)\n" );
		return false;
	}

	if( validation_mode == ValidationModeLua )
	{
		if( !PushHookRun( lua_interface ) )
			return false;

		lua_interface->PushString( hook_name );
		lua_interface->PushString( filepath );

		bool valid = true;
		if( lua_interface->PCall( 2, 1, -4 ) != 0 )
			lua_interface->Msg( "\n[ERROR] %s\n\n", lua_interface->GetString( -1 ) );
		else if( lua_interface->IsType( -1, GarrysMod::Lua::Type::BOOL ) )
			valid = lua_interface->GetBool( -1 );

		lua_interface->Pop( 2 );

		return valid;
	}

	std::string nicefile( filepath, len );
	if( !V_RemoveDotSlashes( &nicefile[0] ) )
		return BlockDownload( filepath );

	len = std::strlen( nicefile.c_str( ) );
	nicefile.resize( len );
	filepath = nicefile.c_str( );

	DebugWarning( "[ServerSecure] Checking file \"%s\"\n", filepath );

	if( !IsValidFileForTransfer( filepath ) )
		return BlockDownload( filepath );

	int32_t index = downloads->FindStringIndex( filepath );
	if( index != INVALID_STRING_INDEX )
		return true;

	if( len == 22 && std::strncmp( filepath, downloads_dir, 10 ) == 0 && std::strncmp( filepath + len - 4, ".dat", 4 ) == 0 )
		return true;

	return BlockDownload( filepath );
}
Пример #2
0
	void LoadRGBAImage(TEXTURE_RGBA& tex, string Filename, string MkFilename) {
		unsigned char *rgb = nullptr, *a = nullptr;
		unsigned int ind = 0;
		bool noMaskFile = (MkFilename == "");
		TEXTURE_RGBA& bitmap = tex; //返回位图
		bitmap.buffer = nullptr; bitmap.sizeX = bitmap.sizeY = 0;
		std::ifstream bmpfile(Filename, std::ios::binary | std::ios::in); //位图文件(二进制)
		std::ifstream maskfile;
		if (!noMaskFile)maskfile.open(MkFilename, std::ios::binary | std::ios::in); //遮罩位图文件(二进制)
		if (!bmpfile.is_open()) {
			std::stringstream ss; ss << "Cannot load bitmap " << Filename;
			DebugWarning(ss.str()); return;
		}
		if (!noMaskFile && !maskfile.is_open()) {
			std::stringstream ss; ss << "Cannot load bitmap " << MkFilename;
			DebugWarning(ss.str()); return;
		}
		BITMAPFILEHEADER bfh; //各种关于文件的参数
		BITMAPINFOHEADER bih; //各种关于位图的参数
							  //开始读取
		if (!noMaskFile) {
			maskfile.read((char*)&bfh, sizeof(BITMAPFILEHEADER)); //这两个是占位mask文件的
			maskfile.read((char*)&bih, sizeof(BITMAPINFOHEADER)); //到了后面mask可以直接从颜色部分开始读取
		}
		bmpfile.read((char*)&bfh, sizeof(BITMAPFILEHEADER)); //真正的info以这个bmp文件为准
		bmpfile.read((char*)&bih, sizeof(BITMAPINFOHEADER)); //它将覆盖之前从mask文件读出来的info数据
		bitmap.sizeX = bih.biWidth;
		bitmap.sizeY = bih.biHeight;
		bitmap.buffer = unique_ptr<ubyte[]>(new unsigned char[bitmap.sizeX * bitmap.sizeY * 4]);
		//读取数据
		rgb = new unsigned char[bitmap.sizeX * bitmap.sizeY * 3];
		bmpfile.read((char*)rgb, bitmap.sizeX*bitmap.sizeY * 3);
		bmpfile.close();
		if (!noMaskFile) {
			a = new unsigned char[bitmap.sizeX*bitmap.sizeY * 3];
			maskfile.read((char*)a, bitmap.sizeX*bitmap.sizeY * 3);
			maskfile.close();
		}
		//合并与转换
		for (unsigned int i = 0; i < bitmap.sizeX * bitmap.sizeY; i++) {
			//把BGR格式转换为RGB格式
			bitmap.buffer[ind] = rgb[i * 3 + 2];
			bitmap.buffer[ind + 1] = rgb[i * 3 + 1];
			bitmap.buffer[ind + 2] = rgb[i * 3];
			//Alpha
			if (noMaskFile) bitmap.buffer[ind + 3] = 255;
			else bitmap.buffer[ind + 3] = 255 - a[i * 3];
			ind += 4;
		}
	}
Пример #3
0
	void chunk::buildRender() {
		//assert(Empty == false);

#ifdef NEWORLD_DEBUG_CONSOLE_OUTPUT
		if (pblocks == nullptr || pbrightness == nullptr){
			DebugWarning("Empty pointer when building vertex buffers!");
			return;
		}
#endif
		//建立chunk显示列表
		int x, y, z;
		for (x = -1; x <= 1; x++) {
			for (y = -1; y <= 1; y++) {
				for (z = -1; z <= 1; z++) {
					if (x == 0 && y == 0 && z == 0) continue;
					if (chunkOutOfBound(cx + x, cy + y, cz + z))  continue;
					if (!chunkLoaded(cx + x, cy + y, cz + z)) return;
				}
			}
		}
		
		rebuiltChunks++;
		updatedChunks++;

		if (renderBuilt == false){
			renderBuilt = true;
			loadAnim = cy * 16.0f + 16.0f;
		}
		
		if (MergeFace) ChunkRenderer::mergeFaceRender(this);
		else ChunkRenderer::renderChunk(this);

		updated = false;

	}
Пример #4
0
	void LoadRGBImage(TEXTURE_RGB& tex, string Filename) {
		unsigned int ind = 0;
		TEXTURE_RGB& bitmap = tex; //返回位图
		bitmap.buffer = nullptr; bitmap.sizeX = bitmap.sizeY = 0;
		std::ifstream bmpfile(Filename, std::ios::binary | std::ios::in); //位图文件(二进制)
		if (!bmpfile.is_open()) {
			std::stringstream ss; ss << "Cannot load bitmap " << Filename;
			DebugWarning(ss.str()); return;
		}
		BITMAPINFOHEADER bih; //各种关于位图的参数
		BITMAPFILEHEADER bfh; //各种关于文件的参数
							  //开始读取
		bmpfile.read((char*)&bfh, sizeof(BITMAPFILEHEADER));
		bmpfile.read((char*)&bih, sizeof(BITMAPINFOHEADER));
		bitmap.sizeX = bih.biWidth;
		bitmap.sizeY = bih.biHeight;
		bitmap.buffer = unique_ptr<ubyte[]>(new unsigned char[bitmap.sizeX * bitmap.sizeY * 3]);
		//读取数据
		bmpfile.read((char*)bitmap.buffer.get(), bitmap.sizeX*bitmap.sizeY * 3);
		bmpfile.close();
		//合并与转换
		for (unsigned int i = 0; i < bitmap.sizeX * bitmap.sizeY; i++) {
			//把BGR格式转换为RGB格式
			unsigned char t = bitmap.buffer[ind];
			bitmap.buffer[ind] = bitmap.buffer[ind + 2];
			bitmap.buffer[ind + 2] = t;
			ind += 3;
		}
	}
Пример #5
0
	TextureID LoadFontTexture(int id) {

		ubyte* buff = new ubyte[256 * 256 * 3];
		ubyte* buffer = new ubyte[256 * 256 * 4];
		ubyte* tp = buffer;
		GLuint ret;

		std::stringstream s; 
		s << "Textures\\Fonts\\unicode\\unicode_glyph_"<<id<<".bmp";

		std::ifstream bmpfile(s.str(), std::ios::binary); //位图文件(二进制)
		if (!bmpfile.is_open()) {DebugWarning("Cannot load bitmap " + s.str()); return 0;}
		bmpfile.read((char*)buff, sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER));
		bmpfile.read((char*)buff, 256 * 256 * 3);
		bmpfile.close();

		std::memset(tp, 255, 256 * 256 * 4);
		tp+=3;

		for (int i = 0; i < 256 * 256; ++i) {
			tp[i * 4] = 255 - buff[i * 3];
		}

		glGenTextures(1, &ret);
		glBindTexture(GL_TEXTURE_2D, ret);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
		delete []buff;
		delete []buffer;
		return ret;
	}
Пример #6
0
	void chunk::build(){
		//生成地形

		int x, y, z, height, h=0, sh=0;
#ifdef NEWORLD_DEBUG_CONSOLE_OUTPUT
		if (pblocks == nullptr || pbrightness == nullptr){
			DebugWarning("Empty pointer when chunk generating!");
			return;
		}
#endif
		Empty = true;
		for (x = 0; x < 16; x++){
			for (z = 0; z < 16; z++){
				if (cy <= 4 && cy >= 0) {
					h = HMap.getHeight(cx * 16 + x, cz * 16 + z);
					sh = WorldGen::WaterLevel + 2;
				}
				for (y = 0; y < 16; y++){
					if (cy > 4) {
						pblocks[x*256 + y*16 + z]= blocks::AIR;
						pbrightness[x*256 + y*16 + z] = skylight;
					}
					else if (cy >= 0){
						height = cy * 16 + y;
						pbrightness[x*256 + y*16 + z] = 0;
						if (height == 0)
							pblocks[x*256 + y*16 + z] = blocks::BEDROCK;
						else if (height == h && height > sh && height > WorldGen::WaterLevel + 1)
							pblocks[x*256 + y*16 + z] = blocks::GRASS;
						else if (height<h && height>sh && height > WorldGen::WaterLevel + 1)
							pblocks[x*256 + y*16 + z] = blocks::DIRT;
						else if ((height >= sh - 5 || height >= h - 5) && height <= h && (height <= sh || height <= WorldGen::WaterLevel + 1))
							pblocks[x*256 + y*16 + z] = blocks::SAND;
						else if ((height < sh - 5 && height < h - 5) && height >= 1 && height <= h)
							pblocks[x*256 + y*16 + z] = blocks::ROCK;
						else {
							if (height <= WorldGen::WaterLevel) {
								pblocks[x*256 + y*16 + z] = blocks::WATER;
								if (skylight - (WorldGen::WaterLevel - height) * 2 < BRIGHTNESSMIN)
									pbrightness[x*256 + y*16 + z] = BRIGHTNESSMIN;
								else
									pbrightness[x*256 + y*16 + z] = skylight - (brightness)((WorldGen::WaterLevel - height) * 2);
							}
							else
							{
								pblocks[x*256 + y*16 + z] = blocks::AIR;
								pbrightness[x*256 + y*16 + z] = skylight;
							}
						}
					}
					else{
						pblocks[x * 256 + y * 16 + z] = blocks::AIR;
						pbrightness[x * 256 + y * 16 + z] = BRIGHTNESSMIN;
					}
					if (pblocks[x*256 + y*16 + z] != blocks::AIR) Empty = false;
				}
			}
		}
	}
Пример #7
0
	void chunk::build() {
		//生成地形
		//assert(Empty == false);
		
		int x, y, z, height, h = 0, sh = 0;
#ifdef NEWORLD_DEBUG_CONSOLE_OUTPUT
		if (pblocks == nullptr || pbrightness == nullptr) {
			DebugWarning("Empty pointer when chunk generating!");
			return;
		}
#endif
		Empty = true;

		if (cy > 8) {
			memset(pblocks, 0, 4096 * sizeof(block));
			for (int index = 0; index < 4096; index++) pbrightness[index] = skylight;
		}
		else if (cy < 0) {
			memset(pblocks, 0, 4096 * sizeof(block));
			for (int index = 0; index < 4096; index++) pbrightness[index] = BRIGHTNESSMIN;
		}
		else {

			int hm[16][16];
			for (x = 0; x < 16; x++) {
				for (z = 0; z < 16; z++) {
					hm[x][z] = HMap.getHeight(cx * 16 + x, cz * 16 + z);
				}
			}
			sh = WorldGen::WaterLevel + 2;

			int index = 0;
			for (x = 0; x < 16; x++) {
				for (y = 0; y < 16; y++) {
					for (z = 0; z < 16; z++) {

						h = hm[x][z]; height = cy * 16 + y;
						pbrightness[index] = 0;
						if (height == 0)
							pblocks[index] = blocks::BEDROCK;
						else if (height == h && height > sh && height > WorldGen::WaterLevel + 1)
							pblocks[index] = blocks::GRASS;
						else if (height<h && height>sh && height > WorldGen::WaterLevel + 1)
							pblocks[index] = blocks::DIRT;
						else if ((height >= sh - 5 || height >= h - 5) && height <= h && (height <= sh || height <= WorldGen::WaterLevel + 1))
							pblocks[index] = blocks::SAND;
						else if ((height < sh - 5 && height < h - 5) && height >= 1 && height <= h)
							pblocks[index] = blocks::ROCK;
						else {
							if (height <= WorldGen::WaterLevel) {
								pblocks[index] = blocks::WATER;
								if (skylight - (WorldGen::WaterLevel - height) * 2 < BRIGHTNESSMIN)
									pbrightness[index] = BRIGHTNESSMIN;
								else
									pbrightness[index] = skylight - (brightness)((WorldGen::WaterLevel - height) * 2);
							}
							else
							{
								pblocks[index] = blocks::AIR;
								pbrightness[index] = skylight;
							}
						}
						if (pblocks[index] != blocks::AIR) Empty = false;
						index++;

					}
				}
			}
		}
		
	}
Пример #8
0
inline bool BlockDownload( const char *filepath )
{
	DebugWarning( "[ServerSecure] Blocking download of \"%s\"\n", filepath );
	return false;
}
Пример #9
0
	void chunk::buildRender(){
		if (Empty) return;
#ifdef NEWORLD_DEBUG_CONSOLE_OUTPUT
		if (pblocks == nullptr || pbrightness == nullptr){
			DebugWarning("Empty pointer when building vertex buffers!");
			return;
		}
#endif
		//建立chunk显示列表
		int x, y, z;
		for (x = -1; x <= 1; x++) {
			for (y = -1; y <= 1; y++) {
				for (z = -1; z <= 1; z++) {
					if (x == 0 && y == 0 && z == 0) continue;
					if (chunkOutOfBound(cx + x, cy + y, cz + z))  continue;
					if (!chunkLoaded(cx + x, cy + y, cz + z)) return;
				}
			}
		}
		
		rebuiltChunks++;
		updatedChunks++;

		if (renderBuilt == false){
			renderBuilt = true;
			loadAnim = cy * 16.0f + 16.0f;
		}

		renderer::Init();
		for (x = 0; x < 16; x++) {
			for (y = 0; y < 16; y++) {
				for (z = 0; z < 16; z++) {
					if (pblocks[x*256 + y*16 + z] == blocks::AIR) continue;
					if (!BlockInfo(pblocks[x*256 + y*16 + z]).isTranslucent())
						renderblock(x, y, z, this);
				}
			}
		}
		renderer::Flush(vbuffer[0], vertexes[0]);
		
		renderer::Init();
		for (x = 0; x < 16; x++){
			for (y = 0; y < 16; y++){
				for (z = 0; z < 16; z++){
					if (pblocks[x*256 + y*16 + z] == blocks::AIR) continue;
					if (BlockInfo(pblocks[x*256 + y*16 + z]).isTranslucent() && BlockInfo(pblocks[x*256 + y*16 + z]).isSolid())
						renderblock(x, y, z, this);
				}
			}
		}
		renderer::Flush(vbuffer[1], vertexes[1]);

		renderer::Init();
		for (x = 0; x < 16; x++){
			for (y = 0; y < 16; y++){
				for (z = 0; z < 16; z++){
					if (pblocks[x*256 + y*16 + z] == blocks::AIR) continue;
					if (!BlockInfo(pblocks[x*256 + y*16 + z]).isSolid())
						renderblock(x, y, z, this);
				}
			}
		}
		renderer::Flush(vbuffer[2], vertexes[2]);
		updated = false;

	}