bool CoreServerShell::CheckProtocolSize(const char* pChar, int nSize) { WORD wCheckSize; BYTE nProtocol = (BYTE)pChar[0]; if (nProtocol >= c2s_end || nProtocol <= c2s_gameserverbegin) { g_DebugLog("[error]NetServer:Invalid Protocol!"); return false; } if (g_nProtocolSize[nProtocol - c2s_gameserverbegin - 1] == -1) { wCheckSize = *(WORD*)&pChar[1] + PROTOCOL_MSG_SIZE; } else { wCheckSize = g_nProtocolSize[nProtocol - c2s_gameserverbegin - 1]; } if (wCheckSize != nSize) { g_DebugLog("[error]网络接收协议大小不匹配"); #ifndef _WIN32 printf("[error]网络接收协议大小不匹配<%d>, should %d, but %d\n", nProtocol, wCheckSize, nSize); #endif return false; } return true; }
BOOL KMission::ExecuteScript(DWORD dwScriptId, char * szFunName, int nParam) { try { KLuaScript * pScript = (KLuaScript* )g_GetScript(dwScriptId); if (pScript) { KSubWorld * pSubWorld = (KSubWorld*)GetOwner(); if (pSubWorld) { Lua_PushNumber(pScript->m_LuaState, pSubWorld->m_nIndex); pScript->SetGlobalName(SCRIPT_SUBWORLDINDEX); } int nTopIndex = 0; pScript->SafeCallBegin(&nTopIndex); pScript->CallFunction(szFunName,0, "d", nParam); pScript->SafeCallEnd(nTopIndex); } return TRUE; } catch(...) { printf("Exception Have Caught When Execute Script[%d]!!!!!", dwScriptId); g_DebugLog("Exception Have Caught When Execute Script[%d]!!!!!", dwScriptId); return FALSE; } return TRUE; }
//--------------------------------------------------------------------------- // 函数: Load // 功能: 加载一个Tab文件 // 参数: FileName 文件名 // 返回: TRUE 成功 // FALSE 失败 //--------------------------------------------------------------------------- BOOL KTabFile::Load(LPSTR FileName) { KPakFile File; DWORD dwSize; PVOID Buffer; // check file name if (FileName[0] == 0) return FALSE; if (!File.Open(FileName)) { g_DebugLog("Can't open tab file : %s", FileName); return FALSE; } dwSize = File.Size(); Buffer = m_Memory.Alloc(dwSize); File.Read(Buffer, dwSize); CreateTabOffset(); return TRUE; }
IFile* g_CreateFile(const char* FileName) { IFile* piFile = QAloneFile::Create(FileName); if (!piFile) g_DebugLog("ERROR: failed to create file[%s]!", FileName); return piFile; }
BOOL KTimerTaskFun::Init() { m_TimerTaskTab.Clear(); if (!m_TimerTaskTab.Load(TIMERTASK_SETTINGFILE)) { g_DebugLog("[TASK]Can Not Load %s,ERRRROR!", TIMERTASK_SETTINGFILE); return FALSE; } return TRUE; }
BOOL KThiefSkill::LoadSetting(char * szSettingFile) { _ASSERT(szSettingFile); KTabFile TabFile ; if (!TabFile.Load(szSettingFile)) { g_DebugLog("无法打开%s", szSettingFile); return FALSE; } TabFile.GetInteger(2, "AttackRadius", 100, (int *)&m_ulAttackRadius); TabFile.GetInteger(2, "TimePerCast", 100, (int*)&m_ulDelayPerCast); TabFile.GetInteger(2, "SkillCostType", 0, (int*)&m_nSkillCostType ); TabFile.GetInteger(2, "Cost", 50, (int *)&m_nCost); TabFile.GetInteger(2, "ThiefPercent", 30, (int *)&m_nThiefPercent); TabFile.GetInteger(2, "TargetEnemy", TRUE, &m_bTargetEnemy); TabFile.GetInteger(2, "TargetAlly", TRUE, &m_bTargetAlly); TabFile.GetInteger(2, "TargetObj", FALSE, &m_bTargetObj); TabFile.GetInteger(2, "ThiefStyle", 0, &m_nThiefStyle); TabFile.GetString(2, "SkillName", "", m_szSkillName, sizeof(m_szSkillName)); TabFile.GetInteger(2, "CostUsePrecent", 1, &m_bUseCostPercent); if (m_nThiefStyle == thief_runscript) { char szScript[200]; TabFile.GetString(2, "Param1", "", szScript, sizeof(szScript)); strlwr(szScript); m_dwParam1 =g_FileName2Id(szScript); } else { TabFile.GetInteger(2, "Param1", 0, (int*)&m_dwParam1); } #ifndef _SERVER TabFile.GetString(2, "Desc", "", m_szSkillDesc, sizeof(m_szSkillDesc)); TabFile.GetString(2, "SkillIcon", "\\spr\\skill\\图标\\通用.spr", m_szSkillIcon, sizeof(m_szSkillIcon)); TabFile.GetString(2, "Movie", "", m_szSkillSpecialFile, sizeof(m_szSkillSpecialFile)); TabFile.GetString(2, "TargetMovie", "", m_szTargetMovie, sizeof(m_szTargetMovie)); TabFile.GetString(2, "TargetMovieInfo", "1,1,1", m_szTargetMovieParam, sizeof(m_szTargetMovieParam)); TabFile.GetString(2, "SkillSound", "", m_szSkillSound, sizeof(m_szSkillSound)); #endif return TRUE; }
int KNpcTemplate::SkillString2Id(char * szSkillString) { if (!szSkillString[0]) return 0; int nSkillNum = g_OrdinSkillsSetting.GetHeight() - 1; char szSkillName[100]; for (int i = 0 ; i < nSkillNum; i ++) { g_OrdinSkillsSetting.GetString(i + 2, "SkillName", "", szSkillName, sizeof(szSkillName)); if (g_StrCmp(szSkillString, szSkillName)) { int nSkillId = 0; g_OrdinSkillsSetting.GetInteger(i + 2, "SkillId", 0, &nSkillId); return nSkillId; } } g_DebugLog("无找到该[%s]魔法的Id,请检查!", szSkillString); return 0; }
int CoreServerShell::OnLunch(LPVOID pServer) { g_SetServer(pServer); // g_SetFilePath("\\script"); KLuaScript * pStartScript =(KLuaScript*) g_GetScript("\\script\\ServerScript.lua"); int i = 0; if (!pStartScript) g_DebugLog("Load ServerScript failed!"); else { pStartScript->CallFunction("StartGame",0,""); } PlayerSet.ReloadWelcomeMsg(); return true; }
void KObj::SetScriptFile(char *lpszScriptFile) { char szScript[80]; if ( !lpszScriptFile || strlen(lpszScriptFile) >= sizeof(szScript)) { g_DebugLog("[error]Script FileName Error!!!"); } else { if (lpszScriptFile[0]) { if (lpszScriptFile[0] == '.') g_StrCpyLen(szScript, &lpszScriptFile[1], sizeof(szScript)); else g_StrCpyLen(szScript, lpszScriptFile, sizeof(szScript)); g_StrLower(szScript); m_dwScriptID = g_FileName2Id(szScript); } } }
//--------------------------------------------------------------------------- // 函数: g_MessageBox // 功能: Display a System Message Box // 参数: char* lpMsg, ... //--------------------------------------------------------------------------- C_ENGINE_API void g_MessageBox(const char* lpMsg, ...) { char szMsg[1024]; va_list va; va_start(va, lpMsg); vsprintf(szMsg, lpMsg, va); va_end(va); g_DebugLog(szMsg); #ifndef __linux HWND hWnd = NULL; GUITHREADINFO info; memset(&info, 0, sizeof(info)); info.cbSize = sizeof(info); if (GetGUIThreadInfo(NULL, &info)) hWnd = info.hwndActive; MessageBox(hWnd, szMsg, 0, MB_OK | MB_ICONINFORMATION); #endif }
//--------------------------------------------------------------------------- // 函数: Mp3Decode // 功能: 解码MP3 // 参数: lpPcmBuf PCM buffer pointer // dwBufLen buffer size in bytes // 返回: void //--------------------------------------------------------------------------- DWORD KMp3Music::Mp3Decode(PBYTE lpPcmBuf, DWORD dwBufLen) { PBYTE pcm_buffer = lpPcmBuf; int pcm_trigger = dwBufLen; int pcm_bufbytes = 0; int mp3_size = 0; int pcm_size = 0; IN_OUT res = {0, 0}; while (TRUE) { // fill mp3 buffer if (!Mp3FillBuffer()) break; // end of mp3 file if (m_mp3bufbytes < m_mp3frmbytes) break; // decode one frame to pcm buffer res = m_Decoder.DecodeFrame(m_mp3bufptr, pcm_buffer); if (res.in_bytes <= 0) { g_DebugLog("KMp3Music: bad sync in mp3 file"); break; } // update buffer pointer and buffer size m_mp3bufptr += res.in_bytes; m_mp3bufbytes -= res.in_bytes; pcm_buffer += res.out_bytes; pcm_bufbytes += res.out_bytes; // is pcm buffer full if (pcm_bufbytes >= pcm_trigger) break; } return pcm_bufbytes; }
//--------------------------------------------------------------------------- // 函数: Load // 功能: 加载一个INI文件 // 参数: FileName 文件名 // 返回: TRUE 成功 // FALSE 失败 //--------------------------------------------------------------------------- BOOL KIniFile::Load(LPCSTR FileName) { KPakFile File; DWORD dwSize; PVOID Buffer; TPackHead* pHeader; // check file name if (FileName[0] == 0) return FALSE; if (m_Header.pNextNode) Clear(); if (!File.Open((char*)FileName)) { g_DebugLog("Can't open ini file : %s", FileName); return FALSE; } #pragma message("KIniFile 当前不支持 KeyName 为中文! by Romandou") dwSize = File.Size(); Buffer = m_MemStack.Push(dwSize + 4); File.Read(Buffer, dwSize); pHeader = (TPackHead*)Buffer; if (pHeader->Id == 0x4b434150) // "PACK" { File.Close(); return LoadPack(FileName); } CreateIniLink(Buffer, dwSize); return TRUE; }
void KOccupyList::Free(int nIdx) { if (nIdx > 0 && nIdx < m_nTotalCount) { int nIndexInList = m_pNodeList[nIdx].nItemInListIndex; if (nIndexInList <= m_nOccupyCount) { if (nIndexInList != m_nOccupyCount) { m_pNodeList[nIndexInList].nItemIndex = m_pNodeList[m_nOccupyCount].nItemIndex; m_pNodeList[m_nOccupyCount].nItemIndex = nIdx; m_pNodeList[nIdx].nItemInListIndex = m_nOccupyCount; m_pNodeList[m_pNodeList[nIndexInList].nItemIndex].nItemInListIndex = nIndexInList; } m_nOccupyCount --; } //else already remove } else { g_DebugLog("[error]Remove invalid node: index %d, size %d", nIdx, m_nTotalCount); } }
void KOccupyList::Occupy(int nIdx) { if (nIdx > 0 && nIdx < m_nTotalCount) { int nIndexInList = m_pNodeList[nIdx].nItemInListIndex; if (nIndexInList > m_nOccupyCount) { m_nOccupyCount++; if (nIndexInList > m_nOccupyCount) { m_pNodeList[nIndexInList].nItemIndex = m_pNodeList[m_nOccupyCount].nItemIndex; m_pNodeList[m_nOccupyCount].nItemIndex = nIdx; m_pNodeList[nIdx].nItemInListIndex = m_nOccupyCount; m_pNodeList[m_pNodeList[nIndexInList].nItemIndex].nItemInListIndex = nIndexInList; } } //else already in occupy } else { g_DebugLog("[error]Insert invalid node: index %d, size %d", nIdx, m_nTotalCount); } }
//主循环,负责处理网络端发来的完整的请求数据 DWORD WINAPI RoleServerMainThreadFun(void * pParam) { TCmd * pCopyCmd = NULL; while(1) { try { g_MainLoopMark ++; if (g_MainLoopMark > MAX_MARK_COUNT) g_MainLoopMark = 0; { CCriticalSection::Owner locker( g_MainMsgListMutex); list<TCmd *>::iterator I = g_MainThreadCmdList.begin(); if (I == g_MainThreadCmdList.end()) pCopyCmd = NULL; else { TCmd * pCmd = (*I); pCopyCmd = (TCmd *)(new char[sizeof(TCmd) + (*I)->ProcessData.nDataLen - 1] ); pCopyCmd->ProcessData.nDataLen = pCmd->ProcessData.nDataLen; pCopyCmd->ProcessData.nProtoId = pCmd->ProcessData.nProtoId; pCopyCmd->ProcessData.ulIdentity = pCmd->ProcessData.ulIdentity; pCopyCmd->ulNetId = pCmd->ulNetId; memcpy(&pCopyCmd->ProcessData.pDataBuffer[0], &(*I)->ProcessData.pDataBuffer[0], (*I)->ProcessData.nDataLen); delete []pCmd; g_MainThreadCmdList.pop_front(); } } if (pCopyCmd) { switch(pCopyCmd->ProcessData.nProtoId) { //Save case c2s_roleserver_createroleinfo: case c2s_roleserver_saveroleinfo://游戏服务器向数据库服务器要求保存数据 { const char * szName = (const char *)GetRoleNameFromRoleBuffer((char *)&pCopyCmd->ProcessData.pDataBuffer[0]); if (!szName[0]) { g_DebugLog("存档过程中发现客户端传来的数据不合法."); g_nMistakeCount ++; break; } BOOL bExistRole = 0; bExistRole = S3DBI_IsRoleNameExisted((char *)szName); char btResult = -1; if (pCopyCmd->ProcessData.nProtoId == c2s_roleserver_createroleinfo) { if (bExistRole) { btResult = -2; } else btResult = 1; } else if (pCopyCmd->ProcessData.nProtoId == c2s_roleserver_saveroleinfo) { if (!bExistRole) { btResult = -2; } else btResult = 1; } else btResult = -1; { CCriticalSection::Owner locker(g_RoleInfoSetMutex); if (btResult > 0 && szName) { KRoleInfomation * pRoleInfomation = g_RoleInfoMap[szName] ; if (!pRoleInfomation)// { KRoleInfomation * pNewRoleInfomation = new KRoleInfomation; if (!pNewRoleInfomation->SetRoleInfoBuffer((unsigned char *)&(pCopyCmd->ProcessData.pDataBuffer[0]), pCopyCmd->ProcessData.nDataLen)) { btResult = -1; delete pNewRoleInfomation; g_nMistakeCount ++; } else { g_RoleInfoMap[szName] = pNewRoleInfomation; g_RoleInfoList.push_back(pNewRoleInfomation); } } else { pRoleInfomation->SetRoleInfoBuffer((unsigned char *)(&pCopyCmd->ProcessData.pDataBuffer[0]), pCopyCmd->ProcessData.nDataLen); } } } TCmd * pNewCmd = (TCmd *)new BYTE[sizeof(TCmd) + 1 - 1]; pNewCmd->ProcessData.nProtoId = (pCopyCmd->ProcessData.nProtoId == c2s_roleserver_saveroleinfo) ? s2c_roleserver_saverole_result: s2c_roleserver_createrole_result; pNewCmd->ProcessData.pDataBuffer[0] = (BYTE)btResult; pNewCmd->ProcessData.nDataLen = 1; pNewCmd->ulNetId = pCopyCmd->ulNetId; pNewCmd->ProcessData.ulIdentity = pCopyCmd->ProcessData.ulIdentity; CCriticalSection::Owner locker(g_NetMsgListMutex); if (g_NetServer.m_ClientUserSet[pNewCmd->ulNetId]) { g_NetServiceThreadCmdList.push_back(pNewCmd); } else { delete []pNewCmd; } } break; //Load case c2s_roleserver_getroleinfo://获得角色数据 { char szName[100]; _ASSERT(pCopyCmd->ProcessData.nDataLen <= 32); memcpy(szName, pCopyCmd->ProcessData.pDataBuffer, pCopyCmd->ProcessData.nDataLen);// GetRoleNameFromRoleBuffer((char *)&pCopyCmd->pDataBuffer); szName[pCopyCmd->ProcessData.nDataLen] = 0; if (szName) { CCriticalSection::Owner locker(g_RoleInfoSetMutex); KRoleInfomation * pRoleInfomation = g_RoleInfoMap[szName]; size_t BufferSize = 0; BYTE * pBuffer = NULL; BOOL bLoadSuccess = FALSE; if (pRoleInfomation) { TCmd *pNewCmd = pRoleInfomation->CreateRoleInfoTCmdData(BufferSize); if (pNewCmd) { pNewCmd->ProcessData.nProtoId = s2c_roleserver_getroleinfo_result; pNewCmd->ProcessData.nDataLen = BufferSize; pNewCmd->ulNetId = pCopyCmd->ulNetId; pNewCmd->ProcessData.ulIdentity = pCopyCmd->ProcessData.ulIdentity; CCriticalSection::Owner locker(g_NetMsgListMutex); if (g_NetServer.m_ClientUserSet[pNewCmd->ulNetId]) { g_NetServiceThreadCmdList.push_back(pNewCmd); bLoadSuccess = TRUE; } else { delete []pNewCmd; g_nMistakeCount ++; } } else { delete []pNewCmd; g_nMistakeCount ++; } } if (FALSE == bLoadSuccess)//没有则需要实际的取数据,需要向LoadThread发送消息 { if (pRoleInfomation) g_nMistakeCount ++; TGetRoleInfoFromDB * pNewCmd = new TGetRoleInfoFromDB; pNewCmd->nNetId = pCopyCmd->ulNetId; strcpy(pNewCmd->szRoleName, szName); pNewCmd->ulIdentity = pCopyCmd->ProcessData.ulIdentity; CCriticalSection::Owner locker(g_GetRoleInfoMutex); g_DBLoadThreadCmdList.push_back(pNewCmd); } } }break; //LoadRoleList case c2s_roleserver_getrolelist://获得某个帐号的角色列表 { unsigned char MaxRoleCount = (unsigned char)pCopyCmd->ProcessData.pDataBuffer[0]; unsigned char * pNewBuffer = new unsigned char [sizeof(TCmd) + sizeof(S3DBI_RoleBaseInfo) * MaxRoleCount + 1 - 1];//列表和1个 TCmd * pCmd = (TCmd*)pNewBuffer; pCmd->ulNetId = pCopyCmd->ulNetId; pCmd->ProcessData.nProtoId = s2c_roleserver_getrolelist_result; pCmd->ProcessData.nDataLen = sizeof(S3DBI_RoleBaseInfo) * MaxRoleCount + 1; pCmd->ProcessData.ulIdentity = pCopyCmd->ProcessData.ulIdentity; S3DBI_RoleBaseInfo * pRoleBaseInfoList = (S3DBI_RoleBaseInfo*) ((char*)&pCmd->ProcessData.pDataBuffer[0] + 1); char szAccountName[32]; memcpy(szAccountName, &pCopyCmd->ProcessData.pDataBuffer[0] + 1, pCopyCmd->ProcessData.nDataLen - 1 ); szAccountName[pCopyCmd->ProcessData.nDataLen - 1] = 0; pCmd->ProcessData.pDataBuffer[0] = (unsigned char )S3DBI_GetRoleListOfAccount(szAccountName, pRoleBaseInfoList, MaxRoleCount); { CCriticalSection::Owner locker(g_RoleInfoSetMutex); for (int i = 0; i < pCmd->ProcessData.pDataBuffer[0]; i ++) { KRoleInfomation * pRoleInfo = g_RoleInfoMap[(pRoleBaseInfoList + i)->szName]; if (pRoleInfo) { size_t nSize = 0; TRoleBaseInfo BaseInfo; BOOL bBase = pRoleInfo->GetBaseRoleInfo(&BaseInfo); if (bBase) { (pRoleBaseInfoList + i)->ArmorType = BaseInfo.iarmorres; (pRoleBaseInfoList + i)->HelmType = BaseInfo.ihelmres; (pRoleBaseInfoList + i)->Level = BaseInfo.ifightlevel; (pRoleBaseInfoList + i)->Sex = BaseInfo.bSex; (pRoleBaseInfoList + i)->WeaponType = BaseInfo.iweaponres; } } } } CCriticalSection::Owner locker(g_NetMsgListMutex); if (g_NetServer.m_ClientUserSet[pCmd->ulNetId]) { g_NetServiceThreadCmdList.push_back(pCmd); } else { delete []pCmd; } } break; case c2s_roleserver_deleteplayer: { char szDelRoleName[100]; if (pCopyCmd->ProcessData.nDataLen > 32) { g_nMistakeCount ++; break; } memcpy(szDelRoleName, &pCopyCmd->ProcessData.pDataBuffer[0], pCopyCmd->ProcessData.nDataLen); szDelRoleName[pCopyCmd->ProcessData.nDataLen] = 0; int nResult = S3DBI_DeleteRole(szDelRoleName); { CCriticalSection::Owner locker(g_RoleInfoSetMutex); g_RoleInfoMap[szDelRoleName]->Clear(); g_RoleInfoMap.erase(szDelRoleName); } TCmd * pNewCmd = (TCmd *)new BYTE[sizeof(TCmd) + 1 - 1]; pNewCmd->ProcessData.nProtoId = s2c_roleserver_deleterole_result; pNewCmd->ProcessData.pDataBuffer[0] = (BYTE)nResult; pNewCmd->ProcessData.nDataLen = 1; pNewCmd->ulNetId = pCopyCmd->ulNetId; pNewCmd->ProcessData.ulIdentity = pCopyCmd->ProcessData.ulIdentity; CCriticalSection::Owner locker(g_NetMsgListMutex); if (g_NetServer.m_ClientUserSet[pNewCmd->ulNetId]) { g_NetServiceThreadCmdList.push_back(pNewCmd); } else { delete []pNewCmd; } }break; //Exit } delete []pCopyCmd; pCopyCmd = NULL; } Sleep(1); } catch(...) { g_nMistakeCount ++; } } return 1; }
// Add by Freeway Chen in 2003.5.30 BOOL KItemGenerator::Gen_MagicAttrib( int nType, const int* pnaryMALevel, int nSeriesReq, int nLucky, KItemNormalAttrib* pnaryMA, int nGameVersion ) { int nResult = false; KBPT_ClassMAIT SelectedMagicTable; // 记录每一个记录选中的魔法属性,主要是为了最后将使用标志清除 KMAGICATTRIB_TABFILE *pMagicAttrTable[6] = { NULL, NULL, NULL, NULL, NULL, NULL }; int i = 0; _ASSERT(pnaryMALevel); _ASSERT(pnaryMA); for (i = 0; i < 6; i++) { // 如果发现级别为零,表示不需要继续处理了,退出 if (pnaryMALevel[i] == 0) break; SelectedMagicTable.Clear(); // 根据前缀后缀、物品类型、五行需求、需求级别将所有符合条件的魔法属性项取出来 const KBPT_ClassMAIT *pCMITItem = m_BPTLib.GetCMIT( 1 - (i & 1), // 前缀后缀 nType, // 物品类型 nSeriesReq, // 五行需求 pnaryMALevel[i] // 需求级别 ); _ASSERT(pCMITItem); if (!pCMITItem) { g_DebugLog( "[GenMagicAttrib] GetCMIT Error, nPrefixPostfix = %d, nType = %d, nSeries = %d, nLevel = %d", 1 - (i & 1), nType, nSeriesReq, pnaryMALevel[i] ); break; } // 遍历符合条件的魔法属性,根据 // 1.是否已经使用, // 2.运气值 // 3.是否有相同的“属性调整类别” // 取出相应的项放在SelectedMagicTable中 int nCMITItemCount = pCMITItem->GetCount(); int j = 0; int nDecide = GetRandomNumber(0, 100 - 1) / (1 + nLucky * 20 / 100); for (j = 0; j < nCMITItemCount; j++) { // 根据索引值,取出相应的项 int nMAIndex = pCMITItem->Get(j); KMAGICATTRIB_TABFILE *pMAItem = (KMAGICATTRIB_TABFILE *)m_BPTLib.GetMARecord(nMAIndex); if (!pMAItem) { _ASSERT(pMAItem); continue; } // 如果已经使用,跳过取下一个 if (pMAItem->m_nUseFlag) continue; // 如果运气不足,取下一个 if ((pMAItem->m_DropRate[nType]) <= nDecide) continue; // 检查是否已经有相同的“属性调整类别” int k = 0; for (k = 0; k < i; k++) { _ASSERT(pMagicAttrTable[k]); if ((pMagicAttrTable[k]->m_MagicAttrib.nPropKind) == (pMAItem->m_MagicAttrib.nPropKind)) break; } // 如果发现 “属性调整类别”相同,说明已经有一个相同的值被选中,那么取下一个 if (k < i) continue; SelectedMagicTable.Insert(nMAIndex); } int nSelectedCount = SelectedMagicTable.GetCount(); if (nSelectedCount == 0) { // 如果没有满足条件的魔法属性,就退出 break; } // 如果发现满足条件的魔法属性,就设置 int nLuckyItemIndex = GetRandomNumber(0, nSelectedCount - 1); KMAGICATTRIB_TABFILE *pMAItem = (KMAGICATTRIB_TABFILE *)m_BPTLib.GetMARecord( SelectedMagicTable.Get(nLuckyItemIndex) ); // 保存满足条件的魔法属性,以便在最后的时候将使用标志清除 pMagicAttrTable[i] = pMAItem; _ASSERT(pMAItem); _ASSERT(!(pMAItem->m_nUseFlag)); // 确定还没有使用 // 设置使用标志 pMAItem->m_nUseFlag = true; pnaryMA[i].nAttribType = pMAItem->m_MagicAttrib.nPropKind; pnaryMA[i].nValue[0] = GetRandomNumber( pMAItem->m_MagicAttrib.aryRange[0].nMin, pMAItem->m_MagicAttrib.aryRange[0].nMax ); pnaryMA[i].nValue[1] = GetRandomNumber( pMAItem->m_MagicAttrib.aryRange[1].nMin, pMAItem->m_MagicAttrib.aryRange[1].nMax ); pnaryMA[i].nValue[2] = GetRandomNumber( pMAItem->m_MagicAttrib.aryRange[2].nMin, pMAItem->m_MagicAttrib.aryRange[2].nMax ); g_DebugLog( "[GenMagicAttrib] pnaryMA[%d]: (%d:%s), nAttribType = %d, nValue[0] = %d, nValue[1] = %d, nValue[2] = %d,", i, SelectedMagicTable.Get(nLuckyItemIndex), pMAItem->m_szName, pnaryMA[i].nAttribType, pnaryMA[i].nValue[0], pnaryMA[i].nValue[1], pnaryMA[i].nValue[2] ); } // for 遍历需要取回的魔法属性表 for (NULL; i < 6; i++) { // 清空剩下的项 pnaryMA[i].nAttribType = 0; pnaryMA[i].nValue[0] = 0; pnaryMA[i].nValue[1] = 0; pnaryMA[i].nValue[2] = 0; } for (i = 0; i < 6; i++) { if (!pMagicAttrTable[i]) break; _ASSERT(pMagicAttrTable[i]->m_nUseFlag); // 确定已经使用 pMagicAttrTable[i]->m_nUseFlag = false; // 设置为没用使用 } nResult = true; //Exit0: return nResult; }
DWORD WINAPI DatabaseSaveThreadFun(void * pParam) { static char RoleBuffer[MAX_ROLEINFORMATION_SIZE]; BYTE * pRoleBuffer = NULL; size_t nSize = 0; char szRoleName[100]; while(1) { try { g_SaveDBThreadMark ++; if (g_SaveDBThreadMark > MAX_MARK_COUNT) g_SaveDBThreadMark = 0; nSize = 0; { CCriticalSection::Owner locker( g_RoleInfoSetMutex); list<KRoleInfomation*>::iterator I = g_RoleInfoList.begin(); int nNodeCount = g_RoleInfoList.size(); int nVisitTime = 0; while(I != g_RoleInfoList.end() && nVisitTime < nNodeCount && nSize == 0) { nVisitTime ++; if ((*I)->IsValid()) { if ((*I)->m_bModify)//数据已被修改,但未存档,需要存档 { nSize = MAX_ROLEINFORMATION_SIZE; BOOL bResult = (*I)->CopyRoleInfoBuffer((BYTE *)RoleBuffer, nSize); if (!bResult || nSize == 0) { g_DebugLog("获得无效角色数据.普通错误"); g_nMistakeCount ++; } else { sprintf(g_SaveMarkString, "正在保存角色%s......", GetRoleNameFromRoleBuffer(RoleBuffer)); g_SaveDBThreadMark = MAX_MARK_COUNT + SAVEMARK_NO; (*I)->m_bModify = false; (*I)->m_nUnModifyTime = 0; } } else { (*I)->m_nUnModifyTime ++; if ((*I)->m_nUnModifyTime > 200) { size_t nTempSize =0; szRoleName[0] = 0; size_t nLen = 100; BOOL bResult = (*I)->GetRoleName(szRoleName, nLen); if (bResult && nLen > 0) { sprintf(g_RemoveMarkString, "正在释放角色信息%s......", szRoleName); g_SaveDBThreadMark = MAX_MARK_COUNT + REMOVEMARK_NO; } delete *I; g_RoleInfoList.pop_front(); if (szRoleName) g_RoleInfoMap.erase(szRoleName); I = g_RoleInfoList.begin(); continue; } } if (nNodeCount > 1) { KRoleInfomation * pRoleInfomation = *I; g_RoleInfoList.pop_front(); g_RoleInfoList.push_back(pRoleInfomation); } } else { delete *I; g_RoleInfoList.pop_front(); if (szRoleName) g_RoleInfoMap.erase(szRoleName); } I = g_RoleInfoList.begin(); } } if (nSize > 0) { S3DBI_SaveRoleInfo((BYTE*)RoleBuffer, GetRoleNameFromRoleBuffer(RoleBuffer), 1); } Sleep(g_dwPerSaveTime); } catch(...) { g_DebugLog("存档线程出错!"); g_nMistakeCount ++; } } return 1; }