Beispiel #1
0
/*****************************************************************************
 * FUNCTION - SaveToFlash
 * DESCRIPTION: Returns true on success
 ****************************************************************************/
bool FlashBlock::SaveToFlash(void)
{
  bool success = false;

#ifndef __PC__

  int count = mpBlockHdr->blockSize;

  // flash is 16-bit - adjust to 2-byte boundary if necessary
  if ((count % 2) != 0)
  {
    count++;
  }

  success = FlashControl::GetInstance()->SaveData(mpBlockCache, count, mFlashControlBlockId);
#else
  success = SaveToDisk();
#endif

  // set / reset error flag
  if (success)
  {
    mErrorFlags &= ~ERROR_FLAG_SAVE_TO_FLASH_FAILED;
  }
  else
  {
    LoadFromFlash(); // Restore previous data (assumed to be valid)
    mErrorFlags |= ERROR_FLAG_SAVE_TO_FLASH_FAILED;
  }

  mModified = false; // Clear this flag here to avoid repeat of SaveToFlash in case of error

  return success;

}
void
GPMPrefsManager::SaveAllBeforeDestruct()
{
	(JXGetChooseSaveFile())->JPrefObject::WritePrefs();

	SetData(kGPMProgramVersionID, GPMGetVersionNumberStr());

	SaveToDisk();
}
Beispiel #3
0
NCXResource::NCXResource(const QString &mainfolder, const QString &fullfilepath, QObject *parent)
    : XMLResource(mainfolder, fullfilepath, parent)
{
    FillWithDefaultText();
    // Make sure the file exists on disk.
    // Among many reasons, this also solves the problem
    // with the Book Browser not displaying an icon for this resource.
    SaveToDisk();
}
Beispiel #4
0
OPFResource::OPFResource(const QString &mainfolder, const QString &fullfilepath, QObject *parent)
  : XMLResource(mainfolder, fullfilepath, parent),
    m_NavResource(NULL),
    m_WarnedAboutVersion(false)
{
    CreateMimetypes();
    FillWithDefaultText();
    // Make sure the file exists on disk.
    // Among many reasons, this also solves the problem
    // with the Book Browser not displaying an icon for this resource.
    SaveToDisk();
}
Beispiel #5
0
bool cPlayer::LoadFromDisk(cWorldPtr & a_World)
{
	LoadRank();

	// Load from the UUID file:
	if (LoadFromFile(GetUUIDFileName(m_UUID), a_World))
	{
		return true;
	}
	
	// Load from the offline UUID file, if allowed:
	AString OfflineUUID = cClientHandle::GenerateOfflineUUID(GetName());
	const char * OfflineUsage = " (unused)";
	if (cRoot::Get()->GetServer()->ShouldLoadOfflinePlayerData())
	{
		OfflineUsage = "";
		if (LoadFromFile(GetUUIDFileName(OfflineUUID), a_World))
		{
			return true;
		}
	}
	
	// Load from the old-style name-based file, if allowed:
	if (cRoot::Get()->GetServer()->ShouldLoadNamedPlayerData())
	{
		AString OldStyleFileName = Printf("players/%s.json", GetName().c_str());
		if (LoadFromFile(OldStyleFileName, a_World))
		{
			// Save in new format and remove the old file
			if (SaveToDisk())
			{
				cFile::Delete(OldStyleFileName);
			}
			return true;
		}
	}
	
	// None of the files loaded successfully
	LOG("Player data file not found for %s (%s, offline %s%s), will be reset to defaults.",
		GetName().c_str(), m_UUID.c_str(), OfflineUUID.c_str(), OfflineUsage
	);

	if (a_World == NULL)
	{
		a_World = cRoot::Get()->GetDefaultWorld();
	}
	return false;
}
Beispiel #6
0
void cPlayer::KilledBy(cEntity * a_Killer)
{
	super::KilledBy(a_Killer);

	if (m_Health > 0)
	{
		return; //  not dead yet =]
	}

	m_bVisible = false; // So new clients don't see the player

	// Puke out all the items
	cItems Pickups;
	m_Inventory.CopyToItems(Pickups);
	m_Inventory.Clear();

	if (GetName() == "Notch")
	{
		Pickups.Add(cItem(E_ITEM_RED_APPLE));
	}

	m_Stats.AddValue(statItemsDropped, Pickups.Size());

	m_World->SpawnItemPickups(Pickups, GetPosX(), GetPosY(), GetPosZ(), 10);
	SaveToDisk();  // Save it, yeah the world is a tough place !

	if (a_Killer == NULL)
	{
		GetWorld()->BroadcastChatDeath(Printf("%s was killed by environmental damage", GetName().c_str()));
	}
	else if (a_Killer->IsPlayer())
	{
		cPlayer * Killer = (cPlayer *)a_Killer;

		GetWorld()->BroadcastChatDeath(Printf("%s was killed by %s", GetName().c_str(), Killer->GetName().c_str()));
	}
	else
	{
		AString KillerClass = a_Killer->GetClass();
		KillerClass.erase(KillerClass.begin()); // Erase the 'c' of the class (e.g. "cWitch" -> "Witch")

		GetWorld()->BroadcastChatDeath(Printf("%s was killed by a %s", GetName().c_str(), KillerClass.c_str()));
	}

	m_Stats.AddValue(statDeaths);

	m_World->GetScoreBoard().AddPlayerScore(GetName(), cObjective::otDeathCount, 1);
}
Beispiel #7
0
cPlayer::~cPlayer(void)
{
    LOGD("Deleting cPlayer \"%s\" at %p, ID %d", m_PlayerName.c_str(), this, GetUniqueID());

    // Notify the server that the player is being destroyed
    cRoot::Get()->GetServer()->PlayerDestroying(this);

    SaveToDisk();

    m_World->RemovePlayer( this );

    m_ClientHandle = NULL;

    delete m_InventoryWindow;

    LOGD("Player %p deleted", this);
}
Beispiel #8
0
void cPlayer::KilledBy(cEntity * a_Killer)
{
    super::KilledBy(a_Killer);

    if (m_Health > 0)
    {
        return; //  not dead yet =]
    }

    m_bVisible = false; // So new clients don't see the player

    // Puke out all the items
    cItems Pickups;
    m_Inventory.CopyToItems(Pickups);
    m_Inventory.Clear();
    m_World->SpawnItemPickups(Pickups, GetPosX(), GetPosY(), GetPosZ(), 10);
    SaveToDisk();  // Save it, yeah the world is a tough place !
}
Beispiel #9
0
	void DataFileDB::DelList(int index)
	{
		if(dbtype==DBNone)
			throw LangErr("DataFileDB::DelList(int)","cannot delete list entries from type DBNone");
		else if(dbtype==DBStringKeys)
		{
			if(index < 0 || index >= (int)vec.size())
				throw Error::Invalid("DataFileDB::DelList(int)","Index out of range");

			unlink(FileName(vec[index][0].String()).c_str());
			
			vec.erase(index);
			status.erase(status.begin()+index);
			SaveToDisk();
		}
		else
			throw Error::NotYetImplemented("DataFileDB::DelList(int)");
	}
