telnetConsole.h 4.2 KB

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