📄 mirkernel.cpp
字号:
{
s_Game.SendString("*");
}
else
{
tmpBuf2[leftlen++]=tmpBuf[i];
}
if(tmpBuf[i]=='!') // 遇到'!'字符表示当前消息结束,开下一条消息
{
tmpBuf2[leftlen]='\0';
pLoginInfo->m_RecvQueue->PutMsg(tmpBuf2);
leftlen=0;
}
}
}
while(pLoginInfo->m_SendQueue->GetMsg(&msg))
{
s_Game.SendMsg(&msg);
}
}
s_Game.Close();
return TRUE;
}
///////////////////////////////////////////////////////////////////////
//
// 函数名 : NetworkThread
// 功能描述 : 用来包装_NetworkThread函数,并且做一些初始化及善后工作
// 参数 : LPVOID pParam
// 返回值 : UINT
//
///////////////////////////////////////////////////////////////////////
UINT NetworkThread(LPVOID pParam)
{
LoginInfo*p=(LoginInfo*)pParam;
p->m_InGame=TRUE;
_NetworkThread(pParam);
LogSystem("通讯线程退出");
p->m_InGame=FALSE;
return TRUE;
}
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
//
// 函数名 : CMirKernel::CMirKernel
// 功能描述 : CMirKernel构造函数
// 返回值 : 无
//
///////////////////////////////////////////////////////////////////////
CMirKernel::CMirKernel()
{
m_LogList.RemoveAll();
m_LoginInfo.m_InGame=FALSE;
}
CMirKernel::~CMirKernel()
{
}
void CMirKernel::Start(LPCTSTR IP, LPCTSTR Name, LPCTSTR UID, LPCTSTR PWD, int Char)
{
m_LoginInfo.m_ServerIP = IP;
m_LoginInfo.m_ServerName = Name;
m_LoginInfo.m_Account = UID;
m_LoginInfo.m_Password = PWD;
m_LoginInfo.m_Character = Char;
m_LoginInfo.m_LogList = &m_LogList;
m_LoginInfo.m_SendQueue = &m_SendQueue;
m_LoginInfo.m_RecvQueue = &m_RecvQueue;
m_LoginInfo.m_InGame = TRUE;
AfxBeginThread(NetworkThread, &m_LoginInfo);
}
BOOL CMirKernel::InGame()
{
return m_LoginInfo.m_InGame;
}
///////////////////////////////////////////////////////////////////////
//
// 函数名 : CMirKernel::GameProc
// 功能描述 : 游戏核心函数
// 返回值 : void
//
///////////////////////////////////////////////////////////////////////
void CMirKernel::GameProc()
{
MMSG msg;
char*pTxt=new char[1024];
int i;
CString str;
ZeroMemory(&msg,sizeof(msg));
while(GetMsg(&msg))
{
//LogSystem("处理消息:wCmd=0x%04x",msg.wCmd);
switch(msg.wCmd)
{
case 0x9:
LogSystem("重新设置角色坐标");
if(msg.dwFlag==m_PlayerInfo.id)
{
SetCharacterPos(msg.w1,msg.w2);
LogSystem("重新设置角色坐标在%d,%d...",msg.w1,msg.w2);
/*if(m_LastAction.action!=0)
{
m_LastAction.x=msg.w1;
m_LastAction.y=msg.w2;
}*/
}
break;
case 0xa:
//LogSystem("有人出现");
if(msg.data[8]!=(char)0)
{
CMirSocket::UnNameCode(&msg.data[8],pTxt);
MonInfo mon;
mon.id=msg.dwFlag;
mon.position.x=msg.w1;
mon.position.y=msg.w2;
mon.name=pTxt;
m_MonList.Appear(&mon);
//LogSystem("%s",pTxt);
}
else
{
MonInfo mon;
mon.id=msg.dwFlag;
mon.position.x=msg.w1;
mon.position.y=msg.w2;
mon.name.Empty();
m_MonList.Appear(&mon);
}
break;
case 0x1e:
//LogSystem("有人消失");
m_MonList.Disappear(msg.dwFlag);
break;
case 0x1f:
LogSystem("HP变化");
if(msg.dwFlag==m_PlayerInfo.id)
{
m_PlayerInfo.hpcur=msg.w1;
m_PlayerInfo.hpmax=msg.w2;
}
else
{
MonInfo mon;
mon.id=msg.dwFlag;
mon.hpcur=msg.w1;
mon.hpmax=msg.w2;
m_MonList.Appear(&mon);
}
break;
case 0x22:
LogSystem("有人被杀死");
if(msg.dwFlag==m_PlayerInfo.id)
{
LogSystem("你被杀死了!");
}
else
{
m_MonList.Disappear(msg.dwFlag);
}
break;
case 0x2a:// 玩家角色名字
LogSystem("玩家角色名字");
if(msg.w1=0xff && m_PlayerInfo.id==msg.dwFlag)
{
m_PlayerInfo.name=msg.data;
LogSystem("玩家角色名字 %s",msg.data);
}
break;
case 0x33:
LogSystem("玩家ID");
m_PlayerInfo.id=msg.dwFlag;
m_GameMap.SetMap(msg.data);
SetCharacterPos(msg.w1,msg.w2);
break;
case 0x34:
{
MMSGSETCHARINFO*pmsginfo=(MMSGSETCHARINFO*)&msg;
LogSystem("等级:%u",pmsginfo->bLevel);
LogSystem("金币:%u",pmsginfo->dwGold);
LogSystem("防御:%u-%u",pmsginfo->ACHi, pmsginfo->ACLow);
LogSystem("魔御:%u-%u",pmsginfo->MACHi, pmsginfo->MACLow);
LogSystem("攻击:%u-%u",pmsginfo->DCHi,pmsginfo->DCLow);
LogSystem("魔法:%u-%u",pmsginfo->MCHi, pmsginfo->MCLow);
LogSystem("道术:%u-%u",pmsginfo->SCHi, pmsginfo->SCLow);
break;
}
case 0x35:
m_PlayerInfo.hpmax=msg.w3;
m_PlayerInfo.hpcur=msg.w1;
m_PlayerInfo.mp=msg.w2;
break;
case 0x36:
{
CString s=msg.data;
LogSystem("当前地图 %s.",s);
break;
}
case 0x64:
str.Format("系统信息> %s",msg.data);
LogSystem(str);
break;
case 0x28:
case 0x68:
str.Format("聊天频道> %s",msg.data);
LogSystem(str);
break;
case 0x262:// 地上出现物品
LogSystem("物品 %s 出现在:(%d,%d)",msg.data,msg.w1,msg.w2);
break;
case 0x279:
LogSystem("切换地图!");
break;
case 0x27a:
if(msg.dwFlag==m_PlayerInfo.id)
{
SetCharacterPos(msg.w1,msg.w2);
LogSystem("切换地图后,重新设置角色坐标在%d,%d ...",msg.w1,msg.w2);
/*if(m_LastAction.action!=0)
{
m_LastAction.x=msg.w1;
m_LastAction.y=msg.w2;
}*/
}
break;
case 0x291:
if(msg.w2==80)
LogSystem("身体状态:隐身");
else
LogSystem("身体状态:正常");
case 0x292:// 进入游戏世界
for(i=0;i<1024;i++)
{
if(msg.data[i]==0x1b || msg.data[i]==0x9)
msg.data[i]=' ';
}
str.Format("传奇公约[%s]",msg.data);
LogSystem(str);
//LogSystem("进入游戏世界...");
break;
case 0x2c4:
if(msg.w1==0)
LogSystem("当前地图不是战斗地图");
else
LogSystem("当前地图是战斗地图");
break;
case 0x2ee:// 玩家行会信息
str.Format("玩家行会信息 %s",msg.data);
LogSystem(str);
break;
default:
break;
}
ZeroMemory(&msg,sizeof(msg));
}
}
///////////////////////////////////////////////////////////////////////
//
// 函数名 : CMirKernel::LogSystem
// 功能描述 : 将字符串格式化后输出到用户界面
// 参数 : const char *line
// 参数 : ...
// 返回值 : void
//
///////////////////////////////////////////////////////////////////////
void CMirKernel::LogSystem(const char *line, ...)
{
CString str;
va_list vl;
va_start(vl,line);
str.Format(line,vl);
va_end(vl);
m_LogList.AddTail((LPCTSTR)str);
}
void CMirKernel::SetCharacterPos(long x, long y)
{
m_PlayerInfo.position.x=x;
m_PlayerInfo.position.y=y;
}
int CMirKernel::GetMsg(MMSG *pMsg)
{
int ilen = 0;
char tmpBuf[8000];
MMSG msg;
ZeroMemory(tmpBuf,8000);
ZeroMemory(&msg,sizeof(MMSG));
if(m_RecvQueue.GetMsg(tmpBuf))
{
ilen=strlen(tmpBuf);
if(tmpBuf[ilen-1]=='!')
{
tmpBuf[ilen-1]='\0';
}
if(tmpBuf[1]=='+' )
{
tmpBuf[6] = '\0';
if(stricmp(tmpBuf,"#+GOOD")==0)
{
//ActionOk();
LogSystem("Action OK!!");
}
else if(stricmp(tmpBuf,"#+FAIL")==0)
{
//ActionFail();
LogSystem("Action Fail!!");
}
return GetMsg(pMsg);
}
ilen=CMirSocket::UnGameCode(&tmpBuf[1],(BYTE*)pMsg);
// 只有这里是这个函数的正确出口
// 处理一些必要的网络操作
if(pMsg->wCmd==0x292)
{
ZeroMemory(&msg,sizeof(msg));
msg.wCmd=0x3fa;
m_LoginInfo.m_GameSocket->SendMsg(&msg);
LogSystem("发送0x3fa");
}
else if(pMsg->wCmd==0x36)
{
ZeroMemory(&msg,sizeof(MMSG));
msg.wCmd=0x409;
m_LoginInfo.m_GameSocket->SendMsg(&msg);
LogSystem("发送0x409");
}
return ilen;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -