Jakg, most of the people who were/are making cruise servers have already gone past the stage this tutorial is at. It's a resource for beginners to show them how to earn cash, buy cars and a couple other things...that's the way I see it anyway
[SIZE=2]BackUp.Enabled = [/SIZE][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]BackUp.Elapsed += [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] System.Timers.[/SIZE][SIZE=2][COLOR=#2b91af]ElapsedEventHandler[/COLOR][/SIZE][SIZE=2](BackUp_Elapsed);[/SIZE]
[SIZE=2]System.Timers.[/SIZE][SIZE=2][COLOR=#2b91af]Timer[/COLOR][/SIZE][SIZE=2] BackUp = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] System.Timers.[/SIZE][SIZE=2][COLOR=#2b91af]Timer[/COLOR][/SIZE][SIZE=2](300000);[/SIZE]
[SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2] BackUp_Elapsed([/SIZE][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][SIZE=2] sender, System.Timers.[/SIZE][SIZE=2][COLOR=#2b91af]ElapsedEventArgs[/COLOR][/SIZE][SIZE=2] e)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff] foreach[/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2b91af]clsConnection[/COLOR][/SIZE][SIZE=2] C [/SIZE][SIZE=2][COLOR=#0000ff]in[/COLOR][/SIZE][SIZE=2] Connections)[/SIZE]
[SIZE=2][COLOR=#2b91af] FileInfo[/COLOR][/SIZE][SIZE=2].UpdateUserLeave(C.Username, C.Cash, C.Cars);[/SIZE]
[SIZE=2]}[/SIZE]
// This is the class where we store info about our drivers.
class Driver
{
public string LfsUserName;
public int Money;
// Insert other info you want to save.
}
// This will save an array of drivers to a file.
void SaveDrivers(string file, Driver[] drivers)
{
System.IO.FileStream stream = null;
System.IO.BinaryWriter writer = null;
try
{
stream = System.IO.File.Open(file, FileMode.Create);
writer = new System.IO.BinaryWriter(stream);
writer.Write(drivers.Length);
foreach (Driver driver in drivers)
{
writer.Write(driver.LfsUserName);
writer.Write(driver.Money);
// Write the rest of the info to file.
}
}
catch (System.IO.IOException ex)
{
// Gracefully handle IO error.
}
finally
{
if (writer != null)
writer.Close();
if (stream != null)
stream.Close();
}
}
// This will read the file back and return an array of drivers.
Driver[] LoadDrivers(string file)
{
List<Driver> drivers = new List<Driver>();
System.IO.FileStream stream = null;
System.IO.BinaryReader reader = null;
try
{
stream = System.IO.File.Open(file, FileMode.Open);
reader = new System.IO.BinaryReader(stream);
int numDrivers = reader.ReadInt32();
for (int i = 0; i < numDrivers; i++)
{
Driver driver = new Driver();
driver.LfsUserName = reader.ReadString();
driver.Money = reader.ReadInt32();
// Read the rest of the info in the same way...
drivers.Add(driver);
}
}
catch (System.IO.IOException ex)
{
// Gracefully handle IO error.
}
finally
{
if (reader != null)
reader.Close();
if (stream != null)
stream.Close();
}
return drivers.ToArray();
}