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); } }
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 } }