June 29, 2022, 01:48:16 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


IRC troubles

Started by WayneA, December 17, 2009, 05:12:15 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

WayneA

Ever since the last post here about someone writing an IRC client, I have been working on my own IRC client off and on. I've done enough tweeking and research without success now that I doubt I'll ever figure this out on my own  :-\

I seemingly have the basic idea of writing a simple IRC client down since I've written 3, one each in 3 other BASIC dialects. One of those being VB6 and the other two are syntacticly very similar. I've noticed some IRC servers are more picky about what they want the client to say to them, however irc.freenode.net and irc.wildirc.net are both pretty loose and my other IRC clients easily connect and communicate with them so I have been stuck with them only when testing my EB client.

My latest attempt is below. What I'm expecting is to tell it my username, pick a nick and just connect to a channel, however I'm only able to connect and after that its almost like the server isn't getting my messages at all.

$Define USER "USER random9090 \"localhost\" \"whatever\" :blarg\n"
$Define NICK "NICK random9090\n"
$Define SERVER "irc.wildirc.net"
$Define PORT 6667
$Define JOIN "JOIN #test\n"
AutoDefine "Off"
SetID "SckMessage",0xBBBB
Declare Import,GetSysColor(nIndex As Int),Int
Dim wndMain As Window
Dim ircsck,scksts As Int
OpenWindow wndMain,0,0,500,500,@MinBox,0,"IRC",&wndMainProc
SetWindowColor wndMain,GetSysColor(15)
WaitUntil wndMain=0
NCSCloseSocket(ircsck)
NCSFree()
End

Sub wndMainProc
Dim l,t,h,w As Int
Dim buff[1024] As IString
Select @Class
Case @IDCreate
GetClientSize wndMain,l,t,h,w
Control wndMain,@Edit,"",8,8,w,h-60,@Border|@CTEditMulti|@VScroll|@CTEditAutoV|@CTEditRO,1
Control wndMain,@Edit,"",8,h-50,w,25,@Border|@CTEditAutoH,2
scksts=NCSInit(1,0)
If scksts<0 Then
Out("Error: scksts=NCSInit(1,0):")
Out(NCSGetErrorText())
Return
Else
scksts=NCSConnectToServer(SERVER,PORT)
If scksts<0 Then
Out("Error: scksts=NCSConnectToServer(SERVER,PORT):")
Out(NCSGetErrorText())
Return
Else
ircsck=scksts
Out("Connected to "+SERVER+":"+Str$(PORT)+".")
scksts=NCSOnDataMessage(wndMain.hWnd,ircsck,@SckMessage)
If scksts<0 Then
Out("Error: NCSOnDataMessage(wndMain.hWnd,ircsck,@SckMessage)")
Out(NCSGetErrorText())
Return
EndIf
EndIf
EndIf
NCSSendData(ircsck,USER,Len(User))
NCSSendData(ircsck,NICK,Len(User))
NCSSendData(ircsck,JOIN,Len(Join))
Case @SckMessage
scksts=NCSReadData(ircsck,buff,1023,2000)
If scksts>0
buff[scksts]=0
Out(buff)
EndIf
Case @IDCloseWindow
CloseWindow wndMain
EndSelect
Return
EndSub

Sub Out(o As String)
Dim ln=Len(GetControlText(wndMain,1))+Len(o) As Int
SetControlText wndMain,1,GetControlText(wndMain,1)+o+"\n"
ControlCMD wndMain,1,@EDSetSelection,ln,ln
Return
EndSub


What am I doing wrong here?
99 little bugs in the code,
99 bugs in the code,
Fix one bug,
Compile again,
104 little bugs in the code...

All code I post is in the public domain.

chris

i'm not sure what the problem is, with my client i used the irc example paul has for sale. Maybe try looking at that?

WayneA

I was forced to purchase 2 licenses for emergence basic because of the changes to how Paul is licensing his products and the license I have for aurora is near useless because the previous freeware edition of it is a more (though not as much as the new licensed version) updated version than the one I purchased.

