Ejemplo n.º 1
0
SimpleConfig::SimpleConfig ()
    : m_need_reload (false)
{
    m_update_timestamp.tv_sec = 0;
    m_update_timestamp.tv_usec = 0;

    load_all_config ();
}
Ejemplo n.º 2
0
// permanently writes all changes
bool
SimpleConfig::flush()
{
    if (!valid ()) return false;

    // If no config has been modified, then just return.
    if (!m_new_config.size () && !m_erased_keys.size ())
        return true;

    String userconf     = get_userconf_filename ();
    String userconf_dir = get_userconf_dir ();

    if (access (userconf_dir.c_str (), R_OK | W_OK) != 0) {
        mkdir (userconf_dir.c_str (), S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
        if (access (userconf_dir.c_str (), R_OK | W_OK) != 0)
            return false;
    }

    if (userconf.length ()) {
        // Reload config to ensure user made modification won't lost.
        load_all_config ();

        std::ofstream os (userconf.c_str ());
        if (!os) return false;

        KeyValueRepository::iterator i;
        std::vector<String>::iterator j;

        // Merge new config with old ones.
        for (i = m_new_config.begin (); i != m_new_config.end (); ++i)
            m_config [i->first] = i->second;

        // Remove all erased keys.
        for (j = m_erased_keys.begin (); j != m_erased_keys.end (); ++j) {
            if ((i = m_config.find (*j)) != m_config.end ())
                m_config.erase (i);
        }

        m_new_config.clear ();
        m_erased_keys.clear ();

        gettimeofday (&m_update_timestamp, 0);

        char buf [128];
        snprintf (buf, 128, "%lu:%lu", m_update_timestamp.tv_sec, m_update_timestamp.tv_usec);

        m_config [String (SCIM_CONFIG_UPDATE_TIMESTAMP)] = String (buf);

        save_config (os);
        return true;
    }

    return false;
}
Ejemplo n.º 3
0
bool
SimpleConfig::reload ()
{
    if (!valid ()) return false;

    if (load_all_config ()) {
        m_new_config.clear ();
        m_erased_keys.clear ();
        m_need_reload = true;
    }

    if (m_need_reload) {
        m_need_reload = false;
        return ConfigBase::reload ();
    }

    return false;
}
Ejemplo n.º 4
0
int main(int argc, char *argv[])
{
	int i;
	int ret;
//	CONTAINER *tmp;
	int resume = 0;
	struct sockaddr_in sin;
	int16_t port;


	FILE *file;
	char *line;
	char *ip;

	srandom(time(NULL));
	
	ret = log4c_init();
	if (ret != 0) {
		printf("log4c_init failed[%d]\n", ret);		
		return ret;
	}
	mycat = log4c_category_get("six13log.log.app");
	if (!mycat) {
		printf("log4c_category_get(\"six13log.log.app.application1\"); failed\n");
		return (0);
	}

	obj_count_loger = log4c_category_get("count_obj_cate");
	if (!obj_count_loger) {
		printf("log4c_category_get(\"six13log.log.app.application2\"); failed\n");
		return (0);
	}

	for (i = 1; i < argc; ++i) {
		if (strcmp(argv[i], "-d") == 0) {
			change_to_deamon();
			--argc;
			break;
		}
	}
	if (argc > 1)
		resume = 1;
	
	ret = load_all_config();
	if (ret != 0) {
		log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "load all config fail[%d]\n", ret);
		return (-1);
	}

	ret = init_gm_system();
	if (ret != 0) {
		log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "init gm system fail[%d]\n", ret);
		return (-1);		
	}

	sc_interface = load_game_script();
	if (!sc_interface) {
		log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "load script fail[%d]\n");		
		return (-1);
	}
	
	log4c_category_log(mycat, LOG4C_PRIORITY_INFO, "game_srv run");

	role_rbdata_init_head();	

	file = fopen("../server_info.ini", "r");
	if (!file) {
		log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "open server_info.ini failed[%d]", errno);				
		return (-1);
	}
	line = get_first_key(file, "game_srv_key");
	key = strtoul(get_value(line), NULL, 0);
	if (key == 0 || key == ULONG_MAX) {
		log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "config file wrong, no game_srv_key");
		return (-1);
	}
	
	if (alloc_shared_mem(resume) != 0) {
		log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "alloc_shared_mem[%d] failed", resume);		
		return (-1);
	}

	ret = init_all_objs(resume);
	if (ret != 0) {
		log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "init_all_objs[%d] failed[%d]", resume, ret);
		return (-1);		
	}

	ret = create_all_static_scene();
	if (ret != 0) {
		log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "creeate_all_static_scene[%d] failed[%d]", resume, ret);
		return (-1);		
	}

