void OnConnectedClient(ref ConnectedClientDataMsg msg, MyNetworkClient sender) { var steamId = sender.SteamUserId; RaiseClientJoined(steamId); MyLog.Default.WriteLineAndConsole("OnConnectedClient " + msg.Name + " attempt"); System.Diagnostics.Debug.Assert(msg.Join); if (m_members.Contains(steamId)) { MyLog.Default.WriteLineAndConsole("Already joined"); SendJoinResult(steamId, JoinResult.AlreadyJoined); return; } if (MySandboxGame.ConfigDedicated.Banned.Contains(steamId)) { MyLog.Default.WriteLineAndConsole("User is banned by admins"); ulong adminID = 0; foreach (var user in m_memberData) { if (user.Value.IsAdmin) { adminID = user.Key; break; } } if (adminID == 0 && MySandboxGame.ConfigDedicated.Administrators.Count > 0) { adminID = ConvertSteamIDTo64(MySandboxGame.ConfigDedicated.Administrators[0]); } SendJoinResult(steamId, JoinResult.BannedByAdmins, adminID); return; } AuthSessionResponseEnum res = SteamSDK.SteamServerAPI.Instance.GameServer.BeginAuthSession(steamId, msg.Token); if (res != AuthSessionResponseEnum.OK) { MyLog.Default.WriteLineAndConsole("Authentication failed (" + res.ToString() + ")"); SendJoinResult(steamId, JoinResult.TicketInvalid); return; } m_pendingMembers.Add(steamId, new MyConnectedClientData() { Name = msg.Name, IsAdmin = MySandboxGame.ConfigDedicated.Administrators.Contains(steamId.ToString()) || MySandboxGame.ConfigDedicated.Administrators.Contains(ConvertSteamIDFrom64(steamId)), }); }
protected void raise_ValidateAuthTicketResponse(ulong value0, AuthSessionResponseEnum value1, ulong value2) { // TODO [vicent] current stub implementation // ValidateAuthTicketResponse validateAuthTicketResponse = this.<backing_store>ValidateAuthTicketResponse; ValidateAuthTicketResponse validateAuthTicketResponse = this.ValidateAuthTicketResponse; if (validateAuthTicketResponse != null) { validateAuthTicketResponse(value0, value1, value2); } }
//Largely copied from SE private void ValidateAuthTicketResponse(ulong steamID, AuthSessionResponseEnum response, ulong ownerSteamID) { _log.Info($"Server ValidateAuthTicketResponse ({response}), owner: {ownerSteamID}"); if (steamID != ownerSteamID) { _log.Info($"User {steamID} is using a game owned by {ownerSteamID}. Tracking..."); _gameOwnerIds[steamID] = ownerSteamID; if (MySandboxGame.ConfigDedicated.Banned.Contains(ownerSteamID)) { _log.Info($"Game owner {ownerSteamID} is banned. Banning and rejecting client {steamID}..."); UserRejected(steamID, JoinResult.BannedByAdmins); BanPlayer(steamID); } } if (response == AuthSessionResponseEnum.OK) { if (MySession.Static.MaxPlayers > 0 && _members.Count - 1 >= MySession.Static.MaxPlayers) { UserRejected(steamID, JoinResult.ServerFull); } else if (MySandboxGame.ConfigDedicated.Administrators.Contains(steamID.ToString()) /*|| MySandboxGame.ConfigDedicated.Administrators.Contains(MyDedicatedServerBase.ConvertSteamIDFrom64(steamID))*/) { UserAccepted(steamID); } else if (MySandboxGame.ConfigDedicated.GroupID == 0) { switch (MySession.Static.OnlineMode) { case MyOnlineModeEnum.PUBLIC: UserAccepted(steamID); break; case MyOnlineModeEnum.PRIVATE: UserRejected(steamID, JoinResult.NotInGroup); break; case MyOnlineModeEnum.FRIENDS: //TODO: actually verify friendship UserRejected(steamID, JoinResult.NotInGroup); break; } } else if (SteamServerAPI.Instance.GetAccountType(MySandboxGame.ConfigDedicated.GroupID) != AccountType.Clan) { UserRejected(steamID, JoinResult.GroupIdInvalid); } else if (SteamServerAPI.Instance.GameServer.RequestGroupStatus(steamID, MySandboxGame.ConfigDedicated.GroupID)) { // Returns false when there's no connection to Steam _waitingForGroup.Add(steamID); } else { UserRejected(steamID, JoinResult.SteamServersOffline); } } else { JoinResult joinResult = JoinResult.TicketInvalid; switch (response) { case AuthSessionResponseEnum.AuthTicketCanceled: joinResult = JoinResult.TicketCanceled; break; case AuthSessionResponseEnum.AuthTicketInvalidAlreadyUsed: joinResult = JoinResult.TicketAlreadyUsed; break; case AuthSessionResponseEnum.LoggedInElseWhere: joinResult = JoinResult.LoggedInElseWhere; break; case AuthSessionResponseEnum.NoLicenseOrExpired: joinResult = JoinResult.NoLicenseOrExpired; break; case AuthSessionResponseEnum.UserNotConnectedToSteam: joinResult = JoinResult.UserNotConnected; break; case AuthSessionResponseEnum.VACBanned: joinResult = JoinResult.VACBanned; break; case AuthSessionResponseEnum.VACCheckTimedOut: joinResult = JoinResult.VACCheckTimedOut; break; } UserRejected(steamID, joinResult); } }
/// <summary> /// Reimplementation of the vanilla event /// </summary> /// <param name="steamID"></param> /// <param name="response"></param> /// <param name="steamOwner"></param> private static void GameServer_ValidateAuthTicketResponse(ulong steamID, AuthSessionResponseEnum response, ulong steamOwner) { try { MyLog.Default.WriteLineAndConsole($"Essentials ValidateAuthTicketResponse ({response}), owner: {steamOwner}"); if (IsClientBanned(steamOwner) || MySandboxGame.ConfigDedicated.Banned.Contains(steamOwner)) { UserRejected(steamID, JoinResult.BannedByAdmins); RaiseClientKicked(steamID); } else { if (IsClientKicked(steamOwner)) { UserRejected(steamID, JoinResult.KickedRecently); RaiseClientKicked(steamID); } } if (response == AuthSessionResponseEnum.OK) { if (MyMultiplayer.Static.MemberLimit > 0 && MyMultiplayer.Static.MemberCount - 1 >= MyMultiplayer.Static.MemberLimit) // Unfortunately, DS counds into the members, so subtract it { if (!PluginSettings.Instance.ReservedSlotsEnabled) { UserRejected(steamID, JoinResult.ServerFull); return; } if (PluginSettings.Instance.ReservedSlotsPlayers.Contains(steamID.ToString()) || PluginSettings.Instance.ReservedSlotsAdmins && MySession.Static.GetUserPromoteLevel(steamID) >= MyPromoteLevel.Admin) { Essentials.Log.Info($"Added whitelisted player {steamID}"); UserAccepted(steamID); } else { if (PluginSettings.Instance.ReservedSlotsGroup != 0) { if (SteamServerAPI.Instance.GameServer.RequestGroupStatus(steamID, PluginSettings.Instance.ReservedSlotsGroup)) { // Returns false when there's no connection to Steam _waitingForWhitelistGroup.Add(steamID); } else { UserRejected(steamID, JoinResult.SteamServersOffline); } } else { UserRejected(steamID, JoinResult.ServerFull); } } } else { if (m_groupId == 0 || MySandboxGame.ConfigDedicated.Administrators.Contains(steamID.ToString()) || MySandboxGame.ConfigDedicated.Administrators.Contains(ConvertSteamIDFrom64(steamID))) { UserAccepted(steamID); } else { if (SteamServerAPI.Instance.GetAccountType(m_groupId) != AccountType.Clan) { UserRejected(steamID, JoinResult.GroupIdInvalid); } else { if (SteamServerAPI.Instance.GameServer.RequestGroupStatus(steamID, m_groupId)) { // Returns false when there's no connection to Steam m_waitingForGroup.Add(steamID); } else { UserRejected(steamID, JoinResult.SteamServersOffline); } } } } } else { var joinResult = JoinResult.TicketInvalid; switch (response) { case AuthSessionResponseEnum.AuthTicketCanceled: joinResult = JoinResult.TicketCanceled; break; case AuthSessionResponseEnum.AuthTicketInvalidAlreadyUsed: joinResult = JoinResult.TicketAlreadyUsed; break; case AuthSessionResponseEnum.LoggedInElseWhere: joinResult = JoinResult.LoggedInElseWhere; break; case AuthSessionResponseEnum.NoLicenseOrExpired: joinResult = JoinResult.NoLicenseOrExpired; break; case AuthSessionResponseEnum.UserNotConnectedToSteam: joinResult = JoinResult.UserNotConnected; break; case AuthSessionResponseEnum.VACBanned: joinResult = JoinResult.VACBanned; break; case AuthSessionResponseEnum.VACCheckTimedOut: joinResult = JoinResult.VACCheckTimedOut; break; } UserRejected(steamID, joinResult); } } catch (Exception ex) { Essentials.Log.Error(ex); } }
protected void raise_ValidateAuthTicketResponse(ulong value0, AuthSessionResponseEnum value1, ulong value2) { // TODO [vicent] current stub implementation // ValidateAuthTicketResponse validateAuthTicketResponse = this.<backing_store>ValidateAuthTicketResponse; ValidateAuthTicketResponse validateAuthTicketResponse = this.ValidateAuthTicketResponse; if (validateAuthTicketResponse != null) { validateAuthTicketResponse(value0, value1, value2); } }
private static void GameServer_ValidateAuthTicketResponse(ulong remoteUserId, AuthSessionResponseEnum response, ulong ownerSteamId) { //using the player join event takes too long, sometimes they can load in before we boot them //we're not replacing the lobby yet, but hooking into this event will give us more time to verify players if (!PluginSettings.Instance.ReservedSlotsEnabled) { return; } if (response != AuthSessionResponseEnum.OK) { return; } if (PluginSettings.Instance.ReservedSlotsPlayers.Contains(remoteUserId.ToString( ))) { _reservedPlayers.Add(remoteUserId); Essentials.Log.Info("Whitelisted player connected: " + remoteUserId); Essentials.Log.Info("{0} whitelisted players connected. {1} of {2} reserved slots allocated.", _reservedPlayers.Count, Math.Min(_reservedPlayers.Count, PluginSettings.Instance.ReservedSlotsCount), PluginSettings.Instance.ReservedSlotsCount); return; } if (PluginSettings.Instance.TicketPlayers.Any(item => item.TicketId == remoteUserId)) { _reservedPlayers.Add(remoteUserId); Essentials.Log.Info("Ticket player connected: " + remoteUserId); Essentials.Log.Info("{0} whitelisted players connected. {1} of {2} reserved slots allocated.", _reservedPlayers.Count, Math.Min(_reservedPlayers.Count, PluginSettings.Instance.ReservedSlotsCount), PluginSettings.Instance.ReservedSlotsCount); return; } if (PluginSettings.Instance.ReservedSlotsAdmins && PlayerManager.Instance.IsUserAdmin(remoteUserId)) { _reservedPlayers.Add(remoteUserId); Essentials.Log.Info("Whitelisted admin connected: " + remoteUserId); Essentials.Log.Info("{0} whitelisted players connected. {1} of {2} reserved slots allocated.", _reservedPlayers.Count, Math.Min(_reservedPlayers.Count, PluginSettings.Instance.ReservedSlotsCount), PluginSettings.Instance.ReservedSlotsCount); return; } if (PluginSettings.Instance.ReservedSlotsGroup != 0) { _waitingPlayers.Add(remoteUserId); //ask Steam if the connecting player is in the whitelisted group. response is raised as an event; GameServer_UserGroupStatus SteamServerAPI.Instance.GameServer.RequestGroupStatus(remoteUserId, PluginSettings.Instance.ReservedSlotsGroup); return; } DenyPlayer(remoteUserId); }