Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: Joe[x86] on May 22, 2005, 01:31 PM

Title: Console Chatbot (Sending Messages)
Post by: Joe[x86] on May 22, 2005, 01:31 PM
I've written a fairly good console chatbot over the past few days.. except.. it can't chat. Does anyone have any idea how I'd send messages from a console without the bot specifically asking for them?

EDIT -
Perhaps I should ask for a message, get on with life, and once ones finally returned, repeat?
No go. It stops all events until a message is returned. If it was simply the way I did it..

On CSB_LoggedOnAs:
Call StartChat()

My StartChat Sub
Public Sub StartChat()
    Dim S as String
    Let S = Console.ReadText()
    Call frmCSBEvents.CSB.Send(CStr(S))
    Call AddChat("<" & frmCSBEvents.CSB.Username & "> " & CStr(S))
End Sub
Title: Re: Console Chatbot (Sending Messages)
Post by: Eric on May 22, 2005, 01:38 PM
QuoteDoes anyone have any idea how I'd send messages from a console without the bot specifically asking for them?

The same way you would from a non-console app.
Title: Re: Console Chatbot (Sending Messages)
Post by: Joe[x86] on May 22, 2005, 01:40 PM
QuoteThe same way you would from a non-console app.

Okay, lets do it your way then. Does anybody know how I can load a textbox on my console that I can type in? No? Hrm, must not be the same way.
Title: Re: Console Chatbot (Sending Messages)
Post by: Eric on May 22, 2005, 01:44 PM
QuoteEDIT -
No go. It stops all events until a message is returned. If it was simply the way I did it..

Generally that's solved by putting ReadConsoleInput (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/readconsoleinput.asp)() in an infinite loop in main() and creating a seperate thread for other functions.
Title: Re: Console Chatbot (Sending Messages)
Post by: Eric on May 22, 2005, 01:48 PM
Quote from: Joex86] link=topic=11667.msg113392#msg113392 date=1116787212]
QuoteThe same way you would from a non-console app.

Okay, lets do it your way then. Does anybody know how I can load a textbox on my console that I can type in? No? Hrm, must not be the same way.

CreateWindow (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/createwindow.asp)().
Title: Re: Console Chatbot (Sending Messages)
Post by: Joe[x86] on May 22, 2005, 01:58 PM
How do I use a second thread in VisualBasic?
Title: Re: Console Chatbot (Sending Messages)
Post by: Eric on May 22, 2005, 02:01 PM
CreateThread (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createthread.asp)().
Title: Re: Console Chatbot (Sending Messages)
Post by: Warrior on May 22, 2005, 02:23 PM
*rofl* Lord
Title: Re: Console Chatbot (Sending Messages)
Post by: Joe[x86] on May 22, 2005, 02:26 PM
Does anybody want to help me here? All I can get out of what LoRd[nK] is telling me is that I need to use an API call.
Title: Re: Console Chatbot (Sending Messages)
Post by: hismajesty on May 22, 2005, 03:06 PM
Click the links.
Title: Re: Console Chatbot (Sending Messages)
Post by: Eric on May 22, 2005, 03:10 PM
Quote from: Joex86] link=topic=11667.msg113404#msg113404 date=1116790002]
Does anybody want to help me here? All I can get out of what LoRd[nK] is telling me is that I need to use an API call.

Were you expecting this to be easy?
Title: Re: Console Chatbot (Sending Messages)
Post by: Warrior on May 22, 2005, 03:22 PM
well he got baby fed the console code, so I'd assume yes :p
Title: Re: Console Chatbot (Sending Messages)
Post by: UserLoser. on May 22, 2005, 04:26 PM
DarkMinion supplied a simple example a long time ago.  It is here (http://www.valhallalegends.com/dmsource.htm).  Yes, it's in C++, but it's no harder to translate it into VB code than it would be to read documentation somewhere else.

Don't use _beginthread() and _endthread(), use CreateThread() and ExitThread(), or don't use any at all and just find a workaround for it which shouldn't be too hard
Title: Re: Console Chatbot (Sending Messages)
Post by: 111787 on May 22, 2005, 04:31 PM
Use WinExec()
Title: Re: Console Chatbot (Sending Messages)
Post by: Eric on May 22, 2005, 05:00 PM
Quote from: 111787 on May 22, 2005, 04:31 PM
Use WinExec()

WinExec (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/winexec.asp)() doesn't create a new thread.  It executes an application.
Title: Re: Console Chatbot (Sending Messages)
Post by: Imperceptus on May 22, 2005, 08:35 PM
I would honestly look into VB Express or VB.Net and do multi-threading that way.  Its muchos easier imho.
Title: Re: Console Chatbot (Sending Messages)
Post by: Joe[x86] on May 24, 2005, 05:52 PM
@LoRd and Warrior: Awesome! I got it working thanks to you guys! No.
Title: Re: Console Chatbot (Sending Messages)
Post by: Eric on May 24, 2005, 07:09 PM
Quote from: Joex86] link=topic=11667.msg113636#msg113636 date=1116975156]
@LoRd and Warrior: Awesome! I got it working thanks to you guys! No.

I've provided you with all that you need short of the actual code.  If all you wanted was to steal someone elses work, you should have said so.

Since you're not willing to do any actual work, perhaps you should Google up a control that has it already done for you.
Title: Re: Console Chatbot (Sending Messages)
Post by: Forged on May 27, 2005, 03:40 PM
Quote from: Joex86] link=topic=11667.msg113636#msg113636 date=1116975156]
@LoRd and Warrior: Awesome! I got it working thanks to you guys! No.

