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