telnetConsole.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _TELNETCONSOLE_H_
  23. #define _TELNETCONSOLE_H_
  24. #ifndef _CONSOLE_H_
  25. #include "console/console.h"
  26. #endif
  27. /// Telnet admin console.
  28. ///
  29. /// Torque supports remote access to its console. This is most useful when
  30. /// running a dedicated server, as you can remotely administer the game
  31. /// (for instance, kicking people). In the context of a MMORPG, this sort of
  32. /// functionality would be useful for managing a server.
  33. ///
  34. /// There are a number of products for Tribes2 which allow remote administration
  35. /// via a nice GUI.
  36. ///
  37. /// @section telnetconsole_use Using the Telnet Console
  38. ///
  39. /// The TelnetConsole is designed to be used globally, so you don't instantiate
  40. /// it like a normal class. Instead, you allow it to manage itself:
  41. ///
  42. /// @code
  43. /// // How to initialize the TelnetConsole.
  44. /// TelnetConsole::create();
  45. ///
  46. /// // How to shut down the TelnetConsole.
  47. /// TelnetConsole::destroy();
  48. /// @endcode
  49. ///
  50. ///
  51. class TelnetConsole
  52. {
  53. NetSocket mAcceptSocket;
  54. S32 mAcceptPort;
  55. enum {
  56. PasswordMaxLength = 32 ///< Maximum length of the telnet and listen passwords.
  57. };
  58. bool mRemoteEchoEnabled;
  59. char mTelnetPassword[PasswordMaxLength+1];
  60. char mListenPassword[PasswordMaxLength+1];
  61. ConsoleEvent mPostEvent;
  62. /// State of a TelnetClient.
  63. enum State
  64. {
  65. PasswordTryOne, ///< Allow three password attempts.
  66. PasswordTryTwo,
  67. PasswordTryThree,
  68. DisconnectThisDude, ///< If they've failed all three, disconnect them.
  69. FullAccessConnected, ///< They presented the telnetPassword, they get full access.
  70. ReadOnlyConnected ///< They presented the listenPassword, they get read only access.
  71. };
  72. /// Represents a connection to the telnet console.
  73. ///
  74. /// This is also a linked list.
  75. struct TelnetClient
  76. {
  77. NetSocket socket;
  78. char curLine[Con::MaxLineLength];
  79. S32 curPos;
  80. S32 state; ///< State of the client.
  81. /// @see TelnetConsole::State
  82. TelnetClient *nextClient;
  83. };
  84. TelnetClient *mClientList;
  85. TelnetConsole();
  86. ~TelnetConsole();
  87. public:
  88. static void create(); ///< Initialize the telnet console.
  89. static void destroy(); ///< Shut down the telnet console.
  90. void process(); ///< Called by the main loop to let the console process commands
  91. /// and connections.
  92. /// Configure the parameter for the telnet console.
  93. ///
  94. /// @param port Port on which to listen for connections.
  95. /// @param telnetPassword Password for full access to the console.
  96. /// @param listenPassword Password for read-only access to the console.
  97. /// @param remoteEcho Enable/disable echoing input back to the client
  98. void setTelnetParameters(S32 port, const char *telnetPassword, const char *listenPassword, bool remoteEcho = false);
  99. /// Callback to handle a line from the console.
  100. ///
  101. /// @note This is used internally by the class; you
  102. /// shouldn't need to call it.
  103. ///
  104. /// @see Con::addConsumer()
  105. void processConsoleLine(const char *line);
  106. };
  107. extern TelnetConsole *TelConsole;
  108. #endif