//	test_fight();
//	return (0);
	
	ret = game_event_init();
	if (ret != 0) {
		log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "game_event_init failed[%d]", ret);		
		return (-1);
	}


	line = get_first_key(file, "conn_srv_ip");	
	for (i = 0; i < MAX_CONN_SRV && line != NULL; ++i) {
		memset(&sin, 0, sizeof(sin));
		sin.sin_family = AF_INET;
		conn_server[i].cb_recv = gamesrv_cb_conn_recv;
		ip = get_value(line);
		if (!ip)
			break;
		line = get_next_key(file, "conn_srv_port");
		if (!line)
			break;
		port = atoi(get_value(line));
		if (port <= 0)
			break;
		line = get_next_key(file, "conn_srv_ip");
		sin.sin_port = htons(port);
		ret = evutil_inet_pton(AF_INET, ip, &sin.sin_addr);
		if (ret != 1) {
			log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "evutil_inet_pton failed[%d], ip[%s] port[%d]", ret, ip, port);
			return (-1);		
		}
		ret = game_add_connect_event((struct sockaddr *)&sin, sizeof(sin), &conn_server[i]);
		if (ret < 0) {
			log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "game_add_connect_event to conn server failed[%d], ip[%s] port[%d]", ret, ip, port);
			return (-1);		
		}
		conn_server[i].fd = ret;
	}
	if (i == 0) {
		log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "config file wrong, no conn_srv");		
		return (-1);				
	}
	max_conn_srv = i;

	line = get_first_key(file, "db_srv_ip");	
	for (i = 0; i < MAX_ROLEDB_SRV && line != NULL; ++i) {
		memset(&sin, 0, sizeof(sin));
		sin.sin_family = AF_INET;
		roledb_server[i].cb_recv = gamesrv_cb_roledb_recv;		
		ip = get_value(line);
		if (!ip)
			break;
		line = get_next_key(file, "db_srv_port");
		if (!line)
			break;
		port = atoi(get_value(line));
		if (port <= 0)
			break;
		line = get_next_key(file, "db_srv_ip");
		sin.sin_port = htons(port);
		ret = evutil_inet_pton(AF_INET, ip, &sin.sin_addr);
		if (ret != 1) {
			log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "evutil_inet_pton failed[%d], ip[%s] port[%d]", ret, ip, port);
			return (-1);		
		}
		ret = game_add_connect_event((struct sockaddr *)&sin, sizeof(sin), &roledb_server[i]);
		if (ret < 0) {
			log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "game_add_connect_event to conn server failed[%d], ip[%s] port[%d]", ret, ip, port);
			return (-1);		
		}
		roledb_server[i].fd = ret;
	}
	if (i == 0) {
		log4c_category_log(mycat, LOG4C_PRIORITY_ERROR, "config file wrong, no roldb_srv");		
		return (-1);				
	}
	max_roledb_srv = i;	
	active_roledb_srv = &roledb_server[0];	
	fclose(file);

	struct timeval t1 = {5, 0};	
	add_timer(t1, &log_object_timer);
	log_object_timer.ev_callback = cb_log_object_timer;

	
	ret = event_base_loop(base, 0);
	log4c_category_log(mycat, LOG4C_PRIORITY_INFO, "event_base_loop stoped[%d]", ret);		

/*	
	tmp = create_container();	
	tmp = create_container();
	tmp = create_container();
	destory_container(tmp);	
	tmp = create_container();
	destory_container(tmp);
	tmp = create_container();
*/

/*	
	GAME_CIRCLEQ_FOREACH(tmp, pool_container_freed, base.list_free) {
		printf("tmp[idx] = %d:%d\n", tmp->base.list_free.idx, tmp->base.list_used.idx);
	}


	printf("\n ================== \n");
	GAME_CIRCLEQ_FOREACH(tmp, pool_container_used, base.list_used) {
		printf("tmp[idx] = %d:%d\n", tmp->base.list_free.idx, tmp->base.list_used.idx);
	}
*/	
	return (0);
}