unit banlist;
interface
uses
SysUtils, Classes;
type
PChannelBan = ^TChannelBan;
TChannelBan =
record
Nickname:
string;
Next: PChannelBan;
end;
TChannelBanList =
class(TObject)
private
FChannelBanNode: PChannelBan;
public
function IsBanned(
const ANickname:
string): Boolean;
procedure GetBanList(
var ChannelBanList: TStringList);
procedure Ban(
const ANickname:
string);
procedure Unban(
const ANickname:
string);
end;
implementation
function TChannelBanList.IsBanned(
const ANickname:
string): Boolean;
var
ChannelBan: PChannelBan;
begin
Result := False;
ChannelBan := FChannelBanNode;
while (ChannelBan <>
nil)
and (
not Result)
do
begin
if Lowercase(ANickname) = Lowercase(ChannelBan^.Nickname)
then
Result := True;
ChannelBan := ChannelBan^.Next;
end;
end;
procedure TChannelBanList.GetBanList(
var ChannelBanList: TStringList);
var
ChannelBan: PChannelBan;
begin
ChannelBan := FChannelBanNode;
while ChannelBan <>
nil do
begin
ChannelBanList.Add(ChannelBan^.Nickname);
ChannelBan := ChannelBan^.Next;
end;
end;
procedure TChannelBanList.Ban(
const ANickname:
string);
var
ChannelBan, TempPtr: PChannelBan;
begin
if not IsBanned(ANickname)
then
begin
New(ChannelBan);
ChannelBan^.Next :=
nil;
ChannelBan^.Nickname := ANickname;
if FChannelBanNode =
nil then
FChannelBanNode := ChannelBan
else
begin
TempPtr := FChannelBanNode;
while TempPtr^.Next <>
nil do
TempPtr := TempPtr^.Next;
TempPtr^.Next := ChannelBan;
end;
end;
end;
procedure TChannelBanList.Unban(
const ANickname:
string);
var
TempPtr, TempPtr2: PChannelBan;
begin
if IsBanned(ANickname)
then
begin
TempPtr := FChannelBanNode;
if FChannelBanNode^.Nickname = ANickname
then
begin
FChannelBanNode := TempPtr^.Next;
Dispose(TempPtr);
end else
begin
while not (TempPtr^.Next^.Nickname = ANickname)
do
TempPtr := TempPtr^.Next;
TempPtr2 := TempPtr^.Next;
TempPtr^.Next := TempPtr^.Next^.Next;
Dispose(TempPtr2);
end;
end;
end;