Files
znc/Client.h
psychon f2d7ae1a08 Change a bunch of tabs into spaces
At the beginning of lines, one uses tabs for indenting. In the middle of the
line, you use spaces. If you want two different lines to line up with each
other, you start them with the same number of tabs and use spaces for the rest
of the indenting in the "other" line.

Really, that's how one does it!


git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1963 726aef4b-f618-498e-8847-2d620e286838
2010-05-01 20:15:01 +00:00

144 lines
3.6 KiB
C++

/*
* Copyright (C) 2004-2010 See the AUTHORS file for details.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published
* by the Free Software Foundation.
*/
#ifndef _CLIENT_H
#define _CLIENT_H
#include "Socket.h"
#include "Utils.h"
#include "main.h"
// Forward Declarations
class CZNC;
class CUser;
class CIRCSock;
class CClient;
// !Forward Declarations
class CAuthBase {
public:
CAuthBase(const CString& sUsername, const CString& sPassword, Csock *pSock) {
SetLoginInfo(sUsername, sPassword, pSock);
}
virtual ~CAuthBase() {}
virtual void SetLoginInfo(const CString& sUsername, const CString& sPassword,
Csock *pSock) {
m_sUsername = sUsername;
m_sPassword = sPassword;
m_pSock = pSock;
}
void AcceptLogin(CUser& User);
void RefuseLogin(const CString& sReason);
const CString& GetUsername() const { return m_sUsername; }
const CString& GetPassword() const { return m_sPassword; }
Csock *GetSocket() const { return m_pSock; }
CString GetRemoteIP() const;
// Invalidate this CAuthBase instance which means it will no longer use
// m_pSock and AcceptLogin() or RefusedLogin() will have no effect.
virtual void Invalidate();
protected:
virtual void AcceptedLogin(CUser& User) = 0;
virtual void RefusedLogin(const CString& sReason) = 0;
private:
CString m_sUsername;
CString m_sPassword;
Csock* m_pSock;
};
class CClientAuth : public CAuthBase {
public:
CClientAuth(CClient* pClient, const CString& sUsername, const CString& sPassword);
virtual ~CClientAuth() {}
void Invalidate() { m_pClient = NULL; CAuthBase::Invalidate(); }
void AcceptedLogin(CUser& User);
void RefusedLogin(const CString& sReason);
private:
protected:
CClient* m_pClient;
};
class CClient : public CZNCSock {
public:
CClient() : CZNCSock() {
m_pUser = NULL;
m_bGotPass = false;
m_bGotNick = false;
m_bGotUser = false;
m_bNamesx = false;
m_bUHNames = false;
EnableReadLine();
// RFC says a line can have 512 chars max, but we are
// a little more gentle ;)
SetMaxBufferThreshold(1024);
SetNick("unknown-nick");
}
virtual ~CClient();
void AcceptLogin(CUser& User);
void RefuseLogin(const CString& sReason);
CString GetNick(bool bAllowIRCNick = true) const;
CString GetNickMask() const;
bool HasNamesx() const { return m_bNamesx; }
bool HasUHNames() const { return m_bUHNames; }
void UserCommand(CString& sCommand);
void StatusCTCP(const CString& sCommand);
void BouncedOff();
bool IsAttached() const { return m_pUser != NULL; }
void PutIRC(const CString& sLine);
void PutClient(const CString& sLine);
unsigned int PutStatus(const CTable& table);
void PutStatus(const CString& sLine);
void PutStatusNotice(const CString& sLine);
void PutModule(const CString& sModule, const CString& sLine);
void PutModNotice(const CString& sModule, const CString& sLine);
virtual void ReadLine(const CString& sData);
bool SendMotd();
void HelpUser();
void AuthUser();
virtual void Connected();
virtual void Timeout();
virtual void Disconnected();
virtual void ConnectionRefused();
virtual void ReachedMaxBuffer();
void SetNick(const CString& s);
CUser* GetUser() const { return m_pUser; }
const CIRCSock* GetIRCSock() const;
CIRCSock* GetIRCSock();
private:
protected:
bool m_bGotPass;
bool m_bGotNick;
bool m_bGotUser;
bool m_bNamesx;
bool m_bUHNames;
CUser* m_pUser;
CString m_sNick;
CString m_sPass;
CString m_sUser;
CSmartPtr<CAuthBase> m_spAuth;
};
#endif // !_CLIENT_H