Пример #1
0
        private void MotdOnce(MyEntity obj)
        {
            if (obj is MyCharacter character)
            {
                Task.Run(() =>
                {
                    Thread.Sleep(1000);
                    Torch.Invoke(() =>
                    {
                        if (_motdOnce.Contains(character.ControlSteamId))
                        {
                            return;
                        }

                        var id = character.ControllerInfo?.ControllingIdentityId;
                        if (!id.HasValue)
                        {
                            return;
                        }

                        SendMotd(id.Value);
                        _motdOnce.Add(character.ControlSteamId);
                    });
                });
            }
        }
Пример #2
0
        private int ConcealGroup(ConcealGroup group)
        {
            if (ConcealedGroups.Any(g => g.Id == group.Id))
            {
                return(0);
            }

            Log.Debug($"Concealing grids: {group.GridNames}");
            group.Conceal();
            foreach (var entity in group.Grids)
            {
                entity.GetStorage().SetValue(Id, "True");
            }

            group.UpdateAABB();
            var aabb = group.WorldAABB;

            group.ProxyId  = _concealedAabbTree.AddProxy(ref aabb, group, 0);
            group.Closing += Group_Closing;
            Task.Run(() =>
            {
                group.UpdatePostConceal();
                Log.Debug($"Group {group.Id} cached");
                group.IsConcealed = true;
                Torch.Invoke(() => ConcealedGroups.Add(group));
            });
            return(group.Grids.Count);
        }
Пример #3
0
 /// <inheritdoc />
 public void BanPlayer(ulong steamId, bool banned = true)
 {
     Torch.Invoke(() =>
     {
         MyMultiplayer.Static.BanClient(steamId, banned);
     });
 }
Пример #4
0
        private void MotdOnce(IPlayer player)
        {
            //TODO: REMOVE ALL THIS TRASH!
            //implement a PlayerSpawned event in Torch. This will work for now.
            Task.Run(() =>
            {
                var start   = DateTime.Now;
                var timeout = TimeSpan.FromMinutes(5);
                var pid     = new MyPlayer.PlayerId(player.SteamId, 0);
                while (DateTime.Now - start <= timeout)
                {
                    if (!MySession.Static.Players.TryGetPlayerById(pid, out MyPlayer p) || p.Character == null)
                    {
                        Thread.Sleep(1000);
                        continue;
                    }

                    Torch.Invoke(() =>
                    {
                        if (_motdOnce.Contains(player.SteamId))
                        {
                            return;
                        }

                        SendMotd(p, true);
                        _motdOnce.Add(player.SteamId);
                    });
                    break;
                }
            });
        }
Пример #5
0
 /// <inheritdoc />
 public void BanPlayer(ulong steamId, bool banned = true)
 {
     Torch.Invoke(() =>
     {
         MyMultiplayer.Static.BanClient(steamId, banned);
         if (_gameOwnerIds.ContainsKey(steamId))
         {
             MyMultiplayer.Static.BanClient(_gameOwnerIds[steamId], banned);
         }
     });
 }
Пример #6
0
 /// <inheritdoc />
 public void DemoteUser(ulong steamId)
 {
     Torch.Invoke(() =>
     {
         var p = MySession.Static.GetUserPromoteLevel(steamId);
         if (p > MyPromoteLevel.None && p < MyPromoteLevel.Owner) //owner cannot be demoted by design
         {
             MySession.Static.SetUserPromoteLevel(steamId, p - 1);
         }
     });
 }
Пример #7
0
 /// <inheritdoc />
 public void PromoteUser(ulong steamId)
 {
     Torch.Invoke(() =>
     {
         var p = MySession.Static.GetUserPromoteLevel(steamId);
         if (p < MyPromoteLevel.Admin) //cannot promote to owner by design
         {
             MySession.Static.SetUserPromoteLevel(steamId, p + 1);
         }
     });
 }
Пример #8
0
        private void KeepAliveCallback(object state)
        {
            var grid = (long)state;

            Log.Debug($"Keepalive expired on grid {grid}");
            Torch.Invoke(() =>
            {
                var timer = _keepAliveTimers[grid];
                timer.Dispose();
                _keepAliveTimers.Remove(grid);
            });
        }
Пример #9
0
 /// <inheritdoc />
 public void PromoteUser(ulong steamId)
 {
     Torch.Invoke(() =>
     {
         var p = MySession.Static.GetUserPromoteLevel(steamId);
         if (p < MyPromoteLevel.Admin) //cannot promote to owner by design
         //MySession.Static.SetUserPromoteLevel(steamId, p + 1);
         {
             MyGuiScreenPlayers.PromoteImplementation(steamId, true);
         }
     });
 }
