#ifndef _CMDHELPER_H_
#define _CMDHELPER_H_

#include "cdefines.h"
#include <string>
#include <sstream>
//////////////////////////////////////////////////////////////////////////
#define MAX_SELECT_GANG					4									/*!< ѡ */
#define MAX_FAN_STYLE					20									/*!<  */
//////////////////////////////// Ϣ //////////////////////////////////////////

/*
//! 齫
/*! ,ׯҿܷƾв,ܡ */
typedef struct tagCMD_S_DealMJ
{
	int32							iBankerUser;							/*!< ׯ */
	int32							iIsRandomBanker;						/*!< Ƿȷׯ */
	int32 							iBaseScore;								/*!<  */
	int32							iDiceNum01;								/*!< 01 ȷׯ */
	int32							iDiceNum02;								/*!< 02 ȷׯ*/
	int32							iDiceNum11;								/*!< 11 ȷλ*/
	int32							iDiceNum12;								/*!< 12 ȷλ*/

	int32							iUserChairID;							/*!< λ */

	int32							iHandMJCount;							/*!< 齫Ŀ */
	MJBYTE							bHandMJ[MAX_HAND_MJ];					/*!< 齫 */
	MJFLAG							bOperation;
	int32							iStatMJPos;								/*!< ʼλ */

	int32							iGangCount;								/*!< Ŀ */
	MJBYTE							bMJGang[MAX_SELECT_GANG];				/*!< ɸܵ*/

	int size()
	{
		return sizeof(tagCMD_S_DealMJ);// - (MAX_HAND_MJ-iHandMJCount)*sizeof(MJBYTE) - (MAX_HAND_MJ-iMJGangCount)*sizeof(MJBYTE);
	}
}CMD_S_DealMJ, *PCMD_S_DealMJ;

/*! 
/*! ƺ,ҿеĲ */
typedef struct tagCMD_S_OutMJ
{
	MJBYTE							bOutMJ;									/*!<  */
	int32							wOutMJUser;								/*!<  */

	MJFLAG							bOperation;
	int32							isOtherPriority;

	int32							isTimeOut;								/*!< Ƿʱɷ */

	int size()
	{
		return sizeof(tagCMD_S_OutMJ);
	}
}CMD_S_OutMJ,*PCMD_S_OutMJ;

//! 
/*! ƺ,еĲ */
typedef struct tagCMD_S_TouchMJ
{
	MJBYTE							bTouchMJ;								/*!<  */
	int32							bTouchType;								/*!< 0ƣ1ǽ */
	int32							wCurrentUser;							/*!< ǰ */

	MJFLAG							bOperation;
	int32							isOtherPriority;
	MJFLAG							bGangType;								/*!< ܵ,,bOperationGANGЧ */

	int32							iGangCount;								/*!< Ŀ */
	MJBYTE							bMJGang[MAX_SELECT_GANG];				/*!< ɸܵ*/

	int size()
	{
		return sizeof(tagCMD_S_TouchMJ);
	}
}CMD_S_TouchMJ, *PCMD_S_TouchMJ;

//! û
/*! ûƺ,ҿеĲ */
typedef struct tagCMD_S_PengMJ
{
	int32							wLastOutUser;							/*!< ϴγ */
	int32							wCurrentUser;							/*!<  */
	MJBYTE							bMJPeng;								/*!<  */

	MJFLAG							bOperation;
	int32							isOtherPriority;

	int size()
	{
		return sizeof(tagCMD_S_PengMJ);
	}
}CMD_S_PengMJ, *PCMD_S_PengMJ;

//! 
/*! ƺ,ҿеĲ */
typedef struct tagCMD_S_GangMJ
{
	MJFLAG							bGangType;								/*!<  */
	int32							wCurrentUser;							/*!<  */
	int32							wOutMJUser;								/*!<  */
	MJBYTE							bMJGang;								/*!<  */

	MJFLAG							bOperation;
	int32							isOtherPriority;

	int32							iGangScore;									/*!< η۳ķ */

	int size()
	{
		return sizeof(tagCMD_S_GangMJ);
	}
}CMD_S_GangMJ, *PCMD_S_GangMJ;

