📄 msgtalk.org
字号:
// MsgTalk.cpp: implementation of the CMsgTalk class.
//
//////////////////////////////////////////////////////////////////////
#include "AllMsg.h"
#ifdef WORLD_KERNEL
#include "userlist.h"
#else
#pragma warning(disable:4786)
#include "mapgroup.h"
#endif
#include "user.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMsgTalk::CMsgTalk()
{
Init();
m_pInfo =(MSG_Info* )m_bufMsg;
m_StrPacker.SetBuf(m_pInfo->szBuf, _MAX_MSGSIZE-sizeof(MSG_Info)+1);
}
CMsgTalk::~CMsgTalk()
{
}
//////////////////////////////////////////////////////////////////////
BOOL CMsgTalk::Create(LPCTSTR pszSpeaker, LPCTSTR pszHearer, LPCTSTR pszWords,
LPCTSTR pszEmotion, DWORD dwColor, unsigned short unAttribute,
unsigned short unStyle)
{
if(!pszSpeaker || strlen(pszSpeaker) >= _MAX_NAMESIZE)
return false;
if(!pszHearer || strlen(pszHearer) >= _MAX_NAMESIZE)
return false;
if(!pszWords || strlen(pszWords) >= _MAX_WORDSSIZE)
return false;
// can be null
if(pszEmotion && strlen(pszEmotion) >= _MAX_NAMESIZE)
return false;
// fill
this->Init();
// fill structure
m_pInfo->dwWordsColor =dwColor;
m_pInfo->unTxtAttribute =unAttribute;
m_pInfo->unTxtStyle =unStyle;
m_pInfo->dwTime =::SysTimeGet();
BOOL bSucMake =true;
bSucMake &=m_StrPacker.AddString(pszSpeaker);
bSucMake &=m_StrPacker.AddString(pszHearer);
bSucMake &=m_StrPacker.AddString(pszEmotion);
bSucMake &=m_StrPacker.AddString(pszWords);
m_unMsgType =_MSG_TALK;
m_unMsgSize =sizeof(MSG_Info)-1+m_StrPacker.GetSize();
return bSucMake;
}
//////////////////////////////////////////////////////////////////////
BOOL CMsgTalk::Create(char* pbufMsg, DWORD dwMsgSize)
{
if(!pbufMsg)
return false;
memcpy(this->m_bufMsg, pbufMsg, dwMsgSize);
return true;
}
//////////////////////////////////////////////////////////////////////
void CMsgTalk::Process(void *pInfo)
{
#ifdef _MSGDEBUG
::LogMsg("Process MsgTalk, Sender:%s, Receiver:%s, Words:%s",
szSender,
szReceiver,
szWords);
#endif
char szSender[_MAX_NAMESIZE];
char szReceiver[_MAX_NAMESIZE];
char szEmotion[_MAX_NAMESIZE];
char szWords[_MAX_WORDSSIZE];
m_StrPacker.GetString(0, szSender, sizeof(szSender));
m_StrPacker.GetString(1, szReceiver, sizeof(szReceiver));
m_StrPacker.GetString(2, szEmotion, sizeof(szEmotion));
m_StrPacker.GetString(3, szWords, sizeof(szWords));
CHECK(strlen(szWords) <= 255);
IRole* pRole = RoleManager()->QueryRole(this);
if(!pRole)
{
if(IsNpcMsg())
return;
// TransmitMsg
switch(m_pInfo->unTxtAttribute)
{
case _TXTATR_SYNDICATE:
{
OBJID idSyn = m_pInfo->idTransmit;
CSyndicate* pSyn = SynManager()->QuerySyndicate(idSyn);
if (pSyn)
{
pSyn->BroadcastSynMsg(this, NULL);
}
}
break;
}
return;
}
CUser* pUser = NULL;
pRole->QueryObj(OBJ_USER, IPP_OF(pUser)); //? pUser may be null
if(pUser && strcmp(pUser->GetName(), szSender) != 0)
{
if (!pUser->IsGM())
{
::GmLogSave("玩家[%s]企图冒用他人名字[%s]发布Talk消息,请予封号。", pUser->GetName(), szSender);
return ;
}
}
if(!pRole->IsTalkEnable())
{
pRole->SendSysMsg(STR_CAN_NOT_TALK);
return;
}
if(pUser && pUser->IsGM())
{
::GmLogSave("-TALK %s->%s: %s", szSender, szReceiver, szWords);
}
if(pUser && szWords[0] == '/')
{
char szCmd[_MAX_WORDSSIZE] = "NO_CMD";
char szParam[_MAX_WORDSSIZE] = "";
DEBUG_TRY // VVVVVVVVVVVVVVVVVVVVVVVVV
sscanf(szWords+1, "%s %s", szCmd, szParam);
if(stricmp(szCmd, "pro") == 0)
{
if(pUser->IsPM())
{
int nData = atoi(szParam);
pUser->SetAttrib(_USERATTRIB_PORFESSION, nData, SYNCHRO_TRUE);
}
}
else if (stricmp(szCmd, "焰火") == 0)
{
if(pUser->IsGM())
{
CMsgItem msg;
IF_OK (msg.Create(pUser->GetID(), ITEMACT_FIREWORKS))
pUser->BroadcastRoomMsg(&msg, true);
}
}
else if (stricmp(szCmd, "焰火2") == 0)
{
if(pUser->IsGM())
{
int nLen = strlen(szParam);
if (nLen > 0 && nLen < 9)
{
CMsgName msg;
IF_OK (msg.Create(NAMEACT_FIREWORKS, szParam))
pUser->BroadcastRoomMsg(&msg, true);
}
}
}
else if (stricmp(szCmd, "kickoutcheat") == 0)
{
if(pUser->IsPM())
{
int nData = 0;
if (2 == sscanf(szWords+1, "%s %d", szCmd, &nData))
{
extern long g_sKickoutCheat;
long nOld = InterlockedExchange(&g_sKickoutCheat, nData);
pUser->SendSysMsg("set kickoutcheat OK! old value is %d", nOld);
}
}
}
#ifdef _DEBUG
else if (stricmp(szCmd, "recover") == 0)
{
int nData = 0;
if (2 == sscanf(szWords+1, "%s %d", szCmd, &nData))
{
pUser->RecoverEquipmentDur(nData);
}
}
else if (stricmp(szCmd, "weaponexp") == 0)
{
int nData = 0, nWeapon = 0;
if (3 == sscanf(szWords+1, "%s %d %d", szCmd, &nWeapon, &nData))
{
pUser->AddWeaponSkillExp(nWeapon, nData);
}
}
else if (stricmp(szCmd, "itemquality") == 0)
{
int nData = atoi(szParam);
pUser->UpEquipmentQuality(nData);
}
else if (stricmp(szCmd, "itemlev") == 0)
{
int nData = atoi(szParam);
pUser->UpEquipmentLevel(nData);
}
else if (stricmp(szCmd, "divoice") == 0)
{
pUser->Divorce();
}
else if (stricmp(szCmd, "resetlev") == 0)
{
int nForce = 5, nSpeed = 2, nHealth = 3, nSoul = 0;
int nPro = pUser->GetProfessionSort();
if (nPro == 1)
pUser->SetAttrib(_USERATTRIB_PORFESSION, 10, SYNCHRO_TRUE);
else if (nPro == 2)
pUser->SetAttrib(_USERATTRIB_PORFESSION, 20, SYNCHRO_TRUE);
else if (nPro >= 10 && nPro < 20)
{
pUser->SetAttrib(_USERATTRIB_PORFESSION, 100, SYNCHRO_TRUE);
nForce = 0;
nSpeed = 2;
nHealth = 3;
nSoul = 5;
}
pUser->SetAttrib(_USERATTRIB_FORCE, nForce, SYNCHRO_TRUE);
pUser->SetAttrib(_USERATTRIB_SOUL, nSoul, SYNCHRO_TRUE);
pUser->SetAttrib(_USERATTRIB_HEALTH, nHealth, SYNCHRO_TRUE);
pUser->SetAttrib(_USERATTRIB_SPEED, nSpeed, SYNCHRO_TRUE);
pUser->SetAttrib(_USERATTRIB_LEV, 1, SYNCHRO_TRUE);
}
else if (stricmp(szCmd, "rename") == 0)
{
pUser->SetName(szParam);
pUser->SendSysMsg("阁下已经更名为%s。", szParam);
}
else if(stricmp(szCmd, "pk") == 0)
{
int nData = 0;
if (2 == sscanf(szWords+1, "%s %d", szCmd, &nData))
{
int nDeltaPk = nData - pUser->GetPk();
pUser->AddPk(nDeltaPk);
}
}
else if(stricmp(szCmd, "addpoint") == 0)
{
int nData = 0;
if (2 == sscanf(szWords+1, "%s %d", szCmd, &nData))
{
pUser->SetAttrib(_USERATTRIB_ADDPOINT, nData, SYNCHRO_TRUE);
}
}
else if(stricmp(szCmd, "testmonster") == 0)
{
DWORD dwType = 0, dwAmount = 0;
if (3 == sscanf(szWords+1, "%s %u %u", szCmd, &dwType, &dwAmount))
{
CNpcType* pType = MonsterType()->GetObj(dwType);
if (pType)
{
for (int j=0; j<dwAmount; j++)
{
ST_CREATENEWNPC info;
memset(&info, 0L, sizeof(info));
info.id = MONSTERID_FIRST+j;
info.idMap = 1002;
CMonster* pMonster = CMonster::CreateNew();
if (pMonster->Create(m_idProcess, pType, &info))
{
pMonster->BeKill(pUser->QueryRole());
}
pMonster->ReleaseByOwner();
}
}
}
}
#endif
else if(stricmp(szCmd, "sp") == 0)
{
if(pUser->IsPM())
{
int nData = atoi(szParam);
pUser->SetAttrib(_USERATTRIB_ENERGY, nData, SYNCHRO_TRUE);
}
}
else if(stricmp(szCmd, "awardmoney") == 0)
{
if(pUser->IsPM())
{
int nMoney = atoi(szParam);
if(pUser->GainMoney(nMoney, SYNCHRO_TRUE))
pUser->SendSysMsg("[您的钱增加了。]");
}
}
else if(stricmp(szCmd, "awarditem") == 0)
{
if(pUser->IsPM())
{
int nItemType = atoi(szParam);
if(pUser->AwardItem(nItemType, SYNCHRO_TRUE))
pUser->SendSysMsg("[您的物品增加了。]");
}
}
else if(stricmp(szCmd, "kickout") == 0)
{
if(pUser->IsGM())
{
CUserPtr pTarget = UserManager()->GetUser(szParam);
if (pTarget)
{
UserManager()->KickOutSocket(pTarget->GetSocketID(), "GM /kickout");
}
}
}
else if(stricmp(szCmd, "kickoutall") == 0)
{
if(pUser->IsGM())
{
LOGMSG("kickoutall process!");
pUser->SendSysMsg(STR_KICKOUT_ALL);
MapGroup(PID)->QueryIntraMsg()->PrintText("Server stop by GM, close server please!");
MapGroup(PID)->QueryIntraMsg()->CloseMapGroup(GetSocketID());
}
}
else if(stricmp(szCmd, "find") == 0)
{
if(pUser->IsGM())
{
CUserPtr pTarget = UserManager()->GetUser(szParam);
if (pTarget)
{
int nPosX = pTarget->GetPosX();
int nPosY = pTarget->GetPosY();
pUser->FlyMap(pTarget->GetMapID(), nPosX, nPosY);
}
}
}
else if(stricmp(szCmd, "uplev") == 0)
{
if (pUser->IsPM())
{
int nLev = atoi(szParam);
if (nLev > 0)
{
pUser->IncLev(nLev);
// pUser->AddAttrib(_USERATTRIB_ADDPOINT, nLev*_ADDITIONALPOINT_NUM, SYNCHRO_TRUE);
pUser->AllotPoint();
CMsgAction msg;
if (msg.Create(pUser->GetID(), 0, 0, 0, actionUplev, 0, 0))
pUser->BroadcastRoomMsg(&msg, INCLUDE_SELF);
pUser->AddAttrib(_USERATTRIB_LEV, 0, SYNCHRO_TRUE);
}
}
}
else if(stricmp(szCmd, "life") == 0)
{
if (pUser->IsGM())
{
int nData = pUser->GetMaxLife();
pUser->SetAttrib(_USERATTRIB_LIFE, nData, SYNCHRO_TRUE);
}
}
else if(stricmp(szCmd, "mana") == 0)
{
if (pUser->IsGM())
{
int nData = pUser->GetMaxMana();
pUser->SetAttrib(_USERATTRIB_MANA, nData, SYNCHRO_TRUE);
}
}
else if(stricmp(szCmd, "mapdata") == 0)
{
if (pUser->IsGM())
{
int x = 0, y = 0;
if (3 == sscanf(szWords+1, "%s %d %d", szCmd, &x, &y))
{
int nAttr=-1, nMask=-1, nAlt=-1, nAlt2=-1;
if(pUser->GetMap()->GetDebugData(&nAttr, &nMask, &nAlt, &nAlt2, x, y))
pUser->SendSysMsg("ATTR: %d, MASK: %d, ALT: %d, ALT2: %d", nAttr, nMask, nAlt, nAlt2);
}
}
}
else if(stricmp(szCmd, "showaction") == 0)
{
if (pUser->IsGM())
{
if(pUser->DebugShowAction())
pUser->SendSysMsg("可以显示ACTION了。");
else
pUser->SendSysMsg("不显示ACTION了。");
}
}
else if(stricmp(szCmd, "fullxp") == 0)
{
if (pUser->IsGM())
{
pUser->SetXp(100);
}
}
else if(stricmp(szCmd, "xp") == 0)
{
if (pUser->IsPM())
{
int nData = 0;
if (2 == sscanf(szWords+1, "%s %d", szCmd, &nData))
{
pUser->SetXp(__min(100, nData));
}
else
pUser->SetXp(100);
}
}
else if(stricmp(szCmd, "awardwskill") == 0)
{
if (pUser->IsPM())
{
int nSkillType = 0, nLev = 0;
if (3 == sscanf(szWords+1, "%s %d %d", szCmd, &nSkillType, &nLev))
{
pUser->AwardWeaponSkill(nSkillType, nLev);
}
}
}
else if(stricmp(szCmd, "awardmagic") == 0)
{
if (pUser->IsPM())
{
int nSkillType = 0, nLev = 0;
if (3 == sscanf(szWords+1, "%s %d %d", szCmd, &nSkillType, &nLev))
{
pUser->QueryMagic()->LearnMagic(nSkillType);
for (int i=0; i<nLev; i++)
pUser->QueryMagic()->UpLevelByTask(nSkillType);
}
}
}
else if(stricmp(szCmd, "superman") == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -