private void Connection(bool nick = false)
{
try
{
NetworkQuit = false;
_cts = new CancellationTokenSource();
if(nick)
{
sMyNickInfo.ChangeNick(IRCConfig.List[_servername].NickName);
if(Rfc2812Util.IsServInLower(sMyNickInfo.NickStorage)) // NickName
{
sMyNickInfo.ChangeNick(); // NickName -> NickName2
if(Rfc2812Util.IsServInLower(sMyNickInfo.NickStorage)) // NickName2
{
sMyNickInfo.ChangeNick(); // NickName2 -> NickName3
if(Rfc2812Util.IsServInLower(sMyNickInfo.NickStorage)) // NickName3
sMyNickInfo.ChangeNick(); // NickName3 -> Other
}
Log.Warning("Network", sLConsole.GetString("This nick name ({0}) is used by a service bot. Your nick is automaticly changed to a placeholder one."), sMyNickInfo.NickStorage);
}
}
Log.Notice("Network", sLConsole.GetString("Connection type: {0}"), CType.ToString());
try
{
client = new TcpClient();
client.Connect(_server, _port);
}
catch(Exception)
{
Log.Error("Network", sLConsole.GetString("Fatal error was happened while established the connection!"));
return;
}
if(!client.IsNull() && client.Connected)
Log.Success("Network", sLConsole.GetString("Successfully established the connection!"));
else
{
Log.Error("Network", sLConsole.GetString("Error was happened while established the connection!"));
return;
}
if(CType == ConnectionType.Ssl)
{
SslStream networkStream = null;
try
{
networkStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback((s,ce,ca,p) => true), null);
networkStream.AuthenticateAsClient(_server);
}
catch(AuthenticationException e)
{
Log.Error("Network", sLConsole.GetString("Certificate not accepted, exception: {0}"), e.Message);
return;
}
catch(Exception e)
{
Log.Error("Network", sLConsole.GetString("Failure details: {0}"), e.Message);
return;
}
if(networkStream.IsNull())
return;
InitializeStream(networkStream);
}
else
InitializeStream(client.GetStream());
if(reader.IsNull() || INetwork.WriterList[_servername].IsNull())
return;
Connected = true;
sSender.RegisterConnection(IRCConfig.List[_servername].Password, sMyNickInfo.NickStorage, IRCConfig.List[_servername].UserName, IRCConfig.List[_servername].UserInfo);
Log.Notice("Network", sLConsole.GetString("Users' datas are sent."));
Online = false;
IsAllJoin = false;
_enabled = true;
KickPrivmsg = string.Empty;
ModePrivmsg = string.Empty;
ChannelPrivmsg = string.Empty;
NewNickPrivmsg = string.Empty;
UrlTitleEnabled = false;
sMyNickInfo.ChangeIdentifyStatus(false);
sMyNickInfo.ChangeVhostStatus(false);
}
catch(Exception e)
{
Online = false;
Connected = false;
Log.Error("Network", sLConsole.GetString("Failure details: {0}"), e.Message);
}
}