//! Բ
/*! Բ,ҿеĲ */
typedef struct tagCMD_S_GiveUp
{
	MJFLAG							bOperation;								/*!< ˵ĲȨ */
	MJBYTE							bOutMJ;									/*!< Ե */
	int32							isOtherPriority;						/*!< ǷȼߵĲֻԵǰң */
	int32							isOtherHu;								/*!< һڶʱҿԺ*/
	int32							iOperUser;								/*!< ǰ */
	int32							iLastOutUser;							/*!<  */

	int size()
	{
		return sizeof(tagCMD_S_GiveUp);
	}
}CMD_S_GiveUp, *PCMD_S_GiveUp;

//! Һ
/*! ƺ */
typedef struct tagCMD_S_HU
{
	MJBYTE							bUserHuMJ;										/*!<  */
	int32							iHuUser;										/*!< Ƶˣ ǿˣôǿ */
	int32							iDianPaoUser;									/*!< ڵˣ ôΪ */

	enHuType						enhuType;										/*!< Ϸ */

	int64							iNomalFan;											/*!< ҵܷ*/
	int64							iExtraFan;										/*!< ҵܷ*/
	int64							iHuScore;										/*!< ķ*/
	int64							iGangScore;										/*!< ηķ*/
	int64							iDianPaoScore;									/*!< ڵķ*/
	int64							iAllScore;										/*!< ܷ*/

	int32							iFanStyle[MAX_FAN_STYLE];						/*!< */

	int32							iAlreadyHu;										/*!< Ѿ*/

	MJFLAG							bOperation;										/*!< ˵ĲȨ */
	int32							isOtherPriority;								/*!< ǷȼߵĲֻԵǰң */
	int32							isNowOper;										/*!< ǿڲڳ */
	int32							isOtherHu;										/*!< һڶʱǷܺΪ1 */

	MJFLAG							bGangType;
	int32							iGangCount;
	MJBYTE							bMJGang[MAX_SELECT_GANG];

	int size()
	{
		return sizeof(tagCMD_S_HU);
	}
}CMD_S_HU, *PCMD_S_HU;


//! Һ
/*! ƺ */
typedef struct tagCMD_S_GameOver
{
	MJBlock							bHUMj[GAME_PLAYER][MAX_BLOCK_COUNT];			/*!< ƿ(ܵ) */
	MJBYTE							bHUMjCount[GAME_PLAYER];						/*!< ƿ */
	MJBYTE							bHandMj[GAME_PLAYER][MAX_HAND_MJ];				/*!< е */
	MJBYTE							bHandMjCount[GAME_PLAYER];						/*!< еƵ */
	MJBYTE							bOutMj[GAME_PLAYER][MAX_OUT_MJ];				/*!< Ѿ */
	MJBYTE							bOutMjCount[GAME_PLAYER];						/*!< ѾƵ */

	int32							iDianPaoUser[GAME_PLAYER];						/*!< ڵˣ ôΪ */

	enEndGameType					enEndType;										/*!< Ϸ */
	enHuType						enhuType[GAME_PLAYER];							/*!< Ϸ */

	int64							iNomalFan[GAME_PLAYER];							/*!< ÿҵܷ*/
	int64							iExtraFan[GAME_PLAYER];
	int64							iFanScore[GAME_PLAYER];							/*!< ÿҷ÷*/
	int64							iGangScore[GAME_PLAYER];						/*!< ÿҹη÷*/
	int64							iTotalScore[GAME_PLAYER];						/*!< ܷ*/

	enUserEndType					enUSEndType[GAME_PLAYER];						/*!< Ϸʱҵ״̬ƽδ*/

	int32							isChangeTable;									/*!< Ƿ*/

	int32							iFanStyle[GAME_PLAYER];							/*!< */

	int size()
	{
		return sizeof(tagCMD_S_GameOver);
	}
}CMD_S_GameOver, *PCMD_S_GameOver;

//! й
/*! й */
typedef struct tagCMD_S_Trustee
{
	int32							bUserTrustee;				//Ƿй	0ȡйܣ1ʼй
	int32							iUserChairID;				//

	int size()
	{
		return sizeof(tagCMD_S_Trustee);
	}
}CMD_S_Trustee, *PCMD_S_Trustee;


