tgstation-server 6.1.2
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 [JsonIgnore]
69 public bool IsPriority => CommandType switch
70 {
71 TopicCommandType.EventNotification
72 or TopicCommandType.ChangePort
73 or TopicCommandType.ChangeRebootState
74 or TopicCommandType.InstanceRenamed
75 or TopicCommandType.ChatChannelsUpdate
76 or TopicCommandType.Broadcast
77 or TopicCommandType.ServerRestarted => true,
78 TopicCommandType.ChatCommand
79 or TopicCommandType.HealthCheck
80 or TopicCommandType.ReceiveChunk => false,
81 TopicCommandType.SendChunk => throw new InvalidOperationException("SendChunk topic priority should be based on the original TopicParameters!"),
82 _ => throw new InvalidOperationException($"Invalid value for {nameof(CommandType)}: {CommandType}"),
83 };
84
90 public static TopicParameters CreateInstanceRenamedTopicParameters(string newInstanceName)
91 => new(
92 newInstanceName ?? throw new ArgumentNullException(nameof(newInstanceName)),
93 TopicCommandType.InstanceRenamed);
94
100 public static TopicParameters CreateBroadcastParameters(string broadcastMessage)
101 => new(
102 broadcastMessage ?? throw new ArgumentNullException(nameof(broadcastMessage)),
103 TopicCommandType.Broadcast);
104
109 public TopicParameters(ChatCommand chatCommand)
111 {
112 ChatCommand = chatCommand ?? throw new ArgumentNullException(nameof(chatCommand));
113 }
114
119 public TopicParameters(EventNotification eventNotification)
121 {
122 EventNotification = eventNotification ?? throw new ArgumentNullException(nameof(eventNotification));
123 }
124
129 public TopicParameters(ushort newPort)
130 : this(TopicCommandType.ChangePort)
131 {
132 NewPort = newPort;
133 }
134
139 public TopicParameters(RebootState newRebootState)
140 : this(TopicCommandType.ChangeRebootState)
141 {
142 NewRebootState = newRebootState;
143 }
144
149 public TopicParameters(ChatUpdate channelsUpdate)
150 : this(TopicCommandType.ChatChannelsUpdate)
151 {
152 ChatUpdate = channelsUpdate ?? throw new ArgumentNullException(nameof(channelsUpdate));
153 }
154
160 public TopicParameters(Version newServerVersion, ushort serverPort)
161 : this(TopicCommandType.ServerRestarted)
162 {
163 NewServerVersion = newServerVersion ?? throw new ArgumentNullException(nameof(newServerVersion));
164 NewPort = serverPort;
165 }
166
172 : this(TopicCommandType.SendChunk)
173 {
174 Chunk = chunk ?? throw new ArgumentNullException(nameof(chunk));
175 }
176
182 : this(TopicCommandType.HealthCheck)
183 {
184 }
185
190 protected TopicParameters(TopicCommandType commandType)
191 : base(String.Empty) // access identifier gets set before send
192 {
193 CommandType = commandType;
194 }
195
201 TopicParameters(string stringCommand, TopicCommandType stringCommandType)
202 : this(stringCommandType)
203 {
204#pragma warning disable IDE0010 // Add missing cases
205 switch (stringCommandType)
206 {
207 case TopicCommandType.InstanceRenamed:
208 NewInstanceName = stringCommand;
209 break;
210 case TopicCommandType.Broadcast:
211 BroadcastMessage = stringCommand;
212 break;
213 default:
214 throw new InvalidOperationException($"Invalid string TopicCommandType: {stringCommandType}");
215 }
216#pragma warning restore IDE0010 // Add missing cases
217 }
218 }
219}
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.
Definition: ChatCommand.cs:11
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(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.
RebootState
Represents the action to take when /world/Reboot() is called.
Definition: RebootState.cs:7