I am unwilling to also pay $25 (more than the current cost for an emergence basic license) for the source to an IRC client just so I could get some support on the support forums that I paid to have access too (with my multiple Ionic Wind product licenses).

Also I am currently unemployed and temporarily disabled so I couldn't afford it even if I was so inclined to purchase it.
99 little bugs in the code,
99 bugs in the code,
Fix one bug,
Compile again,
104 little bugs in the code...

All code I post is in the public domain.

J B Wood (Zumwalt)

Exactly where does it fail?
I am on vacation until the 28'th maybe I can help.

WayneA

It appears that none of the data I am sending to the server is being received, the server doesn't even tell me that I sent an invalid command it just tells me it hasn't received anything at all and eventually disconnects. This happens even though all indications are that the send functions were sucessful and even when I have spammed the server with the register info dozens of times in a loop.
99 little bugs in the code,
99 bugs in the code,
Fix one bug,
Compile again,
104 little bugs in the code...

All code I post is in the public domain.

J B Wood (Zumwalt)

Well, from what I know about networking and I will give your code a try here shortly, is that the server needs to know when the data has finished by some means, either the packet buffer has met its size or some trigger states that the client is through sending to the server, so as long as the send command actually does send the data, the server should receive that data into a buffer then go through your case statement to determine what it belongs to, so maybe the message is never seen as completed on the server. Just got ma lazy butt out of bed, looking at the code and seeing what it does or what it doesn't do.

Copex

December 19, 2009, 03:57:48 AM #6 Last Edit: December 19, 2009, 04:25:59 AM by Copex
Quote from: WayneA on December 18, 2009, 01:10:03 PM
It appears that none of the data I am sending to the server is being received, the server doesn't even tell me that I sent an invalid command it just tells me it hasn't received anything at all and eventually disconnects. This happens even though all indications are that the send functions were sucessful and even when I have spammed the server with the register info dozens of times in a loop.

i have ran the code through a network monitor the data is been sent on port 6667 i can see the nick and user requests packets been sent. it seems the buffer is not been cleared

you send the first request nick then the second request you can see the nick as well as the user data in the secon headder. adding a 10ms pause after each send request seem to sort it out 
-
I really should learn how to use a spell checker! though im not sure how it will help someone who can not spell?
-
Except where otherwise noted, content Posted By Copex is
licensed under a Creative Commons Attribution 3.0 License

http://creativecommons.org/licenses/by/3.0/

Copex

December 19, 2009, 05:11:58 AM #7 Last Edit: December 20, 2009, 02:57:33 AM by Copex
Your problem is you are not sending LF & CR
-
I really should learn how to use a spell checker! though im not sure how it will help someone who can not spell?
-
Except where otherwise noted, content Posted By Copex is
licensed under a Creative Commons Attribution 3.0 License

http://creativecommons.org/licenses/by/3.0/

J B Wood (Zumwalt)

December 19, 2009, 01:24:35 PM #8 Last Edit: December 19, 2009, 01:29:57 PM by Jonathan (zumwalt) Wood
Append the line feed and return to the end of your messages, that should fix that problem.
I didn't look at the packets themself like Copex did, so I switched to the NCS_chat_client and the NCS_chat_server and tested those, which works, by the way, use ports higher than 10,000 I always typically start the server in the 10xxx range and the clients in the 11xxx range myself.

Grab the code from here, also, make sure your firewall has the port open or it will fail, the server is dedicated, so start 2 instances of the client to chat between them.

WayneA

I believe that the \n escape sequence appends the CRLF, which is in the initial code I posted.

If it was modified in a way that it now works, can that working code be posted? Also, I inserted some 10ms sleeps without any benefit.

Thanks for all the help so far guys!
99 little bugs in the code,
99 bugs in the code,
Fix one bug,
Compile again,
104 little bugs in the code...

All code I post is in the public domain.

Copex

