using System; using System.IO; using Oxide.Core; using Oxide.Core.Libraries.Covalence; using Oxide.Core.Plugins; namespace Oxide.Plugins { [Info("PlayerLogs", "Ridamees", "1.0.1")] [Description("Logs player connect/disconnects to separate files")] class PlayerLogs : CovalencePlugin { private readonly PluginData pluginData = new PluginData(); private class PluginData { public string LogDirectory { get; set; } public PluginData() { LogDirectory = Path.Combine(Interface.Oxide.LogDirectory, "PlayerLogs"); Directory.CreateDirectory(LogDirectory); } public string GetLogFilePath(string steamId, string playerName) { return Path.Combine(LogDirectory, $"{playerName}({steamId}).txt"); } } private void OnUserConnected(IPlayer player) { string steamId = player.Id; string playerName = player.Name; string dateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string logFilePath = pluginData.GetLogFilePath(steamId, playerName); string logMessage = $"CONNECTED: {dateTime}"; AppendLogToFile(logFilePath, logMessage); } private void OnUserDisconnected(IPlayer player, string reason) { string steamId = player.Id; string playerName = player.Name; string dateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string logFilePath = pluginData.GetLogFilePath(steamId, playerName); string logMessage = $"DISCONNECTED: {dateTime} ({reason})"; AppendLogToFile(logFilePath, logMessage); } private void AppendLogToFile(string logFilePath, string logMessage) { try { using (StreamWriter sw = File.AppendText(logFilePath)) { sw.WriteLine(logMessage); } } catch (Exception ex) { Puts($"Error writing to log file {logFilePath}: {ex.Message}"); } } } }