The online racing simulator
Problem with saving data
[EDIT]: I don't want to promote TC server, I remember only this server
Hello everyone!
I won't post all code because is useless.
My problem is when someone disconnect or anything else, the program sometimes save info as I want and sometimes doesn't work.
When it works, the written line is: [TC] Cruise Server, S2 server, 20.01.2023 - 14:37
and when doesn't work, the written line is just: ^7, ^6 server^7, 20.01.2023 - 14:37
So sometimes my program doesn't write host name and game version


public string Database = @"Database";
public string Players = @"Players";
public string HostName;
public string GameVersion;

private void ClientLeavesHost(InSim insim_var, IS_CNL CNL)
{
try
{
clsConnection Conn = Connections[GetConnIdx(CNL.UCID)];

switch (CNL.Reason)
{
case "LEAVR_KICKED": // User Kicked
case "LEAVR_BANNED": // User Banned
case "LEAVR_CPW": // Cheat protection wrong.
case "LEAVR_LOSTCONN": // Lost Connection
case "LEAVR_TIMEOUT": // Timed out
case "LEAVR_DISCO": // Disconnected
case "LEAVR_SECURITY": // Out-of-sync (OOS) or cheat protection
case "LEAVR_OOS": // Out of sync with host
case "LEAVR_JOOS": // Join OOS (initial sync failed)
case "LEAVR_HACK": // Invalid packet

StreamWriter Sw = new StreamWriter(Database + "\\" + Players + "\\" + Conn.Username + ".txt");

Sw.WriteLine(Conn.HostName + "^7, ^6" + Conn.GameVersion + " server^7, " + System.DateTime.Now.ToString("dd/MM/yyyy - HH:mm"));
Sw.Flush();
Sw.Close();

break;

}
}
catch(Exception ex)
{
insim.Send(new IS_MSL { Msg = "^1CNL - " + ex.Message});
}
}

private void InSimVersion(InSim insim_var, IS_VER VER)
{
try
{
foreach (clsConnection Conn in Connections)
{
Conn.GameVersion = VER.Product.ToString();
}

catch(Exception ex)
{
insim.Send(new IS_MSL { Msg = "^1VER - " + ex.Message});
}
}

IS_VER and IS_ISM are not guest info packets, its only info about the client your app is connected to.

There is no packet with guest's Product info. I'm not sure why would you need that anyway. Storing HostName in guest info class also doesn't make any sense.
It's an local app and I need that because I want to know when I saw specific user last time and where
That still doesn't change the fact that VER and ISM is info about your client, not about other players's clients. So you cannot get Product info of other players. And HostName is same for all players so storing it for each individual player is nonsense.

My guess is that your HostName is empty if you start your app after you have already joined a server. Because ISM is only sent if you join a host. Request TINY_ISM when you app starts.

insim.Send(new IS_TINY { ReqI = 1, SubT = TinyType.TINY_ISM }); // request ISM

You should consider using AppendAllTextAsync, no need to dispose or flush Thumbs up

await File.AppendAllTextAsync(path, content);

Quote from LakynVonLegendaus :So you cannot get Product info of other players.

I don't want to do that. I'm using product info to see if the user was on demo, s1, s2 or s3 server. That's all!

Thank you guys, but I solved my little problem! Thumbs up

FGED GREDG RDFGDR GSFDG