1. 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:
    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));
    The output in the log file looks like 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
    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?
     
  2. Wulf

    Wulf Community Admin

    Could you provide the code please?
     
  3. Here is the section of the code:

    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 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).

    The base plugin is:: Auto Purge for Rust | Oxide
     
  4. Wulf

    Wulf Community Admin

    You'd probably need to lookup the BasePlayer using the Steam ID, then grab the name from.
     
  5. 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?
     
  6. Wulf

    Wulf Community Admin

    See Oxide/RustCore.cs at master · OxideMod/Oxide · GitHub.

    Rust also has a FindPlayer function that may work.