Ejemplo n.º 1
0
bool AttributeElement::ToBool() const {
	try {
		return boost::lexical_cast<bool>(_value);
	} catch (...) {
		LOGERROR("无法将值 " + ToString() + " 转换为 bool");
		throw FCException("数据转换失败");
	}
}
Ejemplo n.º 2
0
double AttributeElement::ToNumber() const {
	try {
		return boost::lexical_cast<double>(_value);
	} catch (...) {
		LOGERROR("无法将值 " + ToString() + " 转换为 double");
		throw FCException("数据转换失败");
	}
}
Ejemplo n.º 3
0
PlayerDisconnectEvent::PlayerDisconnectEvent(PlayerThread* pThread,int iEID,string sUsername) :
    PlayerEventBase(pThread),
    _iEntityID(iEID),
    _sName(sUsername)
{
    if(_iEntityID <= 100) {
        throw FCException("invalid EID");
    }
}
Ejemplo n.º 4
0
EntityPlayer::EntityPlayer(MinecraftServer* pServer,World* pWorld,string sName) try :
	EntityLiving		(Constants::get("/Entity/Alive/TypeID/Player"),pServer,pWorld),
	_sName				("")
{
	if (sName.compare("") == 0) {throw FCException("Illegal name");}
	_sName.assign(sName);
	_iHealth = 20;
}catch(FCException & ex) {
	ex.rethrow();
}
Ejemplo n.º 5
0
/***************************************************************************************************
* Initialize the block chain and transaction inventory
***************************************************************************************************/
bool FCInventory::init() {
	try {
		boost::filesystem::path dataPath = FC::expandUser(config.getString("datapath", ""));
		if(dataPath == "") {
			throw FCException("Missing data path");
		}
		
		std::cout << dataPath.string() << std::endl;
		
		if(this->wallet.init() == false) {
			throw FCException("");
		}
		this->currBlock.update(0, FCDEFAULT_NBITS);
		
		return true;
	}
	catch(FCException &e) {
		return false;
	}
}
Ejemplo n.º 6
0
EntityPickup::EntityPickup(MinecraftServer* pMCServer,World* pWorld,ItemID ID) try : 
	Entity(pMCServer,pWorld)
{
	if (!_pMCServer->getItemInfoProvider()->isRegistered(ID)) {
		ID.first = ID.second = 0;
		FCException("Item not registered");
	}
	_itemID = ID;
}catch(FCException& ex) { 
	ex.rethrow();
}
Ejemplo n.º 7
0
bool FCTransactionOut::deserialize(std::string &hex) {
	if(hex.size() < 16) {
		throw FCException("Unable to deserialize transaction out, invalid hex[1]");
	}
	//this->coinbasevalue = this->get_number64(hex.substr(0, 16), true);
	hex = hex.substr(16);
	
	//this->scriptPubKey = this->deser_string(hex);
	
	return true;
}
Ejemplo n.º 8
0
/***************************************************************************************************
* Build this configuration object from command line arguments and configuration settings
* ARG argc - Number of command line arguments
* ARG argv - List of command line arguments
* RET boolean value
***************************************************************************************************/
bool FCConfig::build(int argc, char **argv) {
	try {
		FCConfig cmd, cnf;
		
		if(this->setDefaults() == false) {
			throw FCException();
		}
		
		if(this->buildCommandLine(argc, argv, cmd) == false) {
			throw FCException();
		}
		
		if(cmd.getBool("help", false)) {
			this->printUsage();
		}
		
		if(this->buildConfigFile(cmd.getString("configFile", ""), cnf) == false) {
			throw FCException();
		}
		
		if(this->mergeConfig(cmd) == false) {
			throw FCException();
		}
		
		if(this->mergeConfig(cnf) == false) {
			throw FCException();
		}
		
		if(this->fixConfig() == false) {
			
		}
		
		this->buildCommand(argc, argv);
		
		return true;
	}
	catch(FCException &e) {
		return false;
	}
}
Ejemplo n.º 9
0
mongo::DBClientConnection& GetDB() {
	if(!connected) {
		std::string host(GetConfig().GetAttribute("Database.host").ToString());
		LOGINFO("正在连接到 " + host + " 的 mongodb 服务器");
		try {
			dbconnection.connect(host);
			connected = true;
			LOGINFO("已连接");
		} catch(mongo::DBException &e) {
			LOGERROR("连接数据库时发生错误: " + e.toString());
			throw FCException("无法连接至数据库");
		}
	}

	return dbconnection;
}
Ejemplo n.º 10
0
/***************************************************************************************************
* Merge the contents of the given config object with this one
* ARG config - Config object to merge from
* RET boolean value
***************************************************************************************************/
bool FCConfig::mergeConfig(FCConfig &config) {
	try {
		for(const FCConfigItem *item = configItems; item->longName != ""; item++) {
			if(config.items[ item->longName ] != "") {
				if(config.getValue(item->longName, this->items[ item->longName ]) == false) {
					throw FCException("Failed to retrieve value for '%s' during merge", item->longName.c_str());
				}
			}
		}
		
		return true;
	}
	catch(FCException &e) {
		return false;
	}
}
Ejemplo n.º 11
0
NBTBase::NBTBase(ConstString& str,int id) : 
_sName(str)
{
	if (id < 1 || id > 11) {throw FCException("Unknown tag type");}
	_iTagID = (char)id;
}
Ejemplo n.º 12
0
/***************************************************************************************************
* Build a config object from command line arguments
* ARG argc - Number of command line arguments
* ARG argv - List of command line arguments
* ARG config - Config object to build
* RET boolean value
***************************************************************************************************/
bool FCConfig::buildCommandLine(int argc, char **argv, FCConfig &config) {
	try {
		struct option *long_options = (struct option *)malloc(sizeof(struct option) * (this->numItems + 1));
		if(long_options == NULL) {
			throw FCException("Malloc failed");
		}
		
		char *prog = argv[0];
		char *ptr = prog;
		while((ptr = strchr(prog, '/'))) {
			prog = ptr + 1;
		}
		this->programName = std::string(prog);
		
		
		std::string short_options = "";
		for(int i = 0; i < this->numItems; i++) {
			const FCConfigItem *item = &configItems[i];
			long_options[i].name = item->longName.c_str();
			long_options[i].has_arg = !item->flag;
			long_options[i].flag = NULL;
			long_options[i].val = item->shortName.c_str()[0];
			short_options += item->shortName;
			if(!item->flag) {
				short_options += ":";
			}
			if(item->longName.length() > this->maxItem) {
				this->maxItem = item->longName.length();
			}
		}
		
		int option_index = 0;
		int c = getopt_long(argc, argv, short_options.c_str(), long_options, &option_index);
		while(c != -1) {
			bool found = false;
			if(c == '?') {
				throw FCException();
			}
			for(int i = 0; i < this->numItems; i++) {
				const FCConfigItem *item = &configItems[i];
				if(c == item->shortName.c_str()[0]) {
					if(!item->flag) {
						config.items[ item->longName ] = std::string(optarg);
					}
					else {
						config.items[ item->longName ] = "true";
					}
					found = true;
					break;
				}
			}
			if(!found) {
				throw FCException("Unknown option '%c'", c);
			}
			c = getopt_long(argc, argv, short_options.c_str(), long_options, &option_index);
		}
		
		free(long_options);
		
		return true;
	}
	catch(FCException &e) {
		return false;
	}
}