void CChat::DecorateName(CGString &sName, const CChatChanMember * pMember, bool fSystem) // static { ADDTOCALLSTACK("CChat::DecorateName"); CChatChannel * pChannel = NULL; if (pMember) pChannel = pMember->GetChannel(); // 0 = yellow // 1 = purple // 2 = blue // 3 = purple // 4 = white // 5 = green int iResult = 0; if (!pMember || !pChannel) // Must be a system command if these are invalid { if (fSystem) iResult = 5; else iResult = 4; } else if (pChannel->IsModerator(pMember->GetChatName())) iResult = 1; else if (!pChannel->HasVoice(pMember->GetChatName())) iResult = 2; if (!pMember || !pChannel) sName.Format("%i%s", iResult, "SYSTEM"); else sName.Format("%i%s", iResult, static_cast<LPCTSTR>(pMember->GetChatName())); }
static void StringFunction( int iFunc, LPCTSTR pszKey, CGString &sVal ) { GETNONWHITESPACE(pszKey); if ( *pszKey == '(' ) pszKey++; TCHAR * ppCmd[4]; int iCount = Str_ParseCmds( const_cast<TCHAR *>(pszKey), ppCmd, COUNTOF(ppCmd), ",)" ); if ( ! iCount ) { DEBUG_ERR(( "Bad string function usage. missing )\n" )); return; } TCHAR * psArg1 = ppCmd[0]; switch ( iFunc ) { case SSC_CHR: sVal.Format( "%c", Exp_GetSingle( ppCmd[0] ) ); return; case SSC_StrToLower: // strlower(str) = lower case the string sVal = ppCmd[0]; sVal.MakeLower(); return; case SSC_StrToUpper: // strupper(str) = upper case the string sVal = ppCmd[0]; sVal.MakeUpper(); return; } }
void CResourceBase::AddResourceDir( LPCTSTR pszDirName ) { ADDTOCALLSTACK("CResourceBase::AddResourceDir"); if ( pszDirName[0] == '\0' ) return; CGString sFilePath = CGFile::GetMergedFileName( pszDirName, "*" GRAY_SCRIPT ); CFileList filelist; int iRet = filelist.ReadDir( sFilePath, false ); if ( iRet < 0 ) { // also check script file path sFilePath = CGFile::GetMergedFileName(m_sSCPBaseDir, sFilePath.GetPtr()); iRet = filelist.ReadDir( sFilePath, true ); if ( iRet < 0 ) { DEBUG_ERR(( "DirList=%d for '%s'\n", iRet, static_cast<LPCTSTR>(pszDirName) )); return; } } if ( iRet <= 0 ) // no files here. { return; } CGStringListRec * psFile = filelist.GetHead(); for ( ; psFile; psFile = psFile->GetNext()) { sFilePath = CGFile::GetMergedFileName( pszDirName, *psFile ); AddResourceFile( sFilePath ); } }
bool CItemSpawn::r_WriteVal(LPCTSTR pszKey, CGString & sVal, CTextConsole *pSrc) { ADDTOCALLSTACK("CitemSpawn:r_WriteVal"); EXC_TRY("WriteVal"); if (!strnicmp(pszKey, "amount", 6)) { sVal.FormatVal(GetAmount()); return true; } else if ( !strnicmp(pszKey, "at.", 3) ) { pszKey += 3; int objIndex = Exp_GetVal(pszKey); if ( m_obj[objIndex].ItemFind() ) return m_obj[objIndex].ItemFind()->r_WriteVal(pszKey, sVal, pSrc); else if ( m_obj[objIndex].CharFind() ) return m_obj[objIndex].CharFind()->r_WriteVal(pszKey, sVal, pSrc); return true; } else if ( !strnicmp(pszKey, "count", 5) ) { sVal.FormatVal(GetCount()); return true; } EXC_CATCH; return CItem::r_WriteVal(pszKey, sVal, pSrc); }
bool CItemMap::r_WriteVal(LPCTSTR pszKey, CGString &sVal, CTextConsole *pSrc) { ADDTOCALLSTACK("CItemMap::r_WriteVal"); EXC_TRY("WriteVal"); if ( !strnicmp(pszKey, "PINS", 4) ) { sVal.FormatVal(m_Pins.GetCount()); return true; } if ( !strnicmp(pszKey, "PIN.", 4) ) { pszKey += 4; size_t i = Exp_GetVal(pszKey) - 1; if ( m_Pins.IsValidIndex(i) ) { sVal.Format("%i,%i", m_Pins[i].m_x, m_Pins[i].m_y); return true; } } return CItemVendable::r_WriteVal(pszKey, sVal, pSrc); EXC_CATCH; EXC_DEBUG_START; EXC_ADD_KEYRET(pSrc); EXC_DEBUG_END; return false; }
bool CWebPageDef::r_WriteVal( LPCTSTR pszKey, CGString & sVal, CTextConsole * pSrc ) { ADDTOCALLSTACK("CWebPageDef::r_WriteVal"); EXC_TRY("WriteVal"); switch ( FindTableSorted( pszKey, sm_szLoadKeys, COUNTOF( sm_szLoadKeys )-1 )) { case WC_PLEVEL: sVal.FormatVal( m_privlevel ); break; case WC_WEBPAGEFILE: sVal = m_sDstFilePath; break; case WC_WEBPAGELOG: sVal.FormatVal( m_iUpdateLog ); break; case WC_WEBPAGESRC: sVal = m_sSrcFilePath; break; case WC_WEBPAGEUPDATE: // (seconds) sVal.FormatVal( m_iUpdatePeriod / TICK_PER_SEC ); break; default: return( g_Serv.r_WriteVal( pszKey, sVal, pSrc )); } return true; EXC_CATCH; EXC_DEBUG_START; EXC_ADD_KEYRET(pSrc); EXC_DEBUG_END; return false; }
void CChat::FormatName(CGString &sName, const CChatMember *pMember, bool bSystem) //static { ADDTOCALLSTACK("CChat::FormatName"); // Format chat name with proper color // 0 = Yellow (user) // 1 = Purple (moderator) // 2 = Blue (muted) // 3 = Purple (unused?) // 4 = White (me) // 5 = Green (system) int iColor = 0; if ( pMember ) { CChatChannel *pChannel = pMember->GetChannel(); if ( pChannel ) { LPCTSTR pszName = const_cast<CChatMember *>(pMember)->GetChatName(); if ( pChannel->IsModerator(pszName) ) iColor = 1; else if ( !pChannel->HasVoice(pszName) ) iColor = 2; sName.Format("%d%s", iColor, pszName); return; } } iColor = bSystem ? 5 : 4; sName.Format("%d%s", iColor, "SYSTEM"); }
bool CContainer::r_WriteValContainer(LPCTSTR pszKey, CGString & sVal, CTextConsole *pSrc) { ADDTOCALLSTACK("CContainer::r_WriteValContainer"); EXC_TRY("WriteVal"); static LPCTSTR const sm_szParams[] = { "count", "fcount", "rescount", "restest" }; int i = FindTableHeadSorted(pszKey, sm_szParams, COUNTOF(sm_szParams)); if ( i < 0 ) return false; LPCTSTR pKey = pszKey + strlen(sm_szParams[i]); SKIP_SEPARATORS(pKey); switch ( i ) { case 0: // count { int iTotal = 0; for ( CItem* pItem = GetContentHead(); pItem != NULL; pItem = pItem->GetNext() ) iTotal++; sVal.FormatVal(iTotal); } break; case 1: // fcount sVal.FormatVal(ContentCountAll()); break; case 2: // rescount sVal.FormatVal(*pKey ? ContentCount(g_Cfg.ResourceGetID(RES_ITEMDEF, pKey)) : GetCount()); break; case 3: // restest { CResourceQtyArray Resources; sVal.FormatVal(Resources.Load(pKey) ? ResourceConsume(&Resources, 1, true) : 0); } break; default: return false; } return true; EXC_CATCH; EXC_DEBUG_START; EXC_ADD_KEYRET(pSrc); EXC_DEBUG_END; return false; }
int CGString::indexOf(CGString str, int offset) { if (offset < 0) return -1; int len = strlen(m_pchData); if (offset >= len) return -1; int slen = str.GetLength(); if (slen > len) return -1; TCHAR * str_value = new TCHAR[slen + 1]; strcpy(str_value, str.GetPtr()); TCHAR firstChar = str_value[0]; for(int i = offset; i < len; i++) { TCHAR c = m_pchData[i]; if ( c == firstChar ) { int rem = len - i; if ( rem >= slen ) { int j = i; int k = 0; bool found = true; while ( k < slen ) { if(m_pchData[j] != str_value[k]) { found = false; break; } j++; k++; } if (found) { delete[] str_value; return i; } } } } delete[] str_value; return -1; }
void CChat::GenerateChatName(CGString &sName, const CClient * pClient) // static { if (pClient == NULL) return; // decide upon 'base' name LPCTSTR pszName = NULL; if (pClient->GetChar() != NULL) pszName = pClient->GetChar()->GetName(); else if (pClient->GetAccount() != NULL) pszName = pClient->GetAccount()->GetName(); if (pszName == NULL) return; // try the base name CGString sTempName(pszName); if (g_Accounts.Account_FindChat(sTempName.GetPtr()) != NULL) { sTempName.Empty(); // append (n) to the name to make it unique for (unsigned int attempts = 2; attempts <= g_Accounts.Account_GetCount(); attempts++) { sTempName.Format("%s (%u)", pszName, attempts); if (g_Accounts.Account_FindChat(static_cast<LPCTSTR>(sTempName)) == NULL) break; sTempName.Empty(); } } // copy name to output sName.Copy(sTempName.GetPtr()); }
bool CItemMessage::r_WriteVal( LPCTSTR pszKey, CGString &sVal, CTextConsole * pSrc ) { EXC_TRY(("r_WriteVal('%s',,%x)", pszKey, pSrc)); // Load the message body for a book or a bboard message. if ( ! strnicmp( pszKey, "BODY", 4 )) { pszKey += 4; int iPage = Exp_GetVal(pszKey); if ( iPage < 0 || iPage >= m_sBodyLines.GetCount()) return( false ); sVal = *m_sBodyLines[iPage]; return( true ); } switch ( FindTableSorted( pszKey, sm_szLoadKeys, COUNTOF( sm_szLoadKeys )-1 )) { case CIC_AUTHOR: sVal = m_sAuthor; return( true ); case CIC_BODY: // handled above. return( false ); case CIC_PAGES: // not settable. (used for resource stuff) sVal.FormatVal( m_sBodyLines.GetCount()); return( true ); case CIC_TITLE: sVal = GetName(); return( true ); } return CItemVendable::r_WriteVal(pszKey, sVal, pSrc); EXC_CATCH("CItemMessage"); return false; }
bool CVarDefContNum::r_WriteVal( LPCTSTR pKey, CGString & sVal, CTextConsole * pSrc = NULL ) { UNREFERENCED_PARAMETER(pKey); UNREFERENCED_PARAMETER(pSrc); sVal.FormatLLVal( GetValNum() ); return( true ); }
bool CSkillClassDef::r_WriteVal( LPCTSTR pszKey, CGString & sVal, CTextConsole * pSrc ) { ADDTOCALLSTACK("CSkillClassDef::r_WriteVal"); EXC_TRY("WriteVal"); switch ( FindTableSorted( pszKey, sm_szLoadKeys, COUNTOF( sm_szLoadKeys )-1 )) { case SCC_NAME: // "NAME" sVal = m_sName; break; case SCC_SKILLSUM: sVal.FormatVal( m_SkillSumMax ); break; case SCC_STATSUM: sVal.FormatVal( m_StatSumMax ); break; default: { int i = g_Cfg.FindSkillKey( pszKey); if ( i != SKILL_NONE ) { ASSERT( i >= 0 && static_cast<size_t>(i) < COUNTOF(m_SkillLevelMax)); sVal.FormatVal( m_SkillLevelMax[i] ); break; } i = g_Cfg.FindStatKey( pszKey); if ( i >= 0 ) { ASSERT( static_cast<size_t>(i) < COUNTOF(m_StatMax)); sVal.FormatVal( m_StatMax[i] ); break; } } return( CResourceDef::r_WriteVal( pszKey, sVal, pSrc )); } return true; EXC_CATCH; EXC_DEBUG_START; EXC_ADD_KEYRET(pSrc); EXC_DEBUG_END; return false; }
bool CItemMulti::r_WriteVal( LPCTSTR pszKey, CGString & sVal, CTextConsole * pSrc ) { if ( !strnicmp(pszKey, "COMP", 4) ) { const CItemBaseMulti *pMultiDef = Multi_GetDef(); pszKey += 4; // no component uid if ( !*pszKey ) sVal.FormatVal(pMultiDef->m_Components.GetCount()); else if ( *pszKey == '.' ) { CMultiComponentItem item; SKIP_SEPERATORS(pszKey); int iQty = Exp_GetVal(pszKey); if (( iQty < 0 ) || ( iQty >= pMultiDef->m_Components.GetCount())) return false; SKIP_SEPERATORS(pszKey); item = pMultiDef->m_Components.GetAt(iQty); if ( !strnicmp(pszKey, "ID", 2) ) sVal.FormatVal(item.m_id); else if ( !strnicmp(pszKey, "DX", 2) ) sVal.FormatVal(item.m_dx); else if ( !strnicmp(pszKey, "DY", 2) ) sVal.FormatVal(item.m_dy); else if ( !strnicmp(pszKey, "DZ", 2) ) sVal.FormatVal(item.m_dz); else if ( !strnicmp(pszKey, "D", 1) ) sVal.Format("%i,%i,%i", item.m_dx, item.m_dy, item.m_dz); else sVal.Format("%i,%i,%i,%i", item.m_id, item.m_dx, item.m_dy, item.m_dz); } else return false; return true; } return( CItem::r_WriteVal(pszKey, sVal, pSrc)); }
bool CItemVendable::r_WriteVal(LPCTSTR pszKey, CGString &sVal, CTextConsole *pSrc) { ADDTOCALLSTACK("CItemVendable::r_WriteVal"); EXC_TRY("WriteVal"); switch ( FindTableSorted( pszKey, sm_szLoadKeys, COUNTOF( sm_szLoadKeys )-1 )) { case IVC_PRICE: // PRICE sVal.FormatVal( m_price ); return true; case IVC_QUALITY: // QUALITY sVal.FormatVal( GetQuality()); return true; default: return CItem::r_WriteVal( pszKey, sVal, pSrc ); } EXC_CATCH; EXC_DEBUG_START; EXC_ADD_KEYRET(pSrc); EXC_DEBUG_END; return false; }
bool CRegionWorld::r_WriteVal( LPCTSTR pszKey, CGString & sVal, CTextConsole * pSrc ) { ADDTOCALLSTACK("CRegionWorld::r_WriteVal"); EXC_TRY("WriteVal"); //bool fZero = false; switch ( FindTableHeadSorted( pszKey, sm_szLoadKeys, COUNTOF( sm_szLoadKeys )-1 )) { case RWC_DEFNAME: // "DEFNAME" = for the speech system. sVal = GetResourceName(); break; case RWC_RESOURCES: m_Events.WriteResourceRefList( sVal ); break; case RWC_REGION: { // Check that the syntax is correct. if ( pszKey[6] && pszKey[6] != '.' ) return false; CRegionWorld * pRegionTemp = dynamic_cast <CRegionWorld*>(m_pt.GetRegion( REGION_TYPE_AREA )); if ( !pszKey[6] ) { // We're just checking if the reference is valid. sVal.FormatVal( pRegionTemp? 1:0 ); return true; } // ELSE - We're trying to retrieve a property from the region. pszKey += 7; if ( pRegionTemp && m_pt.GetRegion( REGION_TYPE_MULTI ) ) return pRegionTemp->r_WriteVal( pszKey, sVal, pSrc ); return( this->r_WriteVal( pszKey, sVal, pSrc )); } default: return( CRegionBase::r_WriteVal( pszKey, sVal, pSrc )); } return true; EXC_CATCH; EXC_DEBUG_START; g_Log.EventDebug("command '%s' ret '%s' [%p]\n", pszKey, static_cast<LPCTSTR>(sVal), static_cast<void *>(pSrc)); EXC_DEBUG_END; return false; }
bool CItemMap::r_WriteVal( LPCTSTR pszKey, CGString &sVal, CTextConsole * pSrc ) { EXC_TRY(("r_WriteVal('%s',,%x)", pszKey, pSrc)); if ( ! strnicmp( pszKey, "PIN", 3 )) { pszKey += 3; int i = Exp_GetVal(pszKey) - 1; if ( i >= 0 && i < m_Pins.GetCount()) { sVal.Format( "%i,%i", m_Pins[i].m_x, m_Pins[i].m_y ); return( true ); } } return CItemVendable::r_WriteVal(pszKey, sVal, pSrc); EXC_CATCH("CItemMap"); return false; }
bool CItemMessage::r_WriteVal(LPCTSTR pszKey, CGString &sVal, CTextConsole *pSrc) { ADDTOCALLSTACK("CItemMessage::r_WriteVal"); EXC_TRY("WriteVal"); // Load the message body for a book or a bboard message. if ( !strnicmp(pszKey, "BODY", 4) ) { pszKey += 4; size_t iPage = Exp_GetVal(pszKey); if ( m_sBodyLines.IsValidIndex(iPage) == false ) return false; sVal = *m_sBodyLines[iPage]; return true; } switch ( FindTableSorted(pszKey, sm_szLoadKeys, COUNTOF(sm_szLoadKeys) - 1) ) { case CIC_AUTHOR: sVal = m_sAuthor; return true; case CIC_BODY: // handled above return false; case CIC_PAGES: // not settable (used for resource stuff) sVal.FormatVal(m_sBodyLines.GetCount()); return true; case CIC_TITLE: sVal = GetName(); return true; } return CItemVendable::r_WriteVal(pszKey, sVal, pSrc); EXC_CATCH; EXC_DEBUG_START; EXC_ADD_KEYRET(pSrc); EXC_DEBUG_END; return false; }
bool CBaseBaseDef::r_WriteVal( LPCTSTR pszKey, CGString & sVal, CTextConsole * pSrc ) { ADDTOCALLSTACK("CBaseBaseDef::r_WriteVal"); EXC_TRY("WriteVal"); bool fZero = false; int index = FindTableHeadSorted( pszKey, sm_szLoadKeys, COUNTOF( sm_szLoadKeys )-1 ); switch ( index ) { //return as string or hex number or NULL if not set case OBC_CATEGORY: case OBC_DESCRIPTION: case OBC_SUBSECTION: case OBC_HITSPELL: case OBC_SLAYER: case OBC_SLAYERLESSER: case OBC_SLAYERMISC: case OBC_SLAYERSUPER: case OBC_ABILITYPRIMARY: case OBC_ABILITYSECONDARY: case OBC_MANABURST: sVal = GetDefStr(pszKey, false); break; //return as decimal number or 0 if not set case OBC_BALANCED: case OBC_BANE: case OBC_BATTLELUST: case OBC_BLOODDRINKER: case OBC_CASTINGFOCUS: case OBC_DAMCHAOS: case OBC_DAMCOLD: case OBC_DAMDIRECT: case OBC_DAMENERGY: case OBC_DAMFIRE: case OBC_DAMMODIFIER: case OBC_DAMPHYSICAL: case OBC_DECREASEHITCHANCE: case OBC_DAMPOISON: case OBC_EATERCOLD: case OBC_EATERDAM: case OBC_EATERENERGY: case OBC_EATERFIRE: case OBC_EATERKINETIC: case OBC_EATERPOISON: case OBC_ENHANCEPOTIONS: case OBC_EXPANSION: case OBC_FASTERCASTING: case OBC_FASTERCASTRECOVERY: case OBC_HITAREACOLD: case OBC_HITAREAENERGY: case OBC_HITAREAFIRE: case OBC_HITAREAPHYSICAL: case OBC_HITAREAPOISON: case OBC_HITCURSE: case OBC_HITDISPEL: case OBC_HITFATIGUE: case OBC_HITFIREBALL: case OBC_HITHARM: case OBC_HITLEECHLIFE: case OBC_HITLEECHMANA: case OBC_HITLEECHSTAM: case OBC_HITLIGHTNING: case OBC_HITLOWERATK: case OBC_HITLOWERDEF: case OBC_HITMAGICARROW: case OBC_HITMANADRAIN: case OBC_INCREASEDAM: case OBC_INCREASEDEFCHANCE: case OBC_INCREASEDEFCHANCEMAX: case OBC_INCREASEHITCHANCE: case OBC_INCREASEGOLD: case OBC_INCREASEKARMALOSS: case OBC_INCREASESPELLDAM: case OBC_INCREASESWINGSPEED: case OBC_LOWERAMMOCOST: case OBC_LOWERMANACOST: case OBC_LOWERREAGENTCOST: case OBC_LOWERREQ: case OBC_LUCK: case OBC_MANABURSTFREQUENCY: case OBC_MANABURSTKARMA: case OBC_NIGHTSIGHT: case OBC_RAGEFOCUS: case OBC_REACTIVEPARALYZE: case OBC_REFLECTPHYSICALDAM: case OBC_REGENFOOD: case OBC_REGENHITS: case OBC_REGENMANA: case OBC_REGENSTAM: case OBC_REGENVALFOOD: case OBC_REGENVALHITS: case OBC_REGENVALMANA: case OBC_REGENVALSTAM: case OBC_RESCOLD: case OBC_RESFIRE: case OBC_RESENERGY: case OBC_RESPHYSICAL: case OBC_RESPOISON: case OBC_RESCOLDMAX: case OBC_RESFIREMAX: case OBC_RESENERGYMAX: case OBC_RESPHYSICALMAX: case OBC_RESPOISONMAX: case OBC_RESONANCECOLD: case OBC_RESONANCEENERGY: case OBC_RESONANCEFIRE: case OBC_RESONANCEKINETIC: case OBC_RESONANCEPOISON: case OBC_SOULCHARGE: case OBC_SOULCHARGECOLD: case OBC_SOULCHARGEENERGY: case OBC_SOULCHARGEFIRE: case OBC_SOULCHARGEKINETIC: case OBC_SOULCHARGEPOISON: case OBC_SPELLCONSUMPTION: case OBC_SPELLFOCUSING: case OBC_SPLINTERINGWEAPON: case OBC_VELOCITY: case OBC_SPELLCHANNELING: case OBC_NAMELOC: case OBC_HITSPELLSTR: case OBC_WEIGHTREDUCTION: case OBC_COMBATBONUSSTAT: case OBC_COMBATBONUSPERCENT: sVal.FormatLLVal(GetDefNum(pszKey, true)); break; case OBC_DEFNAME: sVal = GetResourceName(); break; case OBC_ARMOR: { pszKey += strlen(sm_szLoadKeys[index]); // 9; if ( *pszKey == '.' ) { SKIP_SEPARATORS( pszKey ); if ( !strnicmp( pszKey, "LO", 2 ) ) { sVal.Format( "%d", m_defenseBase ); } else if ( !strnicmp( pszKey, "HI", 2 ) ) { sVal.Format( "%d", m_defenseBase+m_defenseRange ); } } else { sVal.Format( "%d,%d", m_defenseBase, m_defenseBase+m_defenseRange ); } } break; case OBC_DAM: { pszKey += strlen(sm_szLoadKeys[index]); // 9; if ( *pszKey == '.' ) { SKIP_SEPARATORS( pszKey ); if ( !strnicmp( pszKey, "LO", 2 ) ) { sVal.Format( "%d", m_attackBase ); } else if ( !strnicmp( pszKey, "HI", 2 ) ) { sVal.Format( "%d", m_attackBase+m_attackRange ); } } else { sVal.Format( "%d,%d", m_attackBase, m_attackBase+m_attackRange ); } } break; case OBC_BASEID: sVal = g_Cfg.ResourceGetName( GetResourceID()); break; case OBC_CAN: sVal.FormatHex( m_Can ); break; case OBC_HEIGHT: { //CBaseBaseDef * pBaseBaseDef = dynamic_cast<CBaseBaseDef*>(this); //DEBUG_ERR(("OBC_HEIGHT - m_dwDispIndex %d GetHeight() %d pBaseBaseDef->GetHeight() %d pBaseBaseDef 0x%x\n",m_wDispIndex,GetHeight(),pBaseBaseDef->GetHeight(),pBaseBaseDef)); sVal.FormatVal( GetHeight() ); } break; case OBC_INSTANCES: sVal.FormatVal( GetRefInstances()); break; case OBC_NAME: sVal = GetName(); break; case OBC_RANGE: if ( RangeH() == 0 ) sVal.Format( "%d", RangeL() ); else sVal.Format( "%d,%d", RangeH(), RangeL() ); break; case OBC_RANGEL: // internally: rangel seems to be Range Highest value sVal.FormatVal( RangeH() ); break; case OBC_RANGEH: // but rangeh seems to be the Range Lowest value. sVal.FormatVal( RangeL() ); break; case OBC_RESOURCES: // Print the resources { pszKey += strlen(sm_szLoadKeys[index]); // 9; if ( *pszKey == '.' ) { SKIP_SEPARATORS( pszKey ); if ( !strnicmp( pszKey, "COUNT", 5 )) { sVal.FormatVal(m_BaseResources.GetCount()); } else { bool fQtyOnly = false; bool fKeyOnly = false; index = Exp_GetVal( pszKey ); SKIP_SEPARATORS( pszKey ); if ( !strnicmp( pszKey, "KEY", 3 )) fKeyOnly = true; else if ( !strnicmp( pszKey, "VAL", 3 )) fQtyOnly = true; TCHAR *pszTmp = Str_GetTemp(); m_BaseResources.WriteKeys( pszTmp, index, fQtyOnly, fKeyOnly ); if ( fQtyOnly && pszTmp[0] == '\0' ) strcpy( pszTmp, "0" ); sVal = pszTmp; } } else { TCHAR *pszTmp = Str_GetTemp(); m_BaseResources.WriteKeys( pszTmp ); sVal = pszTmp; } } break; case OBC_RESLEVEL: sVal.FormatVal( GetResLevel() ); break; case OBC_RESDISPDNHUE: sVal.FormatHex( GetResDispDnHue() ); break; case OBC_TAG0: fZero = true; pszKey++; case OBC_TAG: // "TAG" = get/set a local tag. if ( pszKey[3] != '.' ) return( false ); pszKey += 4; sVal = m_TagDefs.GetKeyStr(pszKey, fZero ); break; case OBC_TEVENTS: m_TEvents.WriteResourceRefList( sVal ); break; default: return false; } return true; EXC_CATCH; EXC_DEBUG_START; EXC_ADD_KEYRET(pSrc); EXC_DEBUG_END; return false; }
bool CClient::r_Verb( CScript & s, CTextConsole * pSrc ) // Execute command from script { ADDTOCALLSTACK("CClient::r_Verb"); EXC_TRY("Verb"); // NOTE: This can be called directly from a RES_WEBPAGE script. // So do not assume we are a game client ! // NOTE: Mostly called from CChar::r_Verb // NOTE: Little security here so watch out for dangerous scripts ! ASSERT(pSrc); LPCTSTR pszKey = s.GetKey(); // Old ver if ( s.IsKeyHead( "SET", 3 ) && ( g_Cfg.m_Functions.ContainsKey( pszKey ) == false ) ) { PLEVEL_TYPE ilevel = g_Cfg.GetPrivCommandLevel( "SET" ); if ( ilevel > GetPrivLevel() ) return( false ); ASSERT( m_pChar ); addTargetVerb( pszKey+3, s.GetArgRaw()); return( true ); } if ( toupper( pszKey[0] ) == 'X' && ( g_Cfg.m_Functions.ContainsKey( pszKey ) == false ) ) { PLEVEL_TYPE ilevel = g_Cfg.GetPrivCommandLevel( "SET" ); if ( ilevel > GetPrivLevel() ) return( false ); // Target this command verb on some other object. ASSERT( m_pChar ); addTargetVerb( pszKey+1, s.GetArgRaw()); return( true ); } int index = FindTableSorted( s.GetKey(), sm_szVerbKeys, COUNTOF(sm_szVerbKeys)-1 ); switch (index) { case CV_ADD: if ( s.HasArgs()) { // FindItemName ??? TCHAR * pszArgs = s.GetArgStr(); if ( !IsValidGameObjDef( static_cast<LPCTSTR>(pszArgs) ) ) { g_Log.EventWarn("Invalid ADD argument '%s'\n", pszArgs); SysMessageDefault( DEFMSG_CMD_INVALID ); return true; } RESOURCE_ID rid = g_Cfg.ResourceGetID( RES_QTY, const_cast<LPCTSTR &>(reinterpret_cast<LPTSTR &>(pszArgs))); if (( rid.GetResType() == RES_CHARDEF ) || ( rid.GetResType() == RES_SPAWN )) { m_Targ_PrvUID.InitUID(); return Cmd_CreateChar(static_cast<CREID_TYPE>(rid.GetResIndex()), SPELL_Summon, false ); } ITEMID_TYPE id = static_cast<ITEMID_TYPE>(rid.GetResIndex()); return Cmd_CreateItem( id ); } else { if ( IsValidDef( "d_add" ) ) Dialog_Setup( CLIMODE_DIALOG, g_Cfg.ResourceGetIDType(RES_DIALOG, "d_add"), 0, this->GetChar() ); else Menu_Setup( g_Cfg.ResourceGetIDType( RES_MENU, "MENU_ADDITEM")); } break; case CV_ADDBUFF: { TCHAR * ppArgs[11]; Str_ParseCmds( s.GetArgStr(), ppArgs, COUNTOF(ppArgs)); int iArgs[4]; for ( int idx = 0; idx < 4; ++idx ) { if ( !IsStrNumeric(ppArgs[idx])) { DEBUG_ERR(("Invalid AddBuff argument number %u\n", idx+1)); return true; } iArgs[idx] = Exp_GetVal( ppArgs[idx] ); } if (iArgs[0] < BI_START || iArgs[0] > BI_QTY/* || iArgs[0] == 0x3EB || iArgs[0] == 0x3EC*/) { // 0x3eb and 0x3ec among some others does not exists now, which doesn't mean they won't fill them and, since nothing happens when wrong id is sent, we can let them be sent. DEBUG_ERR(("Invalid AddBuff icon ID\n")); break; } LPCTSTR Args[7]; size_t ArgsCount = 0; for ( int i = 0; i < 7; ++i ) { Args[i] = ppArgs[i + 4]; if ( Args[i] != NULL ) ArgsCount++; } addBuff(static_cast<BUFF_ICONS>(iArgs[0]), iArgs[1], iArgs[2], static_cast<WORD>(iArgs[3]), Args, ArgsCount); } break; case CV_REMOVEBUFF: { BUFF_ICONS IconId = static_cast<BUFF_ICONS>(s.GetArgVal()); if (IconId < BI_START || IconId > BI_QTY/* || IconId == 0x3EB || IconId == 0x3EC*/) { DEBUG_ERR(("Invalid RemoveBuff icon ID\n")); break; } removeBuff(IconId); } break; case CV_ADDCLILOC: // Add cliloc in @ClientTooltip trigger { TCHAR * ppLocArgs[256]; size_t qty = Str_ParseCmds(s.GetArgRaw(), ppLocArgs, COUNTOF(ppLocArgs), ","); DWORD clilocid = Exp_GetVal(ppLocArgs[0]); CGString LocArgs; for ( size_t y = 1 ; y < qty; y++ ) { if ( LocArgs.GetLength() ) LocArgs += "\t"; LocArgs += ( !strcmp(ppLocArgs[y], "NULL") ? " " : ppLocArgs[y] ); } if ( g_Cfg.m_wDebugFlags & DEBUGF_SCRIPTS ) g_Log.EventDebug("SCRIPT: addcliloc(%lu,'%s')\n", clilocid, static_cast<LPCTSTR>(LocArgs)); this->m_TooltipData.Add(new CClientTooltip(clilocid, LocArgs)); } break; case CV_ADDCONTEXTENTRY: { TCHAR * ppLocArgs[20]; if ( Str_ParseCmds(s.GetArgRaw(), ppLocArgs, COUNTOF(ppLocArgs), ",") > 4 ) { DEBUG_ERR(("Bad AddContextEntry usage: Function takes maximum of 4 arguments!\n")); return true; } if (m_pPopupPacket == NULL) { DEBUG_ERR(("Bad AddContextEntry usage: Not used under a @ContextMenuRequest/@itemContextMenuRequest trigger!\n")); return true; } for ( int i = 0; i < 4; i++ ) { if ( i > 1 && IsStrEmpty(ppLocArgs[i]) ) continue; if ( !IsStrNumeric(ppLocArgs[i]) ) { DEBUG_ERR(("Bad AddContextEntry usage: Argument %d must be a number!\n", i+1)); return true; } } int entrytag = Exp_GetVal(ppLocArgs[0]); if ( entrytag < 100 ) { DEBUG_ERR(("Bad AddContextEntry usage: TextEntry < 100 is reserved for server usage!\n")); return true; } m_pPopupPacket->addOption(static_cast<WORD>(entrytag), static_cast<DWORD>(Exp_GetVal(ppLocArgs[1])), static_cast<WORD>(Exp_GetVal(ppLocArgs[2])), static_cast<WORD>(Exp_GetVal(ppLocArgs[3]))); } break; case CV_ARROWQUEST: { INT64 piVal[3]; Str_ParseCmds( s.GetArgRaw(), piVal, COUNTOF(piVal)); addArrowQuest( static_cast<int>(piVal[0]), static_cast<int>(piVal[1]), static_cast<int>(piVal[2]) ); #ifdef _ALPHASPHERE // todo: should use a proper container for these, since the arrows are lost // when the client logs out, and also newer clients support multiple // arrows if ( piVal[0] && piVal[1] && m_pChar ) { m_pChar->SetKeyNum("ARROWQUEST_X", piVal[0]); m_pChar->SetKeyNum("ARROWQUEST_Y", piVal[1]); } else { m_pChar->DeleteKey("ARROWQUEST_X"); m_pChar->DeleteKey("ARROWQUEST_Y"); } #endif } break; case CV_BADSPAWN: { // Loop the world searching for bad spawns bool fFound = false; for ( int m = 0; m < 256 && !fFound; m++ ) { if ( !g_MapList.m_maps[m] ) continue; for ( int d = 0; d < g_MapList.GetSectorQty(m) && !fFound; d++ ) { CSector *pSector = g_World.GetSector(m, d); if ( !pSector ) continue; CItem *pNext; CItem *pItem = STATIC_CAST <CItem*>(pSector->m_Items_Inert.GetHead()); for ( ; pItem != NULL && !fFound; pItem = pNext ) { pNext = pItem->GetNext(); if ( pItem->IsType(IT_SPAWN_ITEM) || pItem->IsType(IT_SPAWN_CHAR) ) { CItemSpawn *pSpawn = static_cast<CItemSpawn*>(pItem); CResourceDef *pDef = pSpawn->FixDef(); if ( !pDef ) { RESOURCE_ID_BASE rid = ( pItem->IsType(IT_SPAWN_ITEM) ? pItem->m_itSpawnItem.m_ItemID : pItem->m_itSpawnChar.m_CharID); CPointMap pt = pItem->GetTopPoint(); m_pChar->Spell_Teleport(pt, true, false); m_pChar->m_Act_Targ = pItem->GetUID(); SysMessagef("Bad spawn (0%lx, id=%s). Set as ACT", (DWORD)pItem->GetUID(), g_Cfg.ResourceGetName(rid)); fFound = true; } } } } } if ( ! fFound ) SysMessage(g_Cfg.GetDefaultMsg( DEFMSG_NO_BAD_SPAWNS )); } break; case CV_BANKSELF: // open my own bank addBankOpen( m_pChar, static_cast<LAYER_TYPE>(s.GetArgVal())); break; case CV_CAST: { SPELL_TYPE spell = static_cast<SPELL_TYPE>(g_Cfg.ResourceGetIndexType(RES_SPELL, s.GetArgStr())); const CSpellDef * pSpellDef = g_Cfg.GetSpellDef(spell); if (pSpellDef == NULL) return true; CObjBase * pObjSrc = dynamic_cast<CObjBase *>(pSrc); if ( IsSetMagicFlags( MAGICF_PRECAST ) && !pSpellDef->IsSpellType( SPELLFLAG_NOPRECAST ) ) { int skill; if (!pSpellDef->GetPrimarySkill(&skill, NULL)) return true; m_tmSkillMagery.m_Spell = spell; // m_atMagery.m_Spell m_pChar->m_atMagery.m_Spell = spell; if (pObjSrc != NULL) { m_Targ_UID = pObjSrc->GetUID(); // default target. m_Targ_PrvUID = pObjSrc->GetUID(); } else { m_Targ_UID.ClearUID(); m_Targ_PrvUID.ClearUID(); } m_pChar->Skill_Start(static_cast<SKILL_TYPE>(skill)); break; } else Cmd_Skill_Magery(spell, pObjSrc); } break; case CV_CHARLIST: { // usually just a gm command new PacketChangeCharacter(this); CharDisconnect(); // since there is no undoing this in the client. SetTargMode( CLIMODE_SETUP_CHARLIST ); } break; case CV_CTAGLIST: if ( ! strcmpi( s.GetArgStr(), "log" )) pSrc = &g_Serv; m_TagDefs.DumpKeys(pSrc, "CTAG."); break; case CV_CLEARCTAGS: { if ( s.HasArgs() ) { LPCTSTR pszArgs = s.GetArgStr(); SKIP_SEPARATORS(pszArgs); m_TagDefs.ClearKeys(pszArgs); } else { m_TagDefs.ClearKeys(); } } break; case CV_CLOSEPAPERDOLL: { CChar *pChar = m_pChar; if ( s.HasArgs() ) { CGrayUID uid = s.GetArgVal(); pChar = uid.CharFind(); } if ( pChar ) closeUIWindow(pChar, 0x01); } break; case CV_CLOSEPROFILE: { CChar *pChar = m_pChar; if ( s.HasArgs() ) { CGrayUID uid = s.GetArgVal(); pChar = uid.CharFind(); } if ( pChar ) closeUIWindow(pChar, 0x08); } break; case CV_CLOSESTATUS: { CChar *pChar = m_pChar; if ( s.HasArgs() ) { CGrayUID uid = s.GetArgVal(); pChar = uid.CharFind(); } if ( pChar ) closeUIWindow(pChar, 0x02); } break; case CV_DYE: if ( s.HasArgs() ) { CGrayUID uid(s.GetArgVal()); CObjBase *pObj = uid.ObjFind(); if ( pObj ) addDyeOption(pObj); } break; case CV_EVERBTARG: m_Prompt_Text = s.GetArgStr(); addPromptConsole( CLIMODE_PROMPT_TARG_VERB, m_Targ_Text.IsEmpty() ? "Enter the verb" : "Enter the text", m_Targ_UID ); break; case CV_EXTRACT: // sort of like EXPORT but for statics. // Opposite of the "UNEXTRACT" command if ( ! s.HasArgs()) { SysMessage( g_Cfg.GetDefaultMsg( DEFMSG_EXTRACT_USAGE ) ); } else { TCHAR * ppArgs[2]; Str_ParseCmds( s.GetArgStr(), ppArgs, COUNTOF( ppArgs )); m_Targ_Text = ppArgs[0]; // Point at the options, if any m_tmTile.m_ptFirst.InitPoint(); // Clear this first m_tmTile.m_Code = CV_EXTRACT; // set extract code. m_tmTile.m_id = Exp_GetVal(ppArgs[1]); // extract id. addTarget( CLIMODE_TARG_TILE, g_Cfg.GetDefaultMsg( DEFMSG_SELECT_EXTRACT_AREA ), true ); } break; case CV_UNEXTRACT: // Create item from script. // Opposite of the "EXTRACT" command if ( ! s.HasArgs()) { SysMessage( g_Cfg.GetDefaultMsg( DEFMSG_UNEXTRACT_USAGE ) ); } else { TCHAR * ppArgs[2]; Str_ParseCmds( s.GetArgStr(), ppArgs, COUNTOF( ppArgs )); m_Targ_Text = ppArgs[0]; // Point at the options, if any m_tmTile.m_ptFirst.InitPoint(); // Clear this first m_tmTile.m_Code = CV_UNEXTRACT; // set extract code. m_tmTile.m_id = Exp_GetVal(ppArgs[1]); // extract id. addTarget( CLIMODE_TARG_UNEXTRACT, g_Cfg.GetDefaultMsg( DEFMSG_SELECT_MULTI_POS ), true ); } break; case CV_GMPAGE: m_Targ_Text = s.GetArgStr(); if ( !m_Targ_Text.IsEmpty() && !strnicmp( m_Targ_Text, "ADD ", 4 ) ) { Cmd_GM_Page( m_Targ_Text + 4 ); break; } addPromptConsole( CLIMODE_PROMPT_GM_PAGE_TEXT, g_Cfg.GetDefaultMsg( DEFMSG_GMPAGE_PROMPT ) ); break; case CV_GOTARG: // go to my (preselected) target. { ASSERT(m_pChar); CObjBase * pObj = m_Targ_UID.ObjFind(); if ( pObj != NULL ) { CPointMap po = pObj->GetTopLevelObj()->GetTopPoint(); CPointMap pnt = po; pnt.MoveN( DIR_W, 3 ); DWORD wBlockFlags = m_pChar->GetMoveBlockFlags(); pnt.m_z = g_World.GetHeightPoint2( pnt, wBlockFlags ); // ??? Get Area m_pChar->m_dirFace = pnt.GetDir( po, m_pChar->m_dirFace ); // Face the player m_pChar->Spell_Teleport( pnt, true, false ); } } break; case CV_INFO: // We could also get ground tile info. addTarget( CLIMODE_TARG_OBJ_INFO, g_Cfg.GetDefaultMsg( DEFMSG_SELECT_ITEM_INFO ), true, false ); break; case CV_INFORMATION: SysMessage( g_Serv.GetStatusString( 0x22 )); SysMessage( g_Serv.GetStatusString( 0x24 )); break; case CV_LAST: // Fake Previous target. if ( GetTargMode() >= CLIMODE_MOUSE_TYPE ) { ASSERT(m_pChar); CObjBase * pObj = m_pChar->m_Act_Targ.ObjFind(); if ( pObj != NULL ) { Event_Target(GetTargMode(), pObj->GetUID(), pObj->GetUnkPoint()); addTargetCancel(); } break; } return( false ); case CV_LINK: // link doors m_Targ_UID.InitUID(); addTarget( CLIMODE_TARG_LINK, g_Cfg.GetDefaultMsg( DEFMSG_SELECT_LINK_ITEM ) ); break; case CV_MENU: Menu_Setup( g_Cfg.ResourceGetIDType( RES_MENU, s.GetArgStr())); break; case CV_MIDILIST: { INT64 piMidi[64]; size_t iQty = Str_ParseCmds( s.GetArgStr(), piMidi, COUNTOF(piMidi)); if ( iQty > 0 ) { addMusic( static_cast<MIDI_TYPE>(piMidi[ Calc_GetRandVal( iQty ) ]) ); } } break; case CV_NUDGE: if ( ! s.HasArgs()) { SysMessage( "Usage: NUDGE dx dy dz" ); } else { m_Targ_Text = s.GetArgRaw(); m_tmTile.m_ptFirst.InitPoint(); // Clear this first m_tmTile.m_Code = CV_NUDGE; addTarget( CLIMODE_TARG_TILE, g_Cfg.GetDefaultMsg( DEFMSG_SELECT_NUDGE_AREA ), true ); } break; case CV_NUKE: m_Targ_Text = s.GetArgRaw(); m_tmTile.m_ptFirst.InitPoint(); // Clear this first m_tmTile.m_Code = CV_NUKE; // set nuke code. addTarget( CLIMODE_TARG_TILE, g_Cfg.GetDefaultMsg( DEFMSG_SELECT_NUKE_AREA ), true ); break; case CV_NUKECHAR: m_Targ_Text = s.GetArgRaw(); m_tmTile.m_ptFirst.InitPoint(); // Clear this first m_tmTile.m_Code = CV_NUKECHAR; // set nuke code. addTarget( CLIMODE_TARG_TILE, g_Cfg.GetDefaultMsg( DEFMSG_SELECT_NUKE_CHAR_AREA ), true ); break; case CV_OPENPAPERDOLL: { CChar *pChar = m_pChar; if ( s.HasArgs() ) { CGrayUID uid = s.GetArgVal(); pChar = uid.CharFind(); } if ( pChar ) addCharPaperdoll(pChar); } break; case CV_PAGE: Cmd_GM_PageCmd( s.GetArgStr()); break; case CV_REPAIR: addTarget( CLIMODE_TARG_REPAIR, g_Cfg.GetDefaultMsg( DEFMSG_SELECT_ITEM_REPAIR ) ); break; case CV_FLUSH: #ifndef _MTNETWORK g_NetworkOut.flush(this); #else g_NetworkManager.flush(GetNetState()); #endif break; case CV_RESEND: addReSync(); break; case CV_SAVE: g_World.Save(s.GetArgVal() != 0); break; case CV_SCROLL: // put a scroll up. addScrollResource( s.GetArgStr(), SCROLL_TYPE_UPDATES ); break; case CV_SENDPACKET: SendPacket( s.GetArgStr() ); break; case CV_SELF: // Fake self target. if ( GetTargMode() >= CLIMODE_MOUSE_TYPE ) { ASSERT(m_pChar); Event_Target(GetTargMode(), m_pChar->GetUID(), m_pChar->GetTopPoint()); addTargetCancel(); break; } return( false ); case CV_SHOWSKILLS: addSkillWindow(static_cast<SKILL_TYPE>(g_Cfg.m_iMaxSkill)); // Reload the real skills break; case CV_SKILLMENU: // Just put up another menu. Cmd_Skill_Menu( g_Cfg.ResourceGetIDType( RES_SKILLMENU, s.GetArgStr())); break; case CV_SKILLSELECT: Event_Skill_Use( g_Cfg.FindSkillKey( s.GetArgStr() ) ); break; case CV_SUMMON: // from the spell skill script. // m_Targ_PrvUID should already be set. return Cmd_CreateChar(static_cast<CREID_TYPE>(g_Cfg.ResourceGetIndexType( RES_CHARDEF, s.GetArgStr())), SPELL_Summon, true ); case CV_SMSG: case CV_SYSMESSAGE: SysMessage( s.GetArgStr() ); break; case CV_SYSMESSAGEF: //There is still an issue with numbers not resolving properly when %i,%d,or other numeric format code is in use { TCHAR * pszArgs[4]; size_t iArgQty = Str_ParseCmds( s.GetArgRaw(), pszArgs, COUNTOF(pszArgs) ); if ( iArgQty < 2 ) { g_Log.EventError("SysMessagef with less than 1 args for the given text\n"); return false; } if ( iArgQty > 4 ) { g_Log.EventError("Too many arguments given to SysMessagef (max = text + 3\n"); return false; } //strip quotes if any if ( *pszArgs[0] == '"' ) pszArgs[0]++; for (TCHAR * pEnd = pszArgs[0] + strlen( pszArgs[0] ) - 1; pEnd >= pszArgs[0]; pEnd-- ) { if ( *pEnd == '"' ) { *pEnd = '\0'; break; } } SysMessagef( pszArgs[0], pszArgs[1], pszArgs[2] ? pszArgs[2] : 0, pszArgs[3] ? pszArgs[3] : 0); }break; case CV_SMSGU: case CV_SYSMESSAGEUA: { TCHAR * pszArgs[5]; size_t iArgQty = Str_ParseCmds( s.GetArgRaw(), pszArgs, COUNTOF(pszArgs) ); if ( iArgQty > 4 ) { // Font and mode are actually ignored here, but they never made a difference // anyway.. I'd like to keep the syntax similar to SAYUA NCHAR szBuffer[ MAX_TALK_BUFFER ]; CvtSystemToNUNICODE( szBuffer, COUNTOF(szBuffer), pszArgs[4], -1 ); addBarkUNICODE( szBuffer, NULL, static_cast<HUE_TYPE>(Exp_GetVal(pszArgs[0])), TALKMODE_SYSTEM, FONT_NORMAL, pszArgs[3] ); } } break; case CV_SMSGL: case CV_SYSMESSAGELOC: { TCHAR * ppArgs[256]; size_t iArgQty = Str_ParseCmds( s.GetArgRaw(), ppArgs, COUNTOF(ppArgs), "," ); if ( iArgQty > 1 ) { int hue = -1; if ( ppArgs[0] ) hue = Exp_GetVal( ppArgs[0] ); int iClilocId = Exp_GetVal( ppArgs[1] ); if ( hue == -1 ) hue = HUE_TEXT_DEF; CGString CArgs; for ( size_t i = 2; i < iArgQty; i++ ) { if ( CArgs.GetLength() ) CArgs += "\t"; CArgs += ( !strcmp(ppArgs[i], "NULL") ? " " : ppArgs[i] ); } addBarkLocalized(iClilocId, NULL, static_cast<HUE_TYPE>(hue), TALKMODE_SYSTEM, FONT_NORMAL, CArgs.GetPtr()); } } break; case CV_SMSGLEX: case CV_SYSMESSAGELOCEX: { TCHAR * ppArgs[256]; size_t iArgQty = Str_ParseCmds( s.GetArgRaw(), ppArgs, COUNTOF(ppArgs), "," ); if ( iArgQty > 2 ) { int hue = -1; int affix = 0; if ( ppArgs[0] ) hue = Exp_GetVal( ppArgs[0] ); int iClilocId = Exp_GetVal( ppArgs[1] ); if ( ppArgs[2] ) affix = Exp_GetVal( ppArgs[2] ); if ( hue == -1 ) hue = HUE_TEXT_DEF; CGString CArgs; for ( size_t i = 4; i < iArgQty; i++ ) { if ( CArgs.GetLength() ) CArgs += "\t"; CArgs += ( !strcmp(ppArgs[i], "NULL") ? " " : ppArgs[i] ); } addBarkLocalizedEx( iClilocId, NULL, static_cast<HUE_TYPE>(hue), TALKMODE_SYSTEM, FONT_NORMAL, static_cast<AFFIX_TYPE>(affix), ppArgs[3], CArgs.GetPtr() ); } } break; case CV_TELE: Cmd_Skill_Magery(SPELL_Teleport, dynamic_cast<CObjBase *>(pSrc)); break; case CV_TILE: if ( ! s.HasArgs()) { SysMessage( "Usage: TILE z-height item1 item2 itemX" ); } else { m_Targ_Text = s.GetArgStr(); // Point at the options m_tmTile.m_ptFirst.InitPoint(); // Clear this first m_tmTile.m_Code = CV_TILE; addTarget( CLIMODE_TARG_TILE, "Pick 1st corner:", true ); } break; case CV_VERSION: // "SHOW VERSION" SysMessage(g_szServerDescription); break; case CV_WEBLINK: addWebLaunch( s.GetArgStr()); break; default: if ( r_LoadVal( s )) { CGString sVal; if ( r_WriteVal( s.GetKey(), sVal, pSrc )) { // if ( !s.IsKeyHead( "CTAG.", 5 ) && !s.IsKeyHead( "CTAG0.", 6 ) ) // We don't want output related to ctag // SysMessagef( "%s = %s", (LPCTSTR) s.GetKey(), (LPCTSTR) sVal ); // feedback on what we just did. return( true ); } } return( CScriptObj::r_Verb( s, pSrc )); // used in the case of web pages to access server level things.. } return true; EXC_CATCH; EXC_DEBUG_START; EXC_ADD_SCRIPTSRC; EXC_DEBUG_END; return false; }
bool CClient::r_WriteVal( LPCTSTR pszKey, CGString & sVal, CTextConsole * pSrc ) { ADDTOCALLSTACK("CClient::r_WriteVal"); EXC_TRY("WriteVal"); int index; if ( !strnicmp("CTAG.", pszKey, 5) ) // CTAG.xxx - client tag { if ( pszKey[4] != '.' ) return( false ); pszKey += 5; CVarDefCont *vardef = m_TagDefs.GetKey(pszKey); sVal = vardef ? vardef->GetValStr() : ""; return true; } if ( !strnicmp("CTAG0.", pszKey, 6) ) // CTAG0.xxx - client tag { if ( pszKey[5] != '.' ) return( false ); pszKey += 6; CVarDefCont *vardef = m_TagDefs.GetKey(pszKey); sVal = vardef ? vardef->GetValStr() : "0"; return true; } if ( !strnicmp( "TARGP", pszKey, 5 ) && ( pszKey[5] == '\0' || pszKey[5] == '.' ) ) index = CC_TARGP; else if ( !strnicmp( "SCREENSIZE", pszKey, 10 ) && ( pszKey[10] == '\0' || pszKey[10] == '.' ) ) index = CC_SCREENSIZE; else if ( !strnicmp( "REPORTEDCLIVER", pszKey, 14 ) && ( pszKey[14] == '\0' || pszKey[14] == '.' ) ) index = CC_REPORTEDCLIVER; else index = FindTableSorted( pszKey, sm_szLoadKeys, COUNTOF(sm_szLoadKeys)-1 ); switch (index) { case CC_ALLMOVE: sVal.FormatVal( IsPriv( PRIV_ALLMOVE )); break; case CC_ALLSHOW: sVal.FormatVal( IsPriv( PRIV_ALLSHOW )); break; case CC_CLIENTIS3D: sVal.FormatVal( GetNetState()->isClient3D() ); break; case CC_CLIENTISKR: sVal.FormatVal( GetNetState()->isClientKR() ); break; case CC_CLIENTISSA: sVal.FormatVal( GetNetState()->isClientSA() ); break; case CC_CLIENTVERSION: { TCHAR szVersion[ 128 ]; sVal = m_Crypt.WriteClientVer( szVersion ); } break; case CC_DEBUG: sVal.FormatVal( IsPriv( PRIV_DEBUG )); break; case CC_DETAIL: sVal.FormatVal( IsPriv( PRIV_DETAIL )); break; case CC_GM: // toggle your GM status on/off sVal.FormatVal( IsPriv( PRIV_GM )); break; case CC_HEARALL: sVal.FormatVal( IsPriv( PRIV_HEARALL )); break; case CC_LASTEVENT: sVal.FormatLLVal( m_timeLastEvent.GetTimeRaw() ); break; case CC_PRIVSHOW: // Show my priv title. sVal.FormatVal( ! IsPriv( PRIV_PRIV_NOSHOW )); break; case CC_REPORTEDCLIVER: { pszKey += strlen(sm_szLoadKeys[index]); GETNONWHITESPACE( pszKey ); int iCliVer = (GetNetState()->getReportedVersion() & 0xFFFFFF0); if ( pszKey[0] != '\0' ) iCliVer = GetNetState()->getReportedVersion(); TCHAR szVersion[128]; sVal = CCrypt::WriteClientVerString( iCliVer, szVersion ); } break; case CC_SCREENSIZE: { if ( pszKey[10] == '.' ) { pszKey += strlen(sm_szLoadKeys[index]); SKIP_SEPARATORS(pszKey); if ( !strnicmp("X", pszKey, 1) ) sVal.Format( "%lu", m_ScreenSize.x ); else if ( !strnicmp("Y", pszKey, 1) ) sVal.Format( "%lu", m_ScreenSize.y ); else return( false ); } else sVal.Format( "%lu,%lu", m_ScreenSize.x, m_ScreenSize.y ); } break; case CC_TARG: sVal.FormatHex(m_Targ_UID); break; case CC_TARGP: if ( pszKey[5] == '.' ) { return m_Targ_p.r_WriteVal( pszKey+6, sVal ); } sVal = m_Targ_p.WriteUsed(); break; case CC_TARGPROP: sVal.FormatHex(m_Prop_UID); break; case CC_TARGPRV: sVal.FormatHex(m_Targ_PrvUID); break; case CC_TARGTXT: sVal = m_Targ_Text; break; default: return( CScriptObj::r_WriteVal( pszKey, sVal, pSrc )); } return true; EXC_CATCH; EXC_DEBUG_START; EXC_ADD_KEYRET(pSrc); EXC_DEBUG_END; return false; }
bool CCharNPC::r_WriteVal( CChar * pChar, LPCTSTR pszKey, CGString & sVal ) { EXC_TRY("WriteVal"); switch ( FindTableSorted( pszKey, sm_szLoadKeys, COUNTOF( sm_szLoadKeys )-1 )) { //return as string or hex number or NULL if not set //On these ones, check BaseDef too if not found on dynamic case CNC_THROWDAM: case CNC_THROWOBJ: case CNC_THROWRANGE: sVal = pChar->GetDefStr(pszKey, false, true); break; //return as decimal number or 0 if not set //On these ones, check BaseDef if not found on dynamic case CNC_BONDED: sVal.FormatVal( m_bonded ); break; case CNC_FOLLOWERSLOTS: sVal.FormatLLVal(pChar->GetDefNum(pszKey, true, true)); break; case CNC_ACTPRI: sVal.FormatVal( m_Act_Motivation ); break; case CNC_NPC: sVal.FormatVal( m_Brain ); break; case CNC_HOMEDIST: sVal.FormatVal( m_Home_Dist_Wander ); break; case CNC_NEED: { TCHAR *pszTmp = Str_GetTemp(); m_Need.WriteKey( pszTmp ); sVal = pszTmp; } break; case CNC_NEEDNAME: { TCHAR *pszTmp = Str_GetTemp(); m_Need.WriteNameSingle( pszTmp ); sVal = pszTmp; } break; case CNC_SPEECH: m_Speech.WriteResourceRefList( sVal ); break; case CNC_SPEECHCOLOR: sVal.FormatVal( m_SpeechHue ); break; case CNC_VENDCAP: { CItemContainer * pBank = pChar->GetBank(); if ( pBank ) sVal.FormatVal( pBank->m_itEqBankBox.m_Check_Restock ); } break; case CNC_VENDGOLD: { CItemContainer * pBank = pChar->GetBank(); if ( pBank ) sVal.FormatVal( pBank->m_itEqBankBox.m_Check_Amount ); } break; default: if ( FindTableHeadSorted( pszKey, CCharPlayer::sm_szLoadKeys, COUNTOF( CCharPlayer::sm_szLoadKeys )-1 ) >= 0 ) { sVal = "0"; return( true ); } if ( FindTableSorted( pszKey, CClient::sm_szLoadKeys, CC_QTY ) >= 0 ) { sVal = "0"; return( true ); } return(false ); } return true; EXC_CATCH; EXC_DEBUG_START; EXC_ADD_KEYRET(pChar); EXC_DEBUG_END; return false; }
bool CCharPlayer::r_WriteVal( CChar * pChar, LPCTSTR pszKey, CGString & sVal ) { ADDTOCALLSTACK("CCharPlayer::r_WriteVal"); EXC_TRY("WriteVal"); if ( !pChar || !GetAccount() ) return false; if ( !strnicmp(pszKey, "SKILLCLASS.", 11) ) { return GetSkillClass()->r_WriteVal(pszKey + 11, sVal, pChar); } else if ( ( !strnicmp(pszKey, "GUILD", 5) ) || ( !strnicmp(pszKey, "TOWN", 4) ) ) { bool bIsGuild = !strnicmp(pszKey, "GUILD", 5); pszKey += bIsGuild ? 5 : 4; if ( *pszKey == 0 ) { CItemStone *pMyGuild = pChar->Guild_Find(bIsGuild ? MEMORY_GUILD : MEMORY_TOWN); if ( pMyGuild ) sVal.FormatHex((DWORD)pMyGuild->GetUID()); else sVal.FormatVal(0); return true; } else if ( *pszKey == '.' ) { pszKey += 1; CItemStone *pMyGuild = pChar->Guild_Find(bIsGuild ? MEMORY_GUILD : MEMORY_TOWN); if ( pMyGuild ) return pMyGuild->r_WriteVal(pszKey, sVal, pChar); } return false; } switch ( FindTableHeadSorted( pszKey, sm_szLoadKeys, COUNTOF( sm_szLoadKeys )-1 )) { case CPC_ACCOUNT: sVal = GetAccount()->GetName(); return( true ); case CPC_DEATHS: sVal.FormatVal( m_wDeaths ); return( true ); case CPC_DSPEECH: m_Speech.WriteResourceRefList( sVal ); return( true ); case CPC_KILLS: sVal.FormatVal( m_wMurders ); return( true ); case CPC_KRTOOLBARSTATUS: sVal.FormatVal( m_bKrToolbarEnabled ); return true; case CPC_ISDSPEECH: if ( pszKey[9] != '.' ) return( false ); pszKey += 10; sVal = m_Speech.ContainsResourceName(RES_SPEECH, pszKey) ? "1" : "0"; return( true ); case CPC_LASTUSED: sVal.FormatLLVal( - g_World.GetTimeDiff( m_timeLastUsed ) / TICK_PER_SEC ); return( true ); case CPC_PFLAG: sVal.FormatVal(m_pflag); return( true ); case CPC_PROFILE: { TCHAR szLine[SCRIPT_MAX_LINE_LEN-16]; Str_MakeUnFiltered( szLine, m_sProfile, sizeof(szLine)); sVal = szLine; } return( true ); case CPC_REFUSETRADES: { CVarDefCont * pVar = pChar->GetDefKey(pszKey, true); sVal.FormatLLVal(pVar ? pVar->GetValNum() : 0); } return( true ); case CPC_SKILLCLASS: sVal = GetSkillClass()->GetResourceName(); return( true ); case CPC_SKILLLOCK: { // "SkillLock[alchemy]" SKILL_TYPE skill = Skill_GetLockType( pszKey ); if ( skill <= SKILL_NONE ) return( false ); sVal.FormatVal( Skill_GetLock( skill )); } return( true ); case CPC_SPEEDMODE: sVal.FormatVal( m_speedMode ); return( true ); case CPC_STATLOCK: { // "StatLock[str]" STAT_TYPE stat = Stat_GetLockType( pszKey ); if (( stat <= STAT_NONE ) || ( stat >= STAT_BASE_QTY )) return( false ); sVal.FormatVal( Stat_GetLock( stat )); } return( true ); default: if ( FindTableSorted( pszKey, CCharNPC::sm_szLoadKeys, COUNTOF( CCharNPC::sm_szLoadKeys )-1 ) >= 0 ) { sVal = "0"; return( true ); } return( false ); } EXC_CATCH; EXC_DEBUG_START; EXC_ADD_KEYRET(pChar); EXC_DEBUG_END; return false; }
bool CSector::r_WriteVal( LPCTSTR pszKey, CGString & sVal, CTextConsole * pSrc ) { ADDTOCALLSTACK("CSector::r_WriteVal"); EXC_TRY("WriteVal"); static const CValStr sm_ComplexityTitles[] = { { "HIGH", INT_MIN }, // speech can be very complex if low char count { "MEDIUM", 5 }, { "LOW", 10 }, { NULL, INT_MAX } }; switch ( FindTableHeadSorted( pszKey, sm_szLoadKeys, COUNTOF( sm_szLoadKeys )-1 )) { case SC_CLIENTS: sVal.FormatVal(m_Chars_Active.HasClients()); return true; case SC_COLDCHANCE: sVal.FormatVal( GetColdChance()); return( true ); case SC_COMPLEXITY: if ( pszKey[10] == '.' ) { pszKey += 11; sVal = ( ! strcmpi( pszKey, sm_ComplexityTitles->FindName( GetCharComplexity()))) ? "1" : "0"; return( true ); } sVal.FormatVal( GetCharComplexity()); return( true ); case SC_FLAGS: sVal.FormatHex(m_dwFlags); return( true ); case SC_LIGHT: sVal.FormatVal(GetLight()); return true; case SC_LOCALTIME: sVal = GetLocalGameTime(); return( true ); case SC_LOCALTOD: sVal.FormatVal( GetLocalTime()); return( true ); case SC_NUMBER: sVal.FormatVal(m_index); return( true ); case SC_ISDARK: sVal.FormatVal( IsDark() ); return( true ); case SC_ISNIGHTTIME: { int iMinutes = GetLocalTime(); sVal = ( iMinutes < 7*60 || iMinutes > (9+12)*60 ) ? "1" : "0"; } return( true ); case SC_RAINCHANCE: sVal.FormatVal( GetRainChance()); return( true ); case SC_ITEMCOUNT: sVal.FormatVal(GetItemComplexity()); return true; case SC_SEASON: sVal.FormatVal(static_cast<int>(GetSeason())); return true; case SC_WEATHER: sVal.FormatVal(static_cast<int>(GetWeather())); return true; } EXC_CATCH; EXC_DEBUG_START; EXC_ADD_KEYRET(pSrc); EXC_DEBUG_END; return false; }
bool CWebPageDef::ServPage( CClient * pClient, TCHAR * pszPage, CGTime * pdateIfModifiedSince ) // static { ADDTOCALLSTACK("CWebPageDef::ServPage"); // make sure this is a valid format for the request. TCHAR szPageName[_MAX_PATH]; Str_GetBare( szPageName, pszPage, sizeof(szPageName), "!\"#$%&()*,:;<=>?[]^{|}-+'`" ); int iError = 404; CWebPageDef * pWebPage = g_Cfg.FindWebPage(szPageName); if ( pWebPage ) { iError = pWebPage->ServPageRequest(pClient, szPageName, pdateIfModifiedSince); if ( ! iError ) return true; } // Is it a file in the Script directory ? if ( iError == 404 ) { const RESOURCE_ID ridjunk( RES_UNKNOWN, 1 ); CWebPageDef tmppage( ridjunk ); if ( tmppage.SetSourceFile( szPageName, pClient )) { if ( !tmppage.ServPageRequest(pClient, szPageName, pdateIfModifiedSince) ) return true; } } // Can't find it !? // just take the default page. or have a custom 404 page ? pClient->m_Targ_Text = pszPage; TCHAR *pszTemp = Str_GetTemp(); sprintf(pszTemp, GRAY_FILE "%d.htm", iError); pWebPage = g_Cfg.FindWebPage(pszTemp); if ( pWebPage ) { if ( ! pWebPage->ServPageRequest( pClient, pszPage, NULL )) return true; } // Hmm we should do something !!!? // Try to give a reasonable default error msg. LPCTSTR pszErrText; switch (iError) { case 401: pszErrText = "Authorization Required"; break; case 403: pszErrText = "Forbidden"; break; case 404: pszErrText = "Object Not Found"; break; case 500: pszErrText = "Internal Server Error"; break; default: pszErrText = "Unknown Error"; break; } CGTime datetime = CGTime::GetCurrentTime(); const char *sDate = datetime.FormatGmt(NULL); CGString sMsgHead; CGString sText; sText.Format( "<html><head><title>Error %d</title>" "<meta name=robots content=noindex>" "</head><body>" "<h2>HTTP Error %d</h2><p><strong>%d %s</strong></p>" "<p>The " GRAY_TITLE " server cannot deliver the file or script you asked for.</p>" "<p>Please contact the server's administrator if this problem persists.</p>" "</body></html>", iError, iError, iError, static_cast<LPCTSTR>(pszErrText)); sMsgHead.Format( "HTTP/1.1 %d %s\r\n" "Date: %s\r\n" "Server: " GRAY_TITLE " V " GRAY_VERSION "\r\n" "Content-Type: text/html\r\n" "Content-Length: %d\r\n" "Connection: close\r\n" "\r\n%s", iError, static_cast<LPCTSTR>(pszErrText), static_cast<LPCTSTR>(sDate), sText.GetLength(), static_cast<LPCTSTR>(sText)); new PacketWeb(pClient, reinterpret_cast<const BYTE *>(sMsgHead.GetPtr()), sMsgHead.GetLength()); return false; }
bool CClient::OnRxConsole( const BYTE * pData, size_t iLen ) { ADDTOCALLSTACK("CClient::OnRxConsole"); // A special console version of the client. (Not game protocol) if ( !iLen || ( GetConnectType() != CONNECT_TELNET )) return false; if ( IsSetEF( EF_AllowTelnetPacketFilter ) ) { bool fFiltered = xPacketFilter(pData, iLen); if ( fFiltered ) return fFiltered; } while ( iLen -- ) { int iRet = OnConsoleKey( m_Targ_Text, *pData++, GetAccount() != NULL ); if ( ! iRet ) return( false ); if ( iRet == 2 ) { if ( GetAccount() == NULL ) { if ( !m_zLogin[0] ) { if ( static_cast<unsigned int>(m_Targ_Text.GetLength()) > (COUNTOF(m_zLogin) - 1) ) { SysMessage("Login?:\n"); } else { strcpy(m_zLogin, m_Targ_Text); SysMessage("Password?:\n"); } m_Targ_Text.Empty(); } else { CGString sMsg; CAccountRef pAccount = g_Accounts.Account_Find(m_zLogin); if (( pAccount == NULL ) || ( pAccount->GetPrivLevel() < PLEVEL_Admin )) { SysMessagef("%s\n", g_Cfg.GetDefaultMsg(DEFMSG_CONSOLE_NOT_PRIV)); m_Targ_Text.Empty(); return false; } if ( LogIn(m_zLogin, m_Targ_Text, sMsg ) == PacketLoginError::Success ) { m_Targ_Text.Empty(); return OnRxConsoleLoginComplete(); } else if ( ! sMsg.IsEmpty()) { SysMessage( sMsg ); return false; } m_Targ_Text.Empty(); } return true; } else { iRet = g_Serv.OnConsoleCmd( m_Targ_Text, this ); if (g_Cfg.m_fTelnetLog && GetPrivLevel() >= g_Cfg.m_iCommandLog) g_Log.Event(LOGM_GM_CMDS, "%lx:'%s' commands '%s'=%d\n", GetSocketID(), static_cast<LPCTSTR>(GetName()), static_cast<LPCTSTR>(m_Targ_Text), iRet); } } } return true; }
bool CClient::OnRxAxis( const BYTE * pData, size_t iLen ) { ADDTOCALLSTACK("CClient::OnRxAxis"); if ( !iLen || ( GetConnectType() != CONNECT_AXIS )) return false; while ( iLen -- ) { int iRet = OnConsoleKey( m_Targ_Text, *pData++, GetAccount() != NULL ); if ( ! iRet ) return( false ); if ( iRet == 2 ) { if ( GetAccount() == NULL ) { if ( !m_zLogin[0] ) { if ( static_cast<unsigned int>(m_Targ_Text.GetLength()) <= (COUNTOF(m_zLogin) - 1) ) strcpy(m_zLogin, m_Targ_Text); m_Targ_Text.Empty(); } else { CGString sMsg; CAccountRef pAccount = g_Accounts.Account_Find(m_zLogin); if (( pAccount == NULL ) || ( pAccount->GetPrivLevel() < PLEVEL_Counsel )) { SysMessagef("\"MSG:%s\"", g_Cfg.GetDefaultMsg(DEFMSG_AXIS_NOT_PRIV)); m_Targ_Text.Empty(); return false; } if ( LogIn(m_zLogin, m_Targ_Text, sMsg ) == PacketLoginError::Success ) { m_Targ_Text.Empty(); if ( GetPrivLevel() < PLEVEL_Counsel ) { SysMessagef("\"MSG:%s\"", g_Cfg.GetDefaultMsg(DEFMSG_AXIS_NOT_PRIV)); return false; } if (GetPeer().IsValidAddr()) { CScriptTriggerArgs Args; Args.m_VarsLocal.SetStrNew("Account",GetName()); Args.m_VarsLocal.SetStrNew("IP",GetPeer().GetAddrStr()); TRIGRET_TYPE tRet = TRIGRET_RET_DEFAULT; r_Call("f_axis_preload", this, &Args, NULL, &tRet); if ( tRet == TRIGRET_RET_FALSE ) return false; if ( tRet == TRIGRET_RET_TRUE ) { SysMessagef("\"MSG:%s\"", g_Cfg.GetDefaultMsg(DEFMSG_AXIS_DENIED)); return false; } time_t dateChange; DWORD dwSize; if ( ! CFileList::ReadFileInfo( "Axis.db", dateChange, dwSize )) { SysMessagef("\"MSG:%s\"", g_Cfg.GetDefaultMsg(DEFMSG_AXIS_INFO_ERROR)); return false; } CGFile FileRead; if ( ! FileRead.Open( "Axis.db", OF_READ|OF_BINARY )) { SysMessagef("\"MSG:%s\"", g_Cfg.GetDefaultMsg(DEFMSG_AXIS_FILE_ERROR)); return false; } TCHAR szTmp[8*1024]; PacketWeb packet; for (;;) { size_t iLength = FileRead.Read( szTmp, sizeof( szTmp ) ); if ( iLength <= 0 ) break; packet.setData((BYTE*)szTmp, iLength); packet.send(this); dwSize -= iLength; if ( dwSize <= 0 ) break; } return true; } return false; } else if ( ! sMsg.IsEmpty()) { SysMessagef("\"MSG:%s\"", (LPCTSTR)sMsg); return false; } m_Targ_Text.Empty(); } return true; } } } return true; }
CGString::CGString(const CGString &s) { m_iMaxLength = m_iLength = 0; m_pchData = NULL; Copy(s.GetPtr()); }
bool CPartyDef::r_WriteVal( LPCTSTR pszKey, CGString &sVal, CTextConsole *pSrc ) { ADDTOCALLSTACK("CPartyDef::r_WriteVal"); EXC_TRY("WriteVal"); CScriptObj *pRef; if ( r_GetRef(pszKey, pRef) ) { if ( pRef == NULL ) // good command but bad link. { sVal = "0"; return true; } if ( pszKey[0] == '\0' ) // we where just testing the ref. { CObjBase *pObj = dynamic_cast<CObjBase *>(pRef); if ( pObj ) sVal.FormatHex(static_cast<DWORD>(pObj->GetUID())); else sVal.FormatVal(1); return true; } return pRef->r_WriteVal(pszKey, sVal, pSrc); } bool fZero = false; switch ( FindTableHeadSorted(pszKey, sm_szLoadKeys, COUNTOF(sm_szLoadKeys) - 1) ) { case PDC_ISSAMEPARTYOF: { pszKey += 13; GETNONWHITESPACE(pszKey); if ( pszKey[0] != '\0' ) { CGrayUID uidToCheck = static_cast<CGrayUID>(Exp_GetVal(pszKey)); CChar *pCharToCheck = uidToCheck.CharFind(); sVal.FormatVal(pCharToCheck && (pCharToCheck->m_pParty == this)); } else return false; } break; case PDC_MEMBERS: sVal.FormatVal(m_Chars.GetCharCount()); break; case PDC_SPEECHFILTER: sVal = m_pSpeechFunction.IsEmpty() ? "" : m_pSpeechFunction; break; case PDC_TAG0: fZero = true; pszKey++; case PDC_TAG: { if ( pszKey[3] != '.' ) return false; pszKey += 4; sVal = m_TagDefs.GetKeyStr(pszKey, fZero); } break; case PDC_TAGAT: { pszKey += 5; // eat the 'TAGAT' if ( *pszKey == '.' ) // do we have an argument? { SKIP_SEPARATORS(pszKey); size_t iQty = static_cast<size_t>(Exp_GetVal(pszKey)); if ( iQty >= m_TagDefs.GetCount() ) return false; // trying to get non-existant tag CVarDefCont *pTagAt = m_TagDefs.GetAt(iQty); if ( !pTagAt ) return false; // trying to get non-existant tag SKIP_SEPARATORS(pszKey); if ( !*pszKey ) { sVal.Format("%s=%s", pTagAt->GetKey(), pTagAt->GetValStr()); return true; } else if ( !strnicmp(pszKey, "KEY", 3) ) { sVal = pTagAt->GetKey(); return true; } else if ( !strnicmp(pszKey, "VAL", 3) ) { sVal = pTagAt->GetValStr(); return true; } } return false; } case PDC_TAGCOUNT: sVal.FormatVal(m_TagDefs.GetCount()); break; default: return false; } return true; EXC_CATCH; EXC_DEBUG_START; EXC_ADD_KEYRET(pSrc); EXC_DEBUG_END; return false; }
bool CRegionBase::r_WriteVal( LPCTSTR pszKey, CGString & sVal, CTextConsole * pSrc ) { ADDTOCALLSTACK("CRegionBase::r_WriteVal"); EXC_TRY("WriteVal"); bool fZero = false; int index = FindTableHeadSorted(pszKey, sm_szLoadKeys, COUNTOF(sm_szLoadKeys) - 1); if ( index < 0 ) return CScriptObj::r_WriteVal(pszKey, sVal, pSrc); switch ( index ) { case RC_ANNOUNCE: sVal.FormatVal( IsFlag(REGION_FLAG_ANNOUNCE)); break; case RC_ARENA: sVal.FormatVal( IsFlag(REGION_FLAG_ARENA)); break; case RC_BUILDABLE: sVal.FormatVal( ! IsFlag(REGION_FLAG_NOBUILDING)); break; case RC_CLIENTS: { int i = 0; size_t iClients = 0; for ( ; ; i++ ) { CSector *pSector = GetSector(i); if ( pSector == NULL ) break; iClients += pSector->m_Chars_Active.HasClients(); } sVal.FormatVal(static_cast<long>(iClients)); break; } case RC_EVENTS: m_Events.WriteResourceRefList( sVal ); break; case RC_ISEVENT: if ( pszKey[7] != '.' ) return( false ); pszKey += 8; sVal.FormatVal(m_Events.ContainsResourceName(RES_EVENTS, pszKey)); return( true ); case RC_FLAGS: sVal.FormatHex( GetRegionFlags() ); break; case RC_GATE: sVal.FormatVal( ! IsFlag(REGION_ANTIMAGIC_GATE)); break; case RC_GROUP: sVal = m_sGroup; break; case RC_GUARDED: sVal.FormatVal( IsFlag(REGION_FLAG_GUARDED)); break; case RC_MAGIC: sVal.FormatVal( ! IsFlag(REGION_ANTIMAGIC_ALL)); break; case RC_MAP: sVal.FormatVal( m_pt.m_map ); break; case RC_MARK: case RC_RECALLIN: sVal.FormatVal( ! IsFlag(REGION_ANTIMAGIC_RECALL_IN)); break; case RC_NAME: // The previous name was really the DEFNAME ??? sVal = GetName(); break; case RC_NOBUILD: sVal.FormatVal( IsFlag(REGION_FLAG_NOBUILDING)); break; case RC_NODECAY: sVal.FormatVal( IsFlag(REGION_FLAG_NODECAY)); break; case RC_NOPVP: sVal.FormatVal( IsFlag(REGION_FLAG_NO_PVP)); break; case RC_P: sVal = m_pt.WriteUsed(); break; case RC_RECALL: case RC_RECALLOUT: sVal.FormatVal( ! IsFlag(REGION_ANTIMAGIC_RECALL_OUT)); break; case RC_RECT: { size_t iQty = m_Rects.GetCount(); pszKey += 4; if ( *pszKey == '\0' ) { sVal.FormatVal( static_cast<long>(iQty)); return true; } SKIP_SEPARATORS( pszKey ); size_t iRect = Exp_GetVal( pszKey ); if ( iRect <= 0 ) { sVal = m_rectUnion.Write(); return true; } iRect -= 1; if ( !m_Rects.IsValidIndex( iRect ) ) { sVal.FormatVal( 0 ); return true; } sVal = m_Rects[iRect].Write(); return( true ); } case RC_SAFE: sVal.FormatVal( IsFlag(REGION_FLAG_SAFE)); break; case RC_TAGCOUNT: sVal.FormatVal( static_cast<long>(m_TagDefs.GetCount()) ); break; case RC_TAGAT: { pszKey += 5; // eat the 'TAGAT' if ( *pszKey == '.' ) // do we have an argument? { SKIP_SEPARATORS( pszKey ); size_t iQty = static_cast<size_t>( Exp_GetVal( pszKey ) ); if ( iQty >= m_TagDefs.GetCount() ) return( false ); // trying to get non-existant tag CVarDefCont * pTagAt = m_TagDefs.GetAt( iQty ); if ( !pTagAt ) return( false ); // trying to get non-existant tag SKIP_SEPARATORS( pszKey ); if ( ! *pszKey ) { sVal.Format("%s=%s", pTagAt->GetKey(), pTagAt->GetValStr()); return( true ); } else if ( !strnicmp( pszKey, "KEY", 3 )) // key? { sVal = pTagAt->GetKey(); return( true ); } else if ( !strnicmp( pszKey, "VAL", 3 )) // val? { sVal = pTagAt->GetValStr(); return( true ); } } return( false ); } break; case RC_TAG0: fZero = true; ++pszKey; // fall through case RC_TAG: // "TAG" = get/set a local tag. { if ( pszKey[3] != '.' ) return( false ); pszKey += 4; sVal = m_TagDefs.GetKeyStr( pszKey, fZero ); return( true ); } case RC_TYPE: { const CItemBase * pBase = NULL; const CItem * pItem = GetResourceID().ItemFind(); if (pItem != NULL) pBase = pItem->Item_GetDef(); if (pBase != NULL) sVal = pBase->GetResourceName(); else sVal = ""; } break; case RC_UID: // Allow use of UID.x.KEY on the REGION object if ( pszKey[3] == '.' ) return CScriptObj::r_WriteVal( pszKey, sVal, pSrc ); sVal.FormatHex( GetResourceID() ); break; case RC_UNDERGROUND: sVal.FormatVal( IsFlag(REGION_FLAG_UNDERGROUND)); break; default: return false; } return true; EXC_CATCH; EXC_DEBUG_START; g_Log.EventDebug("command '%s' ret '%s' [%p]\n", pszKey, static_cast<LPCTSTR>(sVal), static_cast<void *>(pSrc)); EXC_DEBUG_END; return false; }