Пример #1
0
void CScriptRMI::OnPostInitClient( uint16 channelId, IEntity * pEntity )
{
	SmartScriptTable server;
	SmartScriptTable entity = pEntity->GetScriptTable();

	if (!entity.GetPtr())
		return;

	if (!entity->GetValue( "Server", server ) || !server.GetPtr())
		return;

	IScriptSystem * pSystem = entity->GetScriptSystem();
	if ((server->GetValueType( "OnPostInitClient" ) == svtFunction) &&
		pSystem->BeginCall( server, "OnPostInitClient" ))
	{
		pSystem->PushFuncParam( entity );
		pSystem->PushFuncParam( channelId );
		pSystem->EndCall();
	}
}
Пример #2
0
// one-time validation of entity tables
bool CScriptRMI::ValidateDispatchTable( const char * clazz, SmartScriptTable dispatch, SmartScriptTable methods, bool bServerTable )
{
	CryAutoCriticalSection lkDispatch(m_dispatchMutex);

	std::map<string,size_t>::iterator iterN = m_entityClassToEntityTypeID.lower_bound(clazz);
	if (iterN == m_entityClassToEntityTypeID.end() || iterN->first != clazz)
	{
		iterN = m_entityClassToEntityTypeID.insert( iterN, std::make_pair(clazz, m_entityClassToEntityTypeID.size()) );
		CRY_ASSERT(iterN->second == m_dispatch.size());
		m_dispatch.push_back(SDispatch());
	}
	SDispatch& dispatchTblCont = m_dispatch[iterN->second];
	SFunctionDispatchTable& dispatchTbl = bServerTable ? dispatchTblCont.server : dispatchTblCont.client;

	IScriptTable::Iterator iter = dispatch->BeginIteration();
	while (dispatch->MoveNext(iter))
	{
		if (iter.sKey)
		{
			if (iter.sKey[0] == '_' && iter.sKey[1] == '_')
				continue;

			ScriptVarType type = methods->GetValueType( iter.sKey );
			if (type != svtFunction)
			{
				GameWarning( "In class %s: function %s is exposed but not defined",
					clazz, iter.sKey );
				dispatch->EndIteration(iter);
				return false;
			}
		}
		else
		{
			int id = iter.nKey;
			CRY_ASSERT(id>0);
			id--;

			if (id >= dispatchTbl.size())
				dispatchTbl.resize(id+1);
			SFunctionDispatch& dt = dispatchTbl[id];
			if (iter.value.GetVarType() != svtString)
			{
				GameWarning("Expected a string in dispatch table, got type %d", iter.value.GetVarType());
				dispatch->EndIteration(iter);
				return false;
			}

			const char * funcData = iter.value.str;
			const char * colon = strchr(funcData, ':');
			if (colon == NULL)
			{
				dispatch->EndIteration(iter);
				return false;
			}
			if (colon - funcData > MaxSynchedPropertyNameLength)
			{
				dispatch->EndIteration(iter);
				return false;
			}
			memcpy( dt.name, funcData, colon-funcData );
			dt.name[colon-funcData] = 0;
			strcpy(dt.format, colon + 1);
		}
	}
	dispatch->EndIteration(iter);
	dispatch->SetValue( VALIDATED_FIELD, true );

	if (bServerTable)
	{
		dispatchTblCont.m_serverDispatchScriptTable = dispatch;
	}
	else
	{
		dispatchTblCont.m_clientDispatchScriptTable = dispatch;
	}

	return true;
}