Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d9ef60d
Client manager components
Equinox- Aug 22, 2017
2c7b522
Proper delegate naming
Equinox- Aug 22, 2017
4b2fee7
Offline mode fallbacks for the chat manager.
Equinox- Aug 23, 2017
140000d
Test-time reflected event checker
Equinox- Aug 25, 2017
a36e8a4
Merge branch 'staging' into session-mgr-cmp
Equinox- Sep 10, 2017
aa784c1
Null protection in multiplayer manager detach
Equinox- Sep 10, 2017
9d8988a
MyLog logs to the Torch logging system
Equinox- Sep 11, 2017
b42d43c
Redirect Keen console to Info, all else to trace.
Equinox- Sep 11, 2017
0073e10
Fixed issues with operand replacing, and branch instructions.
Equinox- Sep 11, 2017
e57f885
Log errors in ReflectedManager
Equinox- Sep 11, 2017
57acb27
Don't crash when modifying constructor
Equinox- Sep 12, 2017
0810e76
Once the game is created we can patch it with impunity.
Equinox- Sep 12, 2017
b1145c8
Utility method to invert common load and store instructions
Equinox- Sep 12, 2017
373c476
Better guessing on the generic operand type
Equinox- Sep 12, 2017
a61b646
ReflectedMethodInfo allows non-public type names.
Equinox- Sep 12, 2017
5eceb21
Comments
Equinox- Sep 12, 2017
96f813a
IMultiplayerManager: added list of banned steam ID's
jimmble Sep 20, 2017
d8e2072
documentation added
jimmble Sep 20, 2017
f1fc49d
Merge branch 'staging' into session-mgr-cmp
jimmble Sep 20, 2017
eb7f7f4
MultiplayerManagerLobby doesn't implement IMultiplayerManagerServer
jimmble Sep 20, 2017
9c505c4
banned player list made readonly, lobby fakes support
jimmble Sep 20, 2017
205dd1a
Merge pull request #120 from blaho/session-mgr-cmp
Equinox- Sep 20, 2017
0574d59
Merge branch 'staging' into session-mgr-cmp
Equinox- Sep 22, 2017
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'staging' into session-mgr-cmp
  • Loading branch information
Equinox- committed Sep 10, 2017
commit a36e8a406509d164ba3803a0ad0f2354bf7cca3e
31 changes: 0 additions & 31 deletions Torch.API/IChatMessage.cs

This file was deleted.

34 changes: 34 additions & 0 deletions Torch.API/Managers/IChatManagerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sandbox.Engine.Multiplayer;
using Sandbox.Game.Multiplayer;
using VRage.Network;

