int read_conf() { /*read all configuration param into global variable*/ strcpy(g_ds_ini.log_dir, config_get_strval("log_dir")); g_ds_ini.log_level = config_get_intval("log_level", 0); g_ds_ini.log_size = config_get_intval("log_size", 0); g_ds_ini.log_size = static_cast<uint32_t>(g_ds_ini.log_size); strcpy(g_ds_ini.mainlogin_dbproxy_ip, config_get_strval("mainlogin_dbproxy_ip")); g_ds_ini.mainlogin_dbproxy_port = config_get_intval("mainlogin_dbproxy_port", 0); g_ds_ini.business_type = config_get_intval("business_type", 0); strcpy(g_ds_ini.warning_ip, config_get_strval("warning_ip")); g_ds_ini.warning_port= config_get_intval("warning_port", 0); g_ds_ini.svr_timeout = config_get_intval("svr_timeout", 3); #ifndef TW_VER g_ds_ini.count_limited = config_get_intval("count_limited", 0); g_ds_ini.passwd_fail_time_limited = config_get_intval("passwd_fail_time_limited", 0); g_ds_ini.ban_time = config_get_intval("ban_time", 0); g_ds_ini.channel_total = config_get_intval("channel_total", 0); strcpy(g_ds_ini.statistic_file, config_get_strval("statistic_file")); //g_ds_ini.msglog_type_start = config_get_intval("msglog_type_start", 0); //g_ds_ini.weekday_maintance = config_get_intval("weekday_maintance", -1); //g_ds_ini.maintain_ip = inet_addr(config_get_strval("maintain_ip")); //g_ds_ini.inner_ip_start = inet_addr(config_get_strval("inner_ip_start")); //g_ds_ini.inner_ip_end = inet_addr(config_get_strval("inner_ip_end")); #endif return 0; }
int init_service(int isparent) { if (!isparent) { DEBUG_LOG("INIT_SERVICE"); const char *ip= get_ip_ex(0x01); if ( strncmp( ip,"10.",3 )==0 ) { g_is_test_env=true; DEBUG_LOG("1111=============TEST ENV TRUE ============="); }else{ g_is_test_env=false; DEBUG_LOG("1111=============TEST ENV FALSE ============="); } g_log_send_buf_hex_flag=g_is_test_env?1:0; g_pvp[0].game_user_count= config_get_intval("PVP_GAME_USER_COUNT" ,4); g_pvp[1].game_user_count= config_get_intval("PVP_GAME_USER_COUNT" ,4); DEBUG_LOG("PVP_GAME_USER_COUNT game1:%u",g_pvp[0].game_user_count ); DEBUG_LOG("PVP_GAME_USER_COUNT game2:%u",g_pvp[1].game_user_count ); srand(time(0)); setup_timer(); INIT_LIST_HEAD(&tmr.timer_list); ADD_TIMER_EVENT(&tmr, do_time_event, NULL, get_now_tv()->tv_sec + 1); init_hero_cup(); init_home_maps(); init_cli_handle_funs(); memset(all_fds,0,sizeof(all_fds)); } return 0; }
std::string req_verify_md5( char* req_body, int req_body_len ) { static utils::MD5 md5; const uint32_t verify_buf_len = 1024; char verify_buf[verify_buf_len] = {0}; uint32_t s_len = 0; memset(verify_buf, 0x00, verify_buf_len); sprintf(verify_buf, "channelId=%d&securityCode=%u&data=", config_get_intval("channel_id",0), config_get_intval("security_code",0) ); s_len = strlen(verify_buf); if (req_body_len + s_len >= verify_buf_len) { return "00000000000000000000000000000000"; } memcpy(verify_buf + s_len, req_body, req_body_len); md5.reset(); md5.update(verify_buf, s_len + req_body_len); return md5.toString(); }
void main_login_add_game_flag(Csprite * p, uint16_t channelid, uint32_t which_game) { int idx = 0; uint32_t m_idc_zone=1; char tmp_buf[sizeof(m_idc_zone) + sizeof(which_game) + sizeof(channelid)]; //get verify md5 idx = 0; taomee::pack_h(tmp_buf, m_idc_zone, idx); taomee::pack_h(tmp_buf, which_game, idx); taomee::pack_h(tmp_buf, channelid, idx); std::string md5_str=req_verify_md5( tmp_buf, idx ); /* main_login_add_game_in db_in; db_in.channel_id= config_get_intval("channel_id",0); memcpy( db_in.verify_code,md5_str.c_str(),sizeof(db_in.verify_code)); db_in.gameid= which_game; db_in.idczone=m_idc_zone; send_msg_to_db(p, main_login_add_game_cmd ,&db_in ); */ main_login_add_game_with_chanel_in db_in; db_in.channel_code = config_get_intval("channel_id",0); memcpy( db_in.verify_code,md5_str.c_str(),sizeof(db_in.verify_code)); db_in.gameid= which_game; db_in.idczone=m_idc_zone; db_in.channel_id = channelid; send_msg_to_db(p, main_login_add_game_with_chanel_cmd ,&db_in ); }
void do_exchange_cli(int fd, const char *buf, int len) { protocol_t *pp = (protocol_t *)buf; int seq = make_seq(); if (-1 == seq) { ERROR_LOG("make_seq empty"); net_send_cli(fd, buf, len); return; } if (backend_fd == -1) { backend_fd = net_connect_ser(config_get_strval("backend_ip", ""), config_get_intval("backend_port", 0), 1000); if (backend_fd == -1) { ERROR_LOG("can't connect 10.1.1.122"); net_send_cli(fd, buf, len); return; } } exchange_info_t *ei = &g_exchange_tbl[seq]; ei->is_use = true; ei->cli_sock = fd; ei->svr_sock = backend_fd; ei->old_seq = pp->seq; pp->seq = seq; DEBUG_LOG("SEND TO SER fd:%u len:%u", backend_fd, len); net_send_ser(backend_fd, (const char *)buf, len); }
/* @brief 发包到IM */ int send_to_im(int cmd, sprite_t* p, int body_len, const void* body_buf, uint32_t id) { static uint8_t dbbuf[PAGESIZE]; if (im_fd == -1) { im_fd = connect_to_svr(config_get_strval("im_ip"), config_get_intval("im_port", 0), 65535, 1); } int len = sizeof (server_proto_t) + body_len; im_msg_header_t *pkg = (im_msg_header_t *)dbbuf; if (im_fd == -1 || im_fd > epi.maxfd || epi.fds[im_fd].cb.sndbufsz < epi.fds[im_fd].cb.sendlen + len || body_len > sizeof(dbbuf) - sizeof(*pkg)) { ERROR_LOG ("send to im failed, buflen=%d, fd=%d", epi.fds[im_fd].cb.sendlen, im_fd); if (p) { return send_to_self_error(p, p->waitcmd, -ERR_system_error, 1); } return -1; } pkg->proto_length = len; pkg->cmd_id = cmd; pkg->id = id; pkg->proto_id = 0; pkg->result = 0; memcpy (pkg->body, body_buf, body_len); return net_send (im_fd, dbbuf, len, 0); }
/** * @brief connect to switch and send an init package of online information when online is launched */ void connect_to_switch() { DEBUG_LOG("do connect_to_switch"); switch_fd = connect_to_service(config_get_strval("service_switch"), 0, 65535, 1); if (switch_fd != -1) { //连上时 is_add_timer_to_connect_switch=false; static uint32_t seqno = 0; sw_report_online_info_in sw_in; sw_in.domain_id= config_get_intval("domain", 0); sw_in.online_id= get_server_id(); memcpy(sw_in.online_name,get_server_name(),sizeof(sw_in.online_name)); memcpy(sw_in.online_ip,get_server_ip(),sizeof(sw_in.online_ip)); sw_in.online_port=get_server_port(); sw_in.seqno=seqno; g_sprite_map->get_userid_list(sw_in.userid_list); sw_in.user_num=sw_in.userid_list.size() ; ++seqno; send_msg_to_switch(NULL,sw_report_online_info_cmd,0,&sw_in ); KDEBUG_LOG(0, "BEGIN CONNECTING TO CENTRAL ONLINE AND SEND INIT PKG"); }else{// if(! is_add_timer_to_connect_switch){//还没有加入定时器 DEBUG_LOG("ADD TIMER connect_switch "); g_timer_map->add_timer( TimeVal(3),n_sw_report_online_info,0 ); is_add_timer_to_connect_switch=true; } } }
/** * @brief AsyncServer框架要求实现的接口之一。 * */ extern "C" int init_service(int isparent) { if (!isparent) { setup_timer(); init_all_timer_type(); init_funcs(); const char *udp_ip = get_server_ip(); uint16_t udp_port = get_server_port(); bind_udp_socket(udp_ip, udp_port); g_dirty_word = new Cdirty_word(); if (!g_dirty_word->is_inited) return -1; regist_timers(); if (load_xmlconf("../conf/GameSvr.xml", load_game_svr_config) == -1) return -1; max_msg_count = config_get_intval("max_msg_count", 1024); /* if(g_seg_mgr.init("../data/")) { BOOT_LOG(-1,"online udp listen:%s:%d %u",udp_ip, udp_port, max_msg_count); } */ BOOT_LOG(0,"online udp listen:%s:%d %u",udp_ip, udp_port, max_msg_count); } return 0; }
int my_read_conf() { /*read all configuration param into global variable*/ strcpy(my_opt.multicast_interface, config_get_strval("multicast_interface")); strcpy(my_opt.multicast_ip, config_get_strval("multicast_ip")); my_opt.multicast_port = config_get_intval("multicast_port", 0); strcpy(my_opt.mole_dbproxy_name, config_get_strval("mole_dbproxy")); //strcpy(my_opt.mole_dbproxy_ip, config_get_strval("mole_dbproxy_ip")); //my_opt.mole_dbproxy_port = config_get_intval("mole_dbproxy_port", 0); strcpy(my_opt.time_ip, config_get_strval("time_ip")); my_opt.time_port = config_get_intval("time_port", 0); strcpy(my_opt.master_ip, config_get_strval("master_ip")); my_opt.master_port = config_get_intval("master_port", 0); strcpy(my_opt.master_ser, config_get_strval("master_ip")); my_opt.dx_or_wt = config_get_intval("domain", 0); return 0; }
int FCGI_change_thumb(struct fcgi_recv_webclient *recv_pkg){ HeaderContentType("text/html"); HeaderEnd; if (conn_fileserver==NULL){ if(-1 == config_init("/opt/taomee/cgi_conf/bench.conf")){ CGI_ERROR_LOG("read conf_file error"); fcgi_print_result(NULL,FAIL,4000); return FAIL; } conn_fileserver = new Ctcp(config_get_strval("bind_fileserver_ip"),config_get_intval("bind_fileserver_port", 0),1,10); } char tmp[256]={0}; int j = PROTO_H_SIZE; PKG_H_UINT32(tmp,recv_pkg->key,j); PKG_STR(tmp,recv_pkg->lloccode,j,64); PKG_H_UINT32(tmp,recv_pkg->cnt,j); uint32_t i =0; for(i=0;i<recv_pkg->cnt && i<CNT_MAX;i++){ PKG_H_UINT32(tmp,recv_pkg->thumb_arg[i].W,j); PKG_H_UINT32(tmp,recv_pkg->thumb_arg[i].H,j); PKG_H_UINT32(tmp,recv_pkg->thumb_arg[i].start_x,j); PKG_H_UINT32(tmp,recv_pkg->thumb_arg[i].start_y,j); PKG_H_UINT32(tmp,recv_pkg->thumb_arg[i].thumb_x,j); PKG_H_UINT32(tmp,recv_pkg->thumb_arg[i].thumb_y,j); } init_proto_head(tmp, recv_pkg->userid, 2, j); protocol_t* recv = NULL; uint32_t recvlen = 0; struct fcgi_recv_fileser* prtp = NULL; //int i; int flag = conn_fileserver->do_net_io((const char *)tmp, j, (char**)&recv, (int*)&recvlen); if((flag != SUCC) || (recv == NULL) || (recvlen != recv->len)){ CGI_ERROR_LOG("cgi connect fileserver error :errorid:%d",flag); fcgi_print_result(NULL,FAIL,4007); if(recv){ free(recv); } return FAIL; } prtp = (struct fcgi_recv_fileser *)((char*)recv+PROTO_H_SIZE); prtp->lloccode[Lloccode_Len] = '\0'; CGI_DEBUG_LOG("RECV[%u %s %u]",prtp->key,prtp->lloccode,prtp->cnt); fcgi_print_result(prtp,SUCC,0); if(recv){ free(recv); } return SUCC; }
int handle_init(int argc, char** argv, int pid_type) { switch (pid_type) { case PROC_MAIN: break; case PROC_WORK: pReg = new Cregdeal(); cpo = new Cclientproto(config_get_strval("dbproxy_ip"),config_get_intval ("dbproxy_port",0)); net = new CNetComm(config_get_strval("verify_ip"), config_get_intval("verify_port",0)); statfile = config_get_strval("statistic_logfile"); max_register_channel = config_get_intval("max_register_channel",0); if (pReg->get_no_count_ip() == -1) { BOOT_LOG(-1, "get no count ip wrong"); } break; case PROC_CONN: break; default: BOOT_LOG(-1, "Invalid pid_type=%d", pid_type); } return 0; }
void main_login_add_session(Csprite * p, uint32_t which_game, uint32_t ip) { //uint16_t channel = p->channel; static char tmp_buf[sizeof(which_game) + sizeof(ip)]; int idx = 0; taomee::pack_h(tmp_buf, which_game, idx); taomee::pack_h(tmp_buf, ip, idx); std::string md5_str=req_verify_md5( tmp_buf, idx ); main_login_add_session_in db_in; db_in.channel_id= config_get_intval("channel_id",0); memcpy( db_in.verify_code,md5_str.c_str(),sizeof(db_in.verify_code)); db_in.gameid= which_game; db_in.ip=ip; send_msg_to_db(p, main_login_add_session_cmd ,&db_in ); }
/** * @brief AsyncServer框架要求实现的接口之一。 * */ extern "C" int init_service(int isparent) { if (!isparent) { setup_timer(); init_all_timer_type(); init_funcs(); const char *udp_ip = get_server_ip(); uint16_t udp_port = get_server_port(); bind_udp_socket(udp_ip, udp_port); regist_timers(); if (load_xmlconf("../conf/GameSvr.xml", load_game_svr_config) == -1) return -1; max_msg_count = config_get_intval("max_msg_count", 1024); BOOT_LOG(0,"online udp listen:%s:%d %u",udp_ip, udp_port, max_msg_count); } return 0; }
int send_request_to_xhxserver(int cmd, sprite_t* p, int body_len, const void* body_buf, uint32_t id) { static uint8_t dbbuf[PAGESIZE] = {0}; server_proto_t *pkg = NULL; int len; if (xhx_server_fd == -1) { xhx_server_fd = connect_to_svr(config_get_strval("xhx_switch_ip"), config_get_intval("xhx_switch_port", 0), 65535, 1); DEBUG_LOG("RECONNECT TO XIAO HUE XIAN SERVER [%d %d]", id, xhx_server_fd); } len = sizeof (server_proto_t) + body_len; if (xhx_server_fd == -1 || xhx_server_fd > epi.maxfd || epi.fds[xhx_server_fd].cb.sndbufsz < epi.fds[xhx_server_fd].cb.sendlen + len || body_len > sizeof(dbbuf) - sizeof(*pkg)) { ERROR_LOG ("send to xiao hua xian switch server failed, buflen=%d, fd=%d", epi.fds[xhx_server_fd].cb.sendlen, xhx_server_fd); if (p) return send_to_self_error(p, p->waitcmd, -ERR_system_error, 1); return -1; } pkg = (server_proto_t *)dbbuf; pkg->len = len; pkg->cmd = cmd; pkg->id = id; if (!p) pkg->seq = 0; else pkg->seq = (sprite_fd (p) << 16) | p->waitcmd; pkg->ret = 0; memcpy (pkg->body, body_buf, body_len); DEBUG_LOG("sent to xhx server: len=%u body_len=%u", len, body_len); return net_send (xhx_server_fd, dbbuf, len, 0); }
int handle_init () { idle_timeout = config_get_intval("idle_timeout", 300); memset(&fds, 0, sizeof(fds)); /*proxy_fd = connect_to_svr( config_get_strval ("dbproxy_ip"),*/ /*config_get_intval("dbproxy_port", 0), 65535, 1 );*/ statistic_file = config_get_strval("statistic_logfile"); if ( load_dlls(config_get_strval("games_conf")) == -1 ) return -1; setup_timer(); init_sprites(); if (config_get_strval("addr_mcast_ip")) { if (create_addr_mcast_socket() == 0) { send_addr_mcast_pkg(addr_mcast_1st_pkg); DEBUG_LOG("send mcast"); } else { return -1; } } return 0; }
int main(int argc, char* argv[]) { arg_start = argv[0]; arg_end = argv[argc-1] + strlen(argv[argc - 1]) + 1; env_start = environ[0]; if (argc != 2) exit(-1); daemon_start(); INFO_LOG ("async_server %s, report bugs to <*****@*****.**>", VERSION); load_config_file(argv[1]); check_single(); if (config_get_strval("proc_name", NULL)) { set_title("%s-MAIN", config_get_strval("proc_name", NULL)); } else { set_title("%s-MAIN", arg_start); } load_work_file(config_get_strval("work_conf", "")); if (-1 == log_init(config_get_strval("log_dir", "./"), (log_lvl_t)config_get_intval("log_level", 8), config_get_intval("log_size", 33554432), config_get_intval("log_maxfiles", 100), "main_")) { BOOT_LOG(-1, "log init"); } init_warning_system(); plugin_load(config_get_strval("plugin_file", "")); shmq_init(g_work_confs.size(), config_get_intval("shmq_size", 8388608)); int max_connect = config_get_intval("max_connect", 10000); if (max_connect <= 4096) max_connect = 4096; g_max_connect = max_connect; int max_pkg_len = config_get_intval("max_pkg_len", 16384); if (max_pkg_len <= 4096) max_pkg_len = 4096; g_max_pkg_len = max_pkg_len; const char * bind_ip = config_get_strval("bind_ip", NULL); if (NULL == bind_ip) { BOOT_LOG(-1, "unspecified bind_ip"); return -1; } if (0 != get_ip_by_name(bind_ip, g_bind_ip)) { strncpy(g_bind_ip, bind_ip, 16); } if (g_plugin.plugin_init) { if (g_plugin.plugin_init(PROC_MAIN) != 0) BOOT_LOG(-1, "plugin_init init failed PROC_MAIN"); } for (uint32_t i = 0; i < g_work_confs.size(); ++i) g_work_confs[i].pid = fork_work(i); pid_t conn_pid = fork_conn(); while (!g_stop) { int status = 0; pid_t p = waitpid(-1, &status, 0); if(-1 == p) continue; if (WEXITSTATUS(status) == 10) { if (p == conn_pid) { conn_pid = -1; } else { for (uint32_t i = 0; i < g_work_confs.size(); ++i) { if (g_work_confs[i].pid == p) { g_work_confs[i].pid = -1; break; } } } } else { if (p == conn_pid) { conn_pid = fork_conn(); send_warning_msg("conn core", 0, 0, 0, config_get_strval("bind_ip", "0.0.0.0")); ERROR_LOG("conn core"); } else { for (uint32_t i = 0; i < g_work_confs.size(); ++i) { if (g_work_confs[i].pid == p) { ERROR_LOG("work core, id: %u, pid: %d", g_work_confs[i].id, p); g_work_confs[i].pid = fork_work(i); send_warning_msg("work core", g_work_confs[i].id, 0, 0, config_get_strval("bind_ip", "0.0.0.0")); break; } } } } } for (uint32_t i = 0; i < g_work_confs.size(); ++i) { if (g_work_confs[i].pid != -1) kill(g_work_confs[i].pid, SIGTERM); } if (conn_pid != -1) kill(conn_pid, SIGTERM); while (true) { int ret = 0; for (uint32_t i = 0; i < g_work_confs.size(); ++i) { if (g_work_confs[i].pid != -1) ret = 1; } if (ret || conn_pid != -1) { int status = 0; pid_t p = waitpid(-1, &status, 0); if(-1 == p) continue; if (p == conn_pid) { conn_pid = -1; } else { for (uint32_t i = 0; i < g_work_confs.size(); ++i) { if (g_work_confs[i].pid == p) { g_work_confs[i].pid = -1; break; } } } } else { break; } } if (g_plugin.plugin_fini) g_plugin.plugin_fini(PROC_MAIN); }
int main(int argc, char* argv[]) { pid_t pid; parse_args(argc, argv); if (config_init(argv[1]) == -1) { BOOT_LOG(-1, "Failed to Parse File '%s'", argv[1]); } if (config_init("common.conf") == -1) { BOOT_LOG(-1, "Failed to Parse File '%s'", argv[1]); } daemon_start(argc, argv); load_bind_file(); log_init_ex( config_get_strval("log_dir"), config_get_intval("log_level", log_lvl_trace), config_get_intval("log_size", 1<<30), config_get_intval("max_log_files", 0), config_get_strval("log_prefix") , config_get_intval("log_save_next_file_interval_min", 0) ); //Èç¹ûʹÓÃÔà´Ê¼ì²âÂß¼£¬Ôò¿ªÆô¸¸½ø³ÌµÄÔà´Ê¸üÐÂÂß¼. if (config_get_intval("tm_dirty_use_dirty_logical", 1) == 1) { if (tm_dirty_daemon( config_get_strval("tm_dirty_local_dirty_file_path"), config_get_strval("tm_dirty_server_addr"), config_get_intval("tm_dirty_update_cycle", 600), NULL) == -1) { BOOT_LOG(-1, "FAILED TO RUN TM_DIRTY_DAEMON"); } } net_init(MAXFDS, MAXFDS); bind_config_t* bc = get_bind_conf(); //-------------------------------- net_start(config_get_strval("online_ip"), config_get_intval("online_port", 443), bc->configs); //-------------------------------- // bind_config_elem_t* bc_elem; int i = 0; for ( ; i != bc->bind_num; ++i ) { bind_config_elem_t* bc_elem = &(bc->configs[i]); shmq_create(bc_elem); if ( (pid = fork ()) < 0 ) { BOOT_LOG(-1, "fork child process"); } else if (pid > 0) { //parent process close_shmq_pipe(bc, i, 0); do_add_conn(bc_elem->sendq.pipe_handles[0], PIPE_TYPE_FD, 0, bc_elem); //net_start(bc_elem->bind_ip, bc_elem->bind_port, bc_elem); } else { //child process run_worker_process(bc, i, i + 1); } } while (!stop) { net_loop(-1, PAGESIZE, 1); } net_exit(); shmq_destroy(0, bc->bind_num); daemon_stop(); return 0; }
* @author smyang * @version 1.0 * @date 2012-10-16 * Modify $Date: $ * Modify $Author: $ * Copyright: TaoMee, Inc. ShangHai CN. All rights reserved. * ======================================================================== */ #include "node.h" #include "itl_common.h" #include "proto.h" #include "control.h" // 允许连上来的node版本,0表示任意 const uint32_t g_allow_node_version = config_get_intval("node_version", 0); int control_p_get_version(DEFAULT_ARG) { return 0; } int control_p_node_register(DEFAULT_ARG) { return 0; } int control_p_node_register(int fd, const char * body, uint32_t body_len) {
c_file * g_node_bin = new c_file(config_get_strval("plugin_file", "./bin/libnode.so")); // bench.conf c_file * g_bench_conf = new c_file("./conf/bench.conf"); // work.conf c_file * g_work_conf = new c_file(config_get_strval("work_conf", "./conf/work.conf")); // 重启脚本 c_file * g_restart_script = new c_file(config_get_strval("restart_script", "./bin/restart_node.sh")); // 控制脚本 c_file * g_control_script = new c_file("./itl_node.sh"); bool g_collect_flag = true; bool g_auto_update_flag = config_get_intval("enable_auto_update", 1) ? true : false; timer_head_t g_node_event; int get_node_ip() { char node_ip_str[IP_STRING_LEN] = {0}; if (0 != get_inside_ip(node_ip_str)) { return -1; }
ssize_t dns_handler(context_t *ctx, event_t event, driver_data_t *event_data ) { dns_config_t *cf = (dns_config_t *) ctx->data; x_printf(ctx, "<%s> Event = \"%s\" (%d)\n", ctx->name, event_map[event], event); switch( event ) { case EVENT_INIT: if( event_data->type == TYPE_CUSTOM && event_data->event_custom ) { dns_conf_t *init = (dns_conf_t *) (event_data->event_custom); dns_load_servers( ctx, init->dns_resolver ); cf->dns_timeout = init->dns_timeout; cf->current_host = strdup( init->dns_host ); } else { const char *resolver = config_get_item( ctx->config, "resolver" ); const char *host = config_get_item( ctx->config, "host" ); if( ! config_get_timeval( ctx->config, "timeout", & cf->dns_timeout )) cf->dns_timeout = DNS_DEFAULT_TIMEOUT; if( ! config_get_intval( ctx->config, "retry", & cf->dns_max_retry )) cf->dns_max_retry = 5; dns_load_servers(ctx, resolver); cf->current_host = strdup( host ); if( cf->dns_max_retry < cf->dns_max_servers ) cf->dns_max_retry = cf->dns_max_servers; } cf->sock_fd = dns_resolve_host( ctx, cf->current_host ); if( cf->sock_fd >= 0 ) { cf->dns_retries = cf->dns_max_retry ; cf->dns_timer = event_alarm_add( ctx, cf->dns_timeout, ALARM_TIMER ); event_add( ctx, cf->sock_fd, EH_READ ); x_printf(ctx,"attempting to resolve hostname %s (%d attempts)\n",cf->current_host, cf->dns_retries ); } else { x_printf(ctx,"Failed to send query to socket...\n"); } case EVENT_START: cf->state = DNS_STATE_RUNNING; break; case EVENT_TERMINATE: context_terminate( ctx ); break; case EVENT_ALARM: { if( event_data->event_alarm == cf->dns_timer ) { #ifdef ENABLE_GETADDRINFO // This is entirely pointless, because it can't block!! if( (cf->flags & DNS_NETWORK_UP) && (cf->flags & DNS_DNS_ENABLE) ) { x_printf(ctx,"Attempting DNS resolver check for %s\n",cf->dns_host); struct addrinfo *addrinfo = NULL; int rc = getaddrinfo( cf->dns_host, NULL, NULL, &addrinfo ); if( rc == 0 ) { x_printf(ctx,"Name resolver completed..\n"); freeaddrinfo( addrinfo ); } else { x_printf(ctx,"Failure performing DNS name resolution. Disconnecting network\n"); logger(ctx,"Failure performing DNS name resolution. Disconnecting network"); } } #endif x_printf(ctx,"TIMEOUT: dns failed to respond, trying next server\n"); if( cf->sock_fd >= 0 ) { close( cf->sock_fd ); cf->sock_fd = -1; event_delete( ctx, cf->sock_fd, EH_NONE ); } if( cf->dns_retries-- > 0 ) { cf->dns_current = ( cf->dns_current + 1 ) % cf->dns_max_servers; cf->sock_fd = dns_resolve_host( ctx, cf->current_host ); if( cf->sock_fd >= 0 ) { cf->dns_timer = event_alarm_add( ctx, cf->dns_timeout, ALARM_TIMER ); event_add( ctx, cf->sock_fd, EH_READ ); } } else { x_printf(ctx,"DNS RETRIES EXHAUSTED. Terminating\n"); context_owner_notify( ctx, CHILD_EVENT, 0 ); context_terminate( ctx ); } } } break; case EVENT_READ: if( event_data->event_request.fd == cf->sock_fd ) { x_printf(ctx,"Got a read event on file descriptor %ld\n",event_data->event_request.fd); in_addr_t rc = dns_handle_dns_response( ctx, &( event_data->event_request )); x_printf(ctx, "handle response returned %d (0x%08x) (%s)\n", ntohl(rc), ntohl(rc), inet_ntoa( *(struct in_addr *) &rc )); if( rc == (unsigned long) -1 ) { x_printf(ctx,"Error reading from socket, skipping\n"); } else { event_alarm_delete( ctx, cf->dns_timer ); event_delete( ctx, cf->sock_fd, EH_NONE ); close( cf->sock_fd ); cf->sock_fd = -1; context_owner_notify( ctx, CHILD_EVENT, rc ); context_terminate( ctx ); } } break; default: x_printf(ctx,"\n *\n *\n * Emitted some kind of event \"%s\" (%d)\n *\n *\n", event_map[event], event); } return 0; }
int cgiMain(void){ cgiFilePtr file; char fileNameOnServer[512]={0}; char buffer[pic_max_len]; int got = 0; int filelen = 0; Ctcp *conn_fileserver = NULL; char s_data[512]; logo_recv_webclient_t data; uint32_t pic_type = 0; uint32_t branchtype = 0; logo_recv_fileServ_t* recv_data = NULL; log_init("/cgi/log/",(log_lvl_t)8,log_size,0,""); cgiHeaderContentType((char *)"text/html"); cgiFormString((char*)"session_key",s_data,512); if(strlen(s_data) == 0){ CGI_ERROR_LOG("session_key error:len[%u] [%s]",strlen(s_data),s_data); cgi_print_result(recv_data,fileNameOnServer,pic_type,branchtype,FAIL,session_key_err); return FAIL; } parse_web_data(s_data,&data); if(data.cnt >CNT_MAX){ CGI_ERROR_LOG("thumb cnt error[%u]",data.cnt); cgi_print_result(recv_data,fileNameOnServer,pic_type,branchtype,FAIL,thumb_cnt_err); return FAIL; } if(cgiFormFileName((char *)"file",fileNameOnServer, sizeof(fileNameOnServer)) !=cgiFormSuccess){ CGI_ERROR_LOG("could not retrieve filename, file: %s", fileNameOnServer); cgi_print_result(recv_data,"",pic_type,branchtype,FAIL,retrieve_filename_err); return FAIL; } char tfilename[128]; if(cgiFormSuccess != cgiGetFilePath((char *)"file",tfilename,sizeof(tfilename))){ CGI_ERROR_LOG("GET FILE PATH ERROR"); cgi_print_result(recv_data,"",pic_type,branchtype,FAIL,retrieve_filename_err); return FAIL; } cgiFormFileSize((char *)"file", &filelen); if(filelen > pic_max_len){ CGI_ERROR_LOG("file size is too big"); cgi_print_result(recv_data,fileNameOnServer,pic_type,branchtype,FAIL,image_size_err); return FAIL; } if (cgiFormFileOpen((char *)"file", &file) != cgiFormSuccess) { CGI_ERROR_LOG("could not open the file"); cgi_print_result(recv_data,fileNameOnServer,pic_type,branchtype,FAIL,open_file_err); return FAIL; } if(-1 == config_init("/opt/taomee/cgi_conf/bench.conf")){ CGI_ERROR_LOG("read conf_file error"); cgi_print_result(recv_data,fileNameOnServer,pic_type,branchtype,FAIL,unknown_err); return FAIL; } char *bind_ip = config_get_strval("bind_ip"); if(data.ip != inet_addr(bind_ip)){ struct in_addr addr1; memcpy(&addr1, &(data.ip), 4); CGI_ERROR_LOG("request is forbidden bind_ip[%d %s],req_ip[%u %s]",inet_addr(bind_ip),bind_ip,data.ip,inet_ntoa(addr1)); cgi_print_result(recv_data,fileNameOnServer,pic_type,branchtype,FAIL,hostid_err); return FAIL; } time_t now_time; now_time = time(NULL); if((now_time - data.time) > 5*60){ CGI_ERROR_LOG("upload timeout nowtime[%u] data.time[%u]",now_time,data.time); cgi_print_result(recv_data,fileNameOnServer,pic_type,branchtype,FAIL,timeout_err); return FAIL; } conn_fileserver = new Ctcp(config_get_strval("bind_fileserver_ip"),config_get_intval("bind_fileserver_port", 0),0,10); if(cgiFormFileRead(file, buffer, pic_max_len, &got) ==cgiFormSuccess){ if(got > 0){ uint8_t filedate[8]; memcpy(filedate,(uint8_t*)buffer,8); parse_uploadfile_type(&pic_type ,&branchtype,filedate); if(pic_type == 2){ CGI_ERROR_LOG("image type error."); delete conn_fileserver; cgiFormFileClose(file); cgi_print_result(recv_data,fileNameOnServer,pic_type,branchtype,FAIL,image_type_err); config_exit(); return FAIL; } if(NULL == cgi_create_image(branchtype, got, buffer)){ CGI_ERROR_LOG("invalid file"); delete conn_fileserver; cgiFormFileClose(file); cgi_print_result(recv_data,fileNameOnServer,pic_type,branchtype,FAIL,invalid_file); config_exit(); return FAIL; } cgiFormFileClose(file); recv_data = connect_with_fileserver(buffer,conn_fileserver,&data,filelen,pic_type,branchtype,tfilename); if(recv_data == NULL){ CGI_ERROR_LOG("cgi connect fileserver error"); delete conn_fileserver; cgi_print_result(recv_data,fileNameOnServer,pic_type,branchtype,FAIL,net_err); config_exit(); return FAIL; } delete conn_fileserver; cgi_print_result(recv_data,fileNameOnServer,pic_type,branchtype,SUCC,0); config_exit(); return SUCC; } } CGI_ERROR_LOG("cgi read file error:got=%d",got); delete conn_fileserver; cgiFormFileClose(file); cgi_print_result(recv_data,fileNameOnServer,pic_type,branchtype,FAIL,read_file_err); config_exit(); return FAIL; }
static int load_conf() { char *str; int port; int tmp_max_project_number; int tmp_max_page; //int tmp_accepted_proj; int tmp_upper_bound; int tmp_max_idc; str = config_get_strval("dbserver_ip"); if (str != NULL && is_legal_ip( (const char *)str )) strncpy(dbserver_ip, str, sizeof(dbserver_ip)); else ERROR_RETURN(("can't find legal dbserver ip\t"), -1); strncpy((char*)db_server_set[0].ip, dbserver_ip, sizeof(dbserver_ip)); str = config_get_strval("bind_ip"); if (str != NULL && is_legal_ip( (const char *)str )) strncpy(bind_ip, str, sizeof(bind_ip)); else ERROR_RETURN(("can't find legal bind ip\t"), -1); port = config_get_intval("dbserver_port", dbserver_port); if (is_legal_port(port)) dbserver_port = port; else ERROR_RETURN(("can't find legal dbserver port\t"), -1); db_server_set[0].port = dbserver_port; port = config_get_intval("bind_port", bind_port); if (is_legal_port(port)) bind_port = port; else ERROR_RETURN(("can't find legal bind port\t"), -1); tmp_max_project_number = config_get_intval("max_project_number", max_project_number); if (tmp_max_project_number > 0 && tmp_max_project_number <= max_project_number) max_project_number = tmp_max_project_number; else ERROR_RETURN(("max_project_number is illegal, max value is:%u\t",max_project_number), -1); tmp_max_page = config_get_intval("max_page_per_proj", max_page_per_proj); if (tmp_max_page > 0 && tmp_max_page <= max_page_per_proj) max_page_per_proj = tmp_max_page; else ERROR_RETURN(("max_page_per_proj is illegal, max value is:%u\t",max_page_per_proj), -1); tmp_upper_bound = config_get_intval("delay_upper_bound", delay_upper_bound); if (tmp_upper_bound > 0 && tmp_upper_bound <= delay_upper_bound) delay_upper_bound = tmp_upper_bound; else ERROR_RETURN(("delay_upper_bound is illegal, max value is:%u\t",delay_upper_bound), -1); tmp_max_idc = config_get_intval("max_idc_number", max_idc_number); if (tmp_max_idc > 0 && tmp_max_idc <= max_idc_number) max_idc_number = tmp_max_idc; uint32_t tmp_max_cdn_speed; tmp_max_cdn_speed = config_get_intval("max_cdn_speed", cdn_max_speed); if (tmp_max_cdn_speed > 1024 && tmp_max_cdn_speed <= cdn_max_speed) cdn_max_speed = tmp_max_cdn_speed; str = config_get_strval("link_ip_config_file"); if (str != NULL ) strncpy(link_ip_config_file, str, sizeof(link_ip_config_file)); else ERROR_RETURN(("can't find link_ip_config_file\t"), -1); int tmp_remove_or_rename = config_get_intval("remove_or_rename", remove_or_rename); if (tmp_remove_or_rename == REMOVE_IDC_FILE || tmp_remove_or_rename == RENAME_IDC_FILE) remove_or_rename = tmp_remove_or_rename; if (remove_or_rename == RENAME_IDC_FILE) { str = config_get_strval("idc_rename_dirpath"); if (str != NULL) strncpy(idc_rename_dirpath, str, sizeof(idc_rename_dirpath)); else ERROR_RETURN(("can't find idc_file_dirpath\t"), -1); } str = config_get_strval("idc_file_dirpath"); if (str != NULL) strncpy(idc_file_dirpath, str, sizeof(idc_file_dirpath)); else ERROR_RETURN(("can't find idc_file_dirpath\t"), -1); str = config_get_strval("mmap_tmpfile_dirpath"); if (str != NULL) strncpy(mmap_tmpfile_dirpath, str, sizeof(mmap_tmpfile_dirpath)); else ERROR_RETURN(("can't find mmap_tmpfile_dirpath\t"), -1); str = config_get_strval("idc_mmap_file_dirpath"); if (str != NULL) strncpy(idc_mmap_file_dirpath, str, sizeof(idc_mmap_file_dirpath)); else ERROR_RETURN(("can't find idc_mmap_file_dirpath\t"), -1); str = config_get_strval("cdn_mmap_file_dirpath"); if (str != NULL) strncpy(cdn_mmap_file_dirpath, str, sizeof(cdn_mmap_file_dirpath)); else ERROR_RETURN(("can't find cdn_mmap_file_dirpath\t"), -1); str = config_get_strval("url_mmap_file_dirpath"); if (str != NULL) strncpy(url_mmap_file_dirpath, str, sizeof(url_mmap_file_dirpath)); else ERROR_RETURN(("can't find url_mmap_file_dirpath\t"), -1); //add by singku for ignoring some projects str = config_get_strval("ignore_project"); if (str != NULL) { uint32_t i; while(str != NULL) { i = strtoul(str, NULL, 10); if (i == 0 || i == ULONG_MAX) { ERROR_LOG("bad config file: 'ignore_project'!\n"); break; } ignore_project[ i% MAX_PROJECT_NUMBER] = 1; str = strchr(str, ','); if (str == NULL) break; str += 1; } } return 0; }
/** * ======================================================================== * @file config.cpp * @brief * @author smyang * @version 1.0 * @date 2012-10-17 * Modify $Date: $ * Modify $Author: $ * Copyright: TaoMee, Inc. ShangHai CN. All rights reserved. * ======================================================================== */ #include <stdlib.h> #include "config.h" #include "async_server.h" const char *g_p_head_ip = config_get_strval("head_ip", NULL); int g_head_port = config_get_intval("head_port", 0); int g_log_switch_flag = config_get_intval("log_switch_flag", 0); log_node_t g_log_node = {-1, config_get_strval("log_node_ip", NULL), {0}}; const char * g_control_ip = config_get_strval("control_ip", NULL); uint16_t g_control_port = config_get_intval("control_port", 0);
int init_service(int isparent) { if (!isparent) { DEBUG_LOG("INIT_SERVICE"); const char *ip= get_ip_ex(0x01); if ( strncmp( ip,"10.",3 )==0 ) { g_is_test_env=true; DEBUG_LOG("=============TEST ENV TRUE ============="); }else{ g_is_test_env=false; DEBUG_LOG("=============TEST ENV FALSE ============="); } g_log_send_buf_hex_flag=g_is_test_env?1:0; if (sizeof(sprite_t) >= SPRITE_STRUCT_LEN - 800 || sizeof(grp_loop_t) != VIP_BUFF_LEN) { ERROR_RETURN(("sprite struct not big enough\t[%lu %u]", sizeof(sprite_t), SPRITE_STRUCT_LEN), -1); } srand(time(0) * get_server_id()); setup_timer(); INIT_LIST_HEAD(&(g_events.timer_list)); INIT_LIST_HEAD(&active_box_list); if ( config_get_strval("_use_lua_config") ==NULL ){ config_init("./conf/common.conf"); } statistic_logfile = config_get_strval("statistic_file"); if (!statistic_logfile) return -1; if ((init_cli_proto_handles(0) == -1) || (init_db_proto_handles(0) == -1) || (init_home_handle_funs() == -1) || (init_switch_handle_funs() == -1) || (init_all_timer_type() == -1) || (init_magic_code_proto_handles(0) == -1) || (init_spacetime_code_proto_handles(0) == -1) || (init_mall_proto_handles(0) == -1) ) { return -1; } init_sprites(); init_exp_lv(); init_home_maps(); init_all_items(); init_beast_grp(); init_rand_infos(); init_npcs(); init_all_skills(); init_all_clothes(); init_sys_info(); init_all_tasks(); init_mail(); init_shops(); init_vip_items(); init_products(); idc_type = config_get_intval("idc_type" ,1); KDEBUG_LOG(0, "ONLINE START\t[%lu %d]", sizeof(sprite_t), idc_type); if ( //11 (load_xmlconf("./conf/items.xml", load_items) == -1) || (load_xmlconf("./conf/clothes.xml", load_clothes) == -1) || (load_xmlconf("./conf/beasts.xml", load_beasts) == -1) // || (load_xmlconf("./conf/pet_exchange.xml", load_pet_exchange) == -1)//3M || (load_xmlconf("./conf/pet_exchange_egg.xml", load_pet_exchange_egg) == -1) //62 || (load_xmlconf("./conf/gplan.xml", load_rare_beasts) == -1) || (load_xmlconf("./conf/titles.xml", load_honor_titles) == -1) || (load_xmlconf("./conf/picsrv.xml", load_picsrv_config) == -1) ) { return -1; } if ( load_xmlconf("./conf/beastgrp.xml", load_beast_grp) == -1 || (load_xmlconf("./conf/handbook.xml", load_handbook) == -1) || (load_xmlconf("./conf/suits.xml", load_suit) == -1) || ( load_xmlconf("./conf/maps.xml", load_maps) == -1) || (load_xmlconf("./conf/rand_item.xml", load_rand_item) == -1) || (load_xmlconf("./conf/vip_item.xml", load_vip_item) == -1) || (load_xmlconf("./conf/commodity.xml", load_products) == -1) || (load_xmlconf("./conf/skills_price.xml", load_all_skills) == -1) || (load_xmlconf("./conf/tasks_new.xml", load_tasks) == -1)//task:12M || (load_xmlconf("./conf/tasks_new.xml", load_task_loops) == -1) || (load_xmlconf("./conf/holiday.xml", load_holiday_factor) == -1) || (load_xmlconf("./conf/box.xml", load_box) == -1) || (load_xmlconf("./conf/exchanges.xml", load_exchange_info) == -1) || (load_xmlconf("./conf/npc.xml", load_npc) == -1) || (load_xmlconf("./conf/npcSkills.xml", load_shop_skill) == -1) || (load_xmlconf("./conf/npcShop.xml", load_shop_item) == -1) || (load_xmlconf("./conf/mail.xml", load_sys_mail) == -1) || (load_xmlconf("./conf/sysinfo.xml", load_sys_info) == -1) || (load_xmlconf("./conf/fishGame.xml", load_fish_info) == -1) || (load_xmlconf("./conf/professtion.xml", load_init_prof_info) == -1) || (load_xmlconf("./conf/maze.xml", load_maze_xml) == -1) || (load_xmlconf("./conf/mapcopy.xml", load_map_copy) == -1) ) return -1; // sleep(1000); activate_boxes(); start_maze_timer(); /* if(tm_load_dirty("./data/tm_dirty.dat") < 0){ KERROR_LOG(0, "Failed to load drity word file!"); return -1; } */ init_batter_teams(); init_batter_infos(); connect_to_switch_timely(0, 0); regist_timers(); udp_report_fd = create_udp_socket(&udp_report_addr, config_get_strval("report_svr_ip"), config_get_intval("report_svr_port", 0)); udp_post_fd = create_udp_socket(&udp_post_addr, config_get_strval("post_svr_ip"), config_get_intval("post_svr_port", 0)); switch (idc_type) { case idc_type_dx: chat_svr_fd = create_udp_socket(&udp_chat_svr_addr, config_get_strval("dx_chat_svr_ip"), config_get_intval("chat_svr_port", 0)); break; case idc_type_wt: chat_svr_fd = create_udp_socket(&udp_chat_svr_addr, config_get_strval("wt_chat_svr_ip"), config_get_intval("chat_svr_port", 0)); break; case idc_type_internal: case idc_type_internal + 1: chat_svr_fd = create_udp_socket(&udp_chat_svr_addr, config_get_strval("in_chat_svr_ip"), config_get_intval("chat_svr_port", 0)); break; default: return -1; } } return 0; }