#include "BillMessage_KOR.inh"
//////////////
// 사용자 타입
#define BILL_USER_FREE			0		// 무료 사용자


////////////
// 지불 형식
#define BILL_PAY_FREE			0		// 무료 이용

#include "BPacket.h"
#include "BInputBuffer.h"
#include "BInputQueue.h"
#include "BOutputBuffer.h"
#include "DBCmd.h"

//////////////////
// 빌링 클라이언트
class CBillingClient
{
	bool		m_brunning;
	int			m_idleTics;
	CBPacket				m_connmsg;

public:
	bool				m_btrying;
	socket_t			m_desc;

	CBInputBuffer		m_inBuf;					// Input Buffer
	CBInputQueue		m_inQ;						// Input Packet Queue
	CBOutputBuffer		m_outBuf;					// Output Network Message Queue

	CBillingClient();

	bool IsRunning();
	bool IsTrying();
	bool Create();
	void Close();

#ifdef CIRCLE_WINDOWS
	static void BillingConnect(LPVOID p);
#else
	static void* BillingConnect(void* p);
#endif

private:
	void SendHeader();

	void OnCashBalance(CBPacket &pack);
	void OnCanBuy(CBPacket &pack);
	void OnBuy(CBPacket &pack);

#ifdef CASH_ITEM_COUPON
	void OnCashCouponList(CBPacket &pack);
	void OnBuyByCoupon(CBPacket &pack);
#endif //CASH_ITEM_COUPON

public:

	bool ProcessInput();
	bool ProcessOutput();
	void WriteToOutput(CBPacket& pack);

	void ProcessBilling();

	bool Login(const char* name, const char* pw, const char* ip);
	bool Logout(const char* name);
};