//! ػϷ
/*! ػϷػ */
typedef struct tagCMD_S_ReEnterRoom
{
	int32							iBankerUser;							/*!< ׯ */
	int32 							iBaseScore;								/*!<  */
	int32							iIsRandomBanker;						/*!< Ƿȷׯ */
	int32							iDiceNum01;								/*!< 01 ȷׯ */
	int32							iDiceNum02;								/*!< 02 ȷׯ*/
	int32							iDiceNum11;								/*!< 11 ȷλ*/
	int32							iDiceNum12;								/*!< 12 ȷλ*/

	int32							iUserChairID;							/*!< λ */

	int32							iHandMJCount[GAME_PLAYER];				/*!< 齫Ŀ */
	MJBYTE							bHandMJ[GAME_PLAYER][MAX_HAND_MJ];		/*!< 齫 */
	int32							iHuMJCount[GAME_PLAYER];				/*!< 齫Ŀ */
	MJBlock							bHuMJ[GAME_PLAYER][MAX_BLOCK_COUNT];	/*!< 齫 */
	int32							iOutMJCount[GAME_PLAYER];				/*!< 齫Ŀ */
	MJBYTE							bOutMJ[GAME_PLAYER][MAX_OUT_MJ];		/*!< 齫 */

	enPlayerStatu					enUserStatu[GAME_PLAYER];				/*!< ״̬ */

	int32							iOldOperUser;							/*!<  */
	int32							iCurrentUser;							/*!< ǰ */

	int32							isOtherPriority;

	int64							iHuFan;										/*!< Ƶܷ*/
	int64							iGangFan;									/*!< ηܷ*/
	int64							iHuScore;									/*!< ķ*/
	int64							iGangScore;									/*!< η۳ķ */
	int64							iFanStyle[MAX_FAN_STYLE];					/*!< */

	enHuType						enhuType;										/*!< Ϸ */
	int32							iDianPaoUser;								/*!< ڵˣ ôΪ */
	MJBYTE							bDianPaoMJ[GAME_PLAYER];							/*!< ڵʹãδΪ0*/

	int32							isForceQuit;								/*< ǷѾ߳ */
	int32							isYiPaoDuoXiang;							/*< ˺ƣǲһڶ */
	int32							iReadyPlayer;								/*< ڷ֮ǰмѾ׼ */

	int size()
	{
		return sizeof(tagCMD_S_ReEnterRoom);
	}
}CMD_S_ReEnterRoom, *PCMD_S_ReEnterRoom;

//齫
typedef struct tagCMD_S_MJ
{
	MJBlock							bHUMj[GAME_PLAYER][MAX_BLOCK_COUNT];			/*!< ƿ(ܵ) */
	MJBYTE							bHUMjCount[GAME_PLAYER];						/*!< ƿ */
	MJBYTE							bHandMj[GAME_PLAYER][MAX_HAND_MJ];				/*!< е */
	MJBYTE							bHandMjCount[GAME_PLAYER];						/*!< еƵ */
	MJBYTE							bOutMj[GAME_PLAYER][MAX_OUT_MJ];				/*!< Ѿ */
	MJBYTE							bOutMjCount[GAME_PLAYER];						/*!< ѾƵ */

	int size()
	{
		return sizeof(tagCMD_S_MJ);
	}
}CMD_S_MJ, *PCMD_S_MJ;

//! 
/*! Ϣ */
typedef struct tagCMD_S_Chat
{
	int32							iChatUser;										/*!< Ϣ */
	int32							iFaceID;										/*!< ID */
	int32							iTalkID;											/*!< ID */
	enChatType						bType;											/*!< Ϣͣ顢֣ */

	int size()
	{
		return sizeof(tagCMD_S_Chat);
	}
}CMD_S_Chat,*PCMD_S_Chat;

/////////////////////////////ͻϢ/////////////////////////////////////////////
//! 
/*! ܳƲҳ */
typedef struct tagCMD_C_OutMJ
{
	MJBYTE							bOutMJ;									/*!<  */
	int size()
	{
		return sizeof(tagCMD_C_OutMJ);
	}
}CMD_C_OutMJ,*PCMD_C_OutMJ;

//! 
/*! ܵƼ */
typedef struct tagCMD_C_GangMJ
{
	MJBYTE							bGangMJ;									/*!<  */
	enOperationGangType				bGangType;
	int size()
	{
		return sizeof(tagCMD_C_GangMJ);
	}
}CMD_C_GangMJ,*PCMD_C_GangMJ;

