TelnetTransport.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /// \file
  11. /// \brief Contains TelnetTransport , used to supports the telnet transport protocol. Insecure
  12. ///
  13. #include "NativeFeatureIncludes.h"
  14. #if _RAKNET_SUPPORT_TelnetTransport==1 && _RAKNET_SUPPORT_TCPInterface==1
  15. #ifndef __TELNET_TRANSPORT
  16. #define __TELNET_TRANSPORT
  17. #include "TransportInterface.h"
  18. #include "DS_List.h"
  19. #include "Export.h"
  20. namespace RakNet
  21. {
  22. /// Forward declarations
  23. class TCPInterface;
  24. struct TelnetClient;
  25. /// \brief Use TelnetTransport to easily allow windows telnet to connect to your ConsoleServer
  26. /// \details To run Windows telnet, go to your start menu, click run, and in the edit box type "telnet <IP>" where <IP> is the ip address.<BR>
  27. /// of your ConsoleServer (most likely the same IP as your game).<BR>
  28. /// This implementation always echos commands.
  29. class RAK_DLL_EXPORT TelnetTransport : public TransportInterface
  30. {
  31. public:
  32. // GetInstance() and DestroyInstance(instance*)
  33. STATIC_FACTORY_DECLARATIONS(TelnetTransport)
  34. TelnetTransport();
  35. virtual ~TelnetTransport();
  36. bool Start(unsigned short port, bool serverMode);
  37. void Stop(void);
  38. void Send( SystemAddress systemAddress, const char *data, ... );
  39. void CloseConnection( SystemAddress systemAddress );
  40. Packet* Receive( void );
  41. void DeallocatePacket( Packet *packet );
  42. SystemAddress HasNewIncomingConnection(void);
  43. SystemAddress HasLostConnection(void);
  44. CommandParserInterface* GetCommandParser(void);
  45. void SetSendSuffix(const char *suffix);
  46. void SetSendPrefix(const char *prefix);
  47. protected:
  48. struct TelnetClient
  49. {
  50. SystemAddress systemAddress;
  51. char textInput[REMOTE_MAX_TEXT_INPUT];
  52. char lastSentTextInput[REMOTE_MAX_TEXT_INPUT];
  53. unsigned cursorPosition;
  54. };
  55. TCPInterface *tcpInterface;
  56. void AutoAllocate(void);
  57. bool ReassembleLine(TelnetTransport::TelnetClient* telnetClient, unsigned char c);
  58. // Crap this sucks but because windows telnet won't send line at a time, I have to reconstruct the lines at the server per player
  59. DataStructures::List<TelnetClient*> remoteClients;
  60. char *sendSuffix, *sendPrefix;
  61. };
  62. } // namespace RakNet
  63. #endif
  64. #endif // _RAKNET_SUPPORT_*
粤ICP备19079148号