Пример #1
0
int main(int argc, const char **argv) // ignore_convention
{
	IKernel *pKernel = IKernel::Create();
	s_pStorage = CreateStorage("Teeworlds", IStorage::STORAGETYPE_BASIC, argc, argv);
	s_pEngineMap = CreateEngineMap();

	bool RegisterFail = !pKernel->RegisterInterface(s_pStorage);
	RegisterFail |= !pKernel->RegisterInterface(s_pEngineMap);

	if(RegisterFail)
	{
		delete pKernel;
		return -1;
	}

	s_File = s_pStorage->OpenFile("map_version.txt", IOFLAG_WRITE, 1);
	if(s_File)
	{
		io_write(s_File, "static CMapVersion s_aMapVersionList[] = {\n", str_length("static CMapVersion s_aMapVersionList[] = {\n"));
		s_pStorage->ListDirectory(1, "maps", MaplistCallback, 0);
		io_write(s_File, "};\n", str_length("};\n"));
		io_close(s_File);
	}

	delete pKernel;
	return 0;
}
Пример #2
0
int main()
{
	SServer *pServer = new SServer;
	IKernel *pKernel = IKernel::Create();
	pKernel->RegisterInterface(pServer);

	pServer->Init();
	pServer->Run();

	exit(EXIT_SUCCESS);
}
Пример #3
0
void CMainApp::OnUpdate(real timeStep) {
	uint keyMod = keyboardDevice->GetModifiers();

	if (inputSys->CheckAction("Escape")) {
		kernel->Quit();
	}

	if ((keyboardDevice->KeyIsDown(key_RETURN)) && (keyMod & keyModifier_Alt)) {
		bool fs = !renderDriver->GetFullScreen();
		renderDriver->SetFullScreen(fs);
		Log("Alt Key enter -)\n");
	}

	if (keyboardDevice->KeyIsDown(key_UP)) {
		Log("Key up -)\n");
	}
}
Пример #4
0
void CMainApp::Run() {
	kernel->Run();
}
Пример #5
0
int main(int argc, const char **argv) // ignore_convention
{
	int64 LastUpdate = time_get();

	dbg_logger_stdout();
	net_init();

	IKernel *pKernel = IKernel::Create();
	IStorage *pStorage = CreateStorage("Teeworlds", argc, argv); // ignore_convention

	m_pConsole = CreateConsole(CFGFLAG_BANMASTER);
	m_pConsole->RegisterPrintCallback(StandardOutput, 0);
	m_pConsole->Register("ban", "s?r", CFGFLAG_BANMASTER, ConBan, 0, "Bans the specified ip", 0);
	m_pConsole->Register("unban_all", "", CFGFLAG_BANMASTER, ConUnbanAll, 0, "Unbans all ips", 0);
	m_pConsole->Register("bind", "s", CFGFLAG_BANMASTER, ConSetBindAddr, 0, "Binds to the specified address", 0);

	{
		bool RegisterFail = false;

		RegisterFail = RegisterFail || !pKernel->RegisterInterface(m_pConsole);
		RegisterFail = RegisterFail || !pKernel->RegisterInterface(pStorage);
		
		if(RegisterFail)
			return -1;
	}

	m_pConsole->ExecuteFile(BANMASTER_BANFILE);
	
	NETADDR BindAddr;
	if(m_aBindAddr[0] && net_host_lookup(m_aBindAddr, &BindAddr, NETTYPE_IPV4) == 0)
	{
		if(BindAddr.port == 0)
			BindAddr.port = BANMASTER_PORT;
	}
	else
	{
		mem_zero(&BindAddr, sizeof(BindAddr));
		BindAddr.port = BANMASTER_PORT;
	}
		
	m_Net.Open(BindAddr, 0);
	// TODO: DDRace: heinrich5991: check socket for errors

	dbg_msg("banmaster", "started");
	
	while(1)
	{
		m_Net.Update();
		
		// process m_aPackets
		CNetChunk p;
		while(m_Net.Recv(&p))
		{
			if(p.m_DataSize >= (int)sizeof(BANMASTER_IPCHECK) &&
				!mem_comp(p.m_pData, BANMASTER_IPCHECK, sizeof(BANMASTER_IPCHECK)))
			{
				char *pAddr = (char*)p.m_pData + sizeof(BANMASTER_IPCHECK);
				NETADDR CheckAddr;
				if(net_addr_from_str(&CheckAddr, pAddr))
				{
					dbg_msg("banmaster", "dropped weird message ip=%d.%d.%d.%d checkaddr='%s'",
						p.m_Address.ip[0], p.m_Address.ip[1], p.m_Address.ip[2], p.m_Address.ip[3], pAddr);
				}
				else
				{
					int Banned = SendResponse(&p.m_Address, &CheckAddr);
					dbg_msg("banmaster", "responded to checkmsg ip=%d.%d.%d.%d checkaddr=%d.%d.%d.%d result=%s",
						p.m_Address.ip[0], p.m_Address.ip[1], p.m_Address.ip[2], p.m_Address.ip[3], 
						CheckAddr.ip[0], CheckAddr.ip[1], CheckAddr.ip[2], CheckAddr.ip[3], (Banned) ? "ban" : "ok");
				}
			}
		}
		
		if(time_get() - LastUpdate > time_freq() * BAN_REREAD_TIME)
		{
			ClearBans();
			LastUpdate = time_get();
			m_pConsole->ExecuteFile(BANMASTER_BANFILE);
		}
		
		// be nice to the CPU
		thread_sleep(1);
	}
	
	return 0;
}