📄 gamemsg.cpp
字号:
}
}
else
{
int nLast = ( m_nMaxLine < m_dequeMsg[m_usCurShowChannel].size() ) ? m_dequeMsg[m_usCurShowChannel].size() - m_nMaxLine : 0 ;
for ( i = m_dequeMsg[m_usCurShowChannel].size() - 1 - ( m_nLastShowLineIndex[m_usCurShowChannel] - m_nMaxLine );
i >= nLast - ( m_nLastShowLineIndex[m_usCurShowChannel] - m_nMaxLine );
i-- )
{
CGameMsgUnit* pMsg = m_dequeMsg[m_usCurShowChannel][i] ;
if ( pMsg && this->GetChannelStatus(pMsg->m_unTxtAttribute))
{
int nLines = pMsg->GetLines( m_nNorAreaWidth );
nTotalLines += nLines;
if (nTotalLines > m_nMaxLine)
{
break;
}
pos.y = pos.y - (nFontHeight+6) * nLines;
char* pszName = pMsg->Show(pos.x, pos.y, bCapture, m_nNorAreaWidth);
if(pszName)
{
strcpy(m_szCaptureName, pszName);
bGetCapturename = true;
}
}
}
if(bCapture)
{
const OBJID idStr = 100130;
CMyBitmap::ShowString(pos.x+4, this->GetNorAeroTop()-1 -40, 0xff000000, g_objGameDataSet.GetStr(idStr),(char*)g_objGameDataSet.GetStr(FONT_NAME),MSGFONT_HEIGHT);
CMyBitmap::ShowString(pos.x+3, this->GetNorAeroTop()-2 -40, 0xffffff00, g_objGameDataSet.GetStr(idStr),(char*)g_objGameDataSet.GetStr(FONT_NAME),MSGFONT_HEIGHT);
}
}
if(!bGetCapturename)
strcpy(m_szCaptureName, "");
}
m_dwTime++;
#ifdef _ANALYSIS_ON
g_dwTxtMsgTimeCost += ::TimeGet() - dwTimeBegin;
#endif
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
BOOL CGameMsg::AddMsg ( const char *pszSender,
char *pszReceiver,
char *pszEmotion,
char *pszMsg,
DWORD dwWordsColor,
unsigned short unTxtStyle,
unsigned short unTxtAttribute,
DWORD dwTime)
{
// Test if every elements is availability
if ( ( strlen( pszSender ) == 0 ) ||
( !pszMsg || _MAX_WORDSSIZE < strlen( pszMsg ) ) ||
( !pszSender || _MAX_NAMESIZE < strlen( pszSender ) ) ||
( !pszReceiver || _MAX_NAMESIZE < strlen( pszReceiver ) ) ||
( pszEmotion && _MAX_EMOTIONSIZE < strlen( pszEmotion ) ) )
return false;
if ( ( unTxtAttribute < _TXTATR_NORMAL || unTxtAttribute > _TXTATR_SERVE ) && unTxtAttribute != _TXTATR_LEAVEWORD )
{
return false ;
}
//密码警告提示
if (unTxtAttribute != _TXTATR_SYSTEM && m_nWarningTime < 3)
{
char* szMsgUp = strupr(strdup(pszMsg)); //大写化字符串
char* nPos1 = strstr(szMsgUp, g_objGameDataSet.GetStr(WARNING_CHAR1));
char* nPos2 = strstr(szMsgUp, g_objGameDataSet.GetStr(WARNING_CHAR2));
int nResoult1 = nPos1 - szMsgUp + 1;
int nResoult2 = nPos1 - szMsgUp + 1;
char* nPos3 = strstr(szMsgUp, g_objGameDataSet.GetStr(WARNING_CHAR3));
char* nPos4 = strstr(szMsgUp, g_objGameDataSet.GetStr(WARNING_CHAR4));
if (( (nPos1 !=NULL && nPos2 != NULL) && (nPos1 - nPos2) <3)
|| nPos3 != NULL || nPos4 != NULL)
{
m_dwShowWarning = ::TimeGet();
m_nWarningTime++;
strcpy(m_szWarning, g_objGameDataSet.GetStr(20000)); //
this->AddMsg(_TXTATR_GM, (char*)g_objGameDataSet.GetStr(20000));
}
}
if (!g_objHero.IsGhost() && unTxtAttribute == _TXTATR_GHOST)
return false;
// Create a temp message unit and fill it
if ( unTxtAttribute == _TXTATR_SYSTEM )
{
for (int i = m_nSysAreaAmount - 1; i >= 0; i-- )
{
CGameMsgUnit* pMsg = m_dequeMsg[m_nSysAreaShowIndex[i * 2]][m_nSysAreaShowIndex[i * 2 + 1]] ;
if( pMsg )
{
if ( 0 == strcmp(pMsg->m_szMsg, pszMsg))
{
pMsg->m_dwBeginTime = ::TimeGet();
pMsg->m_unTxtStyle |= 0x0002;
return true;
}
}
}
}
CGameMsgUnit* pNewMsg = new CGameMsgUnit;
if(!pNewMsg)
return false;
char szTemp[_MAX_WORDSSIZE * 2];
strcpy(szTemp, pszMsg);
if(_TXTATR_ACTION == unTxtAttribute)
sprintf(szTemp, pszMsg, pszSender, pszReceiver); // 替换动作中的%s
strcpy(pNewMsg->m_szMsg, szTemp);
strcpy(pNewMsg->m_szSender, pszSender);
if (strcmp(pszReceiver,STRING_ALL_USERS) == 0)
strcpy(pNewMsg->m_szReceiver, g_objGameDataSet.GetStr(STR_ALLUSERS));
else
strcpy(pNewMsg->m_szReceiver, pszReceiver);
if (pszEmotion)
strcpy(pNewMsg->m_szEmotion, pszEmotion);
g_objGameMsg.GetChannelColor(unTxtAttribute, pNewMsg->m_dwWordsColor);
pNewMsg->m_unTxtStyle = unTxtStyle;
pNewMsg->m_unTxtAttribute = unTxtAttribute;
pNewMsg->m_dwTime = dwTime;
pNewMsg->m_dwBeginTime = ::TimeGet();
pNewMsg->m_nStartX = 0;
pNewMsg->m_nDragStep = 0;
pNewMsg->m_nQuakeFlag = 1;
pNewMsg->m_bSuper = false;
m_objChatLog.Log ( pNewMsg ) ;
// Add the leaveword to deque
if ( pNewMsg->m_unTxtAttribute == _TXTATR_LEAVEWORD )
{
if ( strcmp( pszSender, g_objHero.GetName() ) == 0 )
{
SAFE_DELETE( pNewMsg ) ;
return false ;
}
else
{
m_dequeLeaveMsg.push_back( pNewMsg ) ;
return true;
}
}
// Add the message to the deque
int nDequeIndex = pNewMsg->m_unTxtAttribute - _TXTATR_NORMAL - 1 ;
// The normal channel
if ( pNewMsg->m_unTxtAttribute == _TXTATR_NORMAL )
nDequeIndex = 6 ;
m_dequeMsg[nDequeIndex].push_back ( pNewMsg ) ;
// Test if the current channel message is out of range
int nDequeSize = ( int ) m_dequeMsg[nDequeIndex].size() ;
if ( nDequeSize > m_nMaxMsgLine[nDequeIndex] )
{
// The deque is full, kick off the first message
SAFE_DELETE ( m_dequeMsg[nDequeIndex][0] ) ;
m_dequeMsg[nDequeIndex].pop_front();
nDequeSize-- ;
// process every area
if ( pNewMsg->m_unTxtAttribute == _TXTATR_SYSTEM )
// The system area
ProcessArea ( m_nSysAreaAmount, _SYSAREA_MSG_LINE, nDequeIndex, nDequeSize, m_nSysAreaShowIndex, true ) ;
else if ( pNewMsg->m_unTxtAttribute == _TXTATR_GM )
// The manager area
ProcessArea ( m_nManAreaAmount, _MANAREA_MSG_LINE, nDequeIndex, nDequeSize, m_nManAreaShowIndex, true ) ;
else
// The normal area
ProcessArea ( m_nNorAreaAmount, _NORAREA_MSG_LINE, nDequeIndex, nDequeSize, m_nNorAreaShowIndex, true ) ;
}
else
{
// process every area
if ( pNewMsg->m_unTxtAttribute == _TXTATR_SYSTEM )
// The system area
ProcessArea ( m_nSysAreaAmount, _SYSAREA_MSG_LINE, nDequeIndex, nDequeSize, m_nSysAreaShowIndex, false ) ;
else if ( pNewMsg->m_unTxtAttribute == _TXTATR_GM )
// The manager area
ProcessArea ( m_nManAreaAmount, _MANAREA_MSG_LINE, nDequeIndex, nDequeSize, m_nManAreaShowIndex, false ) ;
else
// The normal area
ProcessArea ( m_nNorAreaAmount, _NORAREA_MSG_LINE, nDequeIndex, nDequeSize, m_nNorAreaShowIndex, false ) ;
}
pNewMsg->GetText(szTemp);
szTemp[_MAX_WORDSSIZE-1] = '\0';
m_setMsg.AddMsg(szTemp);
return true;
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Add the message have not sender and receiver
BOOL CGameMsg::AddMsg ( const char* pszMsg,
DWORD dwChannel,
DWORD dwWordsColor,
DWORD dwStyle, BOOL bSuper)
{
// Test if the message is availability
if ( !pszMsg || _MAX_WORDSSIZE <= strlen ( pszMsg ) )
return false;
if ( dwChannel < _TXTATR_NORMAL || dwChannel > _TXTATR_SERVE )
{
return false ;
}
if (!g_objHero.IsGhost() && dwChannel == _TXTATR_GHOST)
return false;
// Create a temp message unit and fill it
if ( dwChannel == _TXTATR_SYSTEM )
{
for (int i = m_nSysAreaAmount - 1; i >= 0; i-- )
{
CGameMsgUnit* pMsg = m_dequeMsg[m_nSysAreaShowIndex[i * 2]][m_nSysAreaShowIndex[i * 2 + 1]] ;
if( pMsg )
{
if ( 0 == strcmp(pMsg->m_szMsg, pszMsg))
{
pMsg->m_dwBeginTime = ::TimeGet();
pMsg->m_unTxtStyle |= 0x0002;
return true;
}
}
}
}
CGameMsgUnit* pNewMsg = new CGameMsgUnit;
if(!pNewMsg)
return false;
strcpy(pNewMsg->m_szMsg, pszMsg);
strcpy(pNewMsg->m_szSender, STRING_SYSTEM);
strcpy(pNewMsg->m_szReceiver, g_objGameDataSet.GetStr(STR_ALLUSERS));
strcpy(pNewMsg->m_szEmotion, "");
pNewMsg->m_dwWordsColor = dwWordsColor;
g_objGameMsg.GetChannelColor(dwChannel, pNewMsg->m_dwWordsColor);
pNewMsg->m_unTxtStyle = dwStyle;
pNewMsg->m_unTxtAttribute = dwChannel;
pNewMsg->m_nStartX = 0;
pNewMsg->m_nDragStep = 0;
pNewMsg->m_nQuakeFlag = 1;
pNewMsg->m_bSuper = bSuper;
pNewMsg->m_dwTime = ::SysTimeGet();
pNewMsg->m_dwBeginTime = ::TimeGet();
m_objChatLog.Log ( pNewMsg ) ;
// Add the message to the deque
int nDequeIndex = pNewMsg->m_unTxtAttribute - _TXTATR_NORMAL - 1 ;
// The normal channel
if ( pNewMsg->m_unTxtAttribute == _TXTATR_NORMAL )
nDequeIndex = 6 ;
m_dequeMsg[nDequeIndex].push_back ( pNewMsg ) ;
int nDequeSize = ( int ) m_dequeMsg[nDequeIndex].size() ;
if ( nDequeSize > m_nMaxMsgLine[nDequeIndex] )
{
// The deque is full, kick off the first message
SAFE_DELETE ( m_dequeMsg[nDequeIndex][0] ) ;
m_dequeMsg[nDequeIndex].pop_front();
nDequeSize-- ;
// process every area
if ( pNewMsg->m_unTxtAttribute == _TXTATR_SYSTEM )
// The system area
ProcessArea ( m_nSysAreaAmount, _SYSAREA_MSG_LINE, nDequeIndex, nDequeSize, m_nSysAreaShowIndex, true ) ;
else if ( pNewMsg->m_unTxtAttribute == _TXTATR_GM )
// The manager area
ProcessArea ( m_nManAreaAmount, _MANAREA_MSG_LINE, nDequeIndex, nDequeSize, m_nManAreaShowIndex, true ) ;
else
// The normal area
ProcessArea ( m_nNorAreaAmount, _NORAREA_MSG_LINE, nDequeIndex, nDequeSize, m_nNorAreaShowIndex, true ) ;
}
else
{
// process every area
if ( pNewMsg->m_unTxtAttribute == _TXTATR_SYSTEM )
// The system area
ProcessArea ( m_nSysAreaAmount, _SYSAREA_MSG_LINE, nDequeIndex, nDequeSize, m_nSysAreaShowIndex, false ) ;
else if ( pNewMsg->m_unTxtAttribute == _TXTATR_GM )
// The manager area
ProcessArea ( m_nManAreaAmount, _MANAREA_MSG_LINE, nDequeIndex, nDequeSize, m_nManAreaShowIndex, false ) ;
else
// The normal area
ProcessArea ( m_nNorAreaAmount, _NORAREA_MSG_LINE, nDequeIndex, nDequeSize, m_nNorAreaShowIndex, false ) ;
}
char szTemp[_MAX_WORDSSIZE * 2];
pNewMsg->GetText(szTemp);
szTemp[_MAX_WORDSSIZE-1] = '\0';
m_setMsg.AddMsg(szTemp);
return true;
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
BOOL CGameMsg::AddMsg(DWORD dwChannel, const char* fmt, ...)
{
char szMsg[1024];
vsprintf( szMsg, fmt, (char*) ((&fmt)+1) );
return this->AddMsg(szMsg, dwChannel);
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void CGameMsg::ClearMsg(BOOL bSystem)
{
// Clear every channel's message
for ( int i = 0; i < 14; i++ )
{
if ( !bSystem && i == 4 )
{
continue ;
}
int nCount = m_dequeMsg[i].size() ;
for ( int j = 0; j < nCount; j++ )
{
SAFE_DELETE ( m_dequeMsg[i][j] ) ;
}
m_dequeMsg[i].clear() ;
}
m_nNorAreaAmount = 0 ;
if ( bSystem )
{
m_nSysAreaAmount = 0 ;
}
m_nManAreaAmount = 0 ;
m_nWarningTime = 0;
m_dwShowWarning = 0;
strcpy(m_szWarning, "");
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void CGameMsg::ProcessArea ( int& nCurAmount, int nMsgAmount, int nDequeIndex, int nDequeSize, int* pIndex, BOOL bFull )
{
nDequeSize-- ;
if ( nCurAmount == nMsgAmount )
// The area show message is full, kick off the first message
{
for ( int i = 0; i < nMsgAmount - 1; i++ )
{
pIndex[i * 2] = pIndex[( i + 1 ) * 2] ;
pIndex[i * 2 + 1] = pIndex[( i + 1 ) * 2 + 1] ;
if ( bFull && pIndex[i * 2] == nDequeIndex )
pIndex[i * 2 + 1]-- ;
}
pIndex[ ( nMsgAmount - 1 ) * 2] = nDequeIndex ;
pIndex[ ( nMsgAmount - 1 ) * 2 + 1] = nDequeSize ;
}
else
{
for ( int i = 0; i < nCurAmount; i++ )
{
if ( bFull && pIndex[i * 2] == nDequeIndex )
pIndex[i * 2 + 1]-- ;
}
if ( m_nSysAreaShowIndex[1] < 0 )
int x = 0;
pIndex[nCurAmount * 2] = nDequeIndex ;
pIndex[nCurAmount * 2 + 1] = nDequeSize ;
nCurAmount++ ;
}
}
//--------------------------------------------------------------------
//--------------------------------------------------------------------
void CGameMsg::DestroyBlackName()
{
int nAmount = m_setBlackName.size();
for(int i = 0; i < nAmount; i ++)
{
char* pszName = m_setBlackName[i];
if(pszName)
delete[] pszName;
}
m_setBlackName.clear();
}
//--------------------------------------------------------------------
void CGameMsg::AddBlackName(char* pszName)
{
if(pszName && strlen(pszName) > 0)
{
for(int i=0;i<this->GetBlackNameAmount();i++)
{
if (strcmp(pszName,this->GetBlackNameByIndex(i))==0)
{
this->AddMsg((char*)g_objGameDataSet.GetStr(20001)); //黑名单中已经添加过这个名字
return;
}
}
char* pszBlackName = new char[strlen(pszName)+1];
strcpy(pszBlackName, pszName);
m_setBlackName.push_back(pszBlackName);
if (this->GetBlackNameAmount()>6)
{
this->DelBlackName(0);
}
}
}
//--------------------------------------------------------------------
void CGameMsg::DelBlackName(int nIndex)
{
int nAmount = this->GetBlackNameAmount();
if((nIndex < 0) && (nIndex >= nAmount))
return;
char* pszName = m_setBlackName[nIndex];
delete[] pszName;
m_setBlackName.erase(m_setBlackName.begin() + nIndex);
}
//--------------------------------------------------------------------
int CGameMsg::GetBlackNameAmount()
{
return m_setBlackName.size();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -