telnetConsole.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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. #include "platform/platformNet.h"
  28. /// Telnet admin console.
  29. ///
  30. /// Torque supports remote access to its console. This is most useful when
  31. /// running a dedicated server, as you can remotely administer the game
  32. /// (for instance, kicking people). In the context of a MMORPG, this sort of
  33. /// functionality would be useful for managing a server.
  34. ///
  35. /// There are a number of products for Tribes2 which allow remote administration
  36. /// via a nice GUI.
  37. ///
  38. /// @section telnetconsole_use Using the Telnet Console
  39. ///
  40. /// The TelnetConsole is designed to be used globally, so you don't instantiate
  41. /// it like a normal class.
  42. ///
  43. class TelnetConsole
  44. {
  45. NetSocket mAcceptSocket;
  46. S32 mAcceptPort;
  47. enum {
  48. PasswordMaxLength = 32 ///< Maximum length of the telnet and listen passwords.
  49. };
  50. bool mRemoteEchoEnabled;
  51. char mTelnetPassword[PasswordMaxLength+1];
  52. char mListenPassword[PasswordMaxLength+1];
  53. /// State of a TelnetClient.
  54. enum State
  55. {
  56. PasswordTryOne, ///< Allow three password attempts.
  57. PasswordTryTwo,
  58. PasswordTryThree,
  59. DisconnectThisDude, ///< If they've failed all three, disconnect them.
  60. FullAccessConnected, ///< They presented the telnetPassword, they get full access.
  61. ReadOnlyConnected ///< They presented the listenPassword, they get read only access.
  62. };
  63. /// Represents a connection to the telnet console.
  64. ///
  65. /// This is also a linked list.
  66. struct TelnetClient
  67. {
  68. NetSocket socket;
  69. char curLine[Con::MaxLineLength];
  70. S32 curPos;
  71. S32 state; ///< State of the client.
  72. /// @see TelnetConsole::State
  73. TelnetClient *nextClient;
  74. TelnetClient() { dStrncpy(curLine, "", Con::MaxLineLength); curPos = 0; state = 0; nextClient = NULL; }
  75. };
  76. TelnetClient *mClientList;
  77. TelnetConsole();
  78. ~TelnetConsole();
  79. public:
  80. static void create(); ///< Initialize the telnet console.
  81. static void destroy(); ///< Shut down the telnet console.
  82. void process(); ///< Called by the main loop to let the console process commands
  83. /// and connections.
  84. /// Configure the parameter for the telnet console.
  85. ///
  86. /// @param port Port on which to listen for connections.
  87. /// @param telnetPassword Password for full access to the console.
  88. /// @param listenPassword Password for read-only access to the console.
  89. /// @param remoteEcho Enable/disable echoing input back to the client
  90. void setTelnetParameters(S32 port, const char *telnetPassword, const char *listenPassword, bool remoteEcho = false);
  91. /// Callback to handle a line from the console.
  92. ///
  93. /// @note This is used internally by the class; you
  94. /// shouldn't need to call it.
  95. ///
  96. /// @see Con::addConsumer()
  97. void processConsoleLine(const char *line);
  98. };
  99. #endif