namespace Torch.API.Managers
Expand All @@ -12,6 +14,38 @@ namespace Torch.API.Managers
/// </summary>
public struct TorchChatMessage
{
/// <summary>
/// Creates a new torch chat message with the given author and message.
/// </summary>
/// <param name="author">Author's name</param>
/// <param name="message">Message</param>
public TorchChatMessage(string author, string message)
{
Timestamp = DateTime.Now;
AuthorSteamId = null;
Author = author;
Message = message;
Font = "Blue";
}

/// <summary>
/// Creates a new torch chat message with the given author and message.
/// </summary>
/// <param name="authorSteamId">Author's steam ID</param>
/// <param name="message">Message</param>
public TorchChatMessage(ulong authorSteamId, string message)
{
Timestamp = DateTime.Now;
AuthorSteamId = authorSteamId;
Author = MyMultiplayer.Static?.GetMemberName(authorSteamId) ?? "Player";
Message = message;
Font = "Blue";
}

/// <summary>
/// This message's timestamp.
/// </summary>
public DateTime Timestamp;
/// <summary>
/// The author's steam ID, if available. Else, null.
/// </summary>
Expand Down
9 changes: 1 addition & 8 deletions Torch.API/Managers/IMultiplayerManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@
namespace Torch.API.Managers
{
/// <summary>
/// Delegate for received messages.
/// </summary>
/// <param name="message">Message data.</param>
/// <param name="sendToOthers">Flag to broadcast message to other players.</param>
public delegate void MessageReceivedDel(IChatMessage message, ref bool sendToOthers);

/// <summary>
/// API for multiplayer related functions.
/// API for multiplayer related functions common to servers and clients.
/// </summary>
public interface IMultiplayerManagerBase : IManager
{
Expand Down
3 changes: 3 additions & 0 deletions Torch.API/Managers/IMultiplayerManagerServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace Torch.API.Managers
{
/// <summary>
/// API for multiplayer functions that exist on servers and lobbies
/// </summary>
public interface IMultiplayerManagerServer : IMultiplayerManagerBase
{
/// <summary>
Expand Down
10 changes: 10 additions & 0 deletions Torch.API/Session/ITorchSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,15 @@ public interface ITorchSession

/// <inheritdoc cref="IDependencyManager"/>
IDependencyManager Managers { get; }

/// <summary>
/// The current state of the session
/// </summary>
TorchSessionState State { get; }

/// <summary>
/// Event raised when the <see cref="State"/> changes.
/// </summary>
event TorchSessionStateChangedDel StateChanged;
}
}
19 changes: 4 additions & 15 deletions Torch.API/Session/ITorchSessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,20 @@ namespace Torch.API.Session
/// <returns>The manager that will live in the session, or null if none.</returns>
public delegate IManager SessionManagerFactoryDel(ITorchSession session);

/// <summary>
/// Fired when the given session has been completely loaded or is unloading.
/// </summary>
/// <param name="session">The session</param>
public delegate void TorchSessionLoadDel(ITorchSession session);

/// <summary>
/// Manages the creation and destruction of <see cref="ITorchSession"/> instances for each <see cref="Sandbox.Game.World.MySession"/> created by Space Engineers.
/// </summary>
public interface ITorchSessionManager : IManager
{
/// <summary>
/// Fired when a <see cref="ITorchSession"/> has finished loading.
/// </summary>
event TorchSessionLoadDel SessionLoaded;

/// <summary>
/// Fired when a <see cref="ITorchSession"/> has begun unloading.
/// The currently running session
/// </summary>
event TorchSessionLoadDel SessionUnloading;
ITorchSession CurrentSession { get; }

/// <summary>
/// The currently running session
/// Raised when any <see cref="ITorchSession"/> <see cref="ITorchSession.State"/> changes.
/// </summary>
ITorchSession CurrentSession { get; }
event TorchSessionStateChangedDel SessionStateChanged;

/// <summary>
/// Adds the given factory as a supplier for session based managers
Expand Down
38 changes: 38 additions & 0 deletions Torch.API/Session/TorchSessionState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Torch.API.Session
{
/// <summary>
/// Represents the state of a <see cref="ITorchSession"/>
/// </summary>
public enum TorchSessionState
{
/// <summary>
/// The session has been created, and is now loading.
/// </summary>
Loading,
/// <summary>
/// The session has loaded, and is now running.
/// </summary>
Loaded,
/// <summary>
/// The session was running, and is now unloading.
/// </summary>
Unloading,
/// <summary>
/// The session was unloading, and is now unloaded and stopped.
/// </summary>
Unloaded
}

/// <summary>
/// Callback raised when a session's state changes
/// </summary>
/// <param name="session">The session who had a state change</param>
/// <param name="newState">The session's new state</param>
public delegate void TorchSessionStateChangedDel(ITorchSession session, TorchSessionState newState);
}
2 changes: 1 addition & 1 deletion Torch.API/Torch.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@
<Link>Properties\AssemblyVersion.cs</Link>
</Compile>
<Compile Include="ConnectionState.cs" />
<Compile Include="IChatMessage.cs" />
<Compile Include="ITorchConfig.cs" />
<Compile Include="Managers\DependencyManagerExtensions.cs" />
<Compile Include="Managers\DependencyProviderExtensions.cs" />
Expand All @@ -186,6 +185,7 @@
<Compile Include="ModAPI\TorchAPI.cs" />
<Compile Include="Session\ITorchSession.cs" />
<Compile Include="Session\ITorchSessionManager.cs" />
<Compile Include="Session\TorchSessionState.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
126 changes: 60 additions & 66 deletions Torch.Server/Views/ChatControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -24,6 +25,7 @@
using Torch.API.Session;
using Torch.Managers;
using Torch.Server.Managers;
using VRage.Game;

namespace Torch.Server
{
Expand All @@ -42,49 +44,75 @@ public ChatControl()
public void BindServer(ITorchServer server)
{
_server = (TorchBase)server;
ChatItems.Items.Clear();
Dispatcher.Invoke(() =>
{
ChatItems.Inlines.Clear();
});

var sessionManager = server.Managers.GetManager<ITorchSessionManager>();
sessionManager.SessionLoaded += BindSession;
sessionManager.SessionUnloading += UnbindSession;
if (sessionManager != null)
sessionManager.SessionStateChanged += SessionStateChanged;
}

private void BindSession(ITorchSession session)
private void SessionStateChanged(ITorchSession session, TorchSessionState state)
{
Dispatcher.Invoke(() =>
switch (state)
{
var chatMgr = _server?.CurrentSession?.Managers.GetManager<IChatManagerClient>();
if (chatMgr != null)
DataContext = new ChatManagerProxy(chatMgr);
});
case TorchSessionState.Loading:
Dispatcher.Invoke(() => ChatItems.Inlines.Clear());
break;
case TorchSessionState.Loaded:
{
var chatMgr = session.Managers.GetManager<IChatManagerClient>();
if (chatMgr != null)
chatMgr.MessageRecieved += OnMessageRecieved;
}
break;
case TorchSessionState.Unloading:
{
var chatMgr = session.Managers.GetManager<IChatManagerClient>();
if (chatMgr != null)
chatMgr.MessageRecieved -= OnMessageRecieved;
}
break;
case TorchSessionState.Unloaded:
break;
default:
throw new ArgumentOutOfRangeException(nameof(state), state, null);
}
}

private void UnbindSession(ITorchSession session)
private void OnMessageRecieved(TorchChatMessage msg, ref bool consumed)
{
Dispatcher.Invoke(() =>
{
(DataContext as ChatManagerProxy)?.Dispose();
DataContext = null;
});
InsertMessage(msg);
}

private void ChatHistory_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
private static readonly Dictionary<string, Brush> _brushes = new Dictionary<string, Brush>();
private static Brush LookupBrush(string font)
{
foreach (IChatMessage msg in e.NewItems)
InsertMessage(msg);
if (_brushes.TryGetValue(font, out Brush result))
return result;
Brush brush = typeof(Brushes).GetField(font, BindingFlags.Static)?.GetValue(null) as Brush ?? Brushes.Blue;
_brushes.Add(font, brush);
return brush;
}

private void InsertMessage(IChatMessage msg)
private void InsertMessage(TorchChatMessage msg)
{
bool atBottom = ChatScroller.VerticalOffset + 8 > ChatScroller.ScrollableHeight;
var span = new Span();
span.Inlines.Add($"{msg.Timestamp} ");
span.Inlines.Add(new Run(msg.Name) { Foreground = msg.Name == "Server" ? Brushes.DarkBlue : Brushes.Blue });
span.Inlines.Add($": {msg.Message}");
span.Inlines.Add(new LineBreak());
ChatItems.Inlines.Add(span);
if (atBottom)
ChatScroller.ScrollToBottom();
if (Dispatcher.CheckAccess())
{
bool atBottom = ChatScroller.VerticalOffset + 8 > ChatScroller.ScrollableHeight;
var span = new Span();
span.Inlines.Add($"{msg.Timestamp} ");
span.Inlines.Add(new Run(msg.Author) { Foreground = LookupBrush(msg.Font) });
span.Inlines.Add($": {msg.Message}");
span.Inlines.Add(new LineBreak());
ChatItems.Inlines.Add(span);
if (atBottom)
ChatScroller.ScrollToBottom();
}
else
Dispatcher.Invoke(() => InsertMessage(msg));
}

private void SendButton_Click(object sender, RoutedEventArgs e)
Expand All @@ -108,11 +136,12 @@ private void OnMessageEntered()
var commands = _server.CurrentSession?.Managers.GetManager<Torch.Commands.CommandManager>();
if (commands != null && commands.IsCommand(text))
{
(DataContext as ChatManagerProxy)?.AddMessage(new TorchChatMessage() { Author = "Server", Message = text });
InsertMessage(new TorchChatMessage("Server", text) { Font = MyFontEnum.DarkBlue });
_server.Invoke(() =>
{
var response = commands.HandleCommandFromServer(text);
Dispatcher.BeginInvoke(() => OnMessageEntered_Callback(response));
string response = commands.HandleCommandFromServer(text);
if (!string.IsNullOrWhiteSpace(response))
InsertMessage(new TorchChatMessage("Server", response) { Font = MyFontEnum.Blue });
});
}
else
Expand All @@ -121,40 +150,5 @@ private void OnMessageEntered()
}
Message.Text = "";
}

private void OnMessageEntered_Callback(string response)
{
if (!string.IsNullOrEmpty(response))
(DataContext as ChatManagerProxy)?.AddMessage(new TorchChatMessage() { Author = "Server", Message = response });
}

private class ChatManagerProxy : IDisposable
{
private readonly IChatManagerClient _chatMgr;

public ChatManagerProxy(IChatManagerClient chatMgr)
{
this._chatMgr = chatMgr;
this._chatMgr.MessageRecieved += ChatMgr_MessageRecieved; ;
}

public IList<IChatMessage> ChatHistory { get; } = new ObservableList<IChatMessage>();

/// <inheritdoc />
public void Dispose()
{
_chatMgr.MessageRecieved -= ChatMgr_MessageRecieved;
}

private void ChatMgr_MessageRecieved(TorchChatMessage msg, ref bool consumed)
{
AddMessage(msg);
}

internal void AddMessage(TorchChatMessage msg)
{
ChatHistory.Add(new ChatMessage(DateTime.Now, msg.AuthorSteamId ?? 0, msg.Author, msg.Message));
}
}
}
}
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.