tgstation-server 6.9.2
The /tg/station 13 server suite
Loading...
Searching...
No Matches
IrcConnectionStringBuilder.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Text;
4
6
8{
13 {
15 public override bool Valid => Address != null && Port.HasValue && Port != 0 && UseSsl.HasValue && (PasswordType.HasValue ^ Password == null);
16
20 public string? Address { get; set; }
21
25 public ushort? Port { get; set; }
26
30 public string? Nickname { get; set; }
31
35 public bool? UseSsl { get; set; }
36
40 public IrcPasswordType? PasswordType { get; set; }
41
45 public string? Password { get; set; }
46
51 {
52 }
53
58 public IrcConnectionStringBuilder(string connectionString)
59 {
60 if (connectionString == null)
61 throw new ArgumentNullException(nameof(connectionString));
62 var splits = connectionString.Split(';');
63
64 Address = splits[0];
65
66 if (splits.Length < 2)
67 return;
68
69 if (UInt16.TryParse(splits[1], out var port))
70 Port = port;
71
72 if (splits.Length < 3)
73 return;
74
75 Nickname = splits[2];
76
77 if (splits.Length < 4)
78 return;
79
80 if (Int32.TryParse(splits[3], out var intSsl))
81 UseSsl = Convert.ToBoolean(intSsl);
82
83 if (splits.Length < 5)
84 return;
85 if (Enum.TryParse<IrcPasswordType>(splits[4], out var passwordType))
86 switch (passwordType)
87 {
88 case IrcPasswordType.NickServ:
89 case IrcPasswordType.Sasl:
90 case IrcPasswordType.Server:
91 PasswordType = passwordType;
92 break;
93 default:
94 break;
95 }
96
97 if (splits.Length < 6)
98 return;
99
100 var rest = new List<string>(splits);
101 rest.RemoveRange(0, 5);
102 Password = String.Join(";", rest);
103 }
104
106 public override string ToString()
107 {
108 var sb = new StringBuilder();
109 sb.Append(Address);
110 sb.Append(';');
111 sb.Append(Port);
112 sb.Append(';');
113 sb.Append(Nickname);
114 sb.Append(';');
115
116 if (UseSsl.HasValue)
117 sb.Append(Convert.ToInt32(UseSsl.Value));
118
119 if (PasswordType.HasValue)
120 {
121 sb.Append(';');
122 sb.Append((int)PasswordType);
123 sb.Append(';');
124 sb.Append(Password);
125 }
126
127 return sb.ToString();
128 }
129 }
130}
Helper for building ChatBotSettings.ConnectionStrings.
ChatConnectionStringBuilder for ChatProvider.Irc.
IrcPasswordType? PasswordType
The optional IrcPasswordType to use.
IrcConnectionStringBuilder(string connectionString)
Initializes a new instance of the IrcConnectionStringBuilder class.
string? Address
The IP address or URL of the IRC server.
bool? UseSsl
If the connection should be made using SSL.
IrcConnectionStringBuilder()
Initializes a new instance of the IrcConnectionStringBuilder class.
IrcPasswordType
Represents the type of a password for a ChatProvider.Irc.