Skip to content

Commit 9b1754a

Browse files
authored
Merge pull request #113 from TorchAPI/session-mgr-cmp
Managers for Clients
2 parents 4f7c35d + 0574d59 commit 9b1754a

62 files changed

Lines changed: 3126 additions & 835 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎NLog.config‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
<target xsi:type="File" name="main" layout="${time} [${level:uppercase=true}] ${logger}: ${message}" fileName="Logs\Torch-${shortdate}.log" />
77
<target xsi:type="File" name="chat" layout="${longdate} ${message}" fileName="Logs\Chat.log" />
88
<target xsi:type="ColoredConsole" name="console" layout="${time} [${level:uppercase=true}] ${logger}: ${message}" />
9+
<target xsi:type="File" name="patch" layout="${message}" fileName="Logs\patch.log"/>
910
</targets>
1011

1112
<rules>
1213
<logger name="*" minlevel="Info" writeTo="main, console" />
1314
<logger name="Chat" minlevel="Info" writeTo="chat" />
15+
<!--<logger name="Torch.Managers.PatchManager.*" minlevel="Trace" writeTo="patch"/>-->
1416
</rules>
1517
</nlog>

‎Torch.API/IChatMessage.cs‎

Lines changed: 0 additions & 31 deletions
This file was deleted.

‎Torch.API/ITorchBase.cs‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,19 @@ public interface ITorchBase
4444
/// </summary>
4545
ITorchConfig Config { get; }
4646

47-
/// <inheritdoc cref="IMultiplayerManager"/>
48-
[Obsolete]
49-
IMultiplayerManager Multiplayer { get; }
50-
5147
/// <inheritdoc cref="IPluginManager"/>
5248
[Obsolete]
5349
IPluginManager Plugins { get; }
5450

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

54+
[Obsolete("Prefer using Managers.GetManager for global managers")]
55+
T GetManager<T>() where T : class, IManager;
56+
57+
[Obsolete("Prefer using Managers.AddManager for global managers")]
58+
bool AddManager<T>(T manager) where T : class, IManager;
59+
5860
/// <summary>
5961
/// The binary version of the current instance.
6062
/// </summary>
@@ -101,6 +103,16 @@ public interface ITorchBase
101103
/// Initialize the Torch instance.
102104
/// </summary>
103105
void Init();
106+
107+
/// <summary>
108+
/// The current state of the game this instance of torch is controlling.
109+
/// </summary>
110+
TorchGameState GameState { get; }
111+
112+
/// <summary>
113+
/// Event raised when <see cref="GameState"/> changes.
114+
/// </summary>
115+
event TorchGameStateChangedDel GameStateChanged;
104116
}
105117

