Got a quick question for someone who knows more about C# than I do~
I'm renovating a plugin, adding some logging features. The line im using right now is this:
The output in the log file looks like this:Code:ConVar.Server.Log($"Oxide/Logs/purge_{DateTime.Now.ToString("yyyy-M-d")}.txt", "Entity removed from user " + owner + " at time " + epoch2string(current_time) + " because they havent logged in since " + epoch2string(last_seen_time));
I want the user's name, not their ID. I have googled for 3 days, and found lots of ways that seem like they should work, but none of them work. Anyone know the best way to do this?Code:[2/26/2016 8:54:50 PM] Entity removed from user 76523457677229722728 at time 2/27/2016 2:54:50 AM because they haven't logged in since 2/23/2016 2:12:29 AM
Quick code question on id->name
Discussion in 'Rust Development' started by tufkal, Feb 28, 2016.
-
Wulf Community Admin
Could you provide the code please?
-
Here is the section of the code:
The 2 ConVar.Server.Log lines are all I have added to the original author's code. I simply would like the log output to be more useful (as I stated, player name instead of ID).Code:void MainTimer() { if (Convert.ToBoolean(Config["General", "Messages"])) { PurgeMessage(1); } int count = 0; List<ulong> UNIQUE_HITS = new List<ulong>(); foreach(var entity in BaseNetworkable.serverEntities.All()) { ulong owner = FindOwner(entity.gameObject.ToBaseEntity()); if(owner != 0 && Convert.ToBoolean(ConnectionDB.Call("ConnectionDataExistsFromID", owner))) { DateTime LastSeen = Convert.ToDateTime(ConnectionDB.Call("LastSeenFromID", owner)); long last_seen_time = ConvertToUnixTime(LastSeen); long current_time = UnixTimeStampUTC(); if(current_time - last_seen_time >= Convert.ToInt32(Config["General", "InactiveAfter"])) { entity.Kill(); count++; ConVar.Server.Log($"Oxide/Logs/purge_{DateTime.Now.ToString("yyyy-M-d")}.txt", "Entity removed from user " + owner + " at time " + epoch2string(current_time) + " because they havent logged in since " + epoch2string(last_seen_time)); if (!UNIQUE_HITS.Contains(owner)) { UNIQUE_HITS.Add(owner);} } } } if (Convert.ToBoolean(Config["General", "Messages"])) { PurgeMessage(2, count, UNIQUE_HITS.Count); } if(count != 0) { Puts("Removed: " + count.ToString() + " entities from: " + UNIQUE_HITS.Count.ToString() + " inactive players"); } else { Puts("Nothing to remove... up to date."); ConVar.Server.Log($"Oxide/Logs/purge_{DateTime.Now.ToString("yyyy-M-d")}.txt", "No entities removed."); } }
The base plugin is:: Auto Purge for Rust | Oxide -
Wulf Community Admin
You'd probably need to lookup the BasePlayer using the Steam ID, then grab the name from.
-
Agreed, based on the code i've tried and seen, thats what I need to do. Unfortunately I don't have to the C# knowledge to write a function to do that. Could someone put together a function I could drop at the end of the file and call during that line of code?
-
Wulf Community Admin
See Oxide/RustCore.cs at master · OxideMod/Oxide · GitHub.
Rust also has a FindPlayer function that may work. -
Got it, thanks for pointing me in the right direction Wulf.
