📄 chatlog.cpp
字号:
void CChatLog::DelLogFile(char* pFileName)
{
if(!pFileName)
return;
if(strcmp(pFileName, m_szCurrentLogFile) == 0)
{
this->DestroyLogLineSet();
::PostCmd(CMD_FLASHCHATLOGFILELIST);
::PostCmd(CMD_FLASHCURRENTCHATLOGLINELIST);
}
char szFullFilePath[_MAX_PATH];
sprintf(szFullFilePath, "LOG\\%s\\%s\\CHAT\\%s", g_szServerName, g_objHero.GetName(), pFileName);
::DeleteFile(szFullFilePath);
}
//-------------------------------------------------------------------
void CChatLog::DelLogLine(int nChannel)
{
int nAmount = this->GetLineAmount();
for(int i=nAmount-1;i>=0;i--)
{
ChatLogLine* pLogLine ;
pLogLine = g_objGameMsg.m_objChatLog.m_setLogLine[i] ;
if (pLogLine != NULL)
{
if(this->TestLine(nChannel,pLogLine))
{
this->m_setLogLine.erase(this->m_setLogLine.begin()+i);
SAFE_DELETE(pLogLine);
}
}
}
}
//-------------------------------------------------------------------
void CChatLog::DelLeaveWordLogFile()
{
this->DestroyLeaveWordLogLineSet();
char szFullFilePath[_MAX_PATH];
sprintf(szFullFilePath, "LOG\\%s\\%s\\CHAT\\%s", g_szServerName, g_objHero.GetName(), "leavewordsystem.log");
::DeleteFile(szFullFilePath);
::PostCmd(CMD_FLASH_LEAVE_WORD);
}
//-------------------------------------------------------------------
void CChatLog::DelAllLogFile()
{
int nAmount = this->GetLogFileAmount();
for(int i = nAmount-1; i >= 0; i --)
{
ChatLogFile* pFile = this->GetLogFileByIndex(i);
if(pFile)
{
this->DelLogFile(pFile->szFileName);
}
}
}
//-------------------------------------------------------------------
void CChatLog::LoadLeaveWordLog()
{
this->DestroyLeaveWordLogLineSet();
char szFullFilePath[_MAX_PATH];
sprintf(szFullFilePath, "LOG\\%s\\%s\\CHAT\\%s", g_szServerName, g_objHero.GetName(), "leavewordsystem.log");
FILE* fp = fopen(szFullFilePath, "rb");
if(!fp)
return;
char szHeroName[_MAX_NAMESIZE];
strcpy(szHeroName, g_objHero.GetName());
int nNameLength = strlen(szHeroName);
if(nNameLength <= 1)
nNameLength = 2;
int nServerNameLength = strlen(g_szServerName);
ChatLogLine infoLine;
while(true)
{
if(1 != fread(&infoLine, sizeof(ChatLogLine), 1, fp))
break;
for(int i = 0; i < 512; i ++)
{
char cCharPass = (char)((96120059/(i+1)%256) + szHeroName[i%(nNameLength-1)] + g_szServerName[i%(nServerNameLength-1)]);
infoLine.szTxt[i] = infoLine.szTxt[i]^cCharPass;
}
ChatLogLine* pLine = new ChatLogLine;
MYASSERT(pLine);
infoLine.szSender[_MAX_NAMESIZE-1]='\0';
infoLine.szTxt[512-1]='\0';
strcpy(pLine->szSender, infoLine.szSender);
strcpy(pLine->szTxt, infoLine.szTxt);
m_setLeaveWordLogLine.push_back(pLine);
}
fclose(fp);
::PostCmd(CMD_FLASH_LEAVE_WORD);
}
//-------------------------------------------------------------------
void CChatLog::LogLeaveWord(CGameMsgUnit* pMsgUnit)
{
if(!pMsgUnit)
return;
this->CheckDirectory();
char szDirectory[128];
sprintf(szDirectory, "LOG/%s/%s/CHAT", g_szServerName, g_objHero.GetName());
char szLogName[256];
sprintf(szLogName, "%s/%s", szDirectory, "leavewordsystem.log");
FILE* fp = fopen(szLogName, "a+b");
if(!fp)
return;
//-------------------------------------------------------
// save sender as index ...
char szSenderName[_MAX_NAMESIZE];
strcpy(szSenderName, pMsgUnit->m_szSender);
fwrite(szSenderName, sizeof(char), _MAX_NAMESIZE, fp);
// save
char szTemp[512];
char szData[64];
strcpy(szData, pMsgUnit->m_szEmotion);
strcpy(pMsgUnit->m_szEmotion, "");
pMsgUnit->GetText(szTemp);
// format date ...
char szFormat[64];
int i;
for(i = 0; i < 4; i ++) {szFormat[i] = szData[i];} // year
szFormat[4] = '-';
for(i = 5; i < 7; i ++) {szFormat[i] = szData[i-1];} // month
szFormat[7] = '-';
for(i = 8; i < 10; i ++) {szFormat[i] = szData[i-2];} // date
szFormat[10] = '-';
for(i = 11; i < 13; i ++) {szFormat[i] = szData[i-3];} // hour
szFormat[13] = '-';
for(i = 14; i < 16; i ++) {szFormat[i] = szData[i-4];} // minu
szFormat[16] = '\0';
strcat(szTemp, szFormat);
ChatLogLine* pLine = new ChatLogLine;
MYASSERT(pLine);
strcpy(pLine->szSender, pMsgUnit->m_szSender);
strcpy(pLine->szTxt, szTemp);
m_setLeaveWordLogLine.push_back(pLine);
::PostCmd(CMD_FLASH_LEAVE_WORD);
//simple encrypt
char szHeroName[_MAX_NAMESIZE];
strcpy(szHeroName, g_objHero.GetName());
int nNameLength = strlen(szHeroName);
if(nNameLength <= 1)
nNameLength = 2;
int nServerNameLength = strlen(g_szServerName);
for(i = 0; i < 512; i ++)
{
char cCharPass = (char)((96120059/(i+1)%256) + szHeroName[i%(nNameLength-1)] + g_szServerName[i%(nServerNameLength-1)]);
szTemp[i] = szTemp[i]^cCharPass;
}
fwrite(szTemp, sizeof(char), 512, fp);
//-------------------------------------------------------
fclose(fp);
::PostCmd(CMD_FLASH_LEAVE_WORD);
}
//-------------------------------------------------------------------
void CChatLog::ClearLogBuffer()
{
FILE* fp = NULL;
int nAmount = m_setLogBuffer.size();
char szOldLogFile[256] = "";
for(int i = 0; i < nAmount; i ++)
{
ChatLogLineBuffer* pBuffer = m_setLogBuffer[i];
if(pBuffer)
{
// save ...
if(m_bLog)
{
this->CheckDirectory();
// the file name is YEAR_MONTH_DAY.LOG
char szDirectory[128];
sprintf(szDirectory, "LOG/%s/%s/CHAT", g_szServerName, g_objHero.GetName());
char szLogName[256];
sprintf(szLogName, "%s/%d_%d_%d.log", szDirectory, pBuffer->nYear, pBuffer->nMonth, pBuffer->nDay);
if(strcmp(szOldLogFile, szLogName) != 0)
{
if(fp)
{
fclose(fp);
fp = NULL;
}
fp = fopen(szLogName, "a+b");
if(!fp)
return;
strcpy(szOldLogFile, szLogName);
}
// save sender as index ...
char szSenderName[_MAX_NAMESIZE];
strcpy(szSenderName, pBuffer->szName);
fwrite(szSenderName, sizeof(char), _MAX_NAMESIZE, fp);
// save
char szTemp[512];
strcpy(szTemp, pBuffer->szMsg);
// be update?
/* {
char szLogFile[256];
sprintf(szLogFile, "%d_%d_%d.log", pBuffer->nYear, pBuffer->nMonth, pBuffer->nDay);
if(strcmp(m_szCurrentLogFile, szLogFile) == 0)
{
ChatLogLine* pLine = new ChatLogLine;
MYASSERT(pLine);
strcpy(pLine->szSender, pBuffer->szName);
strcpy(pLine->szTxt, szTemp);
m_setLogLine.push_back(pLine);
::PostCmd(CMD_FLASHCURRENTCHATLOGLINELIST);
}
}*/
//simple encrypt
char szHeroName[_MAX_NAMESIZE];
strcpy(szHeroName, g_objHero.GetName());
int nNameLength = strlen(szHeroName);
if(nNameLength <= 1)
nNameLength = 2;
int nServerNameLength = strlen(g_szServerName);
for(int i = 0; i < 512; i ++)
{
char cCharPass = (char)((96120059/(i+1)%256) + szHeroName[i%(nNameLength-1)] + g_szServerName[i%(nServerNameLength-1)]);
szTemp[i] = szTemp[i]^cCharPass;
}
fwrite(szTemp, sizeof(char), 512, fp);
}
//-------------------------------------------------------
}
// del ...
SAFE_DELETE(pBuffer);
}
// clear ...
if(fp)
fclose(fp);
m_setLogBuffer.clear();
}
//-------------------------------------------------------------------
BOOL CChatLog::TestLine(int nChannel, ChatLogLine* pLine)
{
if(!pLine)
return false;
OBJID idTitle;
switch(nChannel)
{
case 0:
return true;
break;
case _TXTATR_SYSTEM:
idTitle = 100006;
if(strstr(pLine->szTxt, (char*)g_objGameDataSet.GetStr(idTitle)) == pLine->szTxt)
return true;
break;
case _TXTATR_TALK:
idTitle = 100012;
if(strstr(pLine->szTxt, (char*)g_objGameDataSet.GetStr(idTitle)) == pLine->szTxt)
return true;
return false;
break;
case _TXTATR_PRIVATE:
idTitle = 100008;
if(strstr(pLine->szTxt, (char*)g_objGameDataSet.GetStr(idTitle)) == pLine->szTxt)
return true;
return false;
break;
case _TXTATR_SYNDICATE:
idTitle = 100010;
if(strstr(pLine->szTxt, (char*)g_objGameDataSet.GetStr(idTitle)) == pLine->szTxt)
return true;
return false;
break;
case _TXTATR_FRIEND:
idTitle = 100014;
if(strstr(pLine->szTxt, (char*)g_objGameDataSet.GetStr(idTitle)) == pLine->szTxt)
return true;
return false;
break;
case _TXTATR_TEAM:
idTitle = 100009;
if(strstr(pLine->szTxt, (char*)g_objGameDataSet.GetStr(idTitle)) == pLine->szTxt)
return true;
return false;
break;
case _TXTATR_MY:
if (strcmp(pLine->szSender,g_objHero.GetName())==0 || strstr(pLine->szTxt,g_objHero.GetName()))
return true;
return false;
default:
return false;
}
return false;
}
//-------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -