public static void AddPlayer(ReferenceHub player) { try { if (LiteDatabase.GetCollection <Player>().Exists(x => x.Id == DatabasePlayer.GetRawUserId(player))) { return; } LiteDatabase.GetCollection <Player>().Insert(new Player() { Id = DatabasePlayer.GetRawUserId(player), Name = player.GetNickname(), Authentication = DatabasePlayer.GetAuthentication(player), ScpSuicideCount = 0, TotalScpGamesPlayed = 0, TotalScpSuicideKicks = 0, TotalScpSuicideBans = 0, FirstJoin = DateTime.Now, LastSeen = DateTime.Now, ColorPreference = "", CustomNickName = "", BadgeName = "", BadgeExpire = DateTime.MinValue, HideBadge = false }); Log.Info("Trying to add ID: " + player.GetUserId().Split('@')[0] + " Discriminator: " + player.GetUserId().Split('@')[1] + " to Database"); } catch (Exception ex) { Log.Error($"Cannot add new user to Database: {player.GetNickname()} ({player.GetUserId().Split('@')[0]})!\n{ex.ToString()}"); } }
public void AddPlayer(Exiled.API.Features.Player player) { try { if (LiteDatabase.GetCollection <Player>().Exists(x => x.Id == DatabasePlayer.GetRawUserId(player))) { return; } LiteDatabase.GetCollection <Player>().Insert(new Player() { Id = DatabasePlayer.GetRawUserId(player), Name = player.Nickname, Ip = "None", Authentication = DatabasePlayer.GetAuthentication(player), ScpSuicideCount = 0, TotalScpGamesPlayed = 0, TotalScpSuicideKicks = 0, TotalScpSuicideBans = 0, RoundBanLeft = 0, FirstJoin = DateTime.Now, LastSeen = DateTime.Now, ColorPreference = "", CustomNickName = "", BadgeName = "", BadgeExpire = DateTime.MinValue, PreviousBadge = "", HideBadge = false, PlayTimeRecords = null, ASNWhitelisted = false, Restricted = null, KeepPreferences = false, IgnoreDNT = false, PlaytimeSessionsLog = null, Expire = null }); } catch (Exception ex) { Log.Error($"Cannot add new user to Database: {player.Nickname} ({player.UserId.Split('@')[0]})!\n{ex.ToString()}"); } }
internal void OnPlayerVerify(VerifiedEventArgs ev) { if (!Database.LiteDatabase.GetCollection <Player>().Exists(player => player.Id == DatabasePlayer.GetRawUserId(ev.Player))) { pluginInstance.DatabasePlayerData.AddPlayer(ev.Player); } Player databasePlayer = ev.Player.GetDatabasePlayer(); if (Database.PlayerData.ContainsKey(ev.Player)) { return; } Database.PlayerData.Add(ev.Player, databasePlayer); databasePlayer.LastSeen = PreauthTime[ev.Player.UserId]; PreauthTime.Remove(ev.Player.UserId); databasePlayer.Name = ev.Player.Nickname; var sameIP = Database.LiteDatabase.GetCollection <Player>().FindAll().Where(x => x.Ip == databasePlayer.Ip).ToList(); if (databasePlayer.Ip != ev.Player.IPAddress) { pluginInstance.Functions.ChangeIP(ev.Player); } if (sameIP.Count > 1) { pluginInstance.Functions.CheckAccount(ev.Player); } if (databasePlayer.FirstJoin == DateTime.MinValue) { databasePlayer.FirstJoin = DateTime.Now; } if (pluginInstance.Config.WelcomeMessage.Show) { var message = pluginInstance.Config.WelcomeMessage.Content; message = message.Replace("%player%", ev.Player.Nickname); ev.Player.Broadcast(pluginInstance.Config.WelcomeMessage.Duration, message, pluginInstance.Config.WelcomeMessage.Type, false); } if (pluginInstance.Functions.CheckAsnPlayer(ev.Player)) { ev.Player.Kick($"Auto-Kick: {pluginInstance.Config.AsnKickMessage}", "SCPUtils"); } else { pluginInstance.Functions.PostLoadPlayer(ev.Player); } }
internal void OnPlayerVerify(VerifiedEventArgs ev) { if (!Database.LiteDatabase.GetCollection <Player>().Exists(player => player.Id == DatabasePlayer.GetRawUserId(ev.Player))) { pluginInstance.DatabasePlayerData.AddPlayer(ev.Player); } Player databasePlayer = ev.Player.GetDatabasePlayer(); if (Database.PlayerData.ContainsKey(ev.Player)) { return; } Database.PlayerData.Add(ev.Player, databasePlayer); databasePlayer.LastSeen = DateTime.Now; databasePlayer.Name = ev.Player.Nickname; if (databasePlayer.FirstJoin == DateTime.MinValue) { databasePlayer.FirstJoin = DateTime.Now; } if (pluginInstance.Config.WelcomeEnabled) { ev.Player.Broadcast(pluginInstance.Config.WelcomeMessageDuration, pluginInstance.Config.WelcomeMessage.Replace("%player%", ev.Player.Nickname), Broadcast.BroadcastFlags.Normal); } if (pluginInstance.Functions.CheckAsnPlayer(ev.Player)) { ev.Player.Kick($"Auto-Kick: {pluginInstance.Config.AsnKickMessage}", "SCPUtils"); } else { pluginInstance.Functions.PostLoadPlayer(ev.Player); } }