Exemplo n.º 1
0
static void console_command_compile(ConsoleServer& cs, TCPSocket client, const char* json)
{
	TempAllocator4096 ta;
	JsonObject obj(ta);
	DynamicString id(ta);
	DynamicString data_dir(ta);
	DynamicString platform(ta);

	sjson::parse(json, obj);
	sjson::parse_string(obj["id"], id);
	sjson::parse_string(obj["data_dir"], data_dir);
	sjson::parse_string(obj["platform"], platform);

	{
		TempAllocator512 ta;
		StringStream ss(ta);
		ss << "{\"type\":\"compile\",\"id\":\"" << id.c_str() << "\",\"start\":true}";
		cs.send(client, string_stream::c_str(ss));
	}

	logi("Compiling '%s'", id.c_str());
	bool succ = device()->data_compiler()->compile(data_dir.c_str(), platform.c_str());

	if (succ)
		logi("Compiled '%s'", id.c_str());
	else
		loge("Error while compiling '%s'", id.c_str());

	{
		TempAllocator512 ta;
		StringStream ss(ta);
		ss << "{\"type\":\"compile\",\"id\":\"" << id.c_str() << "\",\"success\":" << (succ ? "true" : "false") << "}";
		cs.send(client, string_stream::c_str(ss));
	}
}
Exemplo n.º 2
0
void load_console_api(ConsoleServer& cs)
{
	cs.register_command("script",  console_command_script);
	cs.register_command("reload",  console_command_reload);
	cs.register_command("pause",   console_command_pause);
	cs.register_command("unpause", console_command_unpause);
	cs.register_command("compile", console_command_compile);
}
Exemplo n.º 3
0
void main(void)
{
	printf("Shows how to connect telnet to read PacketLogger output from RakPeer.\n");

	RakPeerInterface *rakPeer = RakNet::RakPeerInterface::GetInstance();
	TelnetTransport tt;
	ConsoleServer consoleServer;
	LogCommandParser lcp;
	PacketConsoleLogger pcl;
	pcl.SetLogCommandParser(&lcp);
	consoleServer.AddCommandParser(&lcp);
	consoleServer.SetTransportProvider(&tt, 23);
	rakPeer->AttachPlugin(&pcl);

	RakNet::SocketDescriptor sd(0,0);
	RakNet::StartupResult sr = rakPeer->Startup(32, &sd, 1);
	(void) sr;
	RakAssert(sr==RAKNET_STARTED);

	printf("Use telnet 127.0.0.1 23 to connect from the command window\n");
	printf("Use 'Turn Windows features on and off' with 'Telnet Client' if needed.\n");
	printf("Once telnet has connected, type 'Logger subscribe'\n");
	printf("Press any key in this window once you have done all this.\n");
	RakNet::Packet *packet;
	while (!kbhit())
	{
		consoleServer.Update();
		RakSleep(30);
	}

	RakNet::ConnectionAttemptResult car = rakPeer->Connect("natpunch.jenkinssoftware.com", 61111, 0, 0);
	(void) car;
	while (1)
	{
		for (packet=rakPeer->Receive(); packet; rakPeer->DeallocatePacket(packet), packet=rakPeer->Receive())
		{
		}

		consoleServer.Update();
		RakSleep(30);
	}	
}
Exemplo n.º 4
0
void TestCommandServer(TransportInterface *ti, unsigned short port)
{
    ConsoleServer consoleServer;
	RakNetCommandParser rcp;
	LogCommandParser lcp;
	RakNetTime lastLog=0;
	RakPeerInterface *rakPeer = RakNetworkFactory::GetRakPeerInterface();

	printf("This sample demonstrates the command console server, which can be.\n");
	printf("a standalone application or part of your game server.  It allows you to\n");
	printf("easily parse text strings sent from a client using either secure RakNet\n");
	printf("or Telnet.\n");
	printf("See the 'CommandConsoleClient' project for the RakNet client.\n");
	printf("Difficulty: Intermediate\n\n");

	printf("Command server started on port %i.\n", port);
	consoleServer.AddCommandParser(&rcp);
	consoleServer.AddCommandParser(&lcp);
	consoleServer.SetTransportProvider(ti, port);
	rcp.SetRakPeerInterface(rakPeer);
	lcp.AddChannel("TestChannel");
	while (1)
	{
		consoleServer.Update();

		if (RakNet::GetTime() > lastLog + 4000)
		{
			lcp.WriteLog("TestChannel", "Test of logger");
			lastLog=RakNet::GetTime();
		}

#ifdef _WIN32
		Sleep( 30 );
#else
		usleep( 30 * 1000 );
#endif
	}	
}
Exemplo n.º 5
0
int main(int sz, char *args[]) {
    init_daemon dm(sz, args);
    WrapServerStart::init(); // config need init handle

	gl_processpid=getpid();

	gl_myconf=new PxConf();
	gl_globalconf=new PxGlobalConf();
	gl_hash_ring=new KTMHashRing();
	if(gl_myconf->init("../bin/dbd_conf.xml")<0)
	{
		cerr <<"myconf init error" <<endl;
		return -1;
	}
	if(gl_globalconf->init("../bin/daoproxy_globalconf.xml")<0)
	{
		cerr <<"global conf init error" <<endl;
		return -1;
	}
	if(gl_hash_ring->init(gl_globalconf->get_hash_ring())<0)
	{
		cerr <<"gl_hash_ring init error" <<endl;
		return -1;
	}

	///init timer
	g_pTimerContainer = new x_timer::TimerContainer(0x7FFFFFFF);
	g_pTimerContainer->init();

	////////////////
	gl_route_strategy=new RouteStrategy();
	if(gl_route_strategy->init_load_conf()<0)
	{
		cerr <<"gl_route_strategy init_load_conf error" <<endl;
		return -1;
	}
	gl_msghook=new MsgHook();

	gl_throughput_statstic=new ThroughputStat();
	if(gl_throughput_statstic->init()<0)
	{
		cerr <<"gl_throughput_statstic init error" <<endl;
		return -1;
	}
	gl_traffic_statstic=new TrafficStat();
	if(gl_traffic_statstic->init()<0)
	{
		cerr <<"gl_traffic_statstic init error" <<endl;
		return -1;
	}
	g_pFSMContainer=new id_map::IDMap<ANYPTRTYPE >();

	gl_daostatmanager=new DaoStatManager();
	if(gl_daostatmanager->init_from_conf()<0)
	{
		cerr <<"gl_daostatmanager init error" <<endl;
		return -1;
	}

	YYThriftHybirdHandler *pxyHandler = new YYThriftHybirdHandler();
	pxyHandler->set_queue_limit(10000);
	g_pHybirdLinkHandler=pxyHandler;

	YYThriftHybirdHandler *pxyHandlerFordao = new YYThriftHybirdHandler();
	pxyHandlerFordao->set_queue_limit(30000);
	g_pHybirdLinkHandlerForDAO=pxyHandlerFordao;

    ServerStategy ss;
    ss.type = DAEMONSERVER;
    ss.threadStategy = SINGLETHREAD;
    ss.groupId = gl_myconf->groupid;
    ss.port = gl_myconf->port;
    ss.name = gl_myconf->server_name;
	ss.queue_pack_size=5000;
	ss.thread_num=10;
	ss.handler=pxyHandler;

	IServerFacade *sf = initEviroment(ss);

	gl_service_connection_manager=sf->getConnManager();

	gl_daoconnectionmanager=new DaoConnectionManager();
	if(gl_daoconnectionmanager->init(sf->getSendConnFactory(),pxyHandlerFordao)<0)
	{
		cerr <<"DaoConnectionManager init error" <<endl;
		return -1;
	}

	if(gl_daoconnectionmanager->rc_calltest()<0)
	{
		cerr <<"gl_daoconnectionmanager init rc_calltest error" <<endl;
		return -1;
	}
	if(gl_daostatmanager->rc_calltest()<0)
	{
		cerr <<"gl_daostatmanager init rc_calltest error" <<endl;
		return -1;
	}
	gl_daostatmanager->stat_poller.start_timer(10);
	gl_daoconnectionmanager->connect_checker.start_timer(5);

	gl_thriftproxymsghandler=new ThriftPxMsgHandler();

	pxyHandler->setAppContext(sf->getAppContext());
	pxyHandler->setProxyProcessor(gl_thriftproxymsghandler);
	///
	pxyHandlerFordao->setAppContext(sf->getAppContext());
	pxyHandlerFordao->setProxyProcessor(gl_thriftproxymsghandler);
	///
	PxYYRequestProcessor __DaoResponseProcessor;
	sf->getAppContext()->addEntry(PxYYRequestProcessor::getFormEntries(), &__DaoResponseProcessor);

	///start x_timer
	g_pMainThreadQueue=sf->getMainThreadWriteQueue();
	g_pMainThreadQueue->push_to_mini_timer_loop(new CoreLoopTimerTask);



	ConsoleServer console;
	IServer* console_srv=sf->getServer(7878, SINGLETHREAD, 1000, 1,&console);
	console_srv->setLinkHandler(&console);
	console.setDaemonServer(sf->getDaemonServer());


	sf->startAllServer();
	sf->loop();

	return 0;
}