TelnetServer.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #pragma once
  2. #include "IOCPSocketServer.h"
  3. #include "AutoLock.h"
  4. #include <map>
  5. #include <list>
  6. #include <vector>
  7. using namespace std;
  8. class CTelnetServer : public CIOCPSocketServer
  9. {
  10. public:
  11. CTelnetServer(void);
  12. virtual ~CTelnetServer(void);
  13. vector<string> SplitString(const char *pLine, char notDelimiterChars[] = NULL);
  14. void SetIgnoreArrowKeys(bool bIgnore){m_bIgnoreArrowKey = bIgnore;}
  15. protected:
  16. virtual void OnEvent(const char *pFormat, ...);
  17. virtual void OnError(const char *pFormat, ...);
  18. virtual string GetPromptString() { return "Telnet Service> ";}
  19. virtual string GetHelloString() { return "Welcome to telnet service, for any help, press [?] or [help]\r\n";}
  20. virtual bool ParseCmdLine(int nConnectionID, const char *pCmdLine, string &strReplyMsg)
  21. {
  22. strReplyMsg = "not supported command: {";
  23. strReplyMsg += pCmdLine;
  24. strReplyMsg += "}\r\n";
  25. return false;
  26. }
  27. string GetLocalTimeString(bool bShort = true);
  28. private:
  29. void OnAccepte(int nConnectionID, const char *pRemoteAddr, int nPort);
  30. void OnSend(int nConnectionID, int nSendLen);
  31. void OnReceive(int nConnectionID, char *pData, int nRecvLen);
  32. void OnClose(int nConnectionID);
  33. string GetErrorReplyString(string errMsg);
  34. bool IsCharIncluded(char ch, char chars[]);
  35. void OnConsoleOutput(bool bError, const char *pFormat, va_list arg);
  36. CLockObject m_LockObject;
  37. struct SessionContext;
  38. map<int, SessionContext*> m_SessionContext;
  39. bool m_bIgnoreArrowKey;
  40. };