Exemplo n.º 1
0
void AudioPrefsDialog::load()
{
	bug_fun();
	cfg.load();
	cfg.dump();

	for(auto page: pages)
	{
		bug_var(page);

		for(auto iter = page->GetIterator(); !iter.AtEnd(); iter.Next())
		{
			auto prop = iter.GetProperty();
			auto key = prop->GetName().ToStdString();
			if(!cfg.has(key))
				continue;
			if(auto p = dynamic_cast<wxStringProperty*>(prop))
				p->SetValueFromString(cfg.get(key, p->GetDefaultValue().GetString().ToStdString()));
			else if(auto p = dynamic_cast<wxColourProperty*>(prop))
				{}
			else if(auto p = dynamic_cast<wxEnumProperty*>(prop))
			{
				p->SetValueFromString(cfg.get(key, p->GetDefaultValue().GetString().ToStdString()));
			}
			else if(auto p = dynamic_cast<wxIntProperty*>(prop))
				p->SetValueFromInt(cfg.get(key, p->GetDefaultValue().GetInteger()));
			else if(auto p = dynamic_cast<wxFontProperty*>(prop))
			{
				bug_var(p->GetValue().GetString().ToStdString());
				p->SetValueFromInt(cfg.get(key, p->GetDefaultValue().GetInteger()));
			}
		}
	}
}
Exemplo n.º 2
0
bool FServerIrcBotPlugin::serve(const message& msg)
{
	BUG_COMMAND(msg);
	//---------------------------------------------------
	// get_nickname()       : Lelly
	// get_user()           : ~lelly
	// get_host()           : wibble.wobble
	// get_userhost()       : [email protected]
	// get_nick()           : Lelly
	// get_chan()           : #ommo
	// get_user_cmd()       : !ommo
	// get_user_params()    : Test #1.zip
	//---------------------------------------------------
	if(done.load())
	{
		bot.fc_reply_pm_notice(msg, "Declined, server shutting down");
		return true;
	}
	bot.fc_reply(msg, "This is a test.");

	// !ommo Test #1.zip
	str data_dir = bot.get("fserver.data.dir", bot.get_data_folder());
	bug_var(data_dir);
	request_file(msg, data_dir + '/' + msg.get_user_params());

	return true;
}
Exemplo n.º 3
0
void AudioPrefsDialog::save()
{
	bug_fun();

	cfg.start_transaction();

	for(auto page: pages)
	{
		bug_var(page);

		for(auto iter = page->GetIterator(); !iter.AtEnd(); iter.Next())
		{
			auto prop = iter.GetProperty();
			auto key = prop->GetName().ToStdString();
			bug_var(key);

			if(auto p = dynamic_cast<wxStringProperty*>(prop))
				cfg.set(key, p->GetValue().GetString().ToStdString());
			else if(auto p = dynamic_cast<wxColourProperty*>(prop))
				{}
			else if(auto p = dynamic_cast<wxEnumProperty*>(prop))
			{
				auto type = cfg.get("wx." + key + ".type", "str");
				if(type == "str")
					cfg.set(key, p->GetValueAsString().ToStdString());
				else if(type == "int")
					cfg.set(key, p->GetValue().GetInteger());
			}
			else if(auto p = dynamic_cast<wxIntProperty*>(prop))
			{
				cfg.set(key, p->GetValue().GetLong());
			}
		}
	}
	cfg.commit();
}
Exemplo n.º 4
0
bool FServerIrcBotPlugin::files(const message& msg)
{
	BUG_COMMAND(msg);
	if(done.load())
	{
		bot.fc_reply_pm_notice(msg, "Declined, server shutting down");
		return true;
	}
	// make zip file
	// ommo-ebooks-YYYY-MM-DD.txt
	str data_dir = bot.get("fserver.data.dir", bot.get_data_folder());
	bug_var(data_dir);
	str fname = data_dir;
	fname += "/" + bot.get("fserver.index.file.prefix", bot.nick + "-files");
	fname += "-" + todays_date();

	if(!have_zip(data_dir, fname))
		return false;

	request_file(msg, fname + ".zip");

	return true;
}
Exemplo n.º 5
0
void FServerIrcBotPlugin::request_file(const message& msg, const str& filename)
{
	log("I: Creating entry for: " << msg.get_userhost());
	auto fid = next_id();
	entry e;
	e.fid = fid;
	e.pathname = filename;
	e.userhost = msg.get_userhost();
	e.size = 0;
	e.sent = 0;
	e.msg = msg;

	log("I: Adding to queue: " << fid);

	soss oss;
	if(!wait_q.push_back(std::move(e)))
	{
		log("I: Wait queue full: " << fid);

		oss << "Request Denied • Priority Queue is FULL!";
		oss << " " << wait_q.size();
		oss << " • " << bot.nick << "'s " << get_name() << " " << get_version();
		oss << " •";
	}
	else
	{
		log("I: In wait queue: " << fid);
		// Request Accepted • List Has Been Placed In The Priority Queue At Position 1 • OmeNServE v2.60 •
		oss << "Request Accepted • Priority Queue Position";
		oss << " " << wait_q.size();
		oss << " • " << bot.nick << "'s " << get_name() << " " << get_version();
		oss << " •";
	}
	bug_var(oss.str());
	bot.fc_reply_pm_notice(msg, oss.str());
}
Exemplo n.º 6
0
void AudioPrefsDialog::OnPGChanged(wxPropertyGridEvent& event)
{
	bug_fun();
	bug_var(event.GetPropertyName().ToStdString());
	bug_var(event.GetProperty()->GetValue().GetString().ToStdString());
}
Exemplo n.º 7
0
// INTERFACE: IrcBotMonitor
void FServerIrcBotPlugin::event(const message& msg)
{
	if(msg.command != "PRIVMSG")
		return;
	if(msg.get_to() != bot.nick)
		return;
	// :[email protected] PRIVMSG oMMo :DCC SEND oMMo-files-2015-07-28.zip 1365602080 6660 229 1

	BUG_COMMAND(msg);
//	str userhost = msg.get_userhost();
//	for(const str& s: ignores)
//		if(userhost.find(s) != str::npos)
//			return;

	str text = msg.get_trailing();
	trim(text, "\001");
	bug_var(text);
	// DCC SEND oMMo-files-2015-07-28.zip <ip> <port> <fsize> <fid>
	// DCC RESUME oMMo-files-2015-07-28.zip 0 925173597 1
	// <fid> = id of offered file
	if(text.find("DCC SEND"))
		return; // malformed

	str dcc = text.substr(9);
	std::reverse(dcc.begin(), dcc.end());

	str s_fid;
	str s_fsize;
	str s_port;
	str s_ip;
	str fname;

	// DCC RESUME "Test #1.zip" 0 925173597 1

	if(!sgl(siss(dcc) >> s_fid >> s_fsize >> s_port >> s_ip >> std::ws, fname))
	{
		log("E: Failed to parse DCC SEND: " << dcc);
		return;
	}

	std::reverse(s_fid.begin(), s_fid.end());
	std::reverse(s_fsize.begin(), s_fsize.end());
	std::reverse(s_port.begin(), s_port.end());
	std::reverse(s_ip.begin(), s_ip.end());
	std::reverse(fname.begin(), fname.end());

	try
	{
		uint32 fid = std::stol(s_fid);
//		uint64 fsize = std::stol(s_fsize);
		uint32 port = std::stol(s_port);
		uint32 ip = std::stol(s_ip);
		dcc_send_file_by_id(ntohl(ip), port, fid);
	}
	catch(...)
	{
		log("E: bad DCC SEND format: " << text);
		// 2015-07-30 06:46:14: E: bad DCC SEND format: DCC RESUME "Test #1.zip" 0 925173597 1 [plugin-fserver.cpp] (703)
		return;
	}

}
Exemplo n.º 8
0
void FServerIrcBotPlugin::dcc_send_file_by_id(uint32 ip, uint32 port, uint32 fid, uint32 pos)
{
	bug_fun();
	bug_var(ip);
	bug_var(port);
	bug_var(fid);

	auto found = send_q.get_data().end();

	str userhost;

	{
		lock_guard lock(send_q.get_mtx());

		for(auto e = send_q.get_data().begin(); e != send_q.get_data().end(); ++e)
		{
			if(e->fid != fid)
				continue;

			found = e;
			break;
		}

		if(found == send_q.get_data().end())
		{
			log("E: file id not found: " << fid);
			return;
		}
	}

	userhost = found->userhost;

	str host = ntoa(ip);
	bug_var(host);
	bug_var(found->fid);
	bug_var(found->pathname);
	bug_var(found->userhost);

	found->fut = std::async(std::launch::async, [found, host, port, pos]
	{
//		netstream ns;
//
//		ns.open(host, std::to_string(port));
//
//		if(!ns)
//		{
//			log("E: opening connection to: " << host << ":" << port);
//			return;
//		}

		std::ifstream ifs;
		ifs.open(found->pathname, std::ios::binary|std::ios::ate);

		if(!ifs)
		{
			log("E: opening file to send: " << found->pathname);
			return;
		}

		found->size = ifs.tellg();
		ifs.seekg(pos);
		found->sent = ifs.tellg();

		bug_var((bool)ifs);

		hostent* he;
		if(!(he = gethostbyname(host.c_str())))
		{
			log("E: " << std::strerror(errno));
			return;
		}

		int sd;
		if((sd = socket(PF_INET, SOCK_STREAM, 0)) == -1)
		{
			log("E: " << std::strerror(errno));
			return;
		}

		auto sd_closer = make_logged_unistd_closer(sd);

		sockaddr_in sin;
		memcpy(&sin.sin_addr.s_addr, he->h_addr, he->h_length);

		sin.sin_family = AF_INET;
		sin.sin_port = htons(port);
		sin.sin_addr = *((in_addr*) he->h_addr);

		if(connect(sd, (sockaddr*) &sin, sizeof(sin)) < 0)
		{
			log("E: " << std::strerror(errno));
			return;
		}

		// working code
//		int len;
//		char buf[1024];
//		while(ifs.read(buf, sizeof(buf)), ifs.gcount())
//		{
//			bug_var(ifs.gcount());
//			if((len = send(sd, buf, ifs.gcount(), 0)) < 0)
//			{
//				log("E: writing to client failed: " << std::strerror(errno));
//				found->error = true;
//				return;
//			}
//
//			if(len < ifs.gcount())
//			{
//				log("E: sent less data than expected: " << len << " < " << ifs.gcount());
//				found->error = true;
//			}
//
//			found->sent += len;
//			bug_var(found->sent);
//		}

		int len;
		char buf[1024];
		while(ifs.read(buf, sizeof(buf)), ifs.gcount())
		{
			bug_var(ifs.gcount());
			auto to_send = ifs.gcount();
			while((len = send(sd, buf, to_send, 0)) != to_send)
			{
				if(len < 1)
				{
					log("E: writing to client failed: " << std::strerror(errno));
					found->error = true;
					return;
				}

				found->sent += len;
				bug_var(found->sent);

				if(!(to_send -= len))
					break;
			}
		}

		if(!ifs.eof())
		{
			log("E: reading incomplete: ");
			found->error = true;
		}

		found->sent = found->size;
	});

	log("I: File sent to " << userhost);
}
Exemplo n.º 9
0
void FServerIrcBotPlugin::process_queues()
{
	while(!done.load())
	{
		std::this_thread::sleep_for(std::chrono::seconds(1));
		// tidy queues
//		decltype(entries.begin()) found;
		{
			lock_guard lock(send_q.get_mtx());

			for(auto e = send_q.get_data().begin(); e != send_q.get_data().end();)
			{
				bug_var(e->fid);
				bug_var(e->size);
				bug_var(e->sent);
				bug_var(e->error);

				if(e->error)
				{
					log("I: send error: [" << e->fid << "] " << e->userhost << " " << e->pathname);
//					end_future(*e);
					e = send_q.get_data().erase(e);
				}
				else if(e->size && e->size == e->sent)
				{
					log("I: file complete: [" << e->fid << "] " << e->userhost << " " << e->pathname);
//					end_future(*e);
					e = send_q.get_data().erase(e);
				}
				else
					++e;
			}
		}

		// check send_q for spaces & fill from wait_q

//		decltype(wait_q)::value_type fid = 0;
//		decltype(entries.begin()) found;

		if(send_q.size() < send_q.capacity()
		&& send_q.push_back_the_pop_front_from(wait_q))
		{
			lock_guard lock(send_q.get_mtx());

			str pathname = send_q.back().pathname;
			bug_var(pathname);
			str filename = get_filename_from_pathname(pathname);
			bug_var(filename);
			str quote;
			if(filename.find(' ') != str::npos)
				quote = "\"";

			auto ip = INADDR_LOOPBACK;//htonl(INADDR_LOOPBACK);//dcc_get_my_address();
			decltype(htonl(0)) port = 0;

			struct stat s;
			if(stat(pathname.c_str(), &s))
			{
				log("E: can not stat zip file: " << pathname);
			}

			str address = "127.0.0.1";

			soss oss;
			oss << "DCC Send " << quote << filename << quote << " (" << address << ")";
			bot.fc_reply_pm_notice(send_q.back().msg, oss.str());

			oss.str("");
			oss << '\001';
			oss << "DCC SEND";
			oss << ' ' << quote << filename << quote;
			oss << ' ' << ip; // the 32bit IP number, host byte order
			oss << ' ' << port;
			oss << ' ' << s.st_size;
			oss << ' ' << send_q.back().fid; // sequence id?
			oss << '\001';
			bot.fc_reply_pm(send_q.back().msg, oss.str());
		}
	}
}
Exemplo n.º 10
0
void SoundIoPlayer::play(region reg, bool loop)
{
	bug_fun();
	bug_var(reg.b);
	bug_var(reg.e);
	bug_var(loop);

	if(is_playing())
		return;

//	AudioContextUPtr ctx(new AudioContext(soundio_create()));
	AudioContextUPtr ctx(new AudioContext());

	if(!ctx)
	{
		logit("E: SoundIo out of memory: ");
		return;
	}

	Config& cfg = app.config();

	auto backend = SoundIoBackend(
		cfg.get("soundio.backend", int(SoundIoBackendNone)));

	auto device_id = cfg.get("soundio.device", str());
	auto old_device_id = device_id;

	if(!ctx->initialize(backend, device_id))
		return;

	if(old_device_id != device_id)
		cfg.set("soundio.device", device_id);

//	if(auto err =
//	(backend == SoundIoBackendNone) ? soundio_connect(ctx->sio) :
//		soundio_connect_backend(ctx->sio, backend))
//	{
//		logit("E: SoundIo can't connect to backend: " << soundio_strerror(err));
//		return;
//	}
//
//	soundio_flush_events(ctx->sio);
//
//	auto selected_device_index = -1;
//
//	auto device_id = cfg.get("soundio.device", str());
//
//	selected_device_index = -1;
//
//	if(!device_id.empty())
//	{
//		auto device_count = soundio_output_device_count(ctx->sio);
//		for(decltype(device_count) i = 0; i < device_count; ++i)
//		{
//			SoundIoDevice* device = soundio_get_output_device(ctx->sio, i);
//			if(!std::strcmp(device->id, device_id.c_str()))
//			{
//				selected_device_index = i;
//				break;
//			}
//		}
//	}
//
//	if(selected_device_index == -1)
//		selected_device_index = soundio_default_output_device_index(ctx->sio);
//
//
//	if(selected_device_index == -1)
//	{
//		logit("E: SoundIo can't find device: ");
//		return;
//	}
//
//	if(!(ctx->dev = soundio_get_output_device(ctx->sio, selected_device_index)))
//	{
//		logit("E: SoundIo out of memory: ");
//		return;
//	}
//
//	if(std::strcmp(ctx->dev->id, device_id.c_str()))
//	{
//		device_id = ctx->dev->id;
//		// update current configured device
//		cfg.set("soundio.device", device_id);
//	}
//
//	if(ctx->dev->probe_error)
//	{
//		logit("E: Cannot probe device: " << soundio_strerror(ctx->dev->probe_error));
//		return;
//	}
//
//	if(!(ctx->out = soundio_outstream_create(ctx->dev)))
//	{
//		logit("E: SoundIo out of memory: ");
//		return;
//	}

	ctx->out->write_callback = write_callback;
	ctx->out->underflow_callback = underflow_callback;
	ctx->out->name = "Sound Killer (libsoundio)";
	ctx->out->userdata = this;
	ctx->out->sample_rate = audio.rate;
	ctx->out->software_latency = 0.1;

	if(soundio_device_supports_format(ctx->dev, SoundIoFormatFloat64NE))
	{
		ctx->out->format = SoundIoFormatFloat64NE;
		write_sample = write_sample_float64ne;
	}
	else if(soundio_device_supports_format(ctx->dev, SoundIoFormatFloat32NE))
	{
		ctx->out->format = SoundIoFormatFloat32NE;
		write_sample = write_sample_float32ne;
	}
	else if(soundio_device_supports_format(ctx->dev, SoundIoFormatS32NE))
	{
		ctx->out->format = SoundIoFormatS32NE;
		write_sample = write_sample_s32ne;
	}
	else if(soundio_device_supports_format(ctx->dev, SoundIoFormatS16NE))
	{
		ctx->out->format = SoundIoFormatS16NE;
		write_sample = write_sample_s16ne;
	}
	else
	{
		logit("E: No suitable device format available.");
		return;
	}

//	if(auto err = soundio_outstream_open(ctx->out))
//	{
//		logit("E: unable to open device: " << soundio_strerror(err));
//		return;
//	}
//
//	if(ctx->out->layout_error)
//	{
//		logit("E: unable to set channel layout: " << ctx->out->layout_error);
//		return;
//	}

	if(!ctx->open())
		return;

	{
		audiogang::write_lock lock(audio.mtx);
		this->reg = reg;
		this->loop = loop;
		this->pos = reg.b;
	}

//	if(auto err = soundio_outstream_start(ctx->out))
//	{
//		logit("E: unable to start device: " << soundio_strerror(err));
//		return;
//	}

	if(ctx->start())
	{
		ctx_lock_guard lock(ctx_mtx);
		this->ctx = std::move(ctx);
	}
}