106118
/// <summary>
@@ -119,6 +131,6 @@ public interface ITorchServer : ITorchBase
119131
/// </summary>
120132
public interface ITorchClient : ITorchBase
121133
{
122-
134+
123135
}
124136
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using Sandbox.Engine.Multiplayer;
7+
using Sandbox.Game.Multiplayer;
8+
using VRage.Network;
9+
10+
namespace Torch.API.Managers
11+
{
12+
/// <summary>
13+
/// Represents a scripted or user chat message.
14+
/// </summary>
15+
public struct TorchChatMessage
16+
{
17+
/// <summary>
18+
/// Creates a new torch chat message with the given author and message.
19+
/// </summary>
20+
/// <param name="author">Author's name</param>
21+
/// <param name="message">Message</param>
22+
public TorchChatMessage(string author, string message)
23+
{
24+
Timestamp = DateTime.Now;
25+
AuthorSteamId = null;
26+
Author = author;
27+
Message = message;
28+
Font = "Blue";
29+
}
30+
31+
/// <summary>
32+
/// Creates a new torch chat message with the given author and message.
33+
/// </summary>
34+
/// <param name="authorSteamId">Author's steam ID</param>
35+
/// <param name="message">Message</param>
36+
public TorchChatMessage(ulong authorSteamId, string message)
37+
{
38+
Timestamp = DateTime.Now;
39+
AuthorSteamId = authorSteamId;
40+
Author = MyMultiplayer.Static?.GetMemberName(authorSteamId) ?? "Player";
41+
Message = message;
42+
Font = "Blue";
43+
}
44+
45+
/// <summary>
46+
/// This message's timestamp.
47+
/// </summary>
48+
public DateTime Timestamp;
49+
/// <summary>
50+
/// The author's steam ID, if available. Else, null.
51+
/// </summary>
52+
public ulong? AuthorSteamId;
53+
/// <summary>
54+
/// The author's name, if available. Else, null.
55+
/// </summary>
56+
public string Author;
57+
/// <summary>
58+
/// The message contents.
59+
/// </summary>
60+
public string Message;
61+
/// <summary>
62+
/// The font, or null if default.
63+
/// </summary>
64+
public string Font;
65+
}
66+
67+
/// <summary>
68+
/// Callback used to indicate that a messaage has been recieved.
69+
/// </summary>
70+
/// <param name="msg"></param>
71+
/// <param name="consumed">If true, this event has been consumed and should be ignored</param>
72+
public delegate void MessageRecievedDel(TorchChatMessage msg, ref bool consumed);
73+
74+
/// <summary>
75+
/// Callback used to indicate the user is attempting to send a message locally.
76+
/// </summary>
77+
/// <param name="msg">Message the user is attempting to send</param>
78+
/// <param name="consumed">If true, this event has been consumed and should be ignored</param>
79+
public delegate void MessageSendingDel(string msg, ref bool consumed);
80+
81+
public interface IChatManagerClient : IManager
82+
{
83+
/// <summary>
84+
/// Event that is raised when a message addressed to us is recieved. <see cref="MessageRecievedDel"/>
85+
/// </summary>
86+
event MessageRecievedDel MessageRecieved;
87+
88+
/// <summary>
89+
/// Event that is raised when we are attempting to send a message. <see cref="MessageSendingDel"/>
90+
/// </summary>
91+
event MessageSendingDel MessageSending;
92+
93+
/// <summary>
94+
/// Triggers the <see cref="MessageSending"/> event,
95+
/// typically raised by the user entering text into the chat window.
96+
/// </summary>
97+
/// <param name="message">The message to send</param>
98+
void SendMessageAsSelf(string message);
99+
100+
/// <summary>
101+
/// Displays a message on the UI given an author name and a message.
102+
/// </summary>
103+
/// <param name="author">Author name</param>
104+
/// <param name="message">Message content</param>
105+
/// <param name="font">font to use</param>
106+
void DisplayMessageOnSelf(string author, string message, string font = "Blue" );
107+
}
108+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using VRage.Network;
7+
8+
namespace Torch.API.Managers
9+
{
10+
11+
/// <summary>
12+
/// Callback used to indicate the server has recieved a message to process and forward on to others.
13+
/// </summary>
14+
/// <param name="authorId">Steam ID of the user sending a message</param>
15+
/// <param name="msg">Message the user is attempting to send</param>
16+
/// <param name="consumed">If true, this event has been consumed and should be ignored</param>
17+
public delegate void MessageProcessingDel(TorchChatMessage msg, ref bool consumed);
18+
19+
public interface IChatManagerServer : IChatManagerClient
20+
{
21+
/// <summary>
22+
/// Event triggered when the server has recieved a message and should process it. <see cref="MessageProcessingDel"/>
23+
/// </summary>
24+
event MessageProcessingDel MessageProcessing;
25+
26+
27+
/// <summary>
28+
/// Sends a message with the given author and message to the given player, or all players by default.
29+
/// </summary>
30+
/// <param name="authorId">Author's steam ID</param>
31+
/// <param name="message">The message to send</param>
32+
/// <param name="targetSteamId">Player to send the message to, or everyone by default</param>
33+
void SendMessageAsOther(ulong authorId, string message, ulong targetSteamId = 0);
34+
35+
36+
/// <summary>
37+
/// Sends a scripted message with the given author and message to the given player, or all players by default.
38+
/// </summary>
39+
/// <param name="author">Author name</param>
40+
/// <param name="message">The message to send</param>
41+
/// <param name="font">Font to use</param>
42+
/// <param name="targetSteamId">Player to send the message to, or everyone by default</param>
43+
void SendMessageAsOther(string author, string message, string font, ulong targetSteamId = 0);
44+
}
45+
}

‎Torch.API/Managers/IMultiplayerManager.cs‎

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Collections.ObjectModel;
4+
using VRage.Game;
5+
using VRage.Game.ModAPI;
6+
7+
namespace Torch.API.Managers
8+
{
9+
/// <summary>
10+
/// API for multiplayer related functions common to servers and clients.
11+
/// </summary>
12+
public interface IMultiplayerManagerBase : IManager
13+
{
14+
/// <summary>
15+
/// Fired when a player joins.
16+
/// </summary>
17+
event Action<IPlayer> PlayerJoined;
18+
19+
/// <summary>
20+
/// Fired when a player disconnects.
21+
/// </summary>
22+
event Action<IPlayer> PlayerLeft;
23+
24+
/// <summary>
25+
/// Gets a player by their Steam64 ID or returns null if the player isn't found.
26+
/// </summary>
27+
IMyPlayer GetPlayerBySteamId(ulong id);
28+
29+
/// <summary>
30+
/// Gets a player by their display name or returns null if the player isn't found.
31+
/// </summary>
32+
IMyPlayer GetPlayerByName(string name);
33+
34+
/// <summary>
35+
/// Gets the steam username of a member's steam ID
36+
/// </summary>
37+
/// <param name="steamId">steam ID</param>
38+
/// <returns>steam username</returns>
39+
string GetSteamUsername(ulong steamId);
40+
}
41+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Torch.API.Managers
8+
{
9+
public interface IMultiplayerManagerClient : IMultiplayerManagerBase
10+
{
11+
}
12+
}

0 commit comments

Comments
 (0)