tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
TopicParameters.cs
Go to the documentation of this file.
1using System;
2
3using Newtonsoft.Json;
4
6
8{
13 {
19
23 public ChatCommand? ChatCommand { get; }
24
29
33 public ushort? NewPort { get; }
34
38 public RebootState? NewRebootState { get; }
39
43 public string? NewInstanceName { get; }
44
48 public string? BroadcastMessage { get; }
49
53 public ChatUpdate? ChatUpdate { get; }
54
58 public Version? NewServerVersion { get; }
59
63 public ChunkData? Chunk { get; }
64
68 public string? EventId { get; set; }
69
73 [JsonIgnore]
74 public bool IsPriority => CommandType switch
75 {
76 TopicCommandType.EventNotification
77 or TopicCommandType.ChangePort
78 or TopicCommandType.ChangeRebootState
79 or TopicCommandType.InstanceRenamed
80 or TopicCommandType.ChatChannelsUpdate
81 or TopicCommandType.Broadcast
82 or TopicCommandType.CompleteEvent
83 or TopicCommandType.ServerRestarted => true,
84 TopicCommandType.ChatCommand
85 or TopicCommandType.HealthCheck
86 or TopicCommandType.ReceiveChunk => false,
87 TopicCommandType.SendChunk => throw new InvalidOperationException("SendChunk topic priority should be based on the original TopicParameters!"),
88 _ => throw new InvalidOperationException($"Invalid value for {nameof(CommandType)}: {CommandType}"),
89 };
90
96 public static TopicParameters CreateInstanceRenamedTopicParameters(string newInstanceName)
97 => new(
98 newInstanceName ?? throw new ArgumentNullException(nameof(newInstanceName)),
99 TopicCommandType.InstanceRenamed);
100
106 public static TopicParameters CreateBroadcastParameters(string broadcastMessage)
107 => new(
108 broadcastMessage ?? throw new ArgumentNullException(nameof(broadcastMessage)),
109 TopicCommandType.Broadcast);
110
115 public TopicParameters(ChatCommand chatCommand)
117 {
118 ChatCommand = chatCommand ?? throw new ArgumentNullException(nameof(chatCommand));
119 }
120
125 public TopicParameters(EventNotification eventNotification)
127 {
128 EventNotification = eventNotification ?? throw new ArgumentNullException(nameof(eventNotification));
129 }
130
135 public TopicParameters(ushort newPort)
137 {
138 NewPort = newPort;
139 }
140
145 public TopicParameters(RebootState newRebootState)
147 {
148 NewRebootState = newRebootState;
149 }
150
155 public TopicParameters(ChatUpdate channelsUpdate)
157 {
158 ChatUpdate = channelsUpdate ?? throw new ArgumentNullException(nameof(channelsUpdate));
159 }
160
166 public TopicParameters(Version newServerVersion, ushort serverPort)
168 {
169 NewServerVersion = newServerVersion ?? throw new ArgumentNullException(nameof(newServerVersion));
170 NewPort = serverPort;
171 }
172
179 {
180 Chunk = chunk ?? throw new ArgumentNullException(nameof(chunk));
181 }
182
187 public TopicParameters(Guid eventId)
189 {
190 EventId = eventId.ToString();
191 }
192
199 {
200 }
201
206 protected TopicParameters(TopicCommandType commandType)
207 : base(String.Empty) // access identifier gets set before send
208 {
209 CommandType = commandType;
210 }
211
217 TopicParameters(string stringCommand, TopicCommandType stringCommandType)
218 : this(stringCommandType)
219 {
220#pragma warning disable IDE0010 // Add missing cases
221 switch (stringCommandType)
222 {
223 case TopicCommandType.InstanceRenamed:
224 NewInstanceName = stringCommand;
225 break;
226 case TopicCommandType.Broadcast:
227 BroadcastMessage = stringCommand;
228 break;
229 default:
230 throw new InvalidOperationException($"Invalid string TopicCommandType: {stringCommandType}");
231 }
232#pragma warning restore IDE0010 // Add missing cases
233 }
234 }
235}
Represents an update of ChannelRepresentations.
Definition ChatUpdate.cs:13
A packet of a split serialized set of data.
Definition ChunkData.cs:7
Represents a chat command to be handled by DD.
Data structure for TopicCommandType.EventNotification requests.
TopicParameters(RebootState newRebootState)
Initializes a new instance of the TopicParameters class.
static TopicParameters CreateInstanceRenamedTopicParameters(string newInstanceName)
Initializes a new instance of the TopicParameters class.
string? BroadcastMessage
The message to broadcast for TopicCommandType.Broadcast requests.
Version? NewServerVersion
The new server Version after a reattach.
TopicParameters(ChatCommand chatCommand)
Initializes a new instance of the TopicParameters class.
static TopicParameters CreateBroadcastParameters(string broadcastMessage)
Initializes a new instance of the TopicParameters class.
ChunkData? Chunk
The ChunkData for a partial request.
RebootState? NewRebootState
The RebootState for TopicCommandType.ChangeRebootState requests.
ushort? NewPort
The new port for TopicCommandType.ChangePort or TopicCommandType.ServerPortUpdate requests.
TopicParameters(EventNotification eventNotification)
Initializes a new instance of the TopicParameters class.
string? NewInstanceName
The new Api.Models.NamedEntity.Name for TopicCommandType.InstanceRenamed requests.
TopicParameters(ushort newPort)
Initializes a new instance of the TopicParameters class.
TopicParameters(Guid eventId)
Initializes a new instance of the TopicParameters class.
TopicParameters(string stringCommand, TopicCommandType stringCommandType)
Initializes a new instance of the TopicParameters class.
TopicParameters()
Initializes a new instance of the TopicParameters class.
TopicParameters(TopicCommandType commandType)
Initializes a new instance of the TopicParameters class.
bool IsPriority
Whether or not the TopicParameters constitute a priority request.
TopicParameters(ChatUpdate channelsUpdate)
Initializes a new instance of the TopicParameters class.
TopicParameters(ChunkData chunk)
Initializes a new instance of the TopicParameters class.
TopicParameters(Version newServerVersion, ushort serverPort)
Initializes a new instance of the TopicParameters class.
TopicCommandType
The type of topic command being sent.
@ CompleteEvent
Notifying about the completion of a custom event.
@ HealthCheck
Ping to ensure the server is running.
@ ServerRestarted
Notify the server of a reattach and potentially new version.
RebootState
Represents the action to take when /world/Reboot() is called.
Definition RebootState.cs:7