Esempio n. 1
0
int select3(struct libdb *dbp, struct rdset *rdsetp, int len, const char *format, ...)
{
	int ret = 0;
	if (!is_open(dbp) && !open(dbp))
	{
		return 0;
	}
	va_list ap;
	va_start(ap, format);

	if (len < 2014)
	{
		char temp[1024];
		bzero(temp, 2014);
		vsnprintf(temp, len, format, ap);
		va_end(ap);
		ret = select2(dbp, rdsetp, temp);
	}
	else
	{
		char strTemp[len];
		vsnprintf(strTemp, len, format, ap);
		va_end(ap);
		ret = select2(dbp, rdsetp, strTemp);
	}

	return ret;
}
Esempio n. 2
0
noinline double select(int s, ...)
{
  va_list ap;
  va_start(ap, s);
  double d = select2(s, ap);
  va_end(ap);
  return d;
}
Esempio n. 3
0
File: LED.cpp Progetto: konao/rasp1
void LED::on(int i) {
  static int _map1[] = {3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2};
  static int _map2[] = {0x0e, 0x07, 0x0b, 0x0d, 0x0e, 0x07, 0x0b, 0x0d, 0x0e, 0x07, 0x0b, 0x0d, 0x0e, 0x07, 0x0b, 0x0d, 0x0e, 0x07, 0x0b, 0x0d, 0x0e, 0x07, 0x0b, 0x0d, 0x0e, 0x07, 0x0b, 0x0d, 0x0e, 0x07, 0x0b, 0x0d, };

  if (!_bInitOk) return;
  if (i<0 || i>31) return;

  select1(_map1[i]);
  select2(_map2[i]);
}
Esempio n. 4
0
	std::string Databases::Create(std::string origin, std::string name)
	{
		if (Exists(origin, name))
		{
			return Path(origin,name);
		}
		static Logger* logger = Logger::Get("Database.Databases");

		Statement select(this->session->GetSession());
		Poco::UInt32 seq = 0;
		select << "SELECT seq FROM sqlite_sequence WHERE name='Databases'", into(seq);
		select.execute();

		++seq;

		std::string filename = Poco::format("%016u.db",(unsigned int)seq);
		logger->Debug("creating new db: %s",filename.c_str());

		Statement select2(this->session->GetSession());
		select2 << "INSERT INTO Databases (origin, name, path) VALUES (:origin,:name,:path)", use(origin), use(name), use(filename);
		select2.execute();

		Statement select5(this->session->GetSession());
		select5 << "SELECT origin from Origins where origin = :origin", use(origin);
		Poco::Int32 count = select5.execute();
		if (count == 0)
		{
			Statement select(this->session->GetSession());
			select << "INSERT INTO Origins (origin,quota) values (:origin,1720462881547374560)", use(origin), now;
		}

		// create the DB file
		std::string dbdir = FileUtils::Join(datadir.c_str(),origin.c_str(),NULL);
		if (!FileUtils::IsDirectory(dbdir))
		{
			logger->Debug("creating new db dir: %s",dbdir.c_str());
			FileUtils::CreateDirectory(dbdir);
		}
		std::string fullpath = FileUtils::Join(dbdir.c_str(),filename.c_str(),NULL);
		logger->Debug("path to new db : %s",fullpath.c_str());

		DBSession s(fullpath);

		// create the metadata table for WebKit
		Statement select3(s.GetSession());
		select3 << "CREATE TABLE __WebKitDatabaseInfoTable__ (key TEXT NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,value TEXT NOT NULL ON CONFLICT FAIL)", now;

		Statement select4(s.GetSession());
		select4 << "insert into __WebKitDatabaseInfoTable__ values ('WebKitDatabaseVersionKey','1.0')", now;

		return fullpath;
	}
	std::string WebKitDatabases::Create(std::string name)
	{
		Statement select(*this->session);
		Poco::UInt32 seq = 0;
		select << "SELECT seq FROM sqlite_sequence WHERE name='Databases'", into(seq);
		select.execute();

		++seq;

		std::string filename = Poco::format("%016u.db", (unsigned int) seq);
		GetLogger()->Debug("Creating new db: %s", filename.c_str());

		Statement select2(*this->session);
		select2 << "INSERT INTO Databases (origin, name, path) VALUES (:origin,:name,:path)",
			 use(this->origin), use(name), use(filename);
		select2.execute();

		Statement select5(*this->session);
		select5 << "SELECT origin from Origins where origin = :origin", use(this->origin);
		Poco::Int32 count = select5.execute();
		if (count == 0)
		{
			Statement select(*this->session);
			select << "INSERT INTO Origins (origin,quota) values (:origin,1720462881547374560)",
				use(this->origin), now;
		}

		// Create the path for this application's origin, if necessary.
		if (!FileUtils::IsDirectory(originPath))
		{
			GetLogger()->Debug("Creating new database directory: %s", originPath.c_str());
			FileUtils::CreateDirectory(originPath);
		}

		std::string filePath(FileUtils::Join(originPath.c_str(), filename.c_str(), NULL));
		GetLogger()->Debug("path to new database: %s", filePath.c_str());

		// Create the metadata table for WebKit
		Session fileSession("SQLite", filePath);
		Statement select3(fileSession);
		select3 << "CREATE TABLE __WebKitDatabaseInfoTable__ (key TEXT NOT NULL "
			"ON CONFLICT FAIL UNIQUE ON CONFLICT REPLACE,value TEXT NOT NULL ON "
			"CONFLICT FAIL)", now;

		Statement select4(fileSession);
		select4 << "insert into __WebKitDatabaseInfoTable__ values "
			"('WebKitDatabaseVersionKey','1.0')", now;

		return filePath;
	}
