212 lines
6.5 KiB
C
212 lines
6.5 KiB
C
|
|
#pragma once
|
||
|
|
#include "cocos2d.h"
|
||
|
|
#include "PlatformHeader.h"
|
||
|
|
#include "SocketMission.h"
|
||
|
|
#include "IClientKernelSink.h"
|
||
|
|
#include "IUserManagerSink.h"
|
||
|
|
#include "ClientUserManager.h"
|
||
|
|
|
||
|
|
//服务状态
|
||
|
|
enum enServiceStatus
|
||
|
|
{
|
||
|
|
ServiceStatus_Unknow, //未知状态
|
||
|
|
ServiceStatus_Entering, //进入状态
|
||
|
|
ServiceStatus_Validate, //验证状态
|
||
|
|
ServiceStatus_RecvInfo, //读取状态
|
||
|
|
ServiceStatus_ServiceIng, //服务状态
|
||
|
|
ServiceStatus_NetworkDown, //中断状态
|
||
|
|
};
|
||
|
|
|
||
|
|
//游戏退出代码
|
||
|
|
enum enGameExitCode
|
||
|
|
{
|
||
|
|
GameExitCode_Normal, //正常退出
|
||
|
|
GameExitCode_CreateFailed, //创建失败
|
||
|
|
GameExitCode_Timeout, //定时到时
|
||
|
|
GameExitCode_Shutdown, //断开连接
|
||
|
|
};
|
||
|
|
|
||
|
|
//房间退出代码
|
||
|
|
enum enServerExitCode
|
||
|
|
{
|
||
|
|
ServerExitCode_Normal, //正常退出
|
||
|
|
ServerExitCode_Shutdown, //断开连接
|
||
|
|
};
|
||
|
|
|
||
|
|
class GameMission : public CSocketMission, public IUserManagerSink
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
GameMission();
|
||
|
|
|
||
|
|
//设置内核接口
|
||
|
|
virtual void SetClientKernelSink(IClientKernelSink* pIClientKernelSink);
|
||
|
|
|
||
|
|
//网络回调接口重载
|
||
|
|
public:
|
||
|
|
//网络连接
|
||
|
|
virtual void onEventTCPSocketLink();
|
||
|
|
//网络关闭
|
||
|
|
virtual void onEventTCPSocketShut();
|
||
|
|
//网络错误
|
||
|
|
virtual void onEventTCPSocketError(int errorCode);
|
||
|
|
//网络消息读取
|
||
|
|
virtual bool onEventTCPSocketRead(int main, int sub, void* data, int dataSize);
|
||
|
|
//网络心跳包
|
||
|
|
virtual bool onEventTCPHeartTick();
|
||
|
|
|
||
|
|
//网络接口
|
||
|
|
public:
|
||
|
|
//发送函数
|
||
|
|
virtual bool SendSocketData(uint16 wMainCmdID, uint16 wSubCmdID);
|
||
|
|
//发送函数
|
||
|
|
virtual bool SendSocketData(uint16 wMainCmdID, uint16 wSubCmdID, void * data, uint16 dataSize);
|
||
|
|
|
||
|
|
//网络消处处理
|
||
|
|
public:
|
||
|
|
//////////////////////////////////////////////////////////////////////////
|
||
|
|
//登录消息
|
||
|
|
bool OnSocketMainLogon(int sub, void* data, int dataSize);
|
||
|
|
//登录成功
|
||
|
|
bool OnSocketSubLogonSuccess(void* data, int dataSize);
|
||
|
|
//登录失败
|
||
|
|
bool OnSocketSubLogonFailure(void* data, int dataSize);
|
||
|
|
//登录完成
|
||
|
|
bool OnSocketSubLogonFinish(void* data, int dataSize);
|
||
|
|
//更新提示
|
||
|
|
bool OnSocketSubUpdateNotify(void* data, int dataSize);
|
||
|
|
|
||
|
|
//////////////////////////////////////////////////////////////////////////
|
||
|
|
//配置信息
|
||
|
|
bool OnSocketMainConfig(int sub, void* data, int dataSize);
|
||
|
|
//房间配置
|
||
|
|
bool OnSocketSubConfigServer(void* data, int dataSize);
|
||
|
|
|
||
|
|
//////////////////////////////////////////////////////////////////////////
|
||
|
|
//用户信息
|
||
|
|
bool OnSocketMainUser(int sub, void* data, int dataSize);
|
||
|
|
//请求失败
|
||
|
|
bool OnSocketSubRequestFailure(void* data, int dataSize);
|
||
|
|
//用户进入
|
||
|
|
bool OnSocketSubUserEnter(void* data, int dataSize);
|
||
|
|
//用户积分
|
||
|
|
bool OnSocketSubUserScore(void* data, int dataSize);
|
||
|
|
//用户状态
|
||
|
|
bool OnSocketSubUserStatus(void* data, int dataSize);
|
||
|
|
//用户位置
|
||
|
|
bool OnSocketSubUserLocation(void* data, int dataSize);
|
||
|
|
|
||
|
|
//////////////////////////////////////////////////////////////////////////
|
||
|
|
//系统主消息
|
||
|
|
bool OnSocketMainSystem(int sub, void* data, int dataSize);
|
||
|
|
//系统子消息
|
||
|
|
bool OnSocketSubSystemMessage(void* data, int dataSize);
|
||
|
|
|
||
|
|
//私人场主消息
|
||
|
|
bool OnSocketMainPrivate(int sub, void* data, int dataSize);
|
||
|
|
//私人场信息
|
||
|
|
bool OnSocketSubPrivateInfo(void* data, int dataSize);
|
||
|
|
//私人场创建成功
|
||
|
|
bool OnSocketSubPrivateCreateSuceess(void* data, int dataSize);
|
||
|
|
//私人场房间信息
|
||
|
|
bool OnSocketSubPrivateRoomInfo(void* data, int dataSize);
|
||
|
|
//私人场结束
|
||
|
|
bool OnSocketSubGMPrivateEnd(void* data, int dataSize);
|
||
|
|
//私人场解散
|
||
|
|
bool OnSocketSubPrivateDismissInfo(void* data, int dataSize);
|
||
|
|
//私人场解散结果
|
||
|
|
bool OnSocketSubPrivateDismissResult(void* data, int dataSize);
|
||
|
|
//自由场玩家状态;
|
||
|
|
bool OnSocketSubPrivateAutoUserStatus(void* data, int dataSize);
|
||
|
|
//自由人数开始状态;
|
||
|
|
bool OnSocketSubAutoUserReady(void* data, int dataSize);
|
||
|
|
//私人场积分
|
||
|
|
bool OnSocketSubPrivateScoreInfo(void* data, int dataSize);
|
||
|
|
//游戏消息,框架消息
|
||
|
|
bool OnSocketMainGameFrame(int main, int sub, void* data, int dataSize);
|
||
|
|
//用户聊天
|
||
|
|
bool OnSocketSubUserChat(void* data, int dataSize);
|
||
|
|
//用户表情
|
||
|
|
bool OnSocketSubUserFace(void* data, int dataSize);
|
||
|
|
//用户语音
|
||
|
|
bool OnSocketSubUserTalk(void* data, int dataSize);
|
||
|
|
//游戏状态
|
||
|
|
bool OnSocketSubGameStatus(void* data, int dataSize);
|
||
|
|
//游戏场景
|
||
|
|
bool OnSocketSubGameScene(void* data, int dataSize);
|
||
|
|
//旁观状态
|
||
|
|
bool OnSocketSubLookonStatus(void* data, int dataSize);
|
||
|
|
//系统消息
|
||
|
|
bool OnSocketSubGameSystemMessage(void* data, int dataSize);
|
||
|
|
//PING网络
|
||
|
|
bool OnSocketSubNetWorkTime(void* data, int dataSize);
|
||
|
|
//游戏已准备好
|
||
|
|
void OnGFGameOption();
|
||
|
|
//游戏关闭
|
||
|
|
void OnGFGameClose(int iExitCode);
|
||
|
|
|
||
|
|
//网络命令
|
||
|
|
public:
|
||
|
|
//发送登录
|
||
|
|
bool SendLogonPacket();
|
||
|
|
//执行快速加入
|
||
|
|
bool PerformQuickSitDown();
|
||
|
|
//执行起立
|
||
|
|
bool PerformStandUpAction();
|
||
|
|
|
||
|
|
//发送坐下
|
||
|
|
bool SendSitDownPacket(uint16 wTableID, uint16 wChairID, const char* lpszPassword);
|
||
|
|
//发送起立
|
||
|
|
bool SendStandUpPacket(uint16 wTableID, uint16 wChairID, uint8 cbForceLeave);
|
||
|
|
|
||
|
|
//////////////////////////////////////////////////////////////////////////
|
||
|
|
// IUserManagerSink
|
||
|
|
//////////////////////////////////////////////////////////////////////////
|
||
|
|
public:
|
||
|
|
virtual void OnUserItemAcitve(IClientUserItem* pIClientUserItem);
|
||
|
|
virtual void OnUserItemDelete(IClientUserItem* pIClientUserItem);
|
||
|
|
virtual void OnUserFaceUpdate(IClientUserItem* pIClientUserItem){ ; }
|
||
|
|
virtual void OnUserItemUpdate(IClientUserItem* pIClientUserItem);
|
||
|
|
virtual void OnUserItemUpdate(IClientUserItem* pIClientUserItem, const tagUserStatus& LastStatus);
|
||
|
|
virtual void OnUserItemUpdate(IClientUserItem* pIClientUserItem, const tagUserAttrib & UserAttrib);
|
||
|
|
|
||
|
|
public:
|
||
|
|
//中断连接
|
||
|
|
bool IntermitConnect(bool force);
|
||
|
|
|
||
|
|
//获取自已
|
||
|
|
IClientUserItem* GetMeUserItem();
|
||
|
|
//游戏用户
|
||
|
|
IClientUserItem * GetTableUserItem(uint16 wChairID);
|
||
|
|
|
||
|
|
//连接服务器
|
||
|
|
void ConnectServerByKind(uint16 wDataID);
|
||
|
|
//连接服务器
|
||
|
|
void ConnectServerByServerID(uint16 wServerID);
|
||
|
|
//设置服务器
|
||
|
|
void SetServerItem(CGameServerItem* pServerItem);
|
||
|
|
|
||
|
|
//获取游戏类型;
|
||
|
|
uint16 getGameKindID() { return m_wGameKindID; }
|
||
|
|
|
||
|
|
static CGameServerItem* g_pGameServerItem;
|
||
|
|
|
||
|
|
// 游戏录像模拟玩家进入;
|
||
|
|
public:
|
||
|
|
void InitRecordGamePlayer(uint16 wChairID, tagGameRecordPlayer& kRecordPlayer);
|
||
|
|
|
||
|
|
private:
|
||
|
|
//房间属性
|
||
|
|
enServiceStatus mServiceStatus;
|
||
|
|
tagUserAttribute mUserAttribute; //用户属性
|
||
|
|
tagServerAttribute mServerAttribute; //房间属性
|
||
|
|
|
||
|
|
//用户
|
||
|
|
IClientUserItem* m_pMeUserItem;
|
||
|
|
CGameUserManager* mUserManager;
|
||
|
|
|
||
|
|
IClientKernelSink* mIClientKernelSink; //内核接口
|
||
|
|
uint8 mGameStatus; //游戏状态
|
||
|
|
|
||
|
|
uint16 m_wGameKindID;
|
||
|
|
};
|