Пример #10
0
 /// <inheritdoc />
 public void DemoteUser(ulong steamId)
 {
     Torch.Invoke(() =>
     {
         var p = MySession.Static.GetUserPromoteLevel(steamId);
         if (p > MyPromoteLevel.None && p < MyPromoteLevel.Owner) //owner cannot be demoted by design
         //MySession.Static.SetUserPromoteLevel(steamId, p - 1);
         {
             MyGuiScreenPlayers.PromoteImplementation(steamId, false);
         }
     });
 }
Пример #11
0
        public void HandleCommand(string message, ulong steamId, ref bool consumed, bool serverConsole = false)
        {
            if (message.Length < 1 || message[0] != Prefix)
            {
                return;
            }

            consumed = true;

            var player = Torch.CurrentSession.Managers.GetManager <IMultiplayerManagerBase>().GetPlayerBySteamId(steamId);

            if (player == null)
            {
                _log.Error($"Command {message} invoked by nonexistant player");
                return;
            }

            var cmdText = new string(message.Skip(1).ToArray());
            var command = Commands.GetCommand(cmdText, out string argText);

            if (command != null)
            {
                var cmdPath = string.Join(".", command.Path);

                if (!HasPermission(steamId, command))
                {
                    _log.Info($"{player.DisplayName} tried to use command {cmdPath} without permission");
                    _chatManager.SendMessageAsOther("Server", $"You need to be a {command.MinimumPromoteLevel} or higher to use that command.", MyFontEnum.Red, steamId);
                    return;
                }

                var splitArgs = Regex.Matches(argText, "(\"[^\"]+\"|\\S+)").Cast <Match>().Select(x => x.ToString().Replace("\"", "")).ToList();
                _log.Trace($"Invoking {cmdPath} for player {player.DisplayName}");
                var context = new CommandContext(Torch, command.Plugin, steamId, argText, splitArgs);
                Torch.Invoke(() =>
                {
                    if (command.TryInvoke(context))
                    {
                        _log.Info($"Player {player.DisplayName} ran command '{message}'");
                    }
                    else
                    {
                        context.Respond($"Invalid Syntax: {command.SyntaxHelp}");
                    }
                });
            }
        }
Пример #12
0
        private void RevealCryoPod(ulong steamId)
        {
            Torch.Invoke(() =>
            {
                Log.Debug(nameof(RevealCryoPod));
                for (var i = ConcealedGroups.Count - 1; i >= 0; i--)
                {
                    var group = ConcealedGroups[i];

                    if (group.IsCryoOccupied(steamId))
                    {
                        RevealGroup(group);
                        return;
                    }
                }
            });
        }
Пример #13
0
 private void MyEntities_OnEntityAdd(VRage.Game.Entity.MyEntity obj)
 {
     if (obj is MyCharacter character)
     {
         Task.Run(() =>
         {
             System.Threading.Thread.Sleep(1000);
             Torch.Invoke(() =>
             {
                 if (_conecting.Contains(character.ControlSteamId) && character.IsPlayer && Config.Join.Length > 0)
                 {
                     DDBridge.SendStatusMessage(character.DisplayName, Config.Join);
                     //After spawn on world, remove from connecting list
                     _conecting.Remove(character.ControlSteamId);
                 }
             });
         });
     }
 }
Пример #14
0
        private void RevealSpawns(PlayerRequestArgs args)
        {
            Torch.Invoke(() =>
            {
                Log.Debug(nameof(RevealSpawns));
                var identityId = MySession.Static.Players.TryGetIdentityId(args.PlayerId.SteamId);
                if (identityId == 0)
                {
                    return;
                }

                for (var i = ConcealedGroups.Count - 1; i >= 0; i--)
                {
                    var group = ConcealedGroups[i];

                    if (group.IsMedicalRoomAvailable(identityId))
                    {
                        RevealGroup(group);
                    }
                }
            });
        }
        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); });
            });
        }
Пример #16
0
 /// <inheritdoc />
 public void KickPlayer(ulong steamId) => Torch.Invoke(() => MyMultiplayer.Static.KickClient(steamId));
Пример #17
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); });
            });
        }
Пример #18
0
 /// <summary>
 /// Notifies the torch.
 /// </summary>
 /// <param name="torchOn">If set to <c>true</c> torch on.</param>
 public void NotifyTorch(bool torchOn)
 {
     Torch?.Invoke(this, torchOn);
 }