Esempio n. 6
0
	Databases::Databases(std::string datadir) : datadir(datadir)
	{
		std::string dbpath = FileUtils::Join(datadir.c_str(),"Databases.db",NULL);

		static Logger* logger = Logger::Get("Database.Databases");
		logger->Debug("DB Path = %s",dbpath.c_str());

		session = new DBSession(dbpath);

		Statement select(this->session->GetSession());
		logger->Debug("Creating table Origins");
		select << "CREATE TABLE IF NOT EXISTS Origins (origin TEXT UNIQUE ON CONFLICT REPLACE, quota INTEGER NOT NULL ON CONFLICT FAIL)", now;

		Statement select2(this->session->GetSession());
		logger->Debug("Creating table Databases");
		select2 << "CREATE TABLE IF NOT EXISTS Databases (guid INTEGER PRIMARY KEY AUTOINCREMENT, origin TEXT, name TEXT, displayName TEXT, estimatedSize INTEGER, path TEXT)", now;
	}
	WebKitDatabases::WebKitDatabases() :
		origin(GetApplicationSecurityOrigin()),
		originPath(GetDataPath(origin)),
		session(0)
	{
		std::string dbPath = FileUtils::Join(GetDataPath().c_str(), "Databases.db", NULL);
		GetLogger()->Debug("DB Path = %s", dbPath.c_str());
		this->session = new Session("SQLite", dbPath);

		Statement select(*this->session);
		GetLogger()->Debug("Creating table Origins");
		select << "CREATE TABLE IF NOT EXISTS Origins (origin TEXT UNIQUE ON "
			"CONFLICT REPLACE, quota INTEGER NOT NULL ON CONFLICT FAIL)", now;

		Statement select2(*this->session);
		GetLogger()->Debug("Creating table Databases");
		select2 << "CREATE TABLE IF NOT EXISTS Databases (guid INTEGER PRIMARY KEY "
			"AUTOINCREMENT, origin TEXT, name TEXT, displayName TEXT, estimatedSize "
			"INTEGER, path TEXT)", now;
	}
