#ifndef _GAME_FRAME_MANAGER_H_INCLUDE_
#define _GAME_FRAME_MANAGER_H_INCLUDE_

#include "../../include/Common/defines.h"
#include "../../include/molnet/Network.h"

#include "gameframe/DBOperator.h"
#include "gameframe/CPlayer.h"

#include <string.h>

using namespace network;

class GameFrameManager : public Singleton<GameFrameManager>
{
public:
	/// 캯
	GameFrameManager();
	/// 
	~GameFrameManager();

	/// ڴյϢ
	void OnProcessNetMes(uint32 connId,CMolMessageIn *mes);

	/// ڴϢ
	void OnProcessConnectedNetMes(uint32 connId);

	/// ڴڶϿϢ
	void OnProcessDisconnectNetMes(uint32 connId);

	/// Ϣ
	void UpdatePlayerInfo(Player *pPlayer);
	/// ·Ϣ
	void UpdateGameRoomInfo(void);
    /// Ϣ
    void OnProcessUserInfo(CPlayer *pPlayer);
    /// Ҷػط
    bool OnProcessReEnterRoomMes(uint32 connId);
    /// ½һµ
    CPlayer* CreateNewPlayer(void);
    /// ָҵ½ɹϢ
    void SendPlayerLoginSuccess(CPlayer *pPlayer);
    /// ڴû뷿
    bool JoinPlayerToGameRoom(CPlayer *pPlayer,int pRoomIndex=-1,int pChairIndex=-1,bool isQueue=true);
	/// ұ׼ʼϷ
	void OnProcessGameReadyMatchingMes(CPlayer *pPlayer);

public:
	/// ڴû¼Ϣ
	void OnProcessUserLoginMes(uint32 connId,Json::Value &mes);
    /// ȴϷϢ
    void OnProcessFrameMes(uint32 connId,Json::Value &mes);
    /// ڴû׼Ϣ
    void OnProcessGameReadyMes(uint32 connId,Json::Value &mes);
    /// ڴû뿪Ϣ
    void OnProcessGameLeaveRoomMes(uint32 connId,Json::Value &mes,bool ismatching=false);

public:
	/// һҵŶб
	void AddQueueList(CPlayer *connId);
	/// ɾһҴŶб
	void DelQueueList(uint32 connId);
	/// Ŷб
	void UpdateQueueList(void);
	/// »
	void UpdateRobot(void);
	/// Ŷб
	void ClearQueueList(void);

public:
	/// ͵ǰŶ
	void SendQueuingCount(void);
	/// õǰŶ
    int GetCurrentQueuePlayerCount(void);
	/// õǰŶ
	int GetQueueRealPlayerCount(void);
	/// õǰŶӻ
	int GetQueueRobotPlayerCount(void);

public:
    /// ϵǮ
    void UpdatePlayerMoney(Player *pPlayer);
    /// ڴû뷿
    bool AddPlayerInServer(CPlayer *pPlayer,int pRoomIndex,int pChairIndex,bool isQueue,bool isGaming);

private:
	std::map<uint32,CPlayer*> m_PlayerQueueList;                 /**< Ŷб */
	Mutex m_PlayerQueueListLock;                                 /**< Ŷб */
};

#define ServerGameFrameManager GameFrameManager::getSingleton()

#endif
