//this file is part of NeoMule
//Copyright (C)2006-2007 David Xanatos ( Xanatos@Lycos.at / http://neomule.sourceforge.net )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#pragma once

#include "MapKey.h"

#ifdef ARGOS // NEO: NA - [NeoArgos] -- Xanatos -->

#define DFLT_DLP_FILENAME _T("dlp.dll")

struct TTestClient{
	uint32		IP;

	CString		strNick;
	CString		strMod;
	CString		strSoft;
	uchar		abyHash[16]; 
};

struct TArgosResult{
	bool		GPLBreaker; // allow 0-score
	CString		Comment;
};

struct TXsExploitEntry{
	uint16		m_uFastXSCounter;
	uint16		m_uXSReqs;
	uint16		m_uXSAnswer;

	DWORD		m_dwInserted;
};

class CArgos: public CWinThread
{
public:
	CArgos();
	~CArgos();

	void	Process();

	//void	ArgosCheckSoftware(CUpDownClient* Client);
	void	CheckForNickThief(CUpDownClient* Client);
	void	CheckForModThief(CUpDownClient* Client);

	void	IncXSReqs(uint32 uIP);
	void	IncXSAnswer(uint32 uIP);
	bool	CheckXSAsk(CUpDownClient* Client);

	void	CheckClient(CUpDownClient* Client);

	CString	GetAntiNickThiefNick();

	bool	LoadDLPlibrary();
	void	UnLoadDLPlibrary();

	CString GetDefaultFilePathDLP() const;
	
	void	EndThread();

private:
	
	// Scanner Engine
	static UINT RunProc(LPVOID pParam);
	UINT	RunInternal();

	// DLP
	TArgosResult* PerformDLPCheck(TTestClient* TestClient);

	// Anti XsExploit
	TXsExploitEntry* GetXsExploitEntry(uint32 uIP);
	void	CreateAntiNickThiefTag();

	void	ClearXsMonitorList();

	// Test queue
    CTypedPtrList<CPtrList, TTestClient*> m_TestClientQueue;

	// Anti XsExploit
	CMap<uint32,uint32,TXsExploitEntry*,TXsExploitEntry*> m_XsMonitorList;
	uint32	m_dwLastTrackedCleanUp;

	// Nick Tag
	CString m_sAntiNickThiefTag;

	// Thread handling
	CCriticalSection threadLocker;
	CCriticalSection QueueLocker;

	CEvent* threadEndedEvent;
	bool doRun;

	// DLP
	HINSTANCE m_dlpInstance;

	typedef uint32 (__cdecl *DLPGETVERSION)();
	typedef bool (__cdecl *DLPINITIALISE)(UINT preferences, void(*log)(int,CString));
	typedef bool (__cdecl *DLPCHECKCLIENT)(TTestClient* client, TArgosResult*& result);
	DLPCHECKCLIENT m_dlpCheckClient;
};

#endif // ARGOS // NEO: NA END <-- Xanatos --