private void StartLogging() { if (Initialized) { return; } DLConfigData config = DLConfig.Data; try { SystemUtil.EnsurePathExists(config.ChatlogPath); _writer = new StreamWriter(config.ChatlogPath, append: true); Initialized = true; } catch (Exception e) { Logger.Error("Error occurred while attempting to initialize the chat logger using path \"" + config.ChatlogPath + "\". Error message: " + e); } if (Initialized) { _flushTimer = new Timer(innerArgs => { lock (_overlapLock) { Flush(); } }, null, 0, CHATLOG_FLUSH_TIMER_INTERAVAL_MS); } }
public static DiscordLinkEmbed GetVerificationDM(User ecoUser) { DLConfigData config = DLConfig.Data; ServerInfo serverInfo = NetworkManager.GetServerInfo(); string serverName = MessageUtil.StripTags(!string.IsNullOrWhiteSpace(config.ServerName) ? DLConfig.Data.ServerName : MessageUtil.StripTags(serverInfo.Description)); DiscordLinkEmbed embed = new DiscordLinkEmbed(); embed.WithTitle("Account Linking Verification"); embed.AddField("Initiator", MessageUtil.StripTags(ecoUser.Name)); embed.AddField("Description", $"Your Eco account has been linked to your Discord account on the server \"{serverName}\"."); embed.AddField("Action Required", $"If you initiated this action, use the command `{config.DiscordCommandPrefix}verifylink` to verify that these accounts should be linked."); embed.WithFooter("If you did not initiate this action, notify a server admin.\nThe account link cannot be used until verified."); return(embed); }
public static DiscordLinkEmbed GetServerInfo(ServerInfoComponentFlag flag) { var plugin = DiscordLink.Obj; if (plugin == null) { return(null); } DLConfigData config = DLConfig.Data; ServerInfo serverInfo = NetworkManager.GetServerInfo(); DiscordLinkEmbed embed = new DiscordLinkEmbed(); embed.WithFooter(GetStandardEmbedFooter()); if (flag.HasFlag(ServerInfoComponentFlag.Name)) { embed.WithTitle($"**{MessageUtil.FirstNonEmptyString(config.ServerName, MessageUtil.StripTags(serverInfo.Description), "[Server Title Missing]")} " + "Server Status" + "**\n" + DateTime.Now.ToShortDateString() + " : " + DateTime.Now.ToShortTimeString()); } else { DateTime time = DateTime.Now; int utcOffset = TimeZoneInfo.Local.GetUtcOffset(time).Hours; embed.WithTitle("**" + "Server Status" + "**\n" + "[" + DateTime.Now.ToString("yyyy-MM-dd : HH:mm", CultureInfo.InvariantCulture) + " UTC " + (utcOffset != 0 ? (utcOffset >= 0 ? "+" : "-") + utcOffset : "") + "]"); } if (flag.HasFlag(ServerInfoComponentFlag.Description)) { embed.WithDescription(MessageUtil.FirstNonEmptyString(config.ServerDescription, MessageUtil.StripTags(serverInfo.Description), "No server description is available.")); } if (flag.HasFlag(ServerInfoComponentFlag.Logo) && !string.IsNullOrWhiteSpace(config.ServerLogo)) { embed.WithThumbnail(config.ServerLogo); } if (flag.HasFlag(ServerInfoComponentFlag.ConnectionInfo)) { string fieldText = "-- Connection info not configured --"; string address = string.Empty; string port = string.Empty; if (!string.IsNullOrEmpty(config.ServerAddress)) { address = config.ServerAddress; } else if (!string.IsNullOrEmpty(serverInfo.Address)) { address = serverInfo.Address; } if (!string.IsNullOrEmpty(address)) { port = serverInfo.GamePort.ToString(); fieldText = $"{address}:{port}"; } embed.AddField("Connection Info", fieldText); } if (flag.HasFlag(ServerInfoComponentFlag.PlayerCount)) { embed.AddField("Online Players Count", $"{UserManager.OnlineUsers.Where(user => user.Client.Connected).Count()}/{serverInfo.TotalPlayers}"); } if (flag.HasFlag(ServerInfoComponentFlag.PlayerList)) { IEnumerable <string> onlineUsers = UserManager.OnlineUsers.Where(user => user.Client.Connected).Select(user => user.Name); string playerList = onlineUsers.Count() > 0 ? string.Join("\n", onlineUsers) : "-- No players online --"; bool useOnlineTime = flag.HasFlag(ServerInfoComponentFlag.PlayerListLoginTime); embed.AddField("Online Players", Shared.GetPlayerList(useOnlineTime)); } if (flag.HasFlag(ServerInfoComponentFlag.CurrentTime)) { TimeSpan timeSinceStartSpan = new TimeSpan(0, 0, (int)serverInfo.TimeSinceStart); embed.AddField("Current Time", $"Day {timeSinceStartSpan.Days + 1} {timeSinceStartSpan.Hours.ToString("00")}:{timeSinceStartSpan.Minutes.ToString("00")}"); // +1 days to get start at day 1 just like ingame } if (flag.HasFlag(ServerInfoComponentFlag.TimeRemaining)) { TimeSpan timeRemainingSpan = new TimeSpan(0, 0, (int)serverInfo.TimeLeft); bool meteorHasHit = timeRemainingSpan.Seconds < 0; timeRemainingSpan = meteorHasHit ? new TimeSpan(0, 0, 0) : timeRemainingSpan; embed.AddField("Time Left Until Meteor", $"{timeRemainingSpan.Days} Days, {timeRemainingSpan.Hours} hours, {timeRemainingSpan.Minutes} minutes"); } if (flag.HasFlag(ServerInfoComponentFlag.MeteorHasHit)) { TimeSpan timeRemainingSpan = new TimeSpan(0, 0, (int)serverInfo.TimeLeft); embed.AddField("Meteor Has Hit", timeRemainingSpan.Seconds < 0 ? "Yes" : "No"); } if (flag.HasFlag(ServerInfoComponentFlag.ActiveElectionCount)) { embed.AddField("Active Elections Count", $"{EcoUtil.ActiveElections.Count()}"); } if (flag.HasFlag(ServerInfoComponentFlag.ActiveElectionList)) { string electionList = string.Empty; foreach (Election election in EcoUtil.ActiveElections) { electionList += $"{MessageUtil.StripTags(election.Name)} **[{election.TotalVotes} Votes]**\n"; } if (string.IsNullOrEmpty(electionList)) { electionList = "-- No active elections --"; } embed.AddField("Active Elections", electionList); } if (flag.HasFlag(ServerInfoComponentFlag.LawCount)) { embed.AddField("Law Count", $"{EcoUtil.ActiveLaws.Count()}"); } if (flag.HasFlag(ServerInfoComponentFlag.LawList)) { string lawList = string.Empty; foreach (Law law in EcoUtil.ActiveLaws) { lawList += $"{MessageUtil.StripTags(law.Name)}\n"; } if (string.IsNullOrEmpty(lawList)) { lawList = "-- No active laws --"; } embed.AddField("Laws", lawList); } return(embed); }