1311 lines
34 KiB
C++
1311 lines
34 KiB
C++
#include "GameMission.h"
|
|
#include "PopScene.h"
|
|
#include "MainScene.h"
|
|
#include "JniFun.h"
|
|
|
|
CGameServerItem* GameMission::g_pGameServerItem = nullptr;
|
|
|
|
GameMission::GameMission()
|
|
{
|
|
mServiceStatus = ServiceStatus_Unknow;
|
|
mIClientKernelSink = nullptr;
|
|
mGameStatus = GAME_STATUS_FREE;
|
|
|
|
m_pMeUserItem = nullptr;
|
|
mUserManager = new CGameUserManager();
|
|
mUserManager->SetUserManagerSink(this);
|
|
|
|
m_wGameKindID = 0;
|
|
|
|
memset(&mUserAttribute, 0, sizeof(mUserAttribute));
|
|
memset(&mServerAttribute, 0, sizeof(mServerAttribute));
|
|
}
|
|
|
|
//设置内核接口
|
|
void GameMission::SetClientKernelSink(IClientKernelSink* pIClientKernelSink)
|
|
{
|
|
mIClientKernelSink = pIClientKernelSink;
|
|
}
|
|
|
|
//网络连接
|
|
void GameMission::onEventTCPSocketLink()
|
|
{
|
|
SendLogonPacket();
|
|
}
|
|
|
|
//网络关闭
|
|
void GameMission::onEventTCPSocketShut()
|
|
{
|
|
cocos2d::log("GameMission::onEventTCPSocketShut()...");
|
|
|
|
mUserManager->ResetUserItem();
|
|
}
|
|
|
|
//网络错误
|
|
void GameMission::onEventTCPSocketError(int errorCode)
|
|
{
|
|
auto callback_ok = [=](){
|
|
Director::getInstance()->popScene();
|
|
};
|
|
|
|
PopScene::Instance().show(utility::a_u8("与服务器断开连接,请重进入房间!"), callback_ok);
|
|
}
|
|
|
|
//网络消息读取
|
|
bool GameMission::onEventTCPSocketRead(int main, int sub, void* data, int dataSize)
|
|
{
|
|
switch (main)
|
|
{
|
|
//登录消息
|
|
case MDM_GR_LOGON: return OnSocketMainLogon(sub, data, dataSize);
|
|
//配置信息
|
|
case MDM_GR_CONFIG: return OnSocketMainConfig(sub, data, dataSize);
|
|
//用户信息
|
|
case MDM_GR_USER: return OnSocketMainUser(sub, data, dataSize);
|
|
//私人场消息
|
|
case MDM_GR_PRIVATE:return OnSocketMainPrivate(sub, data, dataSize);
|
|
//游戏消息
|
|
case MDM_GF_GAME:
|
|
//框架消息
|
|
case MDM_GF_FRAME: return OnSocketMainGameFrame(main, sub, data, dataSize);
|
|
//系统消息
|
|
case MDM_CM_SYSTEM: return OnSocketMainSystem(sub, data, dataSize);
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//登录消息
|
|
bool GameMission::OnSocketMainLogon(int sub, void* data, int dataSize)
|
|
{
|
|
switch (sub)
|
|
{
|
|
//登录成功
|
|
case SUB_GR_LOGON_SUCCESS: return OnSocketSubLogonSuccess(data, dataSize);
|
|
//登录失败
|
|
case SUB_GR_LOGON_FAILURE: return OnSocketSubLogonFailure(data, dataSize);
|
|
//登录完成
|
|
case SUB_GR_LOGON_FINISH: return OnSocketSubLogonFinish(data, dataSize);
|
|
//更新提示
|
|
case SUB_GR_UPDATE_NOTIFY: return OnSocketSubUpdateNotify(data, dataSize);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
//登录成功
|
|
bool GameMission::OnSocketSubLogonSuccess(void* data, int dataSize)
|
|
{
|
|
cocos2d::log(("GameMission::OnSocketSubLogonSuccess\n"));
|
|
|
|
//设置状态
|
|
mServiceStatus = ServiceStatus_RecvInfo;
|
|
|
|
CMD_GR_LogonSuccess* pLogonSuccess = (CMD_GR_LogonSuccess*)data;
|
|
CGlobalUserInfo * pGlobalUserInfo = CGlobalUserInfo::GetInstance();
|
|
pGlobalUserInfo->SetUserRight(pLogonSuccess->dwUserRight);
|
|
pGlobalUserInfo->SetMasterRight(pLogonSuccess->dwMasterRight);
|
|
|
|
return true;
|
|
}
|
|
|
|
//登录失败
|
|
bool GameMission::OnSocketSubLogonFailure(void* data, int dataSize)
|
|
{
|
|
cocos2d::log(("GameMission::OnSocketSubLogonFailure\n"));
|
|
|
|
LoadingScene::Instance().hide();
|
|
|
|
CMD_GR_LogonError* pLogonErr = (CMD_GR_LogonError*)data;
|
|
PopScene::Instance().show(utility::a_u8(pLogonErr->szErrorDescribe));
|
|
|
|
//关闭连接
|
|
IntermitConnect(true);
|
|
|
|
return true;
|
|
}
|
|
|
|
//登录完成
|
|
bool GameMission::OnSocketSubLogonFinish(void* data, int dataSize)
|
|
{
|
|
cocos2d::log(("GameMission::OnSocketSubLogonFinish\n"));
|
|
|
|
LoadingScene::Instance().hide();
|
|
|
|
//设置状态
|
|
mServiceStatus = ServiceStatus_ServiceIng;
|
|
|
|
mUserAttribute.dwUserID = m_pMeUserItem->GetUserID();
|
|
mUserAttribute.wChairID = INVALID_CHAIR;
|
|
mUserAttribute.wTableID = INVALID_TABLE;
|
|
|
|
if (m_pMeUserItem->GetTableID() == INVALID_TABLE || m_pMeUserItem->GetChairID() == INVALID_CHAIR)
|
|
{
|
|
CC_ASSERT(g_pGameServerItem != nullptr);
|
|
if (g_pGameServerItem->IsGoldRoom())
|
|
{
|
|
PerformQuickSitDown();
|
|
}
|
|
else
|
|
{
|
|
auto callback_ok = [=](){
|
|
Director::getInstance()->popScene();
|
|
};
|
|
|
|
PopScene::Instance().show(utility::a_u8("该房间已经解散,请返回大厅!"), callback_ok);
|
|
|
|
this->stop();
|
|
return true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
OnGFGameOption();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//更新提示
|
|
bool GameMission::OnSocketSubUpdateNotify(void* data, int dataSize)
|
|
{
|
|
cocos2d::log(("GameMission::OnSocketSubUpdateNotify\n"));
|
|
LoadingScene::Instance().hide();
|
|
|
|
//IntermitConnect(true);
|
|
|
|
auto callback = []{
|
|
Director::getInstance()->end();
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
exit(0);
|
|
#endif
|
|
};
|
|
|
|
PopScene::Instance().show(utility::a_u8("发现新版本,请前往官网下载并重新安装!"), callback);
|
|
|
|
return true;
|
|
}
|
|
|
|
//配置信息
|
|
bool GameMission::OnSocketMainConfig(int sub, void* data, int dataSize)
|
|
{
|
|
switch (sub)
|
|
{
|
|
//列表配置
|
|
case SUB_GR_CONFIG_COLUMN: return true;
|
|
//房间配置
|
|
case SUB_GR_CONFIG_SERVER: return OnSocketSubConfigServer(data, dataSize);
|
|
//道具配置
|
|
case SUB_GR_CONFIG_PROPERTY: return true;
|
|
//配置玩家权限
|
|
case SUB_GR_CONFIG_USER_RIGHT: return true;
|
|
//配置完成
|
|
case SUB_GR_CONFIG_FINISH: return true;
|
|
}
|
|
|
|
//错误断言
|
|
ASSERT(FALSE);
|
|
return true;
|
|
}
|
|
|
|
//房间配置
|
|
bool GameMission::OnSocketSubConfigServer(void* data, int dataSize)
|
|
{
|
|
cocos2d::log("GameMission::OnSocketSubConfigServer\n");
|
|
|
|
//效验数据
|
|
ASSERT(dataSize == sizeof(CMD_GR_ConfigServer));
|
|
if (dataSize < sizeof(CMD_GR_ConfigServer)) return false;
|
|
|
|
//消息处理
|
|
CMD_GR_ConfigServer * pConfigServer = (CMD_GR_ConfigServer *)data;
|
|
|
|
mServerAttribute.wTableCount = pConfigServer->wTableCount;
|
|
mServerAttribute.wChairCount = pConfigServer->wChairCount;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool GameMission::OnSocketMainUser(int sub, void* data, int dataSize)
|
|
{
|
|
switch (sub)
|
|
{
|
|
//请求坐下失败
|
|
case SUB_GR_SIT_FAILED: return OnSocketSubRequestFailure(data, dataSize);
|
|
//用户进入
|
|
case SUB_GR_USER_ENTER: return OnSocketSubUserEnter(data, dataSize);
|
|
//用户积分
|
|
case SUB_GR_USER_SCORE: return OnSocketSubUserScore(data, dataSize);
|
|
//用户状态
|
|
case SUB_GR_USER_STATUS: return OnSocketSubUserStatus(data, dataSize);
|
|
//用户位置
|
|
case SUB_GR_USER_LOCATION: return OnSocketSubUserLocation(data, dataSize);
|
|
//用户聊天
|
|
case SUB_GR_USER_CHAT: return true;
|
|
//用户表情
|
|
case SUB_GR_USER_EXPRESSION: return true;
|
|
//用户私聊
|
|
case SUB_GR_WISPER_CHAT: return true;
|
|
//私聊表情
|
|
case SUB_GR_WISPER_EXPRESSION: return true;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// 桌子状态
|
|
//请求失败
|
|
bool GameMission::OnSocketSubRequestFailure(void* data, int dataSize)
|
|
{
|
|
cocos2d::log(("GameMission::OnSocketSubRequestFailure\n"));
|
|
//变量定义
|
|
CMD_GR_RequestFailure * pRequestFailure = (CMD_GR_RequestFailure *)data;
|
|
|
|
//效验参数
|
|
ASSERT(dataSize > (sizeof(CMD_GR_RequestFailure) - sizeof(pRequestFailure->szDescribeString)));
|
|
if (dataSize <= (sizeof(CMD_GR_RequestFailure) - sizeof(pRequestFailure->szDescribeString))) return false;
|
|
|
|
PopScene::Instance().show(utility::a_u8(pRequestFailure->szDescribeString));
|
|
|
|
return true;
|
|
}
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//用户进入
|
|
bool GameMission::OnSocketSubUserEnter(void* data, int dataSize)
|
|
{
|
|
cocos2d::log(("GameMission::OnSocketSubUserEnter\n"));
|
|
|
|
int n = sizeof(tagUserInfoHead);
|
|
//变量定义
|
|
tagUserInfo kUserInfo;
|
|
tagCustomFaceInfo CustomFaceInfo;
|
|
zeromemory(&kUserInfo, sizeof(kUserInfo));
|
|
zeromemory(&CustomFaceInfo, sizeof(CustomFaceInfo));
|
|
|
|
//变量定义
|
|
CGlobalUserInfo * pGlobalUserInfo = CGlobalUserInfo::GetInstance();
|
|
tagGlobalUserData * pGlobalUserData = pGlobalUserInfo->GetGlobalUserData();
|
|
|
|
tagUserInfoHead* pUserInfoHead = (tagUserInfoHead*)data;
|
|
|
|
kUserInfo.dwUserID = pUserInfoHead->dwUserID;
|
|
kUserInfo.wTableID = pUserInfoHead->wTableID;
|
|
kUserInfo.wChairID = pUserInfoHead->wChairID;
|
|
kUserInfo.cbUserStatus = pUserInfoHead->cbUserStatus;
|
|
kUserInfo.wFaceID = pUserInfoHead->wFaceID;
|
|
kUserInfo.dwCustomID = pUserInfoHead->dwCustomID;
|
|
kUserInfo.cbGender = pUserInfoHead->cbGender;
|
|
kUserInfo.cbMemberOrder = pUserInfoHead->cbMemberOrder;
|
|
kUserInfo.cbMasterOrder = pUserInfoHead->cbMasterOrder;
|
|
kUserInfo.dwGameID = pUserInfoHead->dwGameID;
|
|
//kUserInfo.dwGroupID = pUserInfoHead->dwLogonIp;
|
|
kUserInfo.lLoveLiness = pUserInfoHead->lLoveLiness;
|
|
kUserInfo.lScore = pUserInfoHead->lScore;
|
|
kUserInfo.lGrade = pUserInfoHead->lGrade;
|
|
kUserInfo.lInsureScore = pUserInfoHead->lInsure;
|
|
kUserInfo.lWinCount = pUserInfoHead->dwWinCount;
|
|
kUserInfo.lLostCount = pUserInfoHead->dwLostCount;
|
|
kUserInfo.lDrawCount = pUserInfoHead->dwDrawCount;
|
|
kUserInfo.lFleeCount = pUserInfoHead->dwFleeCount;
|
|
kUserInfo.lExperience = pUserInfoHead->dwExperience;
|
|
|
|
//ip地址获取;
|
|
BYTE * pClientAddr = (BYTE *)&pUserInfoHead->dwLogonIp;
|
|
sprintf(kUserInfo.szLogonIP, "%d.%d.%d.%d", pClientAddr[0], pClientAddr[1], pClientAddr[2], pClientAddr[3]);
|
|
|
|
//kUserInfo.dwGroupID = pUserInfoHead->dwLogonIp;
|
|
|
|
//获取对象
|
|
CServerListData * pServerListData = CServerListData::shared();
|
|
|
|
void * pDataBuffer = NULL;
|
|
tagDataDescribe DataDescribe;
|
|
CRecvPacketHelper RecvPacket(pUserInfoHead + 1, dataSize - sizeof(tagUserInfoHead));
|
|
|
|
//扩展信息
|
|
while (true)
|
|
{
|
|
pDataBuffer = RecvPacket.GetData(DataDescribe);
|
|
if (DataDescribe.wDataDescribe == DTP_NULL) break;
|
|
switch (DataDescribe.wDataDescribe)
|
|
{
|
|
case DTP_GR_NICK_NAME: //用户昵称
|
|
{
|
|
ASSERT(pDataBuffer != NULL);
|
|
ASSERT(DataDescribe.wDataSize <= sizeof(kUserInfo.szNickName));
|
|
if (DataDescribe.wDataSize <= sizeof(kUserInfo.szNickName))
|
|
{
|
|
memcpy(&kUserInfo.szNickName, pDataBuffer, DataDescribe.wDataSize);
|
|
kUserInfo.szNickName[CountArray(kUserInfo.szNickName) - 1] = 0;
|
|
}
|
|
break;
|
|
}
|
|
case DTP_GR_GROUP_NAME: //用户社团
|
|
{
|
|
ASSERT(pDataBuffer != NULL);
|
|
ASSERT(DataDescribe.wDataSize <= sizeof(kUserInfo.szGroupName));
|
|
if (DataDescribe.wDataSize <= sizeof(kUserInfo.szGroupName))
|
|
{
|
|
memcpy(&kUserInfo.szGroupName, pDataBuffer, DataDescribe.wDataSize);
|
|
kUserInfo.szGroupName[CountArray(kUserInfo.szGroupName) - 1] = 0;
|
|
}
|
|
break;
|
|
}
|
|
case DTP_GR_UNDER_WRITE: //个性签名
|
|
{
|
|
ASSERT(pDataBuffer != NULL);
|
|
ASSERT(DataDescribe.wDataSize <= sizeof(kUserInfo.szUnderWrite));
|
|
if (DataDescribe.wDataSize <= sizeof(kUserInfo.szUnderWrite))
|
|
{
|
|
memcpy(kUserInfo.szUnderWrite, pDataBuffer, DataDescribe.wDataSize);
|
|
kUserInfo.szUnderWrite[CountArray(kUserInfo.szUnderWrite) - 1] = 0;
|
|
}
|
|
break;
|
|
}
|
|
case DTP_GR_HEAD_HTTP: //头像HTTP
|
|
{
|
|
ASSERT(pDataBuffer != NULL);
|
|
ASSERT(DataDescribe.wDataSize <= sizeof(kUserInfo.szHeadHttp));
|
|
if (DataDescribe.wDataSize <= sizeof(kUserInfo.szHeadHttp))
|
|
{
|
|
memcpy(kUserInfo.szHeadHttp, pDataBuffer, DataDescribe.wDataSize);
|
|
kUserInfo.szHeadHttp[CountArray(kUserInfo.szHeadHttp) - 1] = 0;
|
|
}
|
|
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
//激活用户
|
|
IClientUserItem * pIClientUserItem = mUserManager->SearchUserByUserID(kUserInfo.dwUserID);
|
|
pIClientUserItem = mUserManager->ActiveUserItem(kUserInfo, CustomFaceInfo);
|
|
|
|
//人数更新
|
|
if (pServerListData)
|
|
{
|
|
pServerListData->SetServerOnLineCount(mServerAttribute.wServerID, mUserManager->GetActiveUserCount());
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//用户积分
|
|
bool GameMission::OnSocketSubUserScore(void* data, int dataSize)
|
|
{
|
|
cocos2d::log(("GameMission::OnSocketSubUserScore\n"));
|
|
//效验参数
|
|
ASSERT(dataSize == sizeof(CMD_GR_UserScore));
|
|
if (dataSize < sizeof(CMD_GR_UserScore)) return false;
|
|
|
|
//寻找用户
|
|
CMD_GR_UserScore * pUserScore = (CMD_GR_UserScore *)data;
|
|
IClientUserItem * pIClientUserItem = mUserManager->SearchUserByUserID(pUserScore->dwUserID);
|
|
|
|
//用户判断
|
|
if (pIClientUserItem == 0) return true;
|
|
|
|
mUserManager->UpdateUserItemScore(pIClientUserItem, &pUserScore->UserScore);
|
|
|
|
return true;
|
|
}
|
|
|
|
//用户状态
|
|
bool GameMission::OnSocketSubUserStatus(void* data, int dataSize)
|
|
{
|
|
cocos2d::log("GameMission::OnSocketSubUserStatus\n");
|
|
|
|
ASSERT(dataSize >= sizeof(CMD_GR_UserStatus));
|
|
if (dataSize < sizeof(CMD_GR_UserStatus)) return false;
|
|
|
|
//处理数据
|
|
CMD_GR_UserStatus * pUserStatus = (CMD_GR_UserStatus *)data;
|
|
|
|
IClientUserItem * pIClientUserItem = mUserManager->SearchUserByUserID(pUserStatus->dwUserID);
|
|
if (pIClientUserItem == NULL) return true;
|
|
|
|
tagUserStatus UserStatus;
|
|
UserStatus.wTableID = pUserStatus->UserStatus.wTableID;
|
|
UserStatus.wChairID = pUserStatus->UserStatus.wChairID;
|
|
UserStatus.cbUserStatus = pUserStatus->UserStatus.cbUserStatus;
|
|
|
|
//设置状态
|
|
if (UserStatus.cbUserStatus == US_NULL)
|
|
{
|
|
//删除用户
|
|
mUserManager->DeleteUserItem(pIClientUserItem);
|
|
|
|
//获取对象
|
|
CServerListData * pServerListData = CServerListData::shared();
|
|
|
|
//人数更新
|
|
pServerListData->SetServerOnLineCount(mServerAttribute.wServerID, mUserManager->GetActiveUserCount());
|
|
}
|
|
else
|
|
{
|
|
//更新用户
|
|
mUserManager->UpdateUserItemStatus(pIClientUserItem, &UserStatus);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//用户位置
|
|
bool GameMission::OnSocketSubUserLocation(void* data, int dataSize)
|
|
{
|
|
cocos2d::log("GameMission::OnSocketSubUserStatus\n");
|
|
|
|
ASSERT(dataSize >= sizeof(CMD_GF_S_UserLocation));
|
|
if (dataSize < sizeof(CMD_GF_S_UserLocation)) return false;
|
|
|
|
//处理数据
|
|
CMD_GF_S_UserLocation * pLocation = (CMD_GF_S_UserLocation *)data;
|
|
|
|
//寻找用户
|
|
IClientUserItem * pIClientUserItem = mUserManager->SearchUserByUserID(pLocation->dwTargetUserID);
|
|
if (nullptr == pIClientUserItem) return true;
|
|
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->onEventUserLocation(pIClientUserItem, pLocation);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//系统消息
|
|
bool GameMission::OnSocketMainSystem(int sub, void* data, int dataSize)
|
|
{
|
|
switch (sub)
|
|
{
|
|
//系统消息
|
|
case SUB_CM_SYSTEM_MESSAGE: return OnSocketSubSystemMessage(data, dataSize);
|
|
}
|
|
|
|
//错误断言
|
|
ASSERT(FALSE);
|
|
|
|
return true;
|
|
}
|
|
|
|
//系统消息
|
|
bool GameMission::OnSocketSubSystemMessage(void* data, int wDataSize)
|
|
{
|
|
cocos2d::log(("GameMission::OnSocketSubSystemMessage\n"));
|
|
|
|
CMD_CM_SystemMessage * pSystemMessage = (CMD_CM_SystemMessage *)data;
|
|
uint16 wHeadSize = sizeof(CMD_CM_SystemMessage) - sizeof(pSystemMessage->szString);
|
|
|
|
//效验参数
|
|
ASSERT((wDataSize > wHeadSize) && (wDataSize == (wHeadSize + pSystemMessage->wLength*sizeof(char))));
|
|
if ((wDataSize <= wHeadSize) || (wDataSize != (wHeadSize + pSystemMessage->wLength*sizeof(char)))) return false;
|
|
|
|
uint16 wType = pSystemMessage->wType;
|
|
|
|
//关闭处理
|
|
if ((wType&(SMT_CLOSE_ROOM | SMT_CLOSE_LINK)) != 0)
|
|
{
|
|
OnGFGameClose(ServiceStatus_NetworkDown);
|
|
this->stop();
|
|
}
|
|
|
|
//弹出消息
|
|
if(wType&SMT_EJECT)
|
|
{
|
|
PopScene::Instance().show(utility::a_u8(pSystemMessage->szString));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//
|
|
bool GameMission::OnSocketMainPrivate(int sub, void* data, int dataSize)
|
|
{
|
|
switch (sub)
|
|
{
|
|
//费用查询
|
|
case SUB_GR_PRIVATE_INFO: return OnSocketSubPrivateInfo(data, dataSize);
|
|
case SUB_GR_CREATE_PRIVATE_SUCESS: return OnSocketSubPrivateCreateSuceess(data, dataSize);
|
|
case SUB_GF_PRIVATE_ROOM_INFO: return OnSocketSubPrivateRoomInfo(data, dataSize);
|
|
case SUB_GR_PRIVATE_DISMISS: return OnSocketSubPrivateDismissInfo(data, dataSize);
|
|
case SUB_GR_PRIVATE_DISMISS_RESULT: return OnSocketSubPrivateDismissResult(data, dataSize);
|
|
case SUB_GF_GM_PRIVATE_END: return OnSocketSubGMPrivateEnd(data, dataSize);
|
|
case SUB_GR_AUTO_USER_STATUS: return OnSocketSubPrivateAutoUserStatus(data, dataSize);
|
|
case SUB_GR_AUTO_USER_READY: return OnSocketSubAutoUserReady(data, dataSize);
|
|
case SUB_GF_PRIVATE_SCORE_INFO: return OnSocketSubPrivateScoreInfo(data, dataSize);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//
|
|
bool GameMission::OnSocketSubPrivateInfo(void* data, int dataSize)
|
|
{
|
|
cocos2d::log("GameMission::OnSocketSubPrivateInfo\n");
|
|
CMD_GR_Private_Info *pNetInfo = (CMD_GR_Private_Info*)data;
|
|
|
|
return true;
|
|
}
|
|
|
|
//创建成功
|
|
bool GameMission::OnSocketSubPrivateCreateSuceess(void* data, int dataSize)
|
|
{
|
|
cocos2d::log("PrivateMission::OnSocketSubPrivateCreateSuceess\n");
|
|
|
|
ASSERT(dataSize == sizeof(CMD_GR_Create_Private_Sucess));
|
|
if (dataSize != sizeof(CMD_GR_Create_Private_Sucess)) return false;
|
|
|
|
CMD_GR_Create_Private_Sucess *pNetInfo = (CMD_GR_Create_Private_Sucess*)data;
|
|
|
|
return true;
|
|
}
|
|
|
|
//私人场信息
|
|
bool GameMission::OnSocketSubPrivateRoomInfo(void* data, int dataSize)
|
|
{
|
|
cocos2d::log("GameMission::OnSocketSubPrivateRoomInfo\n");
|
|
|
|
DataStream kDataStream(data, dataSize);
|
|
CMD_GF_Private_Room_Info kNetInfo;
|
|
kNetInfo.StreamValue(kDataStream, false);
|
|
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnSocketSubPrivateRoomInfo(&kNetInfo);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//私人场积分信息
|
|
bool GameMission::OnSocketSubPrivateScoreInfo(void* data, int dataSize)
|
|
{
|
|
cocos2d::log("GameMission::OnSocketSubPrivateScoreInfo\n");
|
|
|
|
DataStream kDataStream(data, dataSize);
|
|
CMD_GF_Private_Score_Info kNetInfo;
|
|
kNetInfo.StreamValue(kDataStream, false);
|
|
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnSocketSubPrivateScoreInfo(&kNetInfo);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool GameMission::OnSocketSubGMPrivateEnd(void* data, int dataSize)
|
|
{
|
|
cocos2d::log("GameMission::OnSocketSubGMPrivateEnd\n");
|
|
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnSocketSubPrivateEnd(data, dataSize);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool GameMission::OnSocketSubPrivateDismissInfo(void* data, int dataSize)
|
|
{
|
|
cocos2d::log("GameMission::OnSocketSubPrivateDismissInfo\n");
|
|
|
|
ASSERT(dataSize == sizeof(CMD_GF_Private_Dismiss_Info));
|
|
if (dataSize != sizeof(CMD_GF_Private_Dismiss_Info)) return false;
|
|
|
|
CMD_GF_Private_Dismiss_Info *pNetInfo = (CMD_GF_Private_Dismiss_Info*)data;
|
|
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnSocketSubPrivateDismissInfo(pNetInfo);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool GameMission::OnSocketSubPrivateDismissResult(void* data, int dataSize)
|
|
{
|
|
cocos2d::log("GameMission::OnSocketSubPrivateDismissResult\n");
|
|
|
|
ASSERT(dataSize == sizeof(CMD_GF_Private_Dismiss_Result));
|
|
if (dataSize != sizeof(CMD_GF_Private_Dismiss_Result)) return false;
|
|
|
|
CMD_GF_Private_Dismiss_Result *pNetInfo = (CMD_GF_Private_Dismiss_Result*)data;
|
|
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnSocketSubPrivateDismissResult(pNetInfo);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
//自由场玩家状态;
|
|
bool GameMission::OnSocketSubPrivateAutoUserStatus(void* data, int dataSize)
|
|
{
|
|
cocos2d::log("GameMission::OnSocketSubPrivateAutoUserStatus\n");
|
|
|
|
ASSERT(dataSize == sizeof(tagAutoUserStatus));
|
|
if (dataSize != sizeof(tagAutoUserStatus)) return false;
|
|
|
|
tagAutoUserStatus *pNetInfo = (tagAutoUserStatus*)data;
|
|
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnSocketSubPrivateAutoUserStatus(pNetInfo);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//自由人数开始状态;
|
|
bool GameMission::OnSocketSubAutoUserReady(void* data, int dataSize)
|
|
{
|
|
cocos2d::log("GameMission::OnSocketSubAutoUserReady\n");
|
|
|
|
ASSERT(dataSize == sizeof(CMD_GR_Private_ReadyInfo));
|
|
if (dataSize != sizeof(CMD_GR_Private_ReadyInfo)) return false;
|
|
|
|
CMD_GR_Private_ReadyInfo *pNetInfo = (CMD_GR_Private_ReadyInfo*)data;
|
|
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnSocketSubPrivateAutoUserReady(pNetInfo);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool GameMission::OnSocketMainGameFrame(int main, int sub, void* data, int dataSize)
|
|
{
|
|
//效验数据
|
|
ASSERT(dataSize <= SOCKET_TCP_PACKET);
|
|
if (dataSize > SOCKET_TCP_PACKET) return false;
|
|
|
|
//游戏消息
|
|
if (main == MDM_GF_GAME)
|
|
{
|
|
//效验状态
|
|
ASSERT(mIClientKernelSink != 0);
|
|
if (mIClientKernelSink == 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return mIClientKernelSink->OnEventGameMessage(sub, data, dataSize);
|
|
}
|
|
|
|
//内核处理
|
|
if (main == MDM_GF_FRAME)
|
|
{
|
|
switch (sub)
|
|
{
|
|
case SUB_GF_USER_CHAT:
|
|
{
|
|
return OnSocketSubUserChat(data, dataSize);
|
|
}
|
|
case SUB_GF_USER_EXPRESSION:
|
|
{
|
|
return OnSocketSubUserFace(data, dataSize);
|
|
}
|
|
case SUB_GR_TABLE_TALK: //用户聊天
|
|
{
|
|
return OnSocketSubUserTalk(data, dataSize);
|
|
}
|
|
case SUB_GF_GAME_STATUS: //游戏状态
|
|
{
|
|
return OnSocketSubGameStatus(data, dataSize);
|
|
}
|
|
case SUB_GF_GAME_SCENE: //游戏场景
|
|
{
|
|
return OnSocketSubGameScene(data, dataSize);
|
|
}
|
|
case SUB_GF_SYSTEM_MESSAGE:
|
|
{
|
|
return OnSocketSubGameSystemMessage(data, dataSize);
|
|
}
|
|
case SUB_GF_PING_TIME:
|
|
{
|
|
return OnSocketSubNetWorkTime(data, dataSize);
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//用户聊天
|
|
bool GameMission::OnSocketSubUserChat(void* data, int dataSize)
|
|
{
|
|
if (mIClientKernelSink)
|
|
{
|
|
return mIClientKernelSink->OnSocketSubUserChat(data, dataSize);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//用户表情
|
|
bool GameMission::OnSocketSubUserFace(void* data, int dataSize)
|
|
{
|
|
if (mIClientKernelSink)
|
|
{
|
|
return mIClientKernelSink->OnSocketSubUserFace(data, dataSize);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//游戏消息
|
|
bool GameMission::OnSocketSubUserTalk(void* data, int dataSize)
|
|
{
|
|
if (mIClientKernelSink)
|
|
{
|
|
return mIClientKernelSink->RevTalkFile(data, dataSize);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//游戏状态
|
|
bool GameMission::OnSocketSubGameStatus(void* data, int dataSize)
|
|
{
|
|
cocos2d::log("flow->CClientKernel::OnSocketSubGameStatus\n");
|
|
|
|
//效验参数
|
|
ASSERT(dataSize == sizeof(CMD_GF_GameStatus));
|
|
if (dataSize != sizeof(CMD_GF_GameStatus)) return false;
|
|
|
|
//消息处理
|
|
CMD_GF_GameStatus * pGameStatus = (CMD_GF_GameStatus *)data;
|
|
|
|
mGameStatus = pGameStatus->cbGameStatus;
|
|
return true;
|
|
}
|
|
|
|
//游戏场景
|
|
bool GameMission::OnSocketSubGameScene(void* data, int dataSize)
|
|
{
|
|
cocos2d::log("flow->CClientKernel::OnSocketSubGameScene1");
|
|
|
|
//效验状态
|
|
ASSERT(m_pMeUserItem != 0);
|
|
if (m_pMeUserItem == 0) return true;
|
|
|
|
if (mIClientKernelSink == 0)
|
|
return true;
|
|
//场景处理
|
|
bool bLookonUser = (m_pMeUserItem->GetUserStatus() == US_LOOKON);
|
|
cocos2d::log("GameMission::OnSocketSubGameScene");
|
|
|
|
return mIClientKernelSink->OnEventSceneMessage(mGameStatus, bLookonUser, data, dataSize);
|
|
}
|
|
|
|
//系统消息
|
|
bool GameMission::OnSocketSubGameSystemMessage(void* data, int dataSize)
|
|
{
|
|
cocos2d::log(("GameMission::OnSocketSubGameSystemMessage\n"));
|
|
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnSocketSubGameSystemMessage(data, dataSize);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//PING网络
|
|
bool GameMission::OnSocketSubNetWorkTime(void* data, int dataSize)
|
|
{
|
|
cocos2d::log(("GameMission::OnSocketSubNetWorkTime\n"));
|
|
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnSocketSubNetWorkTime(data, dataSize);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
//发送函数
|
|
bool GameMission::SendSocketData(uint16 wMainCmdID, uint16 wSubCmdID)
|
|
{
|
|
return SendSocketData(wMainCmdID, wSubCmdID, 0, 0);
|
|
}
|
|
|
|
//发送函数
|
|
bool GameMission::SendSocketData(uint16 wMainCmdID, uint16 wSubCmdID, void * data, uint16 dataSize)
|
|
{
|
|
return send(wMainCmdID, wSubCmdID, (unsigned char*)data, dataSize);
|
|
}
|
|
|
|
//发送登录
|
|
bool GameMission::SendLogonPacket()
|
|
{
|
|
//变量定义
|
|
CGlobalUserInfo * pGlobalUserInfo = CGlobalUserInfo::GetInstance();
|
|
tagGlobalUserData * pGlobalUserData = pGlobalUserInfo->GetGlobalUserData();
|
|
|
|
//变量定义
|
|
CMD_GR_LogonUserID LogonUserID;
|
|
zeromemory(&LogonUserID, sizeof(LogonUserID));
|
|
|
|
LogonUserID.wKindID = m_wGameKindID;
|
|
//游戏版本
|
|
//LogonUserID.dwProcessVersion = Helps::Instance()->GetGameVersion();
|
|
//LogonUserID.dwPlazaVersion = Helps::Instance()->GetPlazaVersion();
|
|
LogonUserID.dwPlazaVersion = JniFun::getVersionCode();
|
|
|
|
//登录信息
|
|
LogonUserID.dwUserID = pGlobalUserData->dwUserID;
|
|
strncpy(LogonUserID.szPassword, pGlobalUserData->szPassword, countarray(LogonUserID.szPassword));
|
|
|
|
//发送数据
|
|
SendSocketData(MDM_GR_LOGON, SUB_GR_LOGON_USERID, &LogonUserID, sizeof(LogonUserID));
|
|
return true;
|
|
}
|
|
|
|
//执行快速加入
|
|
bool GameMission::PerformQuickSitDown()
|
|
{
|
|
//密码判断
|
|
char szPassword[LEN_PASSWORD] = { 0 };
|
|
|
|
//发送命令
|
|
SendSitDownPacket(INVALID_TABLE, INVALID_CHAIR, szPassword);
|
|
|
|
return true;
|
|
}
|
|
|
|
//网络心跳包
|
|
bool GameMission::onEventTCPHeartTick()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
// IUserManagerSink
|
|
//////////////////////////////////////////////////////////////////////////
|
|
void GameMission::OnUserItemAcitve(IClientUserItem* pIClientUserItem)
|
|
{
|
|
//判断自己
|
|
if (m_pMeUserItem == 0)
|
|
{
|
|
m_pMeUserItem = pIClientUserItem;
|
|
}
|
|
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnEventUserEnter(pIClientUserItem, pIClientUserItem->GetUserStatus() == US_LOOKON);
|
|
}
|
|
}
|
|
|
|
void GameMission::OnUserItemDelete(IClientUserItem* pIClientUserItem)
|
|
{
|
|
//变量定义
|
|
uint16 wLastTableID = pIClientUserItem->GetTableID();
|
|
uint16 wLastChairID = pIClientUserItem->GetChairID();
|
|
uint32 dwLeaveUserID = pIClientUserItem->GetUserID();
|
|
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnEventUserLeave(pIClientUserItem, pIClientUserItem->GetUserStatus() == US_LOOKON);
|
|
}
|
|
|
|
if (m_pMeUserItem == pIClientUserItem)
|
|
{
|
|
m_pMeUserItem = NULL;
|
|
}
|
|
|
|
}
|
|
|
|
void GameMission::OnUserItemUpdate(IClientUserItem* pIClientUserItem)
|
|
{
|
|
//变量定义
|
|
tagUserInfo * pUserInfo = pIClientUserItem->GetUserInfo();
|
|
tagUserInfo * pMeUserInfo = m_pMeUserItem->GetUserInfo();
|
|
|
|
|
|
//房间界面通知
|
|
if (pIClientUserItem == m_pMeUserItem)
|
|
{
|
|
//变量定义
|
|
CGlobalUserInfo * pGlobalUserInfo = CGlobalUserInfo::GetInstance();
|
|
tagGlobalUserData * pGlobalUserData = pGlobalUserInfo->GetGlobalUserData();
|
|
|
|
pGlobalUserData->lUserScore = pIClientUserItem->GetUserScore();
|
|
pGlobalUserData->lUserInsure = pIClientUserItem->GetUserInsure();
|
|
}
|
|
|
|
//游戏通知
|
|
if ((pMeUserInfo->wTableID != INVALID_TABLE) && (pUserInfo->wTableID == pMeUserInfo->wTableID))
|
|
{
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnEventUserScore(pIClientUserItem, pIClientUserItem->GetUserStatus() == US_LOOKON);
|
|
}
|
|
}
|
|
}
|
|
|
|
void GameMission::OnUserItemUpdate(IClientUserItem* pIClientUserItem, const tagUserStatus& LastStatus)
|
|
{
|
|
cocos2d::log("GameMission::OnUserItemUpdate\n");
|
|
//变量定义
|
|
tagUserInfo * pUserInfo = pIClientUserItem->GetUserInfo();
|
|
tagUserInfo * pMeUserInfo = m_pMeUserItem->GetUserInfo();
|
|
uint16 wNowTableID = pIClientUserItem->GetTableID(), wLastTableID = LastStatus.wTableID;
|
|
uint16 wNowChairID = pIClientUserItem->GetChairID(), wLastChairID = LastStatus.wChairID;
|
|
uint8 cbNowStatus = pIClientUserItem->GetUserStatus(), cbLastStatus = LastStatus.cbUserStatus;
|
|
|
|
//离开通知
|
|
if ((wLastTableID != INVALID_TABLE) && ((wNowTableID != wLastTableID) || (wNowChairID != wLastChairID)))
|
|
{
|
|
cocos2d::log("GameMission::OnUserItemUpdate_6\n");
|
|
//游戏通知
|
|
if ((pMeUserInfo->wTableID != INVALID_TABLE) && (pUserInfo->wLastTableID == pMeUserInfo->wTableID))
|
|
{
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnEventUserStatus(pIClientUserItem, pIClientUserItem->GetUserStatus() == US_LOOKON);
|
|
}
|
|
}
|
|
}
|
|
|
|
//加入处理
|
|
if ((wNowTableID == INVALID_TABLE) && ((wNowTableID != wLastTableID) || (wNowChairID != wLastChairID)))
|
|
{
|
|
if (m_pMeUserItem == pIClientUserItem)
|
|
{
|
|
//设置变量
|
|
//OnGFGameClose(0);
|
|
CC_ASSERT(g_pGameServerItem != nullptr);
|
|
if (g_pGameServerItem->IsGoldRoom())
|
|
{
|
|
Director::getInstance()->popScene();
|
|
return ;
|
|
}
|
|
}
|
|
}
|
|
|
|
//加入处理
|
|
if ((wNowTableID != INVALID_TABLE) && ((wNowTableID != wLastTableID) || (wNowChairID != wLastChairID)))
|
|
{
|
|
//自己判断
|
|
if (m_pMeUserItem == pIClientUserItem)
|
|
{
|
|
//启动进程
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnEventUserEnter(pIClientUserItem, pIClientUserItem->GetUserStatus() == US_LOOKON);
|
|
}
|
|
}
|
|
|
|
//游戏通知
|
|
if ((m_pMeUserItem != pIClientUserItem) && (pMeUserInfo->wTableID == wNowTableID))
|
|
{
|
|
cocos2d::log("GameMission::OnUserItemUpdate_8\n");
|
|
ASSERT(wNowChairID != INVALID_CHAIR);
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnEventUserEnter(pIClientUserItem, pIClientUserItem->GetUserStatus() == US_LOOKON);
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
//状态改变
|
|
if ((wNowTableID != INVALID_TABLE) && (wNowTableID == wLastTableID) && (pMeUserInfo->wTableID == wNowTableID))
|
|
{
|
|
cocos2d::log("GameMission::OnUserItemUpdate_9\n");
|
|
//游戏通知
|
|
tagUserStatus UserStatus;
|
|
UserStatus.wTableID = wNowTableID;
|
|
UserStatus.wChairID = wNowChairID;
|
|
UserStatus.cbUserStatus = cbNowStatus;
|
|
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnEventUserStatus(pIClientUserItem, pIClientUserItem->GetUserStatus() == US_LOOKON);
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
//用户更新
|
|
void GameMission::OnUserItemUpdate(IClientUserItem * pIClientUserItem, const tagUserAttrib & UserAttrib)
|
|
{
|
|
//变量定义
|
|
uint16 wMeTableID = m_pMeUserItem->GetTableID();
|
|
uint16 wUserTableID = pIClientUserItem->GetTableID();
|
|
|
|
//通知游戏
|
|
if ((wMeTableID != INVALID_TABLE) && (wMeTableID == wUserTableID))
|
|
{
|
|
//发送通知
|
|
if (mIClientKernelSink)
|
|
{
|
|
mIClientKernelSink->OnEventUserScore(pIClientUserItem, pIClientUserItem->GetUserStatus() == US_LOOKON);
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
//中断连接
|
|
bool GameMission::IntermitConnect(bool force)
|
|
{
|
|
cocos2d::log("GameMission::IntermitConnect1 mServiceStatus = %d\n", mServiceStatus);
|
|
if (mServiceStatus == ServiceStatus_Unknow || mServiceStatus == ServiceStatus_NetworkDown)
|
|
return false;
|
|
|
|
//设置状态
|
|
cocos2d::log("GameMission::IntermitConnect2");
|
|
mServiceStatus = ServiceStatus_NetworkDown;
|
|
|
|
try
|
|
{
|
|
stop();
|
|
|
|
if (mUserManager)
|
|
{
|
|
mUserManager->ResetUserItem();
|
|
}
|
|
}
|
|
catch (...)
|
|
{
|
|
|
|
}
|
|
|
|
m_pMeUserItem = nullptr;
|
|
|
|
mUserManager->ResetUserItem();
|
|
|
|
return true;
|
|
}
|
|
|
|
//获取自已
|
|
IClientUserItem* GameMission::GetMeUserItem()
|
|
{
|
|
return m_pMeUserItem;
|
|
}
|
|
|
|
//游戏用户
|
|
IClientUserItem * GameMission::GetTableUserItem(uint16 wChairID)
|
|
{
|
|
return mUserManager->EnumUserItem(wChairID);
|
|
}
|
|
|
|
//连接服务器
|
|
void GameMission::ConnectServerByKind(uint16 wDataID)
|
|
{
|
|
CGameServerItem* pServer = CServerListData::getGameServerByKind(wDataID, FindByServerTypeID);
|
|
if (pServer)
|
|
{
|
|
g_pGameServerItem = pServer;
|
|
m_wGameKindID = pServer->m_GameServer.wKindID;
|
|
setUrl(pServer->m_GameServer.szServerAddr, pServer->m_GameServer.wServerPort);
|
|
start();
|
|
}
|
|
else
|
|
{
|
|
PopScene::Instance().show(utility::a_u8("连接游戏服务器失败!"));
|
|
}
|
|
}
|
|
|
|
//连接服务器
|
|
void GameMission::ConnectServerByServerID(uint16 wServerID)
|
|
{
|
|
CGameServerItem* pServer = CServerListData::shared()->SearchGameServer(wServerID);
|
|
if (pServer)
|
|
{
|
|
g_pGameServerItem = pServer;
|
|
m_wGameKindID = pServer->m_GameServer.wKindID;
|
|
setUrl(pServer->m_GameServer.szServerAddr, pServer->m_GameServer.wServerPort);
|
|
start();
|
|
}
|
|
else
|
|
{
|
|
PopScene::Instance().show(utility::a_u8("房间号错误!"));
|
|
}
|
|
}
|
|
|
|
//执行起立
|
|
bool GameMission::PerformStandUpAction()
|
|
{
|
|
cocos2d::log("GameMission::PerformStandUpAction...\n");
|
|
|
|
//状态过滤
|
|
if (mServiceStatus != ServiceStatus_ServiceIng) return false;
|
|
|
|
//设置界面
|
|
cocos2d::log("GameMission::PerformStandUpAction send\n");
|
|
|
|
//发送命令
|
|
SendStandUpPacket(m_pMeUserItem->GetTableID(), m_pMeUserItem->GetChairID(), FALSE);
|
|
|
|
return true;
|
|
}
|
|
|
|
//发送坐下
|
|
bool GameMission::SendSitDownPacket(uint16 wTableID, uint16 wChairID, const char* lpszPassword)
|
|
{
|
|
CMD_GR_UserSitDown UserSitReq;
|
|
zeromemory(&UserSitReq, 0);
|
|
memset(&UserSitReq, 0, sizeof(UserSitReq));
|
|
UserSitReq.wTableID = wTableID;
|
|
UserSitReq.wChairID = wChairID;
|
|
if (lpszPassword)
|
|
{
|
|
strcpy(UserSitReq.szTablePass, lpszPassword);
|
|
}
|
|
//发送数据包
|
|
SendSocketData(MDM_GR_USER, SUB_GR_USER_SITDOWN, &UserSitReq, sizeof(UserSitReq));
|
|
return true;
|
|
}
|
|
|
|
//发送起立
|
|
bool GameMission::SendStandUpPacket(uint16 wTableID, uint16 wChairID, uint8 cbForceLeave)
|
|
{
|
|
CMD_GR_UserStandUp UserStandUp;
|
|
zeromemory(&UserStandUp, sizeof(UserStandUp));
|
|
|
|
//构造数据
|
|
UserStandUp.wTableID = wTableID;
|
|
UserStandUp.wChairID = wChairID;
|
|
UserStandUp.cbForceLeave = cbForceLeave;
|
|
|
|
//发送数据
|
|
SendSocketData(MDM_GR_USER, SUB_GR_USER_STANDUP, &UserStandUp, sizeof(UserStandUp));
|
|
return true;
|
|
}
|
|
|
|
|
|
//游戏已准备好
|
|
void GameMission::OnGFGameOption()
|
|
{
|
|
cocos2d::log("GameMission::OnGFGameOption\n");
|
|
|
|
//发送地里位置;
|
|
tagUserAddr* pUserAddr = CGlobalUserInfo::GetInstance()->GetUserAddr();
|
|
if (pUserAddr && pUserAddr->isInit)
|
|
{
|
|
cocos2d::log("SUB_GF_USER_LOCATION...\n");
|
|
|
|
CMD_GF_C_UserLocation _location;
|
|
zeromemory(&_location, sizeof(_location));
|
|
|
|
_location.lLatitude = pUserAddr->latitude * DOUBLE_TO_SCORE;
|
|
_location.lLongitude = pUserAddr->longitude * DOUBLE_TO_SCORE;
|
|
_location.lAccuracy = pUserAddr->accuracy * DOUBLE_TO_SCORE;
|
|
|
|
strncpy(_location.szAddress, pUserAddr->strAddress.c_str(), countarray(_location.szAddress));
|
|
|
|
//std::string strInfo = cocos2d::StringUtils::format("%ld, %ld, %ld, %s", _location.lLatitude, _location.lLongitude,
|
|
// _location.lAccuracy, _location.szAddress);
|
|
//cocos2d::log(strInfo.c_str());
|
|
|
|
SendSocketData(MDM_GF_FRAME, SUB_GF_USER_LOCATION, &_location, sizeof(_location));
|
|
}
|
|
|
|
//变量定义
|
|
uint16 wTableID = m_pMeUserItem->GetTableID();
|
|
uint16 wChairID = m_pMeUserItem->GetChairID();
|
|
|
|
mUserAttribute.wChairID = wChairID;
|
|
mUserAttribute.wTableID = wTableID;
|
|
|
|
CMD_GF_GameOption GameOption;
|
|
zeromemory(&GameOption, sizeof(GameOption));
|
|
|
|
//构造数据
|
|
GameOption.dwFrameVersion = VERSION_FRAME;
|
|
GameOption.cbAllowLookon = 0;
|
|
GameOption.dwClientVersion = Helps::Instance()->GetGameVersion();
|
|
|
|
//发送数据
|
|
SendSocketData(MDM_GF_FRAME, SUB_GF_GAME_OPTION, &GameOption, sizeof(GameOption));
|
|
|
|
//mIsGameReady = true;
|
|
}
|
|
|
|
//游戏关闭
|
|
void GameMission::OnGFGameClose(int iExitCode)
|
|
{
|
|
cocos2d::log("GameMission::OnGFGameClose %d\n", iExitCode);
|
|
if (!m_pMeUserItem)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//效验状态
|
|
ASSERT(m_pMeUserItem != 0);
|
|
if (m_pMeUserItem == 0) return;
|
|
|
|
//mIsGameReady = false;
|
|
|
|
//变量定义
|
|
uint8 cbUserStatus = m_pMeUserItem->GetUserStatus();
|
|
mUserAttribute.wChairID = INVALID_CHAIR;
|
|
mUserAttribute.wTableID = INVALID_TABLE;
|
|
|
|
if (iExitCode == ServiceStatus_NetworkDown)
|
|
{
|
|
mServiceStatus = ServiceStatus_NetworkDown;
|
|
}
|
|
|
|
//if (mIClientKernelSink)
|
|
//{
|
|
// mIClientKernelSink->CloseGameClient();
|
|
// mIClientKernelSink = NULL;
|
|
//}
|
|
}
|
|
|
|
void GameMission::SetServerItem(CGameServerItem* pServerItem)
|
|
{
|
|
g_pGameServerItem = pServerItem;
|
|
m_wGameKindID = pServerItem->m_GameServer.wKindID;
|
|
|
|
setUrl(pServerItem->m_GameServer.szServerAddr, pServerItem->m_GameServer.wServerPort);
|
|
}
|
|
|
|
// 游戏录像模拟玩家进入;
|
|
void GameMission::InitRecordGamePlayer(uint16 wChairID, tagGameRecordPlayer& kRecordPlayer)
|
|
{
|
|
//变量定义
|
|
tagUserInfo kUserInfo;
|
|
tagCustomFaceInfo CustomFaceInfo;
|
|
zeromemory(&kUserInfo, sizeof(kUserInfo));
|
|
zeromemory(&CustomFaceInfo, sizeof(CustomFaceInfo));
|
|
|
|
// 赋值;
|
|
kUserInfo.dwUserID = kRecordPlayer.dwUserID;
|
|
kUserInfo.dwGameID = kRecordPlayer.dwGameID;
|
|
kUserInfo.cbGender = kRecordPlayer.cbSex;
|
|
kUserInfo.lScore = kRecordPlayer.lScore;
|
|
|
|
//如果游戏中使用GamePlayer需要增加下面三行;
|
|
kUserInfo.wTableID = 0;
|
|
kUserInfo.wChairID = wChairID;
|
|
kUserInfo.cbUserStatus = US_SIT;
|
|
|
|
strcpy(kUserInfo.szNickName, kRecordPlayer.strNickName.c_str());
|
|
strcpy(kUserInfo.szHeadHttp, kRecordPlayer.strHead.c_str());
|
|
|
|
//激活用户
|
|
IClientUserItem * pIClientUserItem = mUserManager->SearchUserByUserID(kUserInfo.dwUserID);
|
|
pIClientUserItem = mUserManager->ActiveUserItem(kUserInfo, CustomFaceInfo);
|
|
|
|
CMD_GR_UserStatus userStatus;
|
|
userStatus.dwUserID = kRecordPlayer.dwUserID;
|
|
userStatus.UserStatus.wTableID = 0;
|
|
userStatus.UserStatus.wChairID = wChairID;
|
|
userStatus.UserStatus.cbUserStatus = US_PLAYING;
|
|
OnSocketSubUserStatus(&userStatus, sizeof(CMD_GR_UserStatus));
|
|
} |