Ejemplo n.º 1
0
/* 取当前KEY对应的数据(包)
 *   注意,当数据有修改时,可能需是更新包的内容,所以
 *   不返回const类型;
 */
Conf *Page::GetCurrentPack()
{
    // 空,则先加载其值;
    if(NULL == m_pack)
    {
        const string &key = GetCurrentKey();
        const string &username = m_request->GetCurrentUser();
        UserData data( username );
        Conf *pack = new Conf;
        if(NULL != pack)
        {
            Ini ini;
            // 填充一个空Conf,以便插入key对应的所有值;
            ini.Set(key, *pack);
            data.Get( ini );
            pack->Set( *(ini.Get(key)) );
            m_pack = pack;
            LOG_DEBUG("Pack[key:%s] loading... ok", key.c_str());
        }
    }
    if(NULL == m_pack)
    {
        // 返回一空值,避免外部做过多的NULL检测;
        static Conf pack;
        return &pack;
    }
    return m_pack;
}
Ejemplo n.º 2
0
void test_ini()
{
    Ini  ini;
    ini.paserFromFile("/tmp/shengdan.ini");
    ini.print();
    std::cout << "====================================>>>>>\n";
    std::cout << "TT_FEEDS_API.HostNum = " << ini.get<int>("TT_FEEDS_API.HostNum", -1) << std::endl;
    std::cout << "General.xml_path = " << ini.get<std::string>("General.xml_path", "nothing ...") << std::endl;
    std::cout << "General.xml_path = " << ini.get<std::string>("General.xml_pathoo", "nothing ...") << std::endl;
    std::cout << "General.test_time = " << ini.get<std::string>("General.test_time", "nothing ...") << std::endl;
}
Ejemplo n.º 3
0
      void Ini::extends(const Ini& other)
      {
	std::map< std::string, Section >::iterator it;
	std::map< std::string, Section >::const_iterator ito;

	for (ito = other.sections().begin(); ito != other.sections().end(); ++ito)
	  {
	    it = _sections.find(ito->first);
	    if (it != _sections.end())
	      it->second.extends(ito->second);
	    else
	      _sections[it->first] = it->second;
	  }
      }
