void Battle::OnHttpRes(const s32 id, const Json::Value * root, const void * context, const s32 size) { switch (id) { case HTTP_REQUEST_ID_COUNT_PVE: { if (NULL == root) { ALERT("请检查你的网络连接"); return; } if ((*root)["code"] == ERROR_CODE::ERROR_CODE_NO_ERROR) { m_equip.id = StringAsInt((*root)["data"]["equipid"].asString().c_str()); m_equip.isequiped = StringAsInt((*root)["data"]["status"].asString().c_str()); m_equip.type = (*root)["data"]["type"].asInt(); m_equip.model = (*root)["data"]["modelname"].asString(); m_equip.exp = (*root)["data"]["exp"].asInt(); m_equip.level = (*root)["data"]["level"].asInt(); g_pEquipManager->saveEquip(m_equip); scheduleOnce(schedule_selector(Battle::pve_vector), 2.0f); } else { ALERT("小火鸡,不要作弊,小心被封号"); } break; } default: break; } }
int ParseArgument(int argc,char * argv[],std::string& local_addr,std::string& remote_addr,int& local_port,int& remote_port) { int ret = 0; int err = 0; bool helpflag = false; const char* short_opts="hi:p:a:t:"; const struct option long_opts[] = { {"help",no_argument,NULL,'h'}, {"local_addr",required_argument,NULL,'i'}, {"local_port",required_argument,NULL,'p'}, {"remote_addr",required_argument,NULL,'a'}, {"remote_port",required_argument,NULL,'t'}, {0,0,0,0} }; std::string temp_local_addr; std::string temp_local_port; std::string temp_remote_addr; std::string temp_remote_port; if ( argc < 2 ) { helpflag = true; err = ERR_LACK_ARGUMENT; } while ( -1 != ( ret=getopt_long(argc,argv,short_opts,long_opts,NULL))) { switch (ret) { case 'h': helpflag=true; break; case 'i': temp_local_addr = optarg; if ( InvalidIP(temp_local_addr) ) { err = ERR_INVALID_IPADDR; std::cerr<<"Invalid ip addr -"<<char(ret)<<" "<<temp_local_addr<<std::endl; } break; case 'p': temp_local_port = optarg; if ( InvalidPort(temp_local_port) ) { err = ERR_INVALID_PORT; std::cerr<<"Invalid port -"<<char(ret)<<" "<<temp_local_port<<std::endl; } break; case 'a': temp_remote_addr = optarg; if ( InvalidIP(temp_remote_addr) ) { err = ERR_INVALID_IPADDR; std::cerr<<"Invalid ip addr -"<<char(ret)<<" "<<temp_remote_addr<<std::endl; } break; case 't': temp_remote_port = optarg; if ( InvalidPort(temp_remote_port) ) { err = ERR_INVALID_PORT; std::cerr<<"Invalid ip addr -"<<char(ret)<<" "<<temp_remote_port<<std::endl; } break; case '?': helpflag = true; err = ERR_PARSE_ARGUMENT; break; default: helpflag = true; err = ERR_UNRECOGNIZED_ARGUMENT; break; } } if ( helpflag || 0 != err ) { Usage(); } else { local_addr = temp_local_addr; remote_addr = temp_remote_addr; local_port = StringAsInt(temp_local_port); remote_port = StringAsInt(temp_remote_port); } return err; }
int StringAsInt(const std::string & value) { return StringAsInt(value.c_str()); }