tgstation-server 6.12.0
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 case IrcPasswordType.Oper:
92 PasswordType = passwordType;
93 break;
94 default:
95 break;
96 }
97
98 if (splits.Length < 6)
99 return;
100
101 var rest = new List<string>(splits);
102 rest.RemoveRange(0, 5);
103 Password = String.Join(";", rest);
104 }
105
107 public override string ToString()
108 {
109 var sb = new StringBuilder();
110 sb.Append(Address);
111 sb.Append(';');
112 sb.Append(Port);
113 sb.Append(';');
114 sb.Append(Nickname);
115 sb.Append(';');
116
117 if (UseSsl.HasValue)
118 sb.Append(Convert.ToInt32(UseSsl.Value));
119
120 if (PasswordType.HasValue)
121 {
122 sb.Append(';');
123 sb.Append((int)PasswordType);
124 sb.Append(';');
125 sb.Append(Password);
126 }
127
128 return sb.ToString();
129 }
130 }
131}
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.