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
Offline mode fallbacks for the chat manager.
  • Loading branch information
Equinox- committed Aug 31, 2017
commit 4b2fee761497dcf03e39bcbdf860b6abc9b3177d
52 changes: 47 additions & 5 deletions Torch/Managers/ChatManager/ChatManagerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
using Sandbox.Engine.Networking;
using Sandbox.Game.Entities.Character;
using Sandbox.Game.Gui;
using Sandbox.Game.Multiplayer;
using Sandbox.Game.World;
using Sandbox.ModAPI;
using Torch.API;
using Torch.API.Managers;
using Torch.Utils;
Expand All @@ -25,11 +27,9 @@ public class ChatManagerClient : Manager, IChatManagerClient
public ChatManagerClient(ITorchBase torchInstance) : base(torchInstance) { }

/// <inheritdoc />
// TODO doesn't work in Offline worlds. Method injection or network injection.
public event MessageRecievedDel MessageRecieved;

/// <inheritdoc />
// TODO doesn't work at all. Method injection or network injection.
public event MessageSendingDel MessageSending;

/// <inheritdoc />
Expand Down Expand Up @@ -71,9 +71,8 @@ public void DisplayMessageOnSelf(string author, string message, string font)
public override void Attach()
{
base.Attach();
if (MyMultiplayer.Static == null)
_log.Warn("Currently ChatManagerClient doesn't support handling on an offline client");
else
MyAPIUtilities.Static.MessageEntered += OnMessageEntered;
if (MyMultiplayer.Static != null)
{
_chatMessageRecievedReplacer = _chatMessageReceivedFactory.Invoke();
_scriptedChatMessageRecievedReplacer = _scriptedChatMessageReceivedFactory.Invoke();
Expand All @@ -82,18 +81,61 @@ public override void Attach()
_scriptedChatMessageRecievedReplacer.Replace(
new Action<string, string, string>(Multiplayer_ScriptedChatMessageReceived), MyMultiplayer.Static);
}
else
{
MyAPIUtilities.Static.MessageEntered += OfflineMessageReciever;
}
}

/// <inheritdoc/>
public override void Detach()
{
MyAPIUtilities.Static.MessageEntered -= OnMessageEntered;
if (_chatMessageRecievedReplacer != null && _chatMessageRecievedReplacer.Replaced)
_chatMessageRecievedReplacer.Restore(MyHud.Chat);
if (_scriptedChatMessageRecievedReplacer != null && _scriptedChatMessageRecievedReplacer.Replaced)
_scriptedChatMessageRecievedReplacer.Restore(MyHud.Chat);
MyAPIUtilities.Static.MessageEntered -= OfflineMessageReciever;
base.Detach();
}

/// <summary>
/// Callback used to process offline messages.
/// </summary>
/// <param name="msg"></param>
/// <returns>true if the message was consumed</returns>
protected virtual bool OfflineMessageProcessor(TorchChatMessage msg)
{
return false;
}

private void OfflineMessageReciever(string messageText, ref bool sendToOthers)
{
if (!sendToOthers)
return;
var torchMsg = new TorchChatMessage()
{
AuthorSteamId = Sync.MyId,
Author = MySession.Static.LocalHumanPlayer?.DisplayName ?? "Player",
Message = messageText
};
var consumed = false;
MessageRecieved?.Invoke(torchMsg, ref consumed);
if (!consumed)
consumed = OfflineMessageProcessor(torchMsg);
sendToOthers = !consumed;
}

private void OnMessageEntered(string messageText, ref bool sendToOthers)
{
if (!sendToOthers)
return;
var consumed = false;
MessageSending?.Invoke(messageText, ref consumed);
sendToOthers = !consumed;
}


private void Multiplayer_ChatMessageReceived(ulong steamUserId, string message)
{
var torchMsg = new TorchChatMessage()
Expand Down
12 changes: 10 additions & 2 deletions Torch/Managers/ChatManager/ChatManagerServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,16 @@ public override void Attach()
MyMultiplayer.Static.ChatMessageReceived += MpStaticChatMessageReceived;
_log.Warn("Failed to initialize network intercept, we can't discard chat messages! Falling back to another method.");
}
else
_log.Error("Failed to initialize network intercept, we can't discard chat messages!");
}

/// <inheritdoc />
protected override bool OfflineMessageProcessor(TorchChatMessage msg)
{
if (MyMultiplayer.Static != null)
return false;
var consumed = false;
MessageProcessing?.Invoke(msg, ref consumed);
return consumed;
}

private void MpStaticChatMessageReceived(ulong a, string b)
Expand Down