Irc Client

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Morgoth.

I found on this Forum a source for a Irc Client by Ricardoviewtopic.php?t=4398">http://forums.pur ... rc/clients
ERROR :Closing Link: PureBasicUser18 by barrysworld2.uk.quakenet.org (Ping Timeout)

Does anyone knows, why?

Morgoth
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

I receive you e mail, just give me a break to reinstall my PC because i have a crash!!!


Best Regards

Ricardo

Dont cry for me Argentina...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Morgoth.

I suppose, that one error is caused by your PING-PONG as in your source you answer with PONG only, but Qnet exspects /QOUTE PONG xxxxxx. The other things is i suppose a missing identd server, but i don't know how an identd server works.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Morgoth.

Here is a basic, but fully working Irc-Client, made by me.
;-Consts
#chat=1
#chatmessage=2
#connect=3
#nick=4
#name=5
#server=6
#port=7
#os=8
#idendtport=9
#servertext=10
#porttext=11
#userid=12
#useridtext=13
#ostext=14
#idendtporttext=15
#nicktext=16
#nametext=17
#connect=18

;-Variable
maxbuffer.l=10000
*Buffer=AllocateMemory(0,maxbuffer,0)
TextBuffer = AllocateMemory(1, 100, 0)
EOL.s = Chr(13)+ Chr(10)

;-Network initalisation
Ergebnis = InitNetwork()

