예제 #1
0
object sqlite3::compile(flusspferd::string sql_in, value bind ) {
    local_root_scope scope;

    size_t n_bytes = sql_in.length() * 2;
    sqlite3_stmt * sth = 0;
    js_char16_t * tail = 0; // uncompiled part of the sql (when multiple stmts)
    
    if (sqlite3_prepare16_v2(db, sql_in.data(), n_bytes, &sth, (const void**)&tail) != SQLITE_OK)
    {
        raise_sqlite_error(db);
    }

    object cursor = create<sqlite3_cursor>(fusion::make_vector(sth));

    string tail_str;
    if (tail) {
        tail_str = string(tail);
    }
    
    string sql = sql_in.substr( 0, sql_in.size() - tail_str.size() );

    cursor.define_property("sql", sql);
    cursor.define_property("tail", tail_str);        

    if ( !bind.is_undefined_or_null() ) {
        cursor.call("bind", bind );
    }
    
    return cursor;
}
예제 #2
0
function flusspferd::create_function(
    std::string const &name,
    unsigned n_args,
    std::vector<std::string> argnames,
    flusspferd::string const &body,
    std::string const &file,
    unsigned line)
{
  JSContext *cx = Impl::current_context();

  std::vector<char const *> argnames_c;
  argnames_c.reserve(argnames.size());

  for (std::vector<std::string>::const_iterator it = argnames.begin();
      it != argnames.end();
      ++it)
    argnames_c.push_back(it->c_str());

  JSFunction *fun =
      JS_CompileUCFunction(
        cx,
        0,
        name.c_str(),
        n_args,
        &argnames_c[0],
        body.data(),
        body.length(),
        file.c_str(),
        line);

  if (!fun)
    throw exception("Could not compile function");

  return Impl::wrap_function(fun);
}
예제 #3
0
void JS_fwrite( flusspferd::string fileName, flusspferd::string str )
{
	std::ofstream OutFile( ( std::string("./js_files/") + fileName.to_string()).c_str() );

	if( OutFile.is_open() )
	{
		OutFile.write( str.to_string().c_str(), MIN(str.size(),1024) );
	}
	OutFile.close();
}
예제 #4
0
void JS_saveSingleObjectToDatabase(JSObject *object, flusspferd::string holderType, flusspferd::string holderId)
{
	if(object->toReal() && object->toReal()->IsPurged() == false) {

		if(holderType.size() < 1) {

			throw flusspferd::exception("Attempting to save object to database with an empty holder type.");
		}

		Object::saveItemToTopLevelHolder(holderType.c_str()[0], holderId.to_string(), object->toReal());
	}
}
예제 #5
0
flusspferd::value JS_getUserIdByUserName(flusspferd::string userName)
{
	PlayerIndex *playerIndex = CharacterUtil::getPlayerIndexByUserName(userName.to_string());

	if(playerIndex == NULL)
		return flusspferd::object();
	return flusspferd::value(playerIndex->id);
}
예제 #6
0
flusspferd::value JS_loadSingleObjectFromDatabase(flusspferd::string objectId)
{
	boost::uuids::string_generator uuidGenerator;

	Object *object = Object::loadSingleItem(uuidGenerator(objectId.to_string()), true);

	return lookupValue(object);
}
예제 #7
0
flusspferd::array JS_loadObjectsByHolderFromDatabase(flusspferd::string holderType, flusspferd::string holderId)
{
	flusspferd::array objects = flusspferd::create_array();

	if(holderType.size() == 0) {

		throw flusspferd::exception("Attempting to load objects from holder of empty type.");
	}

	std::list< Object* > objectList = Object::loadItemList(true, holderType.c_str()[0], holderId.to_string());

	while(objectList.empty() == false) {
		objects.call("push", lookupValue(objectList.front()));
//		objects.push(lookupValue(objectList.front()));

		objectList.pop_front();
	}

	return objects;
}
예제 #8
0
flusspferd::value JS_sendQuery( flusspferd::string qBuffer )
{
	sql::Query MyQuery;
	try {
		MyQuery = gameDatabase->sendQuery( qBuffer.to_string() );
	} catch( sql::QueryException e ) {
		MudLog(BRF, LVL_APPR, TRUE, "JavaScript : sql::Query() : %s", e.getMessage().c_str());
		return flusspferd::value();
	}
	if( MyQuery.use_count() == 0 )
		return flusspferd::value();
	JSBindable *b = new sqlJSQuery( MyQuery );
	return lookupValue( b );
}
예제 #9
0
flusspferd::string JS_fread( flusspferd::string fileName )
{
	std::string inputBuffer;
	char cBuf[1025];
	std::ifstream InFile( (std::string("./js_files/") + fileName.to_string()).c_str() );
	if( InFile.is_open() )
	{
		InFile.get(cBuf, 1024);
		cBuf[ InFile.gcount() ] = '\0';
		InFile.close();
		return flusspferd::string( cBuf );
	}
	return flusspferd::string( "" );
}
예제 #10
0
void JS_sendToZone(int zoneNumber, flusspferd::string message)
{
	Zone *zone = ZoneManager::GetManager().GetZoneByVnum( zoneNumber );
	if( !zone ) return;
	sendToZone(message.c_str(), zone->GetRnum());
}
예제 #11
0
flusspferd::string JS_md5( flusspferd::string key )
{
	return flusspferd::string(MD5::getHashFromString( key.to_string().c_str() ));
}
예제 #12
0
flusspferd::string JS_sqlEsc( flusspferd::string qBuffer )
{
	return sql::escapeString( qBuffer.to_string() );
}
예제 #13
0
flusspferd::string JS_getWeaveAttribute( int wVnum, flusspferd::string attribute )
{
	Weave *w = WeaveManager::GetManager().GetWeave( wVnum );
	return (w ? w->getAttribute(attribute.to_string()) : "<Invalid>");
}
예제 #14
0
int JS_getSkillVnum( flusspferd::string wName )
{
	Weave *w = WeaveManager::GetManager().GetWeave( wName.to_string() );
	return (w ? w->getVnum() : 0);
}
예제 #15
0
void JS_mudLog( int type, int lvl, flusspferd::string str )
{
	MudLog(type, lvl, TRUE, StringUtil::vaEscape( str.to_string() ).c_str());
}