December 20, 2009, 07:11:25 AM #10 Last Edit: December 20, 2009, 09:03:27 AM by Copex
Quote from: WayneA on December 20, 2009, 03:56:11 AM
I believe that the \n escape sequence appends the CRLF, which is in the initial code I posted.

If it was modified in a way that it now works, can that working code be posted? Also, I inserted some 10ms sleeps without any benefit.

Thanks for all the help so far guys!

\n = linefeed (newline) you also nead to send a CR (carage return) so in C you would write "\n\r" at the end of each line but EB dose not support \r so you could use "\n" +chr$(13) or  +chr$(10)+chr$(13)

the join command dont work, but it connects to the server and you can send a private message to the user and it is displayed on screen, no offence i would have to rewrit it from scratch to get it to work correctly
im realy bad when it comes to other peoples code, just wanted to prove the CR was all the code required, so i edited you code so it would connect to a server.

i change the server to freenode to test, wildirc connects and you get a PING from the server. im not sure why the join command dont work but atleast it now connects,


DECLARE "kernel32",Sleep(dwMilliseconds:INT)

string USER = "USER random9090 \"localhost\" \"whatever\" :blarg\n"+chr$(13)
STRING NICK = "NICK random9090\n"+chr$(13)
$Define SERVER "irc.freenode.net"
$Define PORT 6667
string JOIN = "JOIN #randomroom909090\n"+chr$(13)
AutoDefine "Off"
SetID "SckMessage",0xBBBB
Declare Import,GetSysColor(nIndex As Int),Int
Dim wndMain As Window
Dim ircsck,scksts As Int
OpenWindow wndMain,0,0,500,500,@MinBox,0,"IRC",&wndMainProc
SetWindowColor wndMain,GetSysColor(15)
WaitUntil wndMain=0
NCSCloseSocket(ircsck)
NCSFree()
End

Sub wndMainProc
Dim l,t,h,w As Int
Dim buff[1024] As IString
Select @Class
Case @IDCreate
GetClientSize wndMain,l,t,h,w
Control wndMain,@Edit,"",8,8,w,h-60,@Border|@CTEditMulti|@VScroll|@CTEditAutoV|@CTEditRO,1
Control wndMain,@Edit,"",8,h-50,w,25,@Border|@CTEditAutoH,2
scksts=NCSInit(1,0)
If scksts<0 Then
Out("Error: scksts=NCSInit(1,0):")
Out(NCSGetErrorText())
Return
Else
scksts=NCSConnectToServer(SERVER,PORT)
If scksts<0 Then
Out("Error: scksts=NCSConnectToServer(SERVER,PORT):")
Out(NCSGetErrorText())
Return
Else
ircsck=scksts
Out("Connected to "+SERVER+":"+Str$(PORT)+".")
scksts=NCSOnDataMessage(wndMain.hWnd,ircsck,@SckMessage)
If scksts<0 Then
Out("Error: NCSOnDataMessage(wndMain.hWnd,ircsck,@SckMessage)")
Out(NCSGetErrorText())
Return
EndIf
EndIf
EndIf
sleep(10)
NCSSendData(ircsck,USER,Len(User))
sleep(10)
NCSSendData(ircsck,NICK,Len(User))
sleep(10)

Case @SckMessage
scksts=NCSReadData(ircsck,buff,1023,2000)

If scksts>0
buff[scksts]=0
Out(buff)
EndIf
Case @IDCloseWindow
CloseWindow wndMain
EndSelect
Return
EndSub

Sub Out(o As String)
Dim ln=Len(GetControlText(wndMain,1))+Len(o) As Int
SetControlText wndMain,1,GetControlText(wndMain,1)+o+"\n"
ControlCMD wndMain,1,@EDSetSelection,ln,ln
Return
EndSub

-
I really should learn how to use a spell checker! though im not sure how it will help someone who can not spell?
-
Except where otherwise noted, content Posted By Copex is
licensed under a Creative Commons Attribution 3.0 License

http://creativecommons.org/licenses/by/3.0/