Ejemplo n.º 4
0
void threadServerWorker()
{
	try
	{
		try
		{
			auto portWorker = ini.getInt("worker.port");

			if (portWorker == -1)
				portWorker = 8900;

			boost::asio::io_service m_io_service;
			boost::asio::ip::tcp::endpoint m_endpoint(boost::asio::ip::tcp::v4(), portWorker);

			auto m_serverWorker = serverWorker::server(m_io_service, m_endpoint);

			m_serverWorker.run();
		}
		catch (boost::exception_ptr & e)
		{
			BOOST_LOG_TRIVIAL(fatal) << "boost fatal" << boost::diagnostic_information(e);
			exit(-1);
		}
	}
	catch (...)
	{
		BOOST_LOG_TRIVIAL(fatal) << "unknown fatal in worker thread";
		exit(-1);
	}
}
Ejemplo n.º 5
0
// Config Log And Listenning Port 
int init_config(int &port, int &worker_threads) {
	Ini config;
	if (config.LoadFile("../conf/mysqlproxy.ini") != 0) {
		printf("Failed To Initialize Configuration File, Process Abort\n");
		exit(EXIT_FAILURE);
	}

	int ret = 0;
	Loglevel_t level = LOG_TRACE;
	string logprefix, path, suffix, loglevel;
	ret = config.GetStringKey("log", "prefix", logprefix);
	config.DumpAll();
	if (ret != 0) {
		printf("Failed To Initialize Log Prefix, ret= %d Process Abort\n", ret);
		exit(EXIT_FAILURE);
	}

	ret = config.GetStringKey("log", "suffix", suffix);
	if (ret != 0) {
		printf("Failed To Initialize Log Suffix, Process Abort\n");
		exit(EXIT_FAILURE);
	}

	ret = config.GetStringKey("log", "path", path);
	if (ret != 0) {
		printf("Failed To Initialize Log Path, Process Abort\n");
		exit(EXIT_FAILURE);
	}

	ret = config.GetStringKey("log", "level", loglevel);
	if (ret != 0) {
		printf("Failed To Get Config Log Level, Process Abort\n");
		exit(EXIT_FAILURE);
	}

	// Config Listen Port
	ret = config.GetIntKey("server", "port", port);
	if (ret != 0) {
		printf("Failed To Get Config Port, Process Abort\n");
		exit(EXIT_FAILURE);
	}
	
	for (int i = 0; i <= LOG_TRACE; i++) {
		if (strcasecmp(Levelname[i].name, loglevel.c_str()) == 0) {
			level = Levelname[i].level;
		}
	}

	Log::Instance(path, logprefix, suffix, level);

	return ret;
}
Ejemplo n.º 6
0
// 删除一条数据
int Submit_DeleteData::Deal(Page *page)
{
    const string &key = page->GetCurrentKey();
    Conf *pack = page->GetCurrentPack();

    // 设为删除,并调用处理函数:
    pack->Set("status", "delete");
    pack->Set("text", "");
    pack->Set("modify", NowTime("%Y%m%d%H%M%S"));

    Ini data;
    data.Set(key, *pack);

    const string &username = page->GetRequest()->GetCurrentUser();
    UserData del( username );

    /*
     * 保存(删除数据)
     */
    if(del.Set(data, true) < 0)
    {
        LOG_ERROR("Detete error: [%s]", key.c_str());
        return ERR;
    }

    /*
     * 删除附件
     */
    vector<string> attachs;
    vector<string>::iterator it;
    del.GetAttachList(key, attachs);   // 取附件列表
    for(it = attachs.begin(); attachs.end() != it; it++)
    {
        LOG_INFO("Delete attach: [%s]", it->c_str());
        DeleteFile(*it);
    }

    LOG_INFO("Detete: [%s]", key.c_str());

    return OK;
}
Ejemplo n.º 7
0
void MemCacheServerHandler::SetEnbale(bool enable)
{
	m_bEnabled = enable;
	if (!enable)
	{
		Ini myini;
		if (myini.Open("MemErr_Plat.ini") == false)
		{
			//return;
		}
		myini.Write("MemCache", "MemCacheError",1);
		struct tm  tm_val; 
		time_t rawtime = 0; 
		time_t time_now = time ( &rawtime ); 
		tm_val = *localtime ( &rawtime ); 
		char time_str[128] = {0};
		sprintf(time_str,"%d-%d-%d-%d:%d:%d",tm_val.tm_year + 1900,tm_val.tm_mon +1,tm_val.tm_mday,tm_val.tm_hour,tm_val.tm_min,tm_val.tm_sec);
		myini.Write("MemCache", "ErrDate",time_str);
		myini.Save();
	}
}
Ejemplo n.º 8
0
// 统一处理保存(出便于同步处理缓存更新)
int Page::Save(const Ini &pack)
{
    const string &username = m_request->GetCurrentUser();
    UserData save( username );

    // 保存
    if(save.Set( pack ) < 0)
    {
        return ERR;
    }
    // 更新缓存
    const string &key = GetCurrentKey();
    Conf *syn = GetCurrentPack();
    syn->Set( *(pack.Get(key)) );

    return OK;
}
void easily_pcsp(Ini ini, const std::chrono::time_point<std::chrono::system_clock> start, const bool gm_mode) {
	if (gm_mode) return;
	try {
		const time_t minute = static_cast<time_t>(ini.getnum("EPCSP", "time", 0)) * 60;
		if (minute != 0) {
			tm end;
			gmtime_s(&end, &minute);
			tm current;
			using clock = std::chrono::system_clock;
			for (time_t now = clock::to_time_t(clock::now());
				current.tm_hour == end.tm_hour && current.tm_min == end.tm_min;
				now = clock::to_time_t(clock::now()), localtime_s(&current, &now)) {
				if (end_flag) return;
			}
			mutex.lock();
			pcsp_end = true;
			mutex.unlock();
		}
	}
	catch (std::exception) {}
}
Ejemplo n.º 10
0
BOOL AreaManager::Init( const CHAR *pszPathName )
{
__ENTER_FUNCTION

	AREA_FILE* pAreaFile = g_pSceneManager->FindAreaFile(pszPathName) ;
	if( pAreaFile==NULL )
	{//没有读到数据	
		pAreaFile = g_pSceneManager->FindEmptyAreaFile() ;
		if( pAreaFile==NULL )
		{
			Assert(FALSE) ;
			return FALSE ;
		}

		BOOL bResult;
		Ini iniArea;
		bResult = iniArea.Open( pszPathName );
		if ( !bResult )
		{
			Log::SaveLog( SERVER_LOGFILE, " AreaManager::Init can not open file;<filename=%s>", pszPathName );
			return FALSE;
		}

		CHAR szSection[128], szValue[128];
		if ( 0 != iniArea.ReadText( "area_info", "area_count", szValue, sizeof ( szValue ) ) )
		{
			
			pAreaFile->m_Count = (UINT)(atoi(szValue));
			m_uAreaCount = pAreaFile->m_Count ;
			if ( m_uAreaCount > 0 )
			{
				pAreaFile->m_pArea = new Area[pAreaFile->m_Count] ;
				if( pAreaFile->m_pArea==NULL )
				{
					Assert(FALSE) ;
					return FALSE ;
				}

				UINT i;
				for ( i = 0; i < m_uAreaCount; i++ )
				{
					Area *pArea = &(pAreaFile->m_pArea[i]);
					sprintf( szSection, "area%u", i );

					if ( 0 == iniArea.ReadText( szSection, "guid", szValue, sizeof ( szValue ) ) )
						break;
					pArea->m_uAreaID	= (UINT)atoi( szValue );

					if ( 0 == iniArea.ReadText( szSection, "script_id", szValue, sizeof ( szValue ) ) )
						break;
					pArea->m_uScriptID		= (UINT)atoi( szValue );

					if ( 0 == iniArea.ReadText( szSection, "left", szValue, sizeof ( szValue ) ) )
						break;
					pArea->m_rcArea.m_fLeft	= (FLOAT)atof( szValue );

					if ( 0 == iniArea.ReadText( szSection, "top", szValue, sizeof ( szValue ) ) )
						break;
					pArea->m_rcArea.m_fTop	= (FLOAT)atof( szValue );

					if ( 0 == iniArea.ReadText( szSection, "right", szValue, sizeof ( szValue ) ) )
						break;
					pArea->m_rcArea.m_fRight	= (FLOAT)atof( szValue );

					if ( 0 == iniArea.ReadText( szSection, "bottom", szValue, sizeof ( szValue ) ) )
						break;
					pArea->m_rcArea.m_fBottom	= (FLOAT)atof( szValue );

				}

				strncpy( pAreaFile->m_szFileName, pszPathName, _MAX_PATH-1 ) ;
			}
		}
		iniArea.Close();
	}

	//设置事件区数据
	for( INT i=0; i<pAreaFile->m_Count; i++ )
	{
		Area *pArea = &(pAreaFile->m_pArea[i]);
		m_pScene->RegisterArea(pArea);
	}


	return TRUE;

__LEAVE_FUNCTION

	return FALSE;
}
static inline int get_gm_id(Ini ini) {
	return ini.getnum("GameMaster", "ID", 0);
}
Ejemplo n.º 12
0
// Construct By Config
Log::Log():fd_(-1), buff_offset_(0) {
	Ini config;
	if (config.LoadFile("../conf/server.ini") != 0) {
		printf("Failed To Initialize Configuration File, Process Abort\n");
		exit(EXIT_FAILURE);
	}

	int ret = config.GetStringKey("log", "prefix", prefix_);
	if (ret != 0) {
		printf("Failed To Initialize Log Prefix, Process Abort\n");
		exit(EXIT_FAILURE);
	}

	ret = config.GetStringKey("log", "suffix", suffix_);
	if (ret != 0) {
		printf("Failed To Initialize Log Suffix, Process Abort\n");
		exit(EXIT_FAILURE);
	}

	ret = config.GetStringKey("log", "path", path_);
	if (ret != 0) {
		printf("Failed To Initialize Log Path, Process Abort\n");
		exit(EXIT_FAILURE);
	}

	string loglevel;
	ret = config.GetStringKey("log", "level", loglevel);
	if (ret != 0) {
		printf("Failed To Get Config Log Level, Process Abort\n");
		exit(EXIT_FAILURE);
	}

	for (int i = 0; i <= LOG_DEBUG; i++) {
		if (strcasecmp(Levelname[i].name, loglevel.c_str()) == 0) {
			level_ = Levelname[i].level;
		}
	}

	enable_buff_ = true;

	// Check Existence, If Not, Create It
	if (access(path_.c_str(), F_OK) != 0) {
		mkdir(path_.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
	}
	// Maxsum File Size 50MB As Default
	max_size_ = 50 * 1024 * 1024;
	// Initialise current_file_ 
	FindExistingLog();
	// OpenFile, Append Write, Create If Not Exist, User Has RWX right
	fd_ = open(current_file_.c_str(), O_RDWR | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR);

	pbuff_ = NULL;
	// Set 128 KB Cache
	if (enable_buff_) {
		pbuff_ = (char *) malloc(LOG_CACHE_SIZE * sizeof(char));
		if (pbuff_ == NULL) {
			perror("Failed To Allocate Log Buff\n");
			exit(EXIT_FAILURE);
		}
	}
}
Ejemplo n.º 13
0
void Shader::_parseLayers(string iniPath, Ini & ini, Shader & shader) {
    vector<string> parts;
    list<string> matches;
    list<string>::iterator it;
    ShaderLayer * layer;
    int index = 0;
    string value;

    // Get the path of the shader ini file
    path iniFilePath(ini.path);
    iniFilePath.remove_filename();

    ini.queryTokens(iniPath + "/layer", matches);

    // Now we know how many layers this shader has
    shader.nLayers = matches.size();
    shader.layers = new ShaderLayer *[shader.nLayers];

    for (it = matches.begin(); it != matches.end(); ++it) {
        layer = new ShaderLayer();
        shader.layers[index] = layer;

        //  Attempt to load the mipmap setting for this layer
        value = ini[iniPath + "/" + *it + "/mipmap"];
        if (!value.empty() && value == "0") {
            layer->isMipmap = false;
        }

        // Check for a texture on this layer
        value = ini[iniPath + "/" + *it + "/map"];
        if (!value.empty()) {
            layer->textureMapPath = (iniFilePath / value).string();
            // Check if this is a special texture and starts with $
            if (!starts_with(value, "$")) {
                layer->texture = Texture::getOrMakeTexture(
                        layer->textureMapPath, 
                        layer->isMipmap);
            }

            // Add this shader to the map indexed by this texture name
            // .. strip the ending
            std::string tmpName = value;
            vector<string> parts;
            trim(tmpName);
            to_lower(tmpName);
            split(parts, tmpName, is_any_of("."));
            Shader::_shaders[parts[0]] = &shader;
        }

        // Get the culling value if there is one
        value = ini[iniPath + "/" + *it + "/cull"];
        if (value == "front") {
            layer->culling = 2;
        } else if (value == "back") {
            layer->culling = 1;
        }

        // See if there is some alpha function
        value = ini[iniPath + "/" + *it + "/alphafunc"];
        if (!value.empty()) {
            split(parts, value, is_any_of(" "));
            if (parts[0] == "never") layer->alphaFunction = 0;
            else if (parts[0] == "always") layer->alphaFunction = 1;
            else if (parts[0] == "none") layer->alphaFunction = 1;
            else if (parts[0] == "less") layer->alphaFunction = 2;
            else if (parts[0] == "lequal") layer->alphaFunction = 3;
            else if (parts[0] == "equal") layer->alphaFunction = 4;
            else if (parts[0] == "gequal") layer->alphaFunction = 5;
            else if (parts[0] == "greater") layer->alphaFunction = 6;
            else if (parts[0] == "notequal") layer->alphaFunction = 7;

            // Save the value if there is one
            if (parts.size() > 1) {
                layer->alphaValue = atoi(parts[1].c_str());
            }
        }

        // See if there is a texgen_{s,t,r}
        Shader::_checkForTexGen(ini, iniPath + "/" + *it + "/texgen_r", layer->texGenR);
        Shader::_checkForTexGen(ini, iniPath + "/" + *it + "/texgen_s", layer->texGenS);
        Shader::_checkForTexGen(ini, iniPath + "/" + *it + "/texgen_t", layer->texGenT);

        // Get the blending function
        Shader::_checkForBlendFunc(ini[iniPath + "/" + *it + "/blendfunc"], layer);

        // Get the texture wrapping
        Shader::_checkForTextureWrap(ini[iniPath + "/" + *it + "/wrap_t"], layer->wrapT);

        // Get texture environment
        Shader::_checkForTextureEnv(ini[iniPath + "/" + *it + "/texenv"], layer->texEnv);

        ++index;
    }
}
Ejemplo n.º 14
0
void init()
{
	boost::log::core::get()->add_global_attribute("TimeStamp", boost::log::attributes::utc_clock());

	if (ini.getInt("log.file") != -1)
	{
		boost::log::add_file_log(
			boost::log::keywords::file_name = ini.get("log.path"),
			boost::log::keywords::format = "[%TimeStamp%]: %Message%"
		);
	}

	if (ini.getInt("log.display") != -1)
	{
		boost::log::add_console_log(
			std::cout,
			boost::log::keywords::format = "[%TimeStamp%]: %Message%"
		);
	}

	if (ini.get("log.level") != "")
	{
		if (ini.get("log.level") == "info")
		{
			boost::log::core::get()->set_filter
			(
				boost::log::trivial::severity >= boost::log::trivial::info
			);
		}
		else if (ini.get("log.level") == "warning")
		{
			boost::log::core::get()->set_filter
			(
				boost::log::trivial::severity >= boost::log::trivial::warning
			);
		}
		else if (ini.get("log.level") == "error")
		{
			boost::log::core::get()->set_filter
			(
				boost::log::trivial::severity >= boost::log::trivial::error
			);
		}
		else if (ini.get("log.level") == "fatal")
		{
			boost::log::core::get()->set_filter
			(
				boost::log::trivial::severity >= boost::log::trivial::fatal
			);
		}
	}

	auto mysql_addr = ini.get("mysql.addr");
	auto mysql_name = ini.get("mysql.name");
	auto mysql_pass = ini.get("mysql.pwd");
	auto mysql_buffer = ini.getInt("mysql.buffer");

	if (mysql_addr == "" || mysql_name == "" || mysql_pass == "")
	{
		BOOST_LOG_TRIVIAL(fatal) << "no mysql info";
		exit(-1);
	}

	if (mysql_buffer == -1)
	{
		mysql_buffer = 64;
	}

	m_memDB = new DataBase();

	try
	{
		m_mysqlDB = new mysql::DataBase(mysql_addr, mysql_name, mysql_pass, mysql_buffer);
	}
	catch (...)
	{
		BOOST_LOG_TRIVIAL(fatal) << "cannot connect to mysql";
		exit(-1);
	}
	
	
}
Ejemplo n.º 15
0
// 输出http协议头部
int Page_DataExport::OutHead()
{
    FUNCTION_TRACK(); // 函数轨迹跟综

    Connect * const connect = m_request->GetConnect();
    const string &username = m_request->GetCurrentUser();
    const string &backup_range = m_request->GetField("backup_range"); // 导出范围
    const string &include_attach = m_request->GetField("include_attach");
    DataPack pack(username);
    string fullpath;
    string filename; // 传到客户端的文件名

    // 是否需是导出附件
    if("yes" != include_attach)
    {
        // 排除附件
        pack.SetAttrib(DataPack::A_EXCLUDE_ATTACH);
    }

    if("all" == backup_range)
    {
        /*
         * 导出所有数据
         */
        if( pack.MakePack() == ERR
            || pack.AddAll() == ERR
          )
        {
            LOG_ERROR("Export data error");
            return ERR;
        }
    }
    else if("select" == backup_range)
    {
        /*
         * 导出选定的数据
         */
        int i;
        vector<string> keys;
        vector<string>::iterator it;
        UserData data( username );
        Split(m_request->GetField("select_key"), " ", keys); // 分割串为数组

        LOG_DEBUG("keys.size=[%d]", keys.size());
        LOG_DEBUG("keys=[%s]", m_request->GetField("select_key").c_str());

        if( pack.MakePack() == ERR )
        {
            LOG_ERROR("Export data error");
            return ERR;
        }

        it = keys.begin();
        while(1)
        {
            if(keys.end() == it)
            {
                break;
            }

            Ini group;

            // 以50个为一组
            for(i=0; i<50 && keys.end() != it; it++)
            {
                const string &key = *it;
                if("" == key)
                {
                    continue;
                }
                group.Set(key, Conf()); // 先填充一空的Conf()
                LOG_DEBUG("key=[%s]", key.c_str());
            }

            // 取key组对应数据
            if( data.Get( group ) < 0 )
            {
                LOG_ERROR("Get data error, username=[%s]", username.c_str());
                return ERR;
            }

            if( pack.Add( group ) == ERR )
            {
                LOG_ERROR("Pack Add error");
                return ERR;
            }
        }// end of while(1...
    }// end of else if("select" ==...
    else
    {
        LOG_ERROR("Range error: [%s]", backup_range.c_str());
        return OK;
    }

    filename = username + "." + GetCurrentKey() + ".pkg";   // 发送到客户端的文件名
    fullpath = pack.PackFinish(); // 打包完成,取包名;
    LOG_DEBUG("fullpath=[%s] filename=[%s]", fullpath.c_str(), filename.c_str());

    // 再次打开打包文件
    if( !m_file.Open(fullpath) )
    {
        Page::OutHead();
        LOG_ERROR("Export error, Can't open file: [%s]", fullpath.c_str());
        return OK;
    }

    const string &size = IntToString(m_file.Size());

    // 文件下载头部格式
    const string html = ""
                        "HTTP/1.1 200 OK\n"
                        "Accept-Ranges: bytes\n"
                        "Content-Disposition: attachment; filename=\"" + filename + "\"\n"
                        "Content-length: " + size + "\n"
                        "Connection: Keep-Alive\n"
                        "Content-Type: application/ms-excel\n"
                        "\n";

    // 发送
    return connect->Send(html) == html.length() ? OK : ERR;
}