The easiest way to do it would be to make the form have a textbox and minimize it to the tray when you are not using it.  That is what I did anyway.
Title: Re: Console Chatbot (Sending Messages)
Post by: Joe[x86] on May 27, 2005, 05:24 PM
=/. Well, LoRd[nK], perhaps if MSDN wasn't so confusing, I'd be willing to do it. All their examples are in C-ish syntax, and their explinations use terms foreign to me, so no. Just no.
Title: Re: Console Chatbot (Sending Messages)
Post by: Warrior on May 27, 2005, 07:52 PM
I don't get how you can't port it..you know data types right? You know the structure of an API call right? At the bottom it tells you the library to use and everything, it's easy.
Title: Re: Console Chatbot (Sending Messages)
Post by: hismajesty on May 27, 2005, 10:03 PM
Indeed, the MSDN pages are done in such a way that the content can be easily translated across multiple languages.
Title: Re: Console Chatbot (Sending Messages)
Post by: NicoQwertyu on May 30, 2005, 12:14 PM
Quote from: Forged on May 27, 2005, 03:40 PM
Quote from: Joex86] link=topic=11667.msg113636#msg113636 date=1116975156]
@LoRd and Warrior: Awesome! I got it working thanks to you guys! No.

The easiest way to do it would be to make the form have a textbox and minimize it to the tray when you are not using it.  That is what I did anyway.

What "form?"  He's writing a console app in VB (eww >:().
Title: Re: Console Chatbot (Sending Messages)
Post by: Forged on May 30, 2005, 05:37 PM
By default all vb programs still have a form, you just hide it when you launch the console.
Title: Re: Console Chatbot (Sending Messages)
Post by: Eric on May 30, 2005, 07:08 PM
Quote from: Forged on May 30, 2005, 05:37 PM
By default all vb programs still have a form

No they don't.
Title: Re: Console Chatbot (Sending Messages)
Post by: UserLoser. on May 30, 2005, 07:34 PM
Quote from: LoRd[nK] on May 30, 2005, 07:08 PM
Quote from: Forged on May 30, 2005, 05:37 PM
By default all vb programs still have a form

No they don't.

I think he means with default VB IDE settings, when you create a new 'Standard EXE' project, it has a form already there named 'Form1'
Title: Re: Console Chatbot (Sending Messages)
Post by: Eric on May 30, 2005, 07:51 PM
Quote from: UserLoser on May 30, 2005, 07:34 PM
Quote from: LoRd[nK] on May 30, 2005, 07:08 PM
Quote from: Forged on May 30, 2005, 05:37 PM
By default all vb programs still have a form

No they don't.

I think he means with default VB IDE settings, when you create a new 'Standard EXE' project, it has a form already there named 'Form1'

Yes, but you don't have to use it... or even bother to hide it; just remove it and set the program to start in main().

I don't really see a point in adding a window to a console program... you can type directly from a console and by adding a window you'd defeat the purpose of using a console at all.
Title: Re: Console Chatbot (Sending Messages)
Post by: NicoQwertyu on May 30, 2005, 11:00 PM
I believe what you want done can be accomplished, without creating threads, by using WaitForMultipleObjects() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/waitformultipleobjects.asp) -- along with the console's stdin and socket's handles.

Edit: Actually, I think you'd need to use select(), because WaitForMultipleObjects doesn't allow socket descriptors.
Title: Re: Console Chatbot (Sending Messages)
Post by: UserLoser. on May 30, 2005, 11:48 PM
Use a message or network loop?  It's quite easily possible to 'trick' VB into executing a non-stop loop using DoEvents as a your message loop while still performing other functions.
Title: Re: Console Chatbot (Sending Messages)
Post by: Forged on May 31, 2005, 10:29 AM
Quote from: LoRd[nK] on May 30, 2005, 07:51 PM
Quote from: UserLoser on May 30, 2005, 07:34 PM
Quote from: LoRd[nK] on May 30, 2005, 07:08 PM
Quote from: Forged on May 30, 2005, 05:37 PM
By default all vb programs still have a form

No they don't.

I think he means with default VB IDE settings, when you create a new 'Standard EXE' project, it has a form already there named 'Form1'

Right, but he has been stupified by your responses to his question.

Yes, but you don't have to use it... or even bother to hide it; just remove it and set the program to start in main().

I don't really see a point in adding a window to a console program... you can type directly from a console and by adding a window you'd defeat the purpose of using a console at all.
Title: Re: Console Chatbot (Sending Messages)
Post by: Joe[x86] on June 02, 2005, 11:53 AM
Aha, DoEvents. THANK YOU USERLOSER!!! <33.

Thanks to everyone else who tried to help too. <33.
Title: Re: Console Chatbot (Sending Messages)
Post by: Mephisto on June 03, 2005, 04:51 PM
My way of doing it (though C++ oriented, you could do it in VB I think).

I have not tested it yet, but I believe with the API MsgWaitForMultipleObjects(...) you can wait on STD output handles, which in turn could allow you to actively be in a state of accepting console text, which you can have the user input and then send those to battle.net when that handle triggers.

You could also create a new thread dedicated to Battle.net message I/O.  Have it wait for user input, send the message, display the results, and repeat.
Title: Re: Console Chatbot (Sending Messages)
Post by: NicoQwertyu on June 03, 2005, 09:41 PM
Quote from: NicoQwertyu on May 30, 2005, 11:00 PM
I believe what you want done can be accomplished, without creating threads, by using WaitForMultipleObjects() (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/waitformultipleobjects.asp) -- along with the console's stdin and socket's handles.

Edit: Actually, I think you'd need to use select(), because WaitForMultipleObjects doesn't allow socket descriptors.