;-Window Creation
WindowID= OpenWindow(0, 0, 0, 800,540, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget, "bIRC")
If WindowID
If CreateGadgetList(WindowID)
OpenRichEdit(WindowID, 0, 0, 0, 800, 400, "")
hstring= StringGadget(#chatmessage,-1,402,800,20,"")

StringGadget(#server,50,445,100,20,"irc.inter.net.il")
StringGadget(#port,50,475,100,20,"6667")
TextGadget(#servertext,10,448,33,20,"Server")
TextGadget(#porttext,10,478,33,20,"Port")

StringGadget(#userid,220,445,100,20,"anym")
StringGadget(#os,220,475,100,20,"Windoof")
StringGadget(#idendtport,220,505,100,20,"113")
TextGadget(#servertext,170,448,50,20,"User Id")
TextGadget(#ostext,170,478,50,20,"System")
TextGadget(#idendtporttext,170,508,50,20,"Port")

StringGadget(#nick,380,445,100,20,"Morgoth[1]")
StringGadget(#name,380,475,100,20,"anym")
TextGadget(#nicktext,340,448,33,20,"Nick")
TextGadget(#nametext,340,478,33,20,"Name")

ButtonGadget(#connect,500,445,280,85,"Connect")

AddKeyboardShortcut(0,#PB_Shortcut_Return,111)
EndIf

;-Main Loop
Repeat
EventID = WindowEvent()
If connectionid 0
CEvent.l = NetworkClientEvent(ConnectionID)
EndIf
If screate0
SEvent.l = NetworkServerEvent()
EndIf

;-Login
If ConnectionID
If con=0
;USER
;At the beginning comes the USER commando. With which following parameters are determined
;1 The Name, which will appear before the host. [Nick!~@Hostname]
;2 The own hostname, for example localhost
;3 The serverhost, which you are connect to, for example irc.inter.net.il
;4 The name, which is shown next to the nick, after the command whois, for example Max Mustermann
;None of these paramteres is really important for successful connecting. 2 and 3 can be select arbitrarily, but they must exsist. 1 and 4 should be select individual.
text.s="USER "+GetGadgetText(#userid)+" localhost "+GetGadgetText(#server)+" "+GetGadgetText(#name)+EOL
PokeS(*Buffer,text,Len(text))
SendNetworkData(ConnectionID,*Buffer,Len(text))

;NICK
;Um die Connection zu vollenden, muss man sich nun noch seinen Nickname auswählen.
;Hinweis. Auch später kann man dieses Kommado noch benutzen, um seinen Nickname zu ändern.

;NICK
;To finish connection successfully, you have to select your nick.
;Hint. Also later you can use this command, to change your Nick.
text.s="NICK "+GetGadgetText(#nick)+EOL
PokeS(*Buffer,text,Len(text))
SendNetworkData(ConnectionID,*Buffer,Len(text))

con=1
EndIf
EndIf



If CEvent Or SEvent Or EventID
If EventID = #PB_EventMenu
MenuID=EventMenuID()
Select MenuID
;-Return is pushed
Case 111
Select GetFocus_()
Case hstring
If Trim(GetGadgetText(#chatmessage))""
SetRichEditText(0,-1,-1,text+Chr(13)+Chr(10))
RichEditLocate(0,1000)
text.s=GetGadgetText(#chatmessage)+EOL
PokeS(*Buffer,text,Len(text))
SendNetworkData(ConnectionID,*Buffer,Len(text))
EndIf
SetGadgetText(#chatmessage,"")
EndSelect
EndSelect

EndIf

If EventID=#PB_Event_Gadget
GadgetID=EventGadgetID()
Select GadgetID
Case #connect
;-Connecting
;At first shut down old connection, reset variables and then new connection.
con=0
If k = 1
CloseNetworkConnection(ConnectionID)
ConnectionID=0
CloseNetworkServer()
screate=0
EndIf
k=1
ConnectionID = OpenNetworkConnection(GetGadgetText(#server), Val(GetGadgetText(#port)))
screate=CreateNetworkServer(113)
EndSelect
EndIf
;-Clientevents
Select CEvent
Case 0

Case 2
;-Receiving datas
length=ReceiveNetworkData(ConnectionID,*Buffer,10000)
text.s=PeekS(*Buffer,length)
SetRichEditText(0,-1,-1,text+Chr(13)+Chr(10))
RichEditLocate(0,1000)
;-PING
; Nearly each Protocol has Ping -Pong procedure, to see for example, if an client has lost his connection.
; PING
;He asks with this Ping, if you are still connected and waits for your answer.
; PONG
;so for example PONG irc.fu-berlin.de, when before a PING irc.fu-berlin.de has been received. If no Pong has received by server, the connection will be closed by the server.
If FindString(text,"PING",1)0
text.s=ReplaceString(text,"PING :", "PONG :",1)+EOL
PokeS(*Buffer,text,Len(text))
SendNetworkData(ConnectionID,*Buffer,Len(text))
SetRichEditText(0,-1,-1,text+Chr(13)+Chr(10))
RichEditLocate(0,1000)
EndIf

Case 3

EndSelect

;-Serverevents(Idendtserver)
;Many IRC Server desire that one sends Idendt Datas. so you have to open a server on Port 113.
; The Irc server will connect to you and send something like 29470 , 6667
; You have to answer for example with 29470 , 6667 : USERID : Windoof : anym

Select SEvent
If screate 0
ClientID = NetworkClientID()
EndIf

Case 1
;Sign that the Irc Server has connected
SetRichEditText(0,-1,-1,Str(clientid)+Chr(13)+Chr(10))
RichEditLocate(0,1000)

Case 2
;Receive and send
length=ReceiveNetworkData(ClientID,*Buffer,1000)
text.s=PeekS(*Buffer,length)
SetRichEditText(0,-1,-1,text+Chr(13)+Chr(10))
RichEditLocate(0,1000)
text.s= Mid(text,1,12)+" : USERID : "+GetGadgetText(#os)+" : "+GetGadgetText(#userid)+EOL
PokeS(*Buffer,text,Len(text))
SendNetworkData(ClientID,*Buffer,Len(text))
SetRichEditText(0,-1,-1,text+Chr(13)+Chr(10))
RichEditLocate(0,1000)
EndSelect

If EventID = #PB_EventCloseWindow
If EventWindowID() =0
End
EndIf
EndIf
Else
Delay(10)
EndIf
ForEver
EndIf
Post Reply