Merge branch 'master' of https://github.com/TorchAPI/Torch into master

This commit is contained in:
John Gross
2020-11-25 12:26:26 -08:00
9 changed files with 51 additions and 32 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, string serviceName)
{
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

@@ -17,11 +17,13 @@ using VRage.Network;
namespace Torch.Commands
{
public delegate void CommandExecutingDel(Command command, IMyPlayer player, bool hasPermission, ref bool? hasPermissionOverride);
public class CommandManager : Manager
{
public char Prefix { get; set; }
public CommandTree Commands { get; set; } = new CommandTree();
public event CommandExecutingDel OnCommandExecuting;
private Logger _log = LogManager.GetCurrentClassLogger();
[Dependency]
private IChatManagerServer _chatManager;
@@ -124,7 +126,6 @@ namespace Torch.Commands
public void HandleCommand(string message, ulong steamId, ref bool consumed, bool serverConsole = false)
{
if (message.Length < 1 || message[0] != Prefix)
return;
@@ -144,12 +145,24 @@ namespace Torch.Commands
{
var cmdPath = string.Join(".", command.Path);
if (!HasPermission(steamId, command))
var defaultPermission = HasPermission(steamId, command);
bool? cancel = null;
OnCommandExecuting?.Invoke(command, player, defaultPermission, ref cancel);
if (cancel.HasValue)
{
if (!cancel.Value)
return;
}
else
{
if (!defaultPermission)
{
_log.Info($"{player.DisplayName} tried to use command {cmdPath} without permission");
_chatManager.SendMessageAsOther(null, $"You need to be a {command.MinimumPromoteLevel} or higher to use that command.", targetSteamId: steamId);
return;
}
}
var splitArgs = Regex.Matches(argText, "(\"[^\"]+\"|\\S+)").Cast<Match>().Select(x => x.ToString().Replace("\"", "")).ToList();
_log.Trace($"Invoking {cmdPath} for player {player.DisplayName}");

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

@@ -24,10 +24,12 @@ using VRageMath;
namespace Torch.Managers.ChatManager
{
public delegate void ChatReceivedDel(ref ChatMsg msg);
[PatchShim]
internal static class ChatInterceptPatch
{
private static ChatManagerServer _chatManager;
public static event ChatReceivedDel OnChatRecvAccess;
private static ChatManagerServer ChatManager => _chatManager ?? (_chatManager = TorchBase.Instance.CurrentSession.Managers.GetManager<ChatManagerServer>());
internal static void Patch(PatchContext context)
@@ -40,6 +42,7 @@ namespace Torch.Managers.ChatManager
private static bool PrefixMessageProcessing(ref ChatMsg msg)
{
var consumed = false;
OnChatRecvAccess?.Invoke(ref msg);
ChatManager.RaiseMessageRecieved(msg, ref consumed);
return !consumed;
}

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

@@ -136,13 +136,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;

View File

@@ -1 +0,0 @@
theme: jekyll-theme-modernist

View File

@@ -1 +0,0 @@
# Torch