{
Delphi IMC3 Client - Channel type and support routines
Based on client code by Samson of Alsherok.
$Id: imc3_chan.pas,v 1.1 2003/12/12 13:19:54 druid Exp $
}
unit imc3_chan;
interface
uses
Classes,
dtypes,
fsys,
LibXmlParser,
imc3_const;
type
GChannel_I3 = class
public
local_name : string;
host_mud : string;
I3_name : string;
layout_m, layout_e : string;
status : integer;
i3perm : integer;
history : TStringList;
flags : integer;
published
constructor Create();
procedure load(parser : TXmlParser);
procedure save(writer : GFileWriter);
procedure updateHistory(msg : string);
end;
var
chanList : GHashTable;
function findChannel(name : string) : GChannel_I3;
procedure loadChanList();
procedure saveChanList();
implementation
uses
SysUtils,
util;
constructor GChannel_I3.Create();
begin
inherited Create();
history := TStringList.Create();
end;
procedure GChannel_I3.load(parser : TXmlParser);
begin
while (parser.Scan()) do
case parser.CurPartType of // Here the parser tells you what it has found
ptStartTag:
begin
end;
ptContent:
begin
if (prep(parser.CurName) = 'NAME') then
I3_name := parser.CurContent
else
if (prep(parser.CurName) = 'MUD') then
host_mud := parser.CurContent;
end;
ptEndTag : // Process End-Tag here (Parser.CurName)
begin
if (prep(parser.CurName) = 'CHANNEL') then
exit;
end;
end;
end;
procedure GChannel_I3.save(writer : GFileWriter);
begin
writer.writeLine(' <channel status="' + IntToStr(status) + '">');
writer.writeLine(' <name>' + I3_name + '</name>');
writer.writeLine(' <mud>' + host_mud + '</mud>');
writer.writeLine(' </channel>');
end;
procedure GChannel_I3.updateHistory(msg : string);
var
hist : string;
begin
hist := '[' + FormatDateTime('hh:nn', Now) + '] ' + msg;
history.Add(hist);
if (history.count > MAX_I3HISTORY) then
history.Delete(0);
end;
function findChannel(name : string) : GChannel_I3;
begin
Result := GChannel_I3(chanList.get(name));
end;
procedure loadChanList();
var
parser : TXmlParser;
channel : GChannel_I3;
begin
if (not FileExists(I3_CHANLIST_FILE)) then
exit;
parser := TXmlParser.Create();
parser.Normalize := true;
parser.LoadFromFile(I3_CHANLIST_FILE);
parser.StartScan();
while (parser.Scan()) do
case parser.CurPartType of // Here the parser tells you what it has found
ptStartTag:
begin
if (prep(parser.CurName) = 'CHANNEL') then
begin
channel := GChannel_I3.Create();
channel.status := StrToIntDef(parser.CurAttr.Value(0), 0);
channel.load(parser);
chanList.put(channel.I3_name, channel);
end;
end;
end;
parser.Free();
end;
procedure saveChanList();
var
iterator : GIterator;
channel : GChannel_I3;
writer : GFileWriter;
begin
iterator := chanList.iterator();
writer := GFileWriter.Create(I3_CHANLIST_FILE);
writer.writeLine('<?xml version="1.0"?>');
writer.writeLine('<!-- InterMud 3 ChanList -->');
writer.writeLine('<!-- Autogenerated, do not manually edit -->');
writer.writeLine('<chanlist>');
while (iterator.hasNext()) do
begin
channel := GChannel_I3(iterator.next());
channel.save(writer);
end;
writer.writeLine('</chanlist>');
writer.Free();
iterator.Free();
end;
begin
chanList := GHashTable.Create(256);
loadChanList();
end.