/*
	Filename	:	whuser.cpp
	Author(s)	:	winholdem development
	Date		:	2004-JUN-25
	Copyright	:	(c) 2004 HixoxiH Software
	History		:
*/

#define WHUSER_EXPORTS

#include "whuser.h"
#include <windows.h>

/////////////////////////////////////
//card macros
#define RANK(c)			((c>>4)&0x0f)
#define SUIT(c)			((c>>0)&0x0f)
#define ISCARDBACK(c)	(c==0xff)
#define ISUNKNOWN(c)	(c==0)
/////////////////////////////////////

////////////////////////////////////
//consecutive states
holdem_state	m_holdem_state[256];
unsigned char	m_ndx;
////////////////////////////////////

pfgws_t m_pget_winholdem_symbol;

double process_query( const char* pquery )
{
	if (pquery==NULL)
		return 0;

	//////////////////////////////////////
	//test symbols dll$test0 - dll$test9//
	//////////////////////////////////////
	if (strncmp(pquery,"dll$test",8)==0)
		return (pquery[8]-'0');

	//dll$alli logic here
	//dll$rais logic here
	//dll$call logic here
	//dll$play logic here

	return 0;
}

double process_state( holdem_state* pstate )
{
	if (pstate!=NULL)
		m_holdem_state[ (++m_ndx)&0xff ] = *pstate;

	return 0;
}

/////////////////////////////////////////////////////
//WINHOLDEM RUNTIME ENTRY POINT
/////////////////////////////////////////////////////
WHUSER_API double process_message
(
	const char* pmessage,	//type
	const void* param		//data
)
{
	if (pmessage==NULL)
	{
		return 0;
	}

	if (param==NULL)
	{
		return 0;
	}

	if (strcmp(pmessage,"state")==0)
	{
		return process_state( (holdem_state*)param );
	}

	if (strcmp(pmessage,"query")==0)
	{
		return process_query( (const char*)param );
	}
	
	if (strcmp(pmessage,"pfgws")==0)
	{	
		m_pget_winholdem_symbol = (pfgws_t)param;
		return 0;
	}

	return 0;
}
/////////////////////////////////////////////////////

/////////////////////////////////
//DLLMAIN
/////////////////////////////////
BOOL APIENTRY DllMain
(
	HANDLE hModule				, 
	DWORD  ul_reason_for_call	, 
	LPVOID lpReserved
)
{
    switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
		case DLL_PROCESS_DETACH:
			break;
    }
    return TRUE;
}
/////////////////////////////////