Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Help me with my VB Irc!!

  • 07-11-2006 9:08pm
    #1
    Registered Users, Registered Users 2 Posts: 4,946 ✭✭✭


    Scroll down to my next comment!


Comments

  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    First off you do realise that VB 2005 Express Edition is a .NET 2.0 version of the VB language so your system wont compile correctly if written in VB6.0 (but i have noticed that some of your function have the handles keywords as well so you might be writting it in VB.NET)

    First off you will need a reference to your Winsock dll using the add references command (see http://www.freevbcode.com/ShowCode.asp?ID=7557)

    Instead of DoEvents you need to use Application.DoEvents() (VB.NET now!!)


  • Registered Users, Registered Users 2 Posts: 4,946 ✭✭✭red_ice


    Hey ginger - i referenced my winsock.dll and i got another two ones called IrcOCX and SocketOCX which are apparently built for irc!

    I've scrapped it and started a project using .nets System.Net.Sockets!

    I can now connect to irc.quakenet.org! I have used /Notice and /PRIVMSG and i can join channels, but i cant get /SAY working so i can hold a conversation with anyone. Another aspect thats not really helping me and my conversations on irc is the fact that i cant see text...

    as you can see i have it commented out the problem area.

    Private Sub AT(ByVal Text As String)
    'TextBox1.AppendText(Text & vbCrLf)
    'TextBox1.ScrollToCaret()
    End Sub

    It gives the error :
    System.InvalidOperationException was unhandled
    Message="Cross-thread operation not valid: Control 'TextBox1' accessed from a thread other than the thread it was created on."
    Source="System.Windows.Forms"
    StackTrace:
    at System.Windows.Forms.Control.get_Handle()
    at System.Windows.Forms.TextBoxBase.GetSelectionStartAndLength(Int32& start, Int32& length)
    at System.Windows.Forms.TextBoxBase.AppendText(String text)
    at reddypopsIRC.Form1.AT(String Text) in C:\...\Form1.vb:line 154
    at reddypopsIRC.Form1.wsClient_onError(String Description) in C:\...\Form1.vb:line 172
    at reddypopsIRC.SocketsClient.sockConnected(IAsyncResult ar) in C:\...\SocketsClient.vb:line 74
    at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
    at System.Net.ContextAwareResult.CompleteCallback(Object state)
    at System.Threading.ExecutionContext.runTryCode(Object userData)
    at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
    at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Net.ContextAwareResult.Complete(IntPtr userToken)
    at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result, IntPtr userToken)
    at System.Net.Sockets.Socket.ConnectCallback()
    at System.Net.Sockets.Socket.RegisteredWaitCallback(Object state, Boolean timedOut)
    at System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(Object state, Boolean timedOut)


    Is there too much text for it to put into the textbox?


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    Is your system multi threaded by design??? Cross threaded access is not allowed as the error message says and winforms are not thread safe (bit out of my league.. my side of things is web apps)

    But you can if I recall correctly add the following line to the forms constructor

    Control.CheckForIllegalCrossThreadCalls = False

    Not ideal.. there is also a Background worker class (http://msdn2.microsoft.com/en-us/library/4852et58.aspx)

    And here is an MSDN article http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconDevelopingMultithreadedWindowsFormsControl.asp

    THis might also help somewhat
    http://www.codeproject.com/useritems/AccessControlFromThread.asp


  • Registered Users, Registered Users 2 Posts: 4,946 ✭✭✭red_ice


    Absolute legend!

    Control.CheckForIllegalCrossThreadCalls = False

    It works! i can see text! Thanks!!


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    No probs, but I know that the threading thing has been added to VS2005 as a standard so just keep an eye for stupid issues that might arise


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 4,946 ✭✭✭red_ice


    speaking of stupid issues...

    When i type anything that consists of more than one word, for example "Hi there!" it will only send ''there!'' to the channel.
    Private Sub cmdMsg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMsg.Click
    wsClient.SendData(wsClient.StringToBytes("PRIVMSG #" & txtName.Text & " " & txtMsg.Text & vbCrLf))
    End Sub

    PRIVMSG is the IRC code to talk to a person or a channel, txtname.text is the channel or person i want to talk to(which i have stored in a list box apon joining a channel), and txtMsg is the message (Hi There)

    any ideas?


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    Ginger wrote:
    No probs, but I know that the threading thing has been added to VS2005 as a standard so just keep an eye for stupid issues that might arise
    Threading wasn't added, it was always there. When you hook into an Event you are automatically "multithreading" your application, so you need to start dealing with threading issues. The reason why the error is being throw up in VS2005 and not VS2003 is that VS2003 didn't check for those kind of errors, VS2005 is.

    Instead of directly setting the text, you need to do something like this (psuedo code, my syntax may be wrong).
    private void SetText(TextBox textBox, string value)
    {
        // If we are trying to update the textbox from a different thread
        // to the one the textbox is on, we need to Invoke the method
        // on that thread
        if(textBox.InvokeRequired)
             textBox.Invoke(SetText, textBox, value);
    
        // If we don't require an invoke, it means we're on the same thread,
        // so things are safe
        else
            textBox.Text.Append(value)
    }
    

    EDIT: I see you wrote your own StringToBytes method... Try using System.Text.Encoding.UTF8.GetBytes() (or whatever encoding the specs say you should use, i assume utf8).


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    As I said i am more web apps...
    :)


  • Registered Users, Registered Users 2 Posts: 4,946 ✭✭✭red_ice


    cant blame a guy for tryin!! :p


  • Registered Users, Registered Users 2 Posts: 4,946 ✭✭✭red_ice


    Threading wasn't added, it was always there. When you hook into an Event you are automatically "multithreading" your application, so you need to start dealing with threading issues. The reason why the error is being throw up in VS2005 and not VS2003 is that VS2003 didn't check for those kind of errors, VS2005 is.

    Instead of directly setting the text, you need to do something like this (psuedo code, my syntax may be wrong).
    private void SetText(TextBox textBox, string value)
    {
        // If we are trying to update the textbox from a different thread
        // to the one the textbox is on, we need to Invoke the method
        // on that thread
        if(textBox.InvokeRequired)
             textBox.Invoke(SetText, textBox, value);
    
        // If we don't require an invoke, it means we're on the same thread,
        // so things are safe
        else
            textBox.Text.Append(value)
    }
    

    EDIT: I see you wrote your own StringToBytes method... Try using System.Text.Encoding.UTF8.GetBytes() (or whatever encoding the specs say you should use, i assume utf8).



    i didnt see your responce earlier, ill give it a go and let you know the result! Thanks for the help so far!


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 4,946 ✭✭✭red_ice


    alright lads, ill give you a little update on how the IRC is coming along.

    I havnt been able to fix the problem with using multiple words in a sentence... but

    i have it joining multiple IRC channels
    sending PMs
    Giving channel flags
    kicking/banning people
    kicking/banning people with reason
    I have it spamming every 1/2/5/10/20 minutes (controled via menu)
    I have a basic form of AI as in... user: Hello bot!! bot: Hey!

    Really simple stuff.

    i've decided to tackle a harder issue that will make the IRC client come along in terms of useability. Im adding the users in the channel to a listbox. I've managed to get the Data/names into a listbox (after a few headwrecking hours) and i can now send messages via a double click!

    There is a problem tho. In order for me to get the names into the list box, i have had to trim down a (potentially long ass) string and add it item by item to the listbox. This means there will be some lines there taht have nothing to do with any users, they are mearly quakenet/irc server details and userfriendly lines to let you know whats going on.

    I managed to delete the first few lines of crap that is useless by doing
    wsClient.SendData(wsClient.StringToBytes("NAMES #" & lstChan.SelectedItem & vbCrLf))
    nameList()
    For countah = 0 To 6
    lstNames.Items.RemoveAt(0)
    Next countah

    sweet! simple solution to a simple problem...

    Now, there is also some crap at the end/bottom of the list box, about 5 lines of uselessness that i dont want in the list box...

    So i've tried another for loop as follows.
    Lengthoflistbox = lstNames.Items.Count
    Lengthoflistbox2 = Lengthoflistbox - 1
    Label1.Text = (Lengthoflistbox & " " & Lengthoflistbox2)
    For countah2 = 0 To 5
    lstNames.Items.RemoveAt(Lengthoflistbox2)
    Next countah2

    This throws up errors... but before it crashes, you can just see it delete the last few lines

    Can anyone help?


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    Before you go *any* further, have you read up on the IRC protocol? Linky. You really need to know how strings are formatted and whatnot before you can really make any headway into writing a good client.

    Give the initial spec a read and it should clear up issues regarding how to send strings with spaces (maybe the space needs to be escaped in some way?) and how to parse the data you're getting off the server (maybe the string is in a particular structure making it simple to parse out the list of nicks once you know that structure).

    Lengthoflistbox = lstNames.Items.Count
    Lengthoflistbox2 = Lengthoflistbox - 1
    Label1.Text = (Lengthoflistbox & " " & Lengthoflistbox2)
    For countah2 = 0 To 5
    lstNames.Items.RemoveAt(Lengthoflistbox2)
    
    Supposing the listbox has 10 items. Lengthoflistbox is then 10. So Lengthoflistbox2 is 9. So, for countah2 = 0 to 5, you remove the item at position 9. So only one loop would ever successfully run, as after the first loop, there is no item at position 9, hence the crash.

    Change that to lstNames.Items.RemoveAt(lstNames.Items.Count - 1)

    That should fix that problem.


  • Registered Users, Registered Users 2 Posts: 4,946 ✭✭✭red_ice


    Before you go *any* further, have you read up on the IRC protocol? Linky. You really need to know how strings are formatted and whatnot before you can really make any headway into writing a good client.

    Give the initial spec a read and it should clear up issues regarding how to send strings with spaces (maybe the space needs to be escaped in some way?) and how to parse the data you're getting off the server (maybe the string is in a particular structure making it simple to parse out the list of nicks once you know that structure).

    Lengthoflistbox = lstNames.Items.Count
    Lengthoflistbox2 = Lengthoflistbox - 1
    Label1.Text = (Lengthoflistbox & " " & Lengthoflistbox2)
    For countah2 = 0 To 5
    lstNames.Items.RemoveAt(Lengthoflistbox2)
    
    Supposing the listbox has 10 items. Lengthoflistbox is then 10. So Lengthoflistbox2 is 9. So, for countah2 = 0 to 5, you remove the item at position 9. So only one loop would ever successfully run, as after the first loop, there is no item at position 9, hence the crash.

    Change that to lstNames.Items.RemoveAt(lstNames.Items.Count - 1)

    That should fix that problem.

    top man mf!

    im off to the uk for the weekend, ill probs get an hour in of playing around with the bot tonight before bed

    ill be posting more problems on monday :p


Advertisement