Beispiel #10
0
void ordena(void){

	int i,c;

	c=ReadAllToDisk();

	OrdenaOnMemory(c,1);				//*******************************

	borrartodo();					//Funcion que Ordena el Archivo 

	for(i=0;i<c;i++){				//Por Nombre

		r[i].clave=i+1;				//*******************************

		SaveToDisk(r[i]);

	}

	printf("nArchivo Ordenadon");

}
Beispiel #11
0
cPlayer::~cPlayer(void)
{
	if (!cRoot::Get()->GetPluginManager()->CallHookPlayerDestroyed(*this))
	{
		cRoot::Get()->BroadcastChatLeave(Printf("%s has left the game", GetName().c_str()));
		LOGINFO("Player %s has left the game", GetName().c_str());
	}

	LOGD("Deleting cPlayer \"%s\" at %p, ID %d", GetName().c_str(), this, GetUniqueID());
	
	// Notify the server that the player is being destroyed
	cRoot::Get()->GetServer()->PlayerDestroying(this);

	SaveToDisk();

	m_ClientHandle = NULL;
	
	delete m_InventoryWindow;
	m_InventoryWindow = NULL;
	
	LOGD("Player %p deleted", this);
}
Beispiel #12
0
	void DataFileDB::SaveContent()
	{
		if(IsDirty())
			SaveToDisk();
	}
