Skip to content

Commit

Permalink
Remove more IRC stuff don't need
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed May 23, 2021
1 parent 2270d7f commit 5092e84
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 339 deletions.
1 change: 0 additions & 1 deletion MCGalaxy/MCGalaxy_.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,6 @@
<Compile Include="util\UIHelpers.cs" />
<Compile Include="util\Utils.cs" />
<Compile Include="sharkbite.thresher\Connection.cs" />
<Compile Include="sharkbite.thresher\Delegates.cs" />
<Compile Include="sharkbite.thresher\Listener.cs" />
<Compile Include="sharkbite.thresher\NameGenerator.cs" />
<Compile Include="sharkbite.thresher\ReplyCode.cs" />
Expand Down
83 changes: 18 additions & 65 deletions MCGalaxy/sharkbite.thresher/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public sealed class Connection
bool registered;
//TCP/IP connection established with IRC server
bool connected;
bool handleNickFailure;
bool handleNickFailure = true;
Encoding encoding;

/// <summary>
Expand All @@ -56,9 +56,6 @@ public sealed class Connection
/// <param name="textEncoding">The text encoding for the incoming stream.</param>
public Connection( Encoding textEncoding )
{
registered = false;
connected = false;
handleNickFailure = true;
sender = new Sender( this );
listener = new Listener( );
RegisterDelegates();
Expand Down Expand Up @@ -109,23 +106,6 @@ public Connection( Encoding textEncoding )
/// <value>True if the client is connected.</value>
public bool Connected { get { return connected; } }
/// <summary>
/// By default the connection itself will handle the case
/// where, while attempting to register the client's nick
/// is already in use. It does this by simply appending
/// 2 random numbers to the end of the nick.
/// </summary>
/// <remarks>
/// The NickError event is shows that the nick collision has happened
/// and it is fixed by calling Sender's Register() method passing
/// in the replacement nickname.
/// </remarks>
/// <value>True if the connection should handle this case and
/// false if the client will handle it itself.</value>
public bool HandleNickTaken {
get { return handleNickFailure; }
set { handleNickFailure = value; }
}
/// <summary>
/// A user friendly name of this Connection in the form 'nick@host'
/// </summary>
/// <value>Read only string</value>
Expand All @@ -148,34 +128,26 @@ public string Name {
/// Respond to IRC keep-alives.
/// </summary>
/// <param name="message">The message that should be echoed back</param>
private void KeepAlive(string message)
void KeepAlive(string message)
{
sender.Pong( message );
}
/// <summary>
/// Update the ConnectionArgs object when the user
/// changes his nick.
/// </summary>
/// <param name="user">Who changed their nick</param>
/// <param name="newNick">The new nick name</param>
private void MyNickChanged(UserInfo user, string newNick)

void MyNickChanged(UserInfo user, string newNick)
{
if ( Nick == user.Nick )
{
Nick = newNick;
}
}
private void OnRegistered()

void OnRegistered()
{
registered = true;
listener.OnRegistered -= new RegisteredEventHandler( OnRegistered );
listener.OnRegistered -= OnRegistered;
}
/// <summary>
///
/// </summary>
/// <param name="badNick"></param>
/// <param name="reason"></param>
private void OnNickError( string badNick, string reason )

void OnNickError( string badNick, string reason )
{
//If this is our initial connection attempt
if( !registered && handleNickFailure )
Expand All @@ -191,12 +163,13 @@ private void OnNickError( string badNick, string reason )
Sender.Register(nick);
}
}
private void RegisterDelegates()

void RegisterDelegates()
{
listener.OnPing += new PingEventHandler( KeepAlive );
listener.OnNick += new NickEventHandler( MyNickChanged );
listener.OnNickError += new NickErrorEventHandler( OnNickError );
listener.OnRegistered += new RegisteredEventHandler( OnRegistered );
listener.OnPing += KeepAlive;
listener.OnNick += MyNickChanged;
listener.OnNickError += OnNickError;
listener.OnRegistered += OnRegistered;
}

/// <summary>
Expand All @@ -205,7 +178,7 @@ private void RegisterDelegates()
/// Discard CTCP and DCC messages if these protocols
/// are not enabled.
/// </summary>
internal void ReceiveIRCMessages()
void ReceiveIRCMessages()
{
string line;
try
Expand Down Expand Up @@ -262,22 +235,6 @@ internal void SendCommand( StringBuilder command)
}
command.Remove(0, command.Length );
}
/// <summary>
/// Send a message to the IRC server which does
/// not affect the client's idle time. Used for automatic replies
/// such as PONG or Ctcp repsones.
/// </summary>
internal void SendAutomaticReply( StringBuilder command)
{
try
{
writer.WriteLine( command.ToString() );
}
catch( Exception )
{
}
command.Remove(0, command.Length );
}

Stream MakeDataStream()
{
Expand All @@ -287,8 +244,7 @@ Stream MakeDataStream()
}

/// <summary>
/// Connect to the IRC server and start listening for messages
/// on a new thread.
/// Connect to the IRC server and start listening for messages on a new thread.
/// </summary>
/// <exception cref="SocketException">If a connection cannot be established with the IRC server</exception>
public void Connect()
Expand Down Expand Up @@ -323,7 +279,6 @@ public void Disconnect( string reason )
lock ( this )
{
if( !connected ) throw new InvalidOperationException("Not connected to IRC server.");
listener.Disconnecting();
sender.Quit( reason );
listener.Disconnected();
//Thanks to Thomas for this next block
Expand All @@ -334,9 +289,7 @@ public void Disconnect( string reason )

/// <summary> A friendly name for this connection. </summary>
/// <returns>The Name property</returns>
public override string ToString() {
return Name;
}
public override string ToString() { return Name; }

const string ctcpTypes = "(FINGER|USERINFO|VERSION|SOURCE|CLIENTINFO|ERRMSG|PING|TIME)";
static Regex ctcpRegex = new Regex(":([^ ]+) [A-Z]+ [^:]+:\u0001" + ctcpTypes + "([^\u0001]*)\u0001", RegexOptions.Compiled | RegexOptions.Singleline );
Expand Down
Loading

0 comments on commit 5092e84

Please sign in to comment.