// The invoked function, a member of the m_Protocol used below [Command( "433" )] void NickInUse( Connection conn, string Prefix, params object[] Params ) { conn.SendCommand( "NICK " + Params[1] + "_" + "\r\n" ); } // The invoking function private void RunCommand( string Command ) { m_Log.WriteLine( "<<< " + Command ); m_Log.Flush(); string[] Parameters = Command.Split( ' ' ); string[] RealParms; int iOffset = 1; string Cmd = Parameters[0]; string Prefix = null; if( Cmd.StartsWith( ":" ) ) { // It starts with a prefix. Ignore it. Prefix = Parameters[0].Substring( 1 ); Cmd = Parameters[1]; iOffset = 2; } // Parse the parameters // Count until we find a parameter starting with ':' int iParamEnd = Parameters.Length-1; for( int i = iOffset; i < Parameters.Length; i++ ) { if( Parameters[i].StartsWith( ":" ) ) { iParamEnd = i; break; } } // Allocate space for all the parameters RealParms = new string[(iParamEnd - iOffset) + 1]; // Copy all the arguments but the last over for( int i = iOffset; i < iParamEnd; i++ ) RealParms[i - iOffset] = Parameters[i]; // If the last one is not a fullstring, copy it in if( !Parameters[iParamEnd].StartsWith( ":" ) ) { RealParms[iParamEnd-iOffset] = Parameters[iParamEnd]; } // Otherwise... else { // Create a string with the remaining parameters string fullstring = Parameters[iParamEnd].Substring( 1 ); for( int i = iParamEnd+1; i < Parameters.Length; i++ ) { fullstring += " " + Parameters[i]; } // Pop it into the last parameter RealParms[iParamEnd-iOffset] = fullstring; } // Trim a single \r off the end if( RealParms[iParamEnd-iOffset].EndsWith( "\r" ) ) { RealParms[iParamEnd-iOffset] = RealParms[iParamEnd-iOffset].Substring( 0, RealParms[iParamEnd-iOffset].Length - 1 ); } // Call the function object oMI = m_Hashtable[Cmd]; if( oMI == null ) { // It's an unknown command, throw a warning Console.WriteLine( "Unknown command: " + Cmd ); return; } MethodInfo mi = (MethodInfo)oMI; object[] objs = new object[2+RealParms.Length]; objs[0] = this; objs[1] = Prefix; for( int i = 0; i < RealParms.Length; i++ ) { objs[i + 2] = RealParms[i]; } mi.Invoke( m_Protocol, objs ); }