GPrefsMgr::~GPrefsMgr()
{
	SetData(kGProgramVersionID, GMGetVersionNumberStr());
	SaveToDisk();
}
THXPrefsManager::~THXPrefsManager()
{
	SaveToDisk();
}
Beispiel #15
0
void cPlayer::Tick(float a_Dt, cChunk & a_Chunk)
{
	if (m_ClientHandle != NULL)
	{
		if (m_ClientHandle->IsDestroyed())
		{
			// This should not happen, because destroying a client will remove it from the world, but just in case
			m_ClientHandle = NULL;
			return;
		}
		
		if (!m_ClientHandle->IsPlaying())
		{
			// We're not yet in the game, ignore everything
			return;
		}
	}

	m_Stats.AddValue(statMinutesPlayed, 1);
	
	if (!a_Chunk.IsValid())
	{
		// This may happen if the cPlayer is created before the chunks have the chance of being loaded / generated (#83)
		return;
	}
	
	super::Tick(a_Dt, a_Chunk);
	
	// Handle charging the bow:
	if (m_IsChargingBow)
	{
		m_BowCharge += 1;
	}
	
	// Handle updating experience
	if (m_bDirtyExperience)
	{
		SendExperience();
	}

	bool CanMove = true;
	if (!GetPosition().EqualsEps(m_LastPos, 0.01))  // Non negligible change in position from last tick?
	{
		// Apply food exhaustion from movement:
		ApplyFoodExhaustionFromMovement();
		
		if (cRoot::Get()->GetPluginManager()->CallHookPlayerMoving(*this, m_LastPos, GetPosition()))
		{
			CanMove = false;
			TeleportToCoords(m_LastPos.x, m_LastPos.y, m_LastPos.z);
		}
		m_ClientHandle->StreamChunks();
	}

	if (CanMove)
	{
		BroadcastMovementUpdate(m_ClientHandle);
	}

	if (m_Health > 0)  // make sure player is alive
	{
		m_World->CollectPickupsByPlayer(this);

		if ((m_EatingFinishTick >= 0) && (m_EatingFinishTick <= m_World->GetWorldAge()))
		{
			FinishEating();
		}
		
		HandleFood();
	}
	
	if (m_IsFishing)
	{
		HandleFloater();
	}

	// Update items (e.g. Maps)
	m_Inventory.UpdateItems();

	// Send Player List (Once per m_LastPlayerListTime/1000 ms)
	cTimer t1;
	if (m_LastPlayerListTime + PLAYER_LIST_TIME_MS <= t1.GetNowTime())
	{
		m_World->BroadcastPlayerListUpdatePing(*this);
		m_LastPlayerListTime = t1.GetNowTime();
	}

	if (IsFlying())
	{
		m_LastGroundHeight = (float)GetPosY();
	}

	if (m_TicksUntilNextSave == 0)
	{
		SaveToDisk();
		m_TicksUntilNextSave = PLAYER_INVENTORY_SAVE_INTERVAL;
	}
	else
	{
		m_TicksUntilNextSave--;
	}
}
Beispiel #16
0
void cPlayer::KilledBy(TakeDamageInfo & a_TDI)
{
	super::KilledBy(a_TDI);

	if (m_Health > 0)
	{
		return;  //  not dead yet =]
	}

	m_bVisible = false;  // So new clients don't see the player

	// Puke out all the items
	cItems Pickups;
	m_Inventory.CopyToItems(Pickups);
	m_Inventory.Clear();

	if (GetName() == "Notch")
	{
		Pickups.Add(cItem(E_ITEM_RED_APPLE));
	}

	m_Stats.AddValue(statItemsDropped, (StatValue)Pickups.Size());

	m_World->SpawnItemPickups(Pickups, GetPosX(), GetPosY(), GetPosZ(), 10);
	SaveToDisk();  // Save it, yeah the world is a tough place !

	if ((a_TDI.Attacker == NULL) && m_World->ShouldBroadcastDeathMessages())
	{
		AString DamageText;
		switch (a_TDI.DamageType)
		{
			case dtRangedAttack: DamageText = "was shot"; break;
			case dtLightning: DamageText = "was plasmified by lightining"; break;
			case dtFalling: DamageText = (GetWorld()->GetTickRandomNumber(10) % 2 == 0) ? "fell to death" : "hit the ground too hard"; break;
			case dtDrowning: DamageText = "drowned"; break;
			case dtSuffocating: DamageText = (GetWorld()->GetTickRandomNumber(10) % 2 == 0) ? "git merge'd into a block" : "fused with a block"; break;
			case dtStarving: DamageText = "forgot the importance of food"; break;
			case dtCactusContact: DamageText = "was impaled on a cactus"; break;
			case dtLavaContact: DamageText = "was melted by lava"; break;
			case dtPoisoning: DamageText = "died from septicaemia"; break;
			case dtWithering: DamageText = "is a husk of their former selves"; break;
			case dtOnFire: DamageText = "forgot to stop, drop, and roll"; break;
			case dtFireContact: DamageText = "burnt themselves to death"; break;
			case dtInVoid: DamageText = "somehow fell out of the world"; break;
			case dtPotionOfHarming: DamageText = "was magicked to death"; break;
			case dtEnderPearl: DamageText = "misused an ender pearl"; break;
			case dtAdmin: DamageText = "was administrator'd"; break;
			case dtExplosion: DamageText = "blew up"; break;
			default: DamageText = "died, somehow; we've no idea how though"; break;
		}
		GetWorld()->BroadcastChatDeath(Printf("%s %s", GetName().c_str(), DamageText.c_str()));
	}
	else if (a_TDI.Attacker == NULL)  // && !m_World->ShouldBroadcastDeathMessages() by fallthrough
	{
		// no-op
	}
	else if (a_TDI.Attacker->IsPlayer())
	{
		cPlayer * Killer = (cPlayer *)a_TDI.Attacker;

		GetWorld()->BroadcastChatDeath(Printf("%s was killed by %s", GetName().c_str(), Killer->GetName().c_str()));
	}
	else
	{
		AString KillerClass = a_TDI.Attacker->GetClass();
		KillerClass.erase(KillerClass.begin());  // Erase the 'c' of the class (e.g. "cWitch" -> "Witch")

		GetWorld()->BroadcastChatDeath(Printf("%s was killed by a %s", GetName().c_str(), KillerClass.c_str()));
	}

	m_Stats.AddValue(statDeaths);

	m_World->GetScoreBoard().AddPlayerScore(GetName(), cObjective::otDeathCount, 1);
}
Beispiel #17
0
void actualizar(struct agenda registro,int opcion){

	switch(opcion){

		case 1:

			printf (" Nombre ? ");

			scanf  ("%s",registro.nom);

		break;

		case 2:

			printf (" Apellido Paterno ? ");

			scanf  ("%s",registro.ApPat);

		break;						//**********************************

		case 3:						//Funcion que recibe un registro 

			printf (" Apellido Materno ? ");	//y modifica segun "opcion"

			scanf  ("%s",registro.ApMat);		//el campo correspondiente

		break;						//**********************************

		case 4:

			printf (" Edad ? ");

			scanf  ("%d",registro.edad);

		break;

		case 5:

			printf (" Calle ? ");

			scanf  ("%s",registro.calle);

		break;

		case 6:

			printf (" Telefono ? ");

			scanf  ("%ld",registro.tel);

		break;

		case 7:

			printf (" Telefono celular? ");

			scanf  ("%ld",registro.cel);

		break;

		case 8:

			printf (" Cual es tu e-mail ? ");

			scanf  ("%s",registro.mail);

		break;

	}

	SaveToDisk(registro);

}
GLPrefsMgr::~GLPrefsMgr()
{
	JXGetChooseSaveFile()->JPrefObject::WritePrefs();
	SetData(kProgramVersionID, JGetString("VERSION"));
	SaveToDisk();
}
void LevelStateManager::Reset()
{
	levelStates.clear();
	SaveToDisk(DEFAULT_LEVELSTATE_FILE);
}
Beispiel #20
0
void agregar(void){

	int clave;

	struct agenda registro,aux;

	printf("%c[31m",ESCAPE);

	clavesdisponibles();

	printf("%c[0m",ESCAPE);

	do{

		printf (" Dame tu clave: ");				//******************************

		scanf  ("%d",&clave);					//Codigo para validar la clave

		if(clave>MAX) {						//debe de ser menor que MAX

			printf("%c[31m",ESCAPE);			//Y no puede usar una con datos

			printf("Tu clave debe ser menor que %dn",MAX);	//asociados

			printf("%c[0m",ESCAPE);				//******************************

		}

		aux=ReadToDisk(clave);

		if(aux.sw==1){

			printf("%c[31m",ESCAPE);

			printf("La clave ya esta en uso n");

			printf("%c[0m",ESCAPE);

		}

	}while(clave>MAX || aux.sw==1);

	registro.clave=clave;

	printf (" Cual es tu nombre ? ");				//****************************** 

	scanf  ("%s",registro.nom);					//Metodo para Pedir datos

	printf (" Cual es tu Apellido Paterno ? ");			//y despues agregarlos a disco

	scanf  ("%s",registro.ApPat);					//******************************

	printf (" Cual es tu Apellido Materno ? ");

	scanf  ("%s",registro.ApMat);

	printf (" Cual es tu edad ? ");

	scanf  ("%d",registro.edad);

	printf (" Cual es tu telefono ? ");

	scanf  ("%ld",registro.tel);

	printf (" Cual es tu telefono celular? ");

	scanf  ("%ld",registro.cel);

	printf (" Cual es tu calle ? ");

	scanf  ("%s",registro.calle);

	printf (" Cual es tu colonia ? ");

	scanf  ("%s",registro.col);

	printf (" Cual es tu Municipio ? ");

	scanf  ("%s",registro.mun);

	printf (" En que Estado vives ? ");

	scanf  ("%s",registro.estado);

	printf (" Cual es tu e-mail ? ");

	scanf  ("%s",registro.mail);

	registro.sw=1;

	SaveToDisk(registro);

	printf ("Se ha agregado otro elemento a la agenda");

}