ShellSession跟业务隔离

This commit is contained in:
xiongziliang
2017-12-01 11:42:49 +08:00
parent e2d509e63f
commit 473b9356a6
11 changed files with 183 additions and 1765 deletions

View File

@@ -28,7 +28,6 @@
#define SRC_SHELL_SHELLSESSION_H_
#include <functional>
#include "CMD.h"
#include "Common/config.h"
#include "Util/TimeTicker.h"
#include "Network/TcpLimitedSession.h"
@@ -40,40 +39,31 @@ using namespace ZL::Network;
namespace ZL {
namespace Shell {
class ShellSession: public TcpLimitedSession<MAX_TCP_SESSION>, public OutStream {
class ShellSession: public TcpLimitedSession<MAX_TCP_SESSION> {
public:
ShellSession(const std::shared_ptr<ThreadPool> &_th, const Socket::Ptr &_sock);
virtual ~ShellSession();
void onRecv(const Socket::Buffer::Ptr &) override;
void onError(const SockException &err) override;
void onError(const SockException &err) override {};
void onManager() override;
static void addUser(const string &userName,const string &userPwd){
g_mapUser[userName] = userPwd;
}
private:
friend class CMD_help;
inline bool onProcessLine(const string &);
inline void requestLogin();
inline void requestPasswd();
inline void sendHead();
inline bool authUser(const string &user, const string &pwd);
void response(const string &str) override{
send(str);
}
string &operator[](const string &key) override{
return m_mapConfig[key];
}
int erase(const string &key) override{
return m_mapConfig.erase(key);
}
inline bool onCommandLine(const string &);
inline bool onAuth(const string &user, const string &pwd);
inline void pleaseInputUser();
inline void pleaseInputPasswd();
inline void printShellPrefix();
function<bool(const string &)> m_requestCB;
string m_strRecvBuf;
Ticker m_beatTicker;
string m_strUserName;
unordered_map<string,string> m_mapConfig;
static unordered_map<string, string> g_mapUser;
static map<string, CMD&> g_mapCmd;
static string g_serverName;
};