Merge pull request #413 from TorchAPI/command-perms

Command perms
This commit is contained in:
Jimmacle
2020-11-25 11:35:51 -08:00
committed by GitHub
5 changed files with 29 additions and 24 deletions

View File

@@ -156,11 +156,11 @@ namespace Torch.Server.Managers
#pragma warning disable 649
[ReflectedEventReplace(typeof(MySteamGameServer), nameof(MySteamGameServer.ValidateAuthTicketResponse),
[ReflectedEventReplace("VRage.Steam.MySteamGameServer, VRage.Steam", "ValidateAuthTicketResponse",
typeof(MyDedicatedServerBase), "GameServer_ValidateAuthTicketResponse")]
private static Func<ReflectedEventReplacer> _gameServerValidateAuthTicketFactory;
[ReflectedEventReplace(typeof(MySteamGameServer), nameof(MySteamGameServer.UserGroupStatusResponse),
[ReflectedEventReplace("VRage.Steam.MySteamGameServer, VRage.Steam", "UserGroupStatusResponse",
typeof(MyDedicatedServerBase), "GameServer_UserGroupStatus")]
private static Func<ReflectedEventReplacer> _gameServerUserGroupStatusFactory;
@@ -216,15 +216,16 @@ namespace Torch.Server.Managers
//Largely copied from SE
private void ValidateAuthTicketResponse(ulong steamId, JoinResult response, ulong steamOwner)
{
var state = new MyP2PSessionState();
MySteamServiceWrapper.Static.Peer2Peer.GetSessionState(steamId, ref state);
var ip = new IPAddress(BitConverter.GetBytes(state.RemoteIP).Reverse().ToArray());
// TODO: Find another way to do this
//var state = new MyP2PSessionState();
//MySteamServiceWrapper.Static.Peer2Peer.GetSessionState(steamId, ref state);
//var ip = new IPAddress(BitConverter.GetBytes(state.RemoteIP).Reverse().ToArray());
Torch.CurrentSession.KeenSession.PromotedUsers.TryGetValue(steamId, out MyPromoteLevel promoteLevel);
_log.Debug($"ValidateAuthTicketResponse(user={steamId}, response={response}, owner={steamOwner}, permissions={promoteLevel})");
_log.Info($"Connection attempt by {steamId} from {ip}");
_log.Info($"Connection attempt by {steamId}");
if (IsProfiling(steamId))
{

View File

@@ -115,14 +115,6 @@ namespace Torch.Server.ViewModels
public DateTime InGameTime { get => _checkpoint.InGameTime; set => SetValue(ref _checkpoint.InGameTime, value); }
public MyObjectBuilder_SessionComponentMission MissionTriggers { get => _checkpoint.MissionTriggers; set => SetValue(ref _checkpoint.MissionTriggers, value); }
public string Briefing { get => _checkpoint.Briefing; set => SetValue(ref _checkpoint.Briefing, value); }
public string BriefingVideo { get => _checkpoint.BriefingVideo; set => SetValue(ref _checkpoint.BriefingVideo, value); }
public string CustomLoadingScreenImage { get => _checkpoint.CustomLoadingScreenImage; set => SetValue(ref _checkpoint.BriefingVideo, value); }
public string CustomLoadingScreenText { get => _checkpoint.CustomLoadingScreenText; set => SetValue(ref _checkpoint.CustomLoadingScreenText, value); }
public string CustomSkybox { get => _checkpoint.CustomSkybox; set => SetValue(ref _checkpoint.CustomSkybox, value); }

View File

@@ -37,13 +37,14 @@ namespace Torch.Commands
[Permission(MyPromoteLevel.None)]
public void GetIP(ulong steamId = 0)
{
if (steamId == 0)
steamId = Context.Player.SteamUserId;
VRage.GameServices.MyP2PSessionState statehack = new VRage.GameServices.MyP2PSessionState();
MySteamServiceWrapper.Static.Peer2Peer.GetSessionState(steamId, ref statehack);
var ip = new IPAddress(BitConverter.GetBytes(statehack.RemoteIP).Reverse().ToArray());
Context.Respond($"Your IP is {ip}");
Context.Respond("Command no longer working!");
//if (steamId == 0)
// steamId = Context.Player.SteamUserId;
//
//VRage.GameServices.MyP2PSessionState statehack = new VRage.GameServices.MyP2PSessionState();
//MySteamServiceWrapper.Static.Peer2Peer.GetSessionState(steamId, ref statehack);
//var ip = new IPAddress(BitConverter.GetBytes(statehack.RemoteIP).Reverse().ToArray());
//Context.Respond($"Your IP is {ip}");
}
[Command("help", "Displays help for a command")]

View File

@@ -47,5 +47,14 @@ namespace Torch.Utils
TargetDeclaringType = targetDeclaringType;
TargetName = targetName;
}
public ReflectedEventReplaceAttribute(string eventDeclaringType, string eventName, Type targetDeclaringType,
string targetName)
{
EventDeclaringType = Type.GetType(eventDeclaringType);
EventName = eventName;
TargetDeclaringType = targetDeclaringType;
TargetName = targetName;
}
}
}

View File

@@ -135,13 +135,15 @@ namespace Torch
private void Create()
{
bool dedicated = Sandbox.Engine.Platform.Game.IsDedicated;
bool dedicated = true;
Environment.SetEnvironmentVariable("SteamAppId", _appSteamId.ToString());
var service = MySteamServiceWrapper.Init(dedicated, _appSteamId);
var service = MySteamGameService.Create(true, _appSteamId);
MyServiceManager.Instance.AddService<IMyGameService>(service);
var serviceInstance = MySteamUgcService.Create(_appSteamId, service);
MyServiceManager.Instance.AddService<IMyUGCService>(serviceInstance);
if (dedicated && !MyGameService.HasGameServer)
MyServiceManager.Instance.AddService(new MyNullMicrophone());
MySteamGameService.InitNetworking(dedicated, service);
if (!MyGameService.HasGameServer)
{
_log.Warn("Steam service is not running! Please reinstall dedicated server.");
return;