int main()
{
    std::cout << "[moeoDetArchiveSelect] => \n";

	moeoUnboundedArchive <Solution> archive;
	Solution sol1, sol2, sol3, sol4, sol5;
	ObjectiveVector obj1, obj2, obj3, obj4, obj5;
	obj1[0]=10;
	obj1[1]=0;
	obj2[0]=9;
	obj2[1]=1;
	obj3[0]=8;
	obj3[1]=2;
	obj4[0]=7;
	obj4[1]=3;
	obj5[0]=6;
	obj5[1]=4;

	sol1.objectiveVector(obj1);
	sol2.objectiveVector(obj2);
	sol3.objectiveVector(obj3);
	sol4.objectiveVector(obj4);
	sol5.objectiveVector(obj5);

	archive(sol1);
	archive(sol2);
	archive(sol3);
	archive(sol4);
	archive(sol5);
	assert(archive.size() == 5);

	//archive.printOn(std::cout);

	eoPop <Solution> source, dest;

	// test with max > archive size
	moeoDetArchiveSelect <Solution> select1(archive, 10);
	select1(source, dest);
	for(unsigned int i=0; i< archive.size(); i++){
		assert(dest[i].objectiveVector()[0]==archive[i].objectiveVector()[0]);
		assert(dest[i].objectiveVector()[1]==archive[i].objectiveVector()[1]);
	}

	//test with a max < archive size
	dest.resize(0);
	moeoDetArchiveSelect <Solution> select2(archive, 3);
	select2(source, dest);
	assert(dest.size()==3);

	//test with archive size < min
	dest.resize(0);
	moeoDetArchiveSelect <Solution> select3(archive, 100, 10);
	select3(source, dest);
	for(int i=0; i< 10; i++){
		assert(dest[i].objectiveVector()[0]==archive[i%archive.size()].objectiveVector()[0]);
		assert(dest[i].objectiveVector()[1]==archive[i%archive.size()].objectiveVector()[1]);
	}

	//test with bad value
	dest.resize(0);
	moeoDetArchiveSelect <Solution> select4(archive, 10, 11);
	select4(source, dest);
	assert(dest.size()==0);

	std::cout << " OK\n";
    return EXIT_SUCCESS;
}
Esempio n. 9
0
void plogin::process()
{
	obj2["data"] = amf3object();
	amf3object & data2 = obj2["data"];

	//errors:
	//-5 = captcha
	//-99 = general error
	//-100 = holiday
	string username = data["user"];
	string password = data["pwd"];

	if (gserver->maxplayers <= gserver->currentplayersonline + 1)
	{
		gserver->SendObject(req.conn, gserver->CreateError("server.LoginResponse", -99, "Servers are currently overloaded. Please try again later."));
		return;
	}

	string newuser;
	string newpass;
	newuser = makesafe(username);
	newpass = makesafe(password);


	{
		Session ses(gserver->accountpool->get());
		Statement select(ses);
		select << "SELECT COUNT(*) AS a FROM `account` WHERE `email`=?;", use(newuser);
		select.execute();
		RecordSet rs(select);

		if (rs.value("a").convert<int32_t>() == 0)
		{
			//account does not exist - insert new row
			try
			{
				Statement insert(ses);
				insert << "INSERT INTO `account` (`name`, `email`, `ip`, `lastlogin`, `creation`, `password`, `status`, `reason`) VALUES ('null', ?, '', ?, ?, ?, 0, '');", use(newuser), use(unixtime()), use(unixtime()), use(newpass), now;
			}
			catch (Poco::Data::MySQL::StatementException * e)
			{
				gserver->consoleLogger->error(Poco::format("Account Create Exception: %s", e->displayText()));
				return;
			}
		}
	}

	{
		Session ses(gserver->accountpool->get());
		Statement select(ses);
		select << "SELECT * FROM `account` WHERE `email`=? AND `password`=?;", use(newuser), use(newpass);
		select.execute();
		RecordSet rs(select);

		if (rs.rowCount() == 0)
		{
			//account doesn't exist or password is wrong
			gserver->SendObject(req.conn, gserver->CreateError("server.LoginResponse", -2, "Incorrect account or password."));
			return;
		}
		else
		{
			int32_t masteraccountid = rs.value("id").convert<int32_t>();
			client = gserver->GetClientByParent(masteraccountid);

			bool banned = false;

			{
				//are they banned? if so, globally or for this server?
				Session ses2(gserver->serverpool->get());
				Statement select2(ses2);
				select2 << "SELECT * FROM `accounts` WHERE `parentid`=?;", use(masteraccountid);
				select2.execute();
				RecordSet rs2(select2);

				if (rs.value("status").convert<int32_t>() == -99)
					banned = true;

				if (rs2.rowCount() > 0 && rs2.value("status").convert<int32_t>() == -99)
					banned = true;

				if (banned)
				{
					string errormsg = "You are banned. Reason: ";
					errormsg += rs.value("reason").convert<string>().length() > 0 ? rs.value("reason").convert<string>() : rs2.value("reason").convert<string>();

					gserver->SendObject(req.conn, gserver->CreateError("server.LoginResponse", -99, errormsg));

					return;
				}
			}

			//client = gserver->GetClientByParent(parentid);
			if (client == 0)
			{
				client = gserver->NewClient();
				client->masteraccountid = masteraccountid;
				client->m_socknum = req.conn->uid;
				client->socket = req.conn;
				req.conn->client_ = client;
				client->m_connected = true;
			}
			else
			{
				if (client->m_connected)
				{
					//player already logged on
					gserver->CloseClient(client, 3, "");//multiple people logging into the same account
				}
				//Login is valid
				client->m_connected = true;
				double logintime = unixtime();
				if (logintime - client->m_lastlogin < 1000 * 5)
				{
					gserver->SendObject(req.conn, gserver->CreateError("server.LoginResponse", 6, "You have tried logging in too frequently. Please try again later."));
					req.conn->stop();
					return;
				}
				client->m_lastlogin = logintime;
				if (client->socket) gserver->CloseClient(client, 3, "");
				client->socket = req.conn;
				client->m_socknum = req.conn->uid;
				client->m_ipaddress = req.conn->address;
				req.conn->client_ = client;
				gserver->consoleLogger->information(Poco::format("Already established client found # %?d", (uint32_t)client->m_clientnumber));

				if (client->m_email == "Daisy")
				{
					client->m_bdenyotherplayer = true;
					client->m_icon = 7;
				}
			}

			if (client == 0)
			{
				//error creating client object
				gserver->consoleLogger->information(Poco::format("Error creating client object @ %s:%?d", (string)__FILE__, __LINE__));
				gserver->SendObject(client, gserver->CreateError("server.LoginResponse", -99, "Error with connecting. Please contact support."));
				return;
			}


			//account exists
			Session ses2(gserver->serverpool->get());
			Statement select2(ses2);
			select2 << "SELECT * FROM `accounts` WHERE `parentid`=?;", use(masteraccountid);
			select2.execute();
			RecordSet rs2(select2);

			if (rs2.rowCount() == 0)
			{
				//does not have an account on server
				gserver->SendObject(client, gserver->CreateError("server.LoginResponse", -4, "need create player"));
				client->m_loggedin = true;

				return;
			}
			else
			{
				int accountid = rs2.value("accountid").convert<int32_t>();
				client->m_accountid = accountid;

				//has an account, what about cities?
				Session ses3(gserver->serverpool->get());
				Statement select3(ses3);
				select3 << "SELECT * FROM `cities` WHERE `accountid`=?;", use(accountid);
				select3.execute();
				RecordSet rs3(select3);

				if (rs3.rowCount() == 0)
				{
					//does not have any cities on server but did have an account - this only happens if you try to "restart" your account. it saves the account info while deleting your cities
					gserver->SendObject(client, gserver->CreateError("server.LoginResponse", -4, "need create player"));
					client->m_loggedin = true;
					return;
				}
				else
				{
					//has an account and cities. process the list and send account info

					amf3object obj;
					obj["cmd"] = "server.LoginResponse";
					obj["data"] = amf3object();
					amf3object & data = obj["data"];
					data["packageId"] = 0.0f;

					double tslag = unixtime();

					if (client->GetItemCount("consume.1.a") < 10000)
						client->SetItem("consume.1.a", 10000);
					client->m_cents = 5000;

					data["player"] = client->ToObject();
					//UNLOCK(M_CLIENTLIST);

					if (client->m_city.size() == 0)
					{
						//problem
						gserver->consoleLogger->error(Poco::format("Error client has no cities @ %s:%?d", (string)__FILE__, __LINE__));
						gserver->SendObject(client, gserver->CreateError("server.LoginResponse", -99, "Error with connecting. Please contact support."));
						return;
					}
					client->m_currentcityid = ((PlayerCity*)client->m_city.at(0))->m_castleid;
					client->m_currentcityindex = 0;
					client->m_accountexists = true;


					//check for holiday status
					stBuff * holiday = client->GetBuff("FurloughBuff");
					if (holiday && holiday->endtime > tslag)
					{
						//is in holiday - send holiday info too

						string s;
						{
							int32_t hours;
							int32_t mins;
							int32_t secs = (holiday->endtime - tslag) / 1000;

							hours = secs / 60 / 60;
							mins = secs / 60 - hours * 60;
							secs = secs - mins * 60 - hours * 60 * 60;

							std::stringstream ss;
							ss << hours << "," << mins << "," << secs;

							s = ss.str();
						}

						data["ok"] = -100;
						data["msg"] = s;
						data["errorMsg"] = s;
					}
					else
					{
						data["ok"] = 1;
						data["msg"] = "success";
					}

					gserver->SendObject(client, obj);
					//SendObject(*req.connection, obj);

					client->m_lag = unixtime() - tslag;

					client->m_loggedin = true;

					gserver->currentplayersonline++;
					client->SaveToDB();

					return;
				}
			}
		}
	}
	return;
}