Exemple #1
0
        private void RunEvent(ValidateAuthTicketEvent info)
        {
            JoinResult internalAuth;


            if (IsBanned(info.SteamOwner) || IsBanned(info.SteamID))
            {
                internalAuth = JoinResult.BannedByAdmins;
            }
            else if (_isClientKicked(MyMultiplayer.Static, info.SteamID) ||
                     _isClientKicked(MyMultiplayer.Static, info.SteamOwner))
            {
                internalAuth = JoinResult.KickedRecently;
            }
            else if (info.SteamResponse == JoinResult.OK)
            {
                var config = (TorchConfig)Torch.Config;
                if (config.EnableWhitelist && !config.Whitelist.Contains(info.SteamID))
                {
                    _log.Warn($"Rejecting user {info.SteamID} because they are not whitelisted in Torch.cfg.");
                    internalAuth = JoinResult.NotInGroup;
                }
                else if (MySandboxGame.ConfigDedicated.Reserved.Contains(info.SteamID))
                {
                    internalAuth = JoinResult.OK;
                }
                //Admins can bypass member limit
                else if (MySandboxGame.ConfigDedicated.Administrators.Contains(info.SteamID.ToString()) ||
                         MySandboxGame.ConfigDedicated.Administrators.Contains(_convertSteamIDFrom64(info.SteamID)))
                {
                    internalAuth = JoinResult.OK;
                }
                //Server counts as a client, so subtract 1 from MemberCount
                else if (MyMultiplayer.Static.MemberLimit > 0 &&
                         MyMultiplayer.Static.MemberCount - 1 >= MyMultiplayer.Static.MemberLimit)
                {
                    internalAuth = JoinResult.ServerFull;
                }
                else if (MySandboxGame.ConfigDedicated.GroupID == 0uL)
                {
                    internalAuth = JoinResult.OK;
                }
                else
                {
                    if (MySandboxGame.ConfigDedicated.GroupID == info.Group && (info.Member || info.Officer))
                    {
                        internalAuth = JoinResult.OK;
                    }
                    else
                    {
                        internalAuth = JoinResult.NotInGroup;
                    }
                }
            }
            else
            {
                internalAuth = info.SteamResponse;
            }

            info.FutureVerdict = Task.FromResult(internalAuth);

            MultiplayerManagerDedicatedEventShim.RaiseValidateAuthTicket(ref info);

            info.FutureVerdict.ContinueWith((task) =>
            {
                JoinResult verdict;
                if (task.IsFaulted)
                {
                    _log.Error(task.Exception, $"Future validation verdict faulted");
                    verdict = JoinResult.TicketCanceled;
                }
                else
                {
                    verdict = task.Result;
                }

                Torch.Invoke(() => { CommitVerdict(info.SteamID, verdict); });
            });
        }
        private void RunEvent(ValidateAuthTicketEvent info)
        {
            MultiplayerManagerDedicatedEventShim.RaiseValidateAuthTicket(ref info);

            if (info.FutureVerdict == null)
            {
                if (IsBanned(info.SteamOwner) || IsBanned(info.SteamID))
                {
                    CommitVerdict(info.SteamID, JoinResult.BannedByAdmins);
                }
                else if (_isClientKicked(MyMultiplayer.Static, info.SteamID) ||
                         _isClientKicked(MyMultiplayer.Static, info.SteamOwner))
                {
                    CommitVerdict(info.SteamID, JoinResult.KickedRecently);
                }
                else if (info.SteamResponse == JoinResult.OK)
                {
                    //Admins can bypass member limit
                    if (MySandboxGame.ConfigDedicated.Administrators.Contains(info.SteamID.ToString()) ||
                        MySandboxGame.ConfigDedicated.Administrators.Contains(_convertSteamIDFrom64(info.SteamID)))
                    {
                        CommitVerdict(info.SteamID, JoinResult.OK);
                    }
                    //Server counts as a client, so subtract 1 from MemberCount
                    else if (MyMultiplayer.Static.MemberLimit > 0 &&
                             MyMultiplayer.Static.MemberCount - 1 >= MyMultiplayer.Static.MemberLimit)
                    {
                        CommitVerdict(info.SteamID, JoinResult.ServerFull);
                    }
                    else if (MySandboxGame.ConfigDedicated.GroupID == 0uL)
                    {
                        CommitVerdict(info.SteamID, JoinResult.OK);
                    }
                    else
                    {
                        if (MySandboxGame.ConfigDedicated.GroupID == info.Group && (info.Member || info.Officer))
                        {
                            CommitVerdict(info.SteamID, JoinResult.OK);
                        }
                        else
                        {
                            CommitVerdict(info.SteamID, JoinResult.NotInGroup);
                        }
                    }
                }
                else
                {
                    CommitVerdict(info.SteamID, info.SteamResponse);
                }

                return;
            }

            info.FutureVerdict.ContinueWith((task) =>
            {
                JoinResult verdict;
                if (task.IsFaulted)
                {
                    _log.Error(task.Exception, $"Future validation verdict faulted");
                    verdict = JoinResult.TicketCanceled;
                }
                else
                {
                    verdict = task.Result;
                }

                Torch.Invoke(() => { CommitVerdict(info.SteamID, verdict); });
            });
        }