Building an IRC Client - Processing Server Commands
(Page 5 of 5 )
This event handler processes every single command that comes from the server.
procedure TForm1.IdIRC1ServerListReceived(ASender: TIdContext;
AServerList: TStrings);
var
i:integer;
begin
for i:= 0 to AServerList.Count-1 do begin
memo1.lines.add(AServerList.Strings[i]);
end;
end;
This event is fired when you receive a list of server names.
procedure TForm1.IdIRC1ServerWelcome(ASender: TIdContext;
AWelcomeInfo: TStrings);
var
i:integer;
begin
for i:= 0 to AWelcomeInfo.Count-1 do begin
memo1.lines.add(AWelcomeInfo.Strings[i]);
end;
end;
procedure TForm1.IdIRC1ServerVersion(ASender: TIdContext;
Version, Host,
Comments: String);
begin
memo1.Lines.Add(Version +'Host '+Host+'Comments '+Comments);
end;
procedure TForm1.Edit2Click(Sender: TObject);
begin
button1.Enabled:=true;
end;
procedure TForm1.Edit3Click(Sender: TObject);
begin
button1.Enabled:=true;
end;
procedure TForm1.IdIRC1MOTD(ASender: TIdContext; AMOTD:
TStrings);
var
i:integer;
begin
for i:= 0 to AMOTD.Count-1 do begin
memo1.lines.add(AMOTD.Strings[i]);
end;
end;
procedure TForm1.IdIRC1UserInfoReceived(ASender: TIdContext;
AUserInfo: TStrings);
var
i:integer;
begin
for i:= 0 to AUserInfo.Count-1 do begin
memo1.lines.add(AUserInfo.Strings[i]);
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
idIRC1.Join(edit3.text);
//after joining you can request the names of the channels here,
using the ListChannel() //function and then displaying the names
in a memo.
end;
procedure TForm1.IdIRC1NicknamesListReceived(ASender: TIdContext;
AChannel: String; ANicknameList: TStrings);
var
i:integer;
begin
memo1.Lines.Add('Nicknames in Channel: '+AChannel);
for i:= 0 to ANicknameList.Count-1 do begin
memo1.lines.add(ANicknameList.Strings[i]);
end;
end;
This event fires when you receive a list of nicknames in a channel. The list itself is returned by the ListChannelNicknames() procedure. You also get other info such as the channel name.
procedure TForm1.IdIRC1ServerUsersListReceived(ASender:
TIdContext;
AUsers: TStrings);
var
i:integer;
begin
for i:= 0 to AUsers.Count-1 do begin
memo1.lines.add(AUsers.Strings[i]);
end;
end;
procedure TForm1.IdIRC1NicknameError(ASender: TIdContext; AError:
Integer);
begin
//here you get the error number(stored in AError above) and find
the error that corresponds to the number.
end;
The last three procedures just make the GUI fun by setting the progress bar position whenever the client does any work.
procedure TForm1.IdIRC1Work(ASender: TObject; AWorkMode:
TWorkMode;
AWorkCount: Integer);
begin
progb.Position:=AWorkCount;
end;
procedure TForm1.IdIRC1WorkBegin(ASender: TObject; AWorkMode:
TWorkMode;
AWorkCountMax: Integer);
begin
progb.Max:=AWorkCountMax;
end;
procedure TForm1.IdIRC1WorkEnd(ASender: TObject; AWorkMode:
TWorkMode);
begin
progb.Position:=progb.Max;
end;
Below is a screen shot of the client in action:

Conclusion
I've shown you all the commands that this client application will implement. It is by no means all of the commands available, but it should give you the basis and inspiration to continue working through all the remaining commands.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |