tgstation-server  4.4.0
The /tg/station 13 server suite
IrcConnectionStringBuilder.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Text;
5 
6 namespace Tgstation.Server.Api.Models
7 {
12  {
14  public override bool Valid => Address != null && Port.HasValue && Port != 0 && UseSsl.HasValue && (PasswordType.HasValue ^ Password == null);
15 
19  public string? Address { get; set; }
20 
24  public ushort? Port { get; set; }
25 
29  public string? Nickname { get; set; }
30 
34  public bool? UseSsl { get; set; }
35 
39  public IrcPasswordType? PasswordType { get; set; }
40 
44  public string? Password { get; set; }
45 
50 
55  public IrcConnectionStringBuilder(string connectionString)
56  {
57  if (connectionString == null)
58  throw new ArgumentNullException(nameof(connectionString));
59  var splits = connectionString.Split(';');
60 
61  Address = splits[0];
62 
63  if (splits.Length < 2)
64  return;
65 
66  if (UInt16.TryParse(splits[1], out var port))
67  Port = port;
68 
69  if (splits.Length < 3)
70  return;
71 
72  Nickname = splits[2];
73 
74  if (splits.Length < 4)
75  return;
76 
77  if (Int32.TryParse(splits[3], out var intSsl))
78  UseSsl = Convert.ToBoolean(intSsl);
79 
80  if (splits.Length < 5)
81  return;
82  if (Enum.TryParse<IrcPasswordType>(splits[4], out var passwordType))
83  switch (passwordType)
84  {
85  case IrcPasswordType.NickServ:
86  case IrcPasswordType.Sasl:
87  case IrcPasswordType.Server:
88  PasswordType = passwordType;
89  break;
90  default:
91  break;
92  }
93 
94  if (splits.Length < 6)
95  return;
96 
97  var rest = new List<string>(splits);
98  rest.RemoveRange(0, 5);
99  Password = String.Join(";", rest);
100  }
101 
103  public override string ToString()
104  {
105  var sb = new StringBuilder();
106  sb.Append(Address);
107  sb.Append(';');
108  sb.Append(Port);
109  sb.Append(';');
110  sb.Append(Nickname);
111  sb.Append(';');
112  if(UseSsl.HasValue)
113  sb.Append(Convert.ToInt32(UseSsl.Value));
114  if (PasswordType.HasValue)
115  {
116  sb.Append(';');
117  sb.Append((int)PasswordType);
118  sb.Append(';');
119  sb.Append(Password);
120  }
121 
122  return sb.ToString();
123  }
124  }
125 }
IrcConnectionStringBuilder(string connectionString)
Construct a DiscordConnectionStringBuilder from a connectionString
IrcConnectionStringBuilder()
Construct an IrcConnectionStringBuilder
IrcPasswordType
Represents the type of a password for a ChatProvider.Irc
ChatConnectionStringBuilder for ChatProvider.Irc
override string ToString()
Gets the ChatBot.ConnectionString associated with the ChatConnectionStringBuilder ...