//! 
/*! Ϣ */
typedef struct tagCMD_C_Chat
{
	int32							iFaceID;										/*!< ID */
	int32							iTalkID;											/*!< ID */
	enChatType						bType;											/*!< Ϣͣ顢֣ */

	int size()
	{
		return sizeof(tagCMD_C_Chat);
	}
}CMD_C_Chat,*PCMD_C_Chat;

//////////////////////////////////////////////////////////////////////////
class CmdHelper
{
public:
	//////
	///////////////////////////// CMD_S_DealMJ /////////////////////////////////////////////
	static bool CodeMessage(tagCMD_S_DealMJ &info, Json::Value &msg);

	static bool DeCodeMessage(tagCMD_S_DealMJ &info, Json::Value &msg);

	////////////////////////////// CMD_S_OutMJ ////////////////////////////////////////////
	static bool CodeMessage(CMD_S_OutMJ &info, Json::Value &msg);

	static bool DeCodeMessage(CMD_S_OutMJ &info, Json::Value &msg);

	/////////////////////////////// CMD_S_TouchMJ ///////////////////////////////////////////
	static bool CodeMessage(CMD_S_TouchMJ &info, Json::Value &msg);

	static bool DeCodeMessage(CMD_S_TouchMJ &info, Json::Value &msg);

	///////////////////////////////// CMD_S_PengMJ /////////////////////////////////////////
	static bool CodeMessage(CMD_S_PengMJ &info, Json::Value &msg);

	static bool DeCodeMessage(CMD_S_PengMJ &info, Json::Value &msg);

	///////////////////////////////// CMD_S_GangMJ /////////////////////////////////////////
	static bool CodeMessage(CMD_S_GangMJ &info, Json::Value &msg);

	static bool DeCodeMessage(CMD_S_GangMJ &info, Json::Value &msg);

	/////////////////////////////////// CMD_S_GiveUp ///////////////////////////////////////
	static bool CodeMessage(CMD_S_GiveUp &info, Json::Value &msg);

	static bool DeCodeMessage(CMD_S_GiveUp &info, Json::Value &msg);

	/////////////////////////////////// CMD_S_TRUSTEE ///////////////////////////////////////
	static bool CodeMessage(CMD_S_Trustee &info, Json::Value &msg);

	static bool DeCodeMessage(CMD_S_Trustee &info, Json::Value &msg);

	/////////////////////////////////// CMD_S_HU ///////////////////////////////////////
	static bool CodeMessage(CMD_S_HU &info, Json::Value &msg);

	static bool DeCodeMessage(CMD_S_HU &info, Json::Value &msg);

	/////////////////////////////////// CMD_S_GameOver ///////////////////////////////////////
	static bool CodeMessage(CMD_S_GameOver &info, Json::Value &msg);

	static bool DeCodeMessage(CMD_S_GameOver &info, Json::Value &msg);

	/////////////////////////////////// CMD_S_ReEnterRoom ///////////////////////////////////////
	static bool CodeMessage(CMD_S_ReEnterRoom &info, Json::Value &msg);

	static bool DeCodeMessage(CMD_S_ReEnterRoom &info, Json::Value &msg);

	/////////////////////////////////// CMD_S_MJ ///////////////////////////////////////
	static bool CodeMessage(CMD_S_MJ &info, Json::Value &msg);

	static bool DeCodeMessage(CMD_S_MJ &info, Json::Value &msg);

	/////////////////////////////////// CMD_S_Chat ///////////////////////////////////////
	static bool CodeMessage(CMD_S_Chat &info, Json::Value &msg);

	static bool DeCodeMessage(CMD_S_Chat &info, Json::Value &msg);

	//////ͻ
	//////////////////////////////// CMD_C_OutMJ //////////////////////////////////////////
	static bool CodeMessage(CMD_C_OutMJ &info, Json::Value &msg);

	static bool DeCodeMessage(CMD_C_OutMJ &info, Json::Value &msg);

	//////////////////////////////// CMD_C_GangMJ //////////////////////////////////////////
	static bool CodeMessage(CMD_C_GangMJ &info, Json::Value &msg);

	static bool DeCodeMessage(CMD_C_GangMJ &info, Json::Value &msg);

	//////////////////////////////// CMD_C_Chat //////////////////////////////////////////
	static bool CodeMessage(CMD_C_Chat &info, Json::Value &msg);

	static bool DeCodeMessage(CMD_C_Chat &info, Json::Value &msg);

};


#endif

