private async Task NetMgrOnConnecting(NetConnectingArgs e) { // Check if banned. var addr = e.IP.Address; var userId = e.UserId; var ban = await _db.GetServerBanAsync(addr, userId); if (ban != null) { var expires = "This is a permanent ban."; if (ban.ExpirationTime is { } expireTime) { var duration = expireTime - ban.BanTime; var utc = expireTime.ToUniversalTime(); expires = $"This ban is for {duration.TotalMinutes:N0} minutes and will expire at {utc:f} UTC."; } var reason = $@"You, or another user of this computer or connection, are banned from playing here. The ban reason is: ""{ban.Reason}"" {expires}"; e.Deny(reason); return; } if (!ServerPreferencesManager.ShouldStorePrefs(e.AuthType)) { return; } await _db.UpdatePlayerRecordAsync(userId, e.UserName, addr); await _db.AddConnectionLogAsync(userId, e.UserName, addr); }
/* * private async Task<NetApproval> HandleApproval(NetApprovalEventArgs eventArgs) * { * var ban = await _db.GetServerBanByIpAsync(eventArgs.Connection.RemoteEndPoint.Address); * if (ban != null) * { * var expires = "This is a permanent ban."; * if (ban.ExpirationTime is { } expireTime) * { * var duration = expireTime - ban.BanTime; * var utc = expireTime.ToUniversalTime(); * expires = $"This ban is for {duration.TotalMinutes} minutes and will expire at {utc:f} UTC."; * } * var reason = $@"You, or another user of this computer or connection is banned from playing here. * The ban reason is: ""{ban.Reason}"" * {expires}"; * return NetApproval.Deny(reason); * } * * return NetApproval.Allow(); * } */ private async Task NetMgrOnConnecting(NetConnectingArgs e) { // Check if banned. var addr = e.IP.Address; var userId = e.UserId; ImmutableArray <byte>?hwId = e.UserData.HWId; if (hwId.Value.Length == 0 || !_cfg.GetCVar(CCVars.BanHardwareIds)) { // HWId not available for user's platform, don't look it up. // Or hardware ID checks disabled. hwId = null; } var adminData = await _dbManager.GetAdminDataForAsync(e.UserId); var wasInGame = EntitySystem.TryGet <GameTicker>(out var ticker) && ticker.PlayersInGame.Contains(userId); if ((_plyMgr.PlayerCount >= _cfg.GetCVar(CCVars.SoftMaxPlayers) && adminData is null) && !wasInGame) { e.Deny(Loc.GetString("soft-player-cap-full")); return; } var ban = await _db.GetServerBanAsync(addr, userId, hwId); if (ban != null) { e.Deny(ban.DisconnectMessage); return; } if (_cfg.GetCVar(CCVars.WhitelistEnabled) && await _db.GetWhitelistStatusAsync(userId) == false && adminData is null) { e.Deny(Loc.GetString("whitelist-not-whitelisted")); return; } if (!ServerPreferencesManager.ShouldStorePrefs(e.AuthType)) { return; } await _db.UpdatePlayerRecordAsync(userId, e.UserName, addr, e.UserData.HWId); await _db.AddConnectionLogAsync(userId, e.UserName, addr, e.UserData.HWId); }
/* * private async Task<NetApproval> HandleApproval(NetApprovalEventArgs eventArgs) * { * var ban = await _db.GetServerBanByIpAsync(eventArgs.Connection.RemoteEndPoint.Address); * if (ban != null) * { * var expires = "This is a permanent ban."; * if (ban.ExpirationTime is { } expireTime) * { * var duration = expireTime - ban.BanTime; * var utc = expireTime.ToUniversalTime(); * expires = $"This ban is for {duration.TotalMinutes} minutes and will expire at {utc:f} UTC."; * } * var reason = $@"You, or another user of this computer or connection is banned from playing here. * The ban reason is: ""{ban.Reason}"" * {expires}"; * return NetApproval.Deny(reason); * } * * return NetApproval.Allow(); * } */ private async Task NetMgrOnConnecting(NetConnectingArgs e) { // Check if banned. var addr = e.IP.Address; var userId = e.UserId; ImmutableArray <byte>?hwId = e.UserData.HWId; if (hwId.Value.Length == 0 || !_cfg.GetCVar(CCVars.BanHardwareIds)) { // HWId not available for user's platform, don't look it up. // Or hardware ID checks disabled. hwId = null; } var ban = await _db.GetServerBanAsync(addr, userId, hwId); if (ban != null) { var expires = "This is a permanent ban."; if (ban.ExpirationTime is { } expireTime) { var duration = expireTime - ban.BanTime; var utc = expireTime.ToUniversalTime(); expires = $"This ban is for {duration.TotalMinutes:N0} minutes and will expire at {utc:f} UTC."; } var reason = $@"You, or another user of this computer or connection, are banned from playing here. The ban reason is: ""{ban.Reason}"" {expires}"; e.Deny(reason); return; } if (!ServerPreferencesManager.ShouldStorePrefs(e.AuthType)) { return; } await _db.UpdatePlayerRecordAsync(userId, e.UserName, addr, e.UserData.HWId); await _db.AddConnectionLogAsync(userId, e.UserName, addr, e.UserData.HWId); }
/* * private async Task<NetApproval> HandleApproval(NetApprovalEventArgs eventArgs) * { * var ban = await _db.GetServerBanByIpAsync(eventArgs.Connection.RemoteEndPoint.Address); * if (ban != null) * { * var expires = "This is a permanent ban."; * if (ban.ExpirationTime is { } expireTime) * { * var duration = expireTime - ban.BanTime; * var utc = expireTime.ToUniversalTime(); * expires = $"This ban is for {duration.TotalMinutes} minutes and will expire at {utc:f} UTC."; * } * var reason = $@"You, or another user of this computer or connection is banned from playing here. * The ban reason is: ""{ban.Reason}"" * {expires}"; * return NetApproval.Deny(reason); * } * * return NetApproval.Allow(); * } */ private async Task NetMgrOnConnecting(NetConnectingArgs e) { // Check if banned. var addr = e.IP.Address; var userId = e.UserId; ImmutableArray <byte>?hwId = e.UserData.HWId; if (hwId.Value.Length == 0 || !_cfg.GetCVar(CCVars.BanHardwareIds)) { // HWId not available for user's platform, don't look it up. // Or hardware ID checks disabled. hwId = null; } if (_plyMgr.PlayerCount >= _cfg.GetCVar(CCVars.SoftMaxPlayers) && await _dbManager.GetAdminDataForAsync(e.UserId) is null) { e.Deny("The server is full!"); return; } var ban = await _db.GetServerBanAsync(addr, userId, hwId); if (ban != null) { e.Deny(ban.DisconnectMessage); return; } if (!ServerPreferencesManager.ShouldStorePrefs(e.AuthType)) { return; } await _db.UpdatePlayerRecordAsync(userId, e.UserName, addr, e.UserData.HWId); await _db.AddConnectionLogAsync(userId, e.UserName, addr, e.UserData.HWId); }