home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
CUNIT_20
/
COMUNIT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-03-18
|
33KB
|
1,362 lines
Unit COMUNIT;
INTERFACE
Type CharSet = Set of Char;
UserRec = Record
Name: String[35]; { Name of the User online }
City: String[25]; { City where User lives }
TimeLeft: word; { Time user has left }
TimeOut : byte; { Inactivity time for user }
Ansi : Boolean; { Does the user support ANSI}
end;
var Port : byte; {comm port 0-3}
Baud : word; {current connect speed}
Online : boolean; {whether it's a local/remote login}
Mstatus : word; {Modem status, word}
Foreground: byte; {foreground color, so you can check and change...}
Background: byte; {background color so you can check and change...}
Stop : Boolean; {variable used for some stop procedures.}
ModemOnly : Boolean; {If True then output will only be sent to
the modem!}
SysopName : String; {Name of the System Operator}
ShowStatWin: Boolean;
User : UserRec;
Procedure Send(s: string); {modem equivalent of write}
Procedure SendLn(s: string); {modem equivalent of writeln}
Procedure ReadStr(var s : string;
len: byte); {read a string with max length = len}
Procedure ReadInt(var int: word;
len: byte); {read a word with max number of chars = len}
Procedure EditStr(var s : string;
len: byte); {edit a string with max length = len,
if the string s has a length > len then
len := length(s) !! }
Procedure PortColor(f: byte); {modem equivalent of textcolor}
Procedure PortBackGround(b: byte);{modem equivalent of textbackground}
Procedure ClrPortScr; {modem equivalent of clrscr}
Procedure ClrPortEol; {modem equivalent of clreol}
Procedure AutoAnsiDetect; {detect if remote has User.Ansi support}
Procedure PurgeInBuffer; {purge input buffer}
Procedure PortXY(x,y: byte); {modem equivalent of gotoXY}
Procedure DisplayFile(Fname: string;
StopKeys: CharSet;
PauseKeys: CharSet;
Var Ch : Char);
{display a file with hotkeys in set HotKeys}
Function WaitChar(Cset: CharSet): Char;
{waits till a key has been pressed in
Cset and returns that key}
Procedure InitTimes; {you MUST run this after assign the
User.TimeLeft, and User.TimeOut variables in order
for the unit to start counting down...}
Function PortX: byte; {modem equivalent of wherex}
Function PortY: byte; {modem equivalent of wherey}
Function ReadChar: Char; {modem equivalent of readch}
Function GetStatus: word; {returns modem status}
Function PortKeyPressed: Boolean;{modem equivalent of keypressed}
Procedure ResetCounter(num: byte;Col: byte);
{reset line counter to num lines
and with prompt color = col}
Procedure StopCounter; {stop the line counter.}
Procedure HangUp; {Hang up the modem!}
{Other helpfull functions and procedures}
Function Ms(l: longint): string; {convert a word to a string fast}
Function Rep(Ch: char;b: byte): string;
{Return a string with filled with Ch and
with length b}
Function UprCase(s: string): string;
{convert a string to uprcase}
Procedure Trim(var s: string); {Trim all leading and trailing #0 and #32}
Function Byte_Set(b,bit: byte): Boolean;
{Checks to see if bit is set in b}
Function Lz(w: word): String; {Aka Leading Zero, adds a 0 before one digit
numbers, handy for dates!}
Procedure Chat(Full: Boolean); {Full refers to FULL screen chat or normal
mode}
Procedure ShowSysopStatWin; {show sysop status window}
{This option isn't really finished yet, but
the part that is done works...}
Procedure Delay(Num: byte); {A replacement for the Delay in the CRT
unit. This Delay works with seconds, and
it works in and outside of DV}
IMPLEMENTATION
{$M 5000, 0, 262144}
{$R-}
uses dos, crt,pdl, AnsiUnit;
const Esc = #27;
Fore: array[0..15] of string[5] = (
'[0;30', '[0;34', '[0;32', '[0;36', '[0;31', '[0;35', '[0;33', '[0;37',
'[1;30', '[1;34', '[1;32', '[1;36', '[1;31', '[1;35', '[1;33', '[1;37');
Back: array[0..7] of string[4] = (
';40m', ';44m', ';42m', ';46m', ';41m', ';45m', ';43m', ';47m');
Var StartTime,
EndTime ,
Inactivity,
InactLimit : Longint;
_2warned,
_1warned : boolean;
_Iwarned : Boolean;
_CountLine: boolean;
_LineCount: byte;
_PauseCount: byte;
_CheckTime : Boolean;
PromptColor: byte;
Procedure Delay(Num: byte);
var StopTime,
CurTime : Longint;
Regs : Registers;
begin
regs.ah := $00;
intr($1A,regs);
StopTime := regs.CX*65536 + regs.DX + (Num * 18);
if StopTime > $1800B0 then StopTime := StopTime - $1800B0;
Repeat
regs.ah := $00;
intr($1A,regs);
CurTime := regs.CX*65536 + regs.DX;
Until CurTime >= StopTime;
end;
Procedure ShowSysopStatWin;
begin
Window(1,24,80,25);
TextColor(Yellow);
TextBackGround(7);
ClrScr;
GotoXY(1,1);
Write(User.Name,', From ',User.City);
GotoXY(64,1);
Write('Baud: ',Baud);
GotoXY(1,2);
Write('Time left: ',User.TimeLeft);
Window(1,1,80,23);
TextAttr := 7;
end;
Function Lz(w: word): String;
var s: string;
begin
str(w,s);
if length(s) < 2 then s := '0'+s;
Lz := s;
end;
Function Byte_Set(b,bit: byte): Boolean;
var V: byte;
begin
V := 1 shl bit;
Byte_Set := V = V and b;
end;
Function GetBTime: Longint;
var regs: registers;
begin
fillchar(regs,sizeof(regs),$00);
intr($1A,regs);
GetBTime := Regs.cx*65536+Regs.dx;
end;
Procedure InitTimes;
begin
StartTime := GetBTime;
EndTime := (User.TimeLeft*60*18)+((User.TimeLeft*60*2) div 10)+GetBTime;
if EndTime > $1800B0 then EndTime := EndTime - $1800B0;
Inactivity := GetBTime;
InactLimit := User.TimeOut*60*18;
_CheckTime := True;
end;
Function Ms(l: longint): string;
var s: string;
begin
str(l,s);
Ms := s;
end;
Function Rep(Ch: Char;b: byte): string;
var s: string;
begin
fillchar(s,sizeof(s),Ch);
s[0] := chr(b);
Rep := s;
end;
Function UprCase(s: string): string;
var j: byte;
begin
for j := 1 to length(s) do
s[j] := upcase(s[j]);
UprCase := s;
end;
Function GetStatus: word;
var regs: registers;
begin
fillchar(regs,sizeof(regs),$00);
regs.AH := $03;
intr($14,regs);
GetStatus := regs.AH*256+regs.AL;
writeln(regs.ah);
end;
Procedure Trim(var s: string);
begin
While (s[1] in [' ',#0]) do Delete(s,1,1);
While (s[Length(s)] in [' ',#0]) do Delete(s,Length(s),1);
end;
Procedure CarrierLost;
begin
writeln('Carrier lost, returning to board...');
halt;
end;
Procedure CheckCarrier;
var regs: registers;
begin
fillchar(regs,sizeof(regs),$0);
regs.ah := $03;
regs.dx := port;
intr($14,regs);
if not byte_set(regs.al, 7) then CarrierLost;
end;
Procedure ResetCounter(num: byte;Col: byte);
begin
PromptColor := Col;
Stop := False;
_PauseCount := num;
_CountLine := True;
_LineCount := 0;
end;
Procedure StopCounter;
begin
_CountLine := False;
Stop := False;
end;
Procedure PromptContinue;
var cnt: byte;
s : string;
ch : char;
OldF: byte;
OldB: byte;
begin
OldF := Foreground;
OldB := BackGround;
PortColor(PromptColor);
PortBackground(0);
Send('More [Y/n]');
ch := #255;
repeat
if PortKeyPressed then Ch := ReadChar;
ch := upcase(ch);
until ch in [#13,'Y','N'];
Stop := ch = 'N';
_LineCount := 0;
Send(Rep(#08,10)+rep(#32,10)+rep(#08,10));
PortColor(OldF);
PortBackGround(OldB);
end;
Procedure ClickCounter;
begin
Inc(_LineCount);
if _Linecount = _PauseCount then PromptContinue;
end;
Procedure SendChar(ch: char);
var regs: registers;
begin
if Online then
begin
CheckCarrier;
fillchar(regs,sizeof(regs),$00);
regs.AH := $01;
regs.AL := ord(ch);
regs.DX := port;
intr($14,regs);
end;
if not ModemOnly then write(ch);
end;
Procedure Send(s: string);
var cnt: byte;
begin
for cnt := 1 to length(s) do
SendChar(s[cnt]);
end;
Procedure SendLn(s: string);
var cnt: byte;
begin
for cnt := 1 to length(s) do
SendChar(s[cnt]);
SendChar(#13);
SendChar(#10);
if _CountLine then ClickCounter;
end;
Procedure CheckTime;
var Now: Longint;
Dtime: Longint;
Itime: Longint;
OldFore,
OldBack : byte;
begin
if _CheckTime then
begin
Now := GetBTime;
if Now > EndTime then Dtime := $1800B0 - Now + EndTime else
Dtime := EndTime-now;
Itime := Now-InActivity;
if (Itime >= 3 * (InactLimit div 4)) and not _Iwarned then
begin
OldFore := Foreground;
OldBack := BackGround;
PortColor(12);
PortBackGround(0);
Sendln('');
Sendln('Hello?? You still alive??');
_Iwarned := True;
PortColor(OldFore);
PortBackGround(OldBack);
end;
if (Itime >= InactLimit) then
begin
OldFore := Foreground;
OldBack := BackGround;
PortColor(12);
PortBackGround(OldBack);
Sendln('');
SendLn('Inactivity time expired, returning to BBS!');
Halt;
end;
if (Dtime >= 2184) and (Dtime <= 3276) and not _2warned then
begin
OldFore := Foreground;
OldBack := BackGround;
PortColor(12);
PortBackGround(0);
Sendln('');
Sendln('Warning only 2 minutes left!');
_2warned := True;
PortColor(OldFore);
PortBackGround(OldBack);
end;
if (Dtime >= 1092) and (Dtime <= 2184) and not _1warned then
begin
OldFore := Foreground;
OldBack := BackGround;
PortColor(12);
PortBackGround(0);
Sendln('');
SendLn('Warning only 1 minute left!');
_1warned := True;
PortColor(OldFore);
PortBackGround(OldBack);
end;
if (Dtime < 500) then
begin
OldFore := Foreground;
OldBack := BackGround;
PortColor(12);
PortBackGround(0);
Sendln('');
SendLn('Less than 30 seconds left, returning to BBS');
Halt;
end;
end;
end;
Procedure PurgeInBuffer;
var regs: registers;
begin
fillchar(regs,sizeof(regs),$00);
regs.AH := $0A;
regs.DX := port;
intr($14,regs);
end;
Function PortPressed: Boolean;
var regs: registers;
begin
PortPressed := False;
fillchar(regs,sizeof(regs),$00);
if Online then
begin
regs.AH := $03;
regs.DX := port;
intr($14,regs);
PortPressed := Byte_Set(regs.ah,0);
if not Byte_Set(regs.al,7) then CarrierLost;
if Byte_Set(regs.ah,0) then Inactivity := GetBTime;
end;
end;
Function PortKeyPressed: Boolean;
Var Ok: Boolean;
begin
CheckTime;
Ok := Keypressed or PortPressed;
if Ok then
begin
_1warned := False;
_2warned := False;
end;
PortKeyPressed := Ok;
end;
Procedure JumpToDos;
Var Y: byte;
begin
PortColor(15);
PortBackGround(0);
sendln('');
Y := WhereY;
sendln('Sysop is jumping to DOS, please wait...');
textattr := 7;
ClrScr;
swapvectors;
exec(GetEnv('COMSPEC'),'');
swapvectors;
if ShowStatWin then ShowSysopStatWin;
PortXY(1,Y);
PortColor(15);
PortBackGround(0);
sendln('Sysop has returned, thank you for waiting.');
end;
Function ReadChar: char;
var regs: registers;
ch : char;
begin
if Online and PortPressed then
begin
CheckCarrier;
fillchar(regs,sizeof(regs),$00);
regs.AH := $02;
regs.DX := port;
intr($14,regs);
ReadChar := chr(regs.AL);
end else if keypressed then
begin
Ch := readkey;
if Ch = #0 then
begin
Ch := readkey;
case Ch of
#46: Chat(not LeftShift);
#35: HangUp;
#36: JumpToDos;
end;
ReadChar := #255;
end else ReadChar := Ch;
end;
end;
Procedure ReadStr(var s : string;
len: byte);
var ch: char;
begin
s := '';
ch := #0;
repeat
if PortKeyPressed then
begin
ch := ReadChar;
if (ch = #08) and (length(s) > 0) then
begin
delete(s,length(s),1);
Send(#08#32#08);
end;
if (ch = #0) then
begin
Ch := Readkey;
ch := #255;
end;
if (ch = #27) then
begin
if PortKeyPressed then Ch := ReadChar;
if Ch = '[' then if PortKeyPressed then Ch := ReadChar;
ch := #255;
end;
if (ch <> #08) and (ch <> #13) and (length(s) < len) and
(ch > #31) and (ch < #127) then
begin
s := s + ch;
Send(ch);
end;
end;
until (length(s) > len) or (ch = #13);
end;
Procedure ReadInt(var int: word;
len: byte);
var ch: char;
s : string;
code: integer;
begin
s := '';
ch := #0;
repeat
if PortKeyPressed then
begin
ch := ReadChar;
if (ch = #08) and (length(s) > 0) then
begin
delete(s,length(s),1);
Send(#08#32#08);
end;
if (ch <> #08) and (ch <> #13) and (length(s) < len) and
(ch > #47) and (ch < #58) then
begin
s := s + ch;
Send(ch);
end;
end;
until (length(s) > len) or (ch = #13);
val(s,int,code);
end;
Procedure EditStr(var s : string;
len: byte);
var ch: char;
begin
ch := #0;
Send(s);
if len < length(s) then len := length(s);
repeat
if PortKeyPressed then
begin
ch := ReadChar;
if (ch = #08) and (length(s) > 0) then
begin
delete(s,length(s),1);
Send(#08#32#08);
end;
if (ch <> #08) and (ch <> #13) and (length(s) < len) and
(ch > #31) and (ch < #127) then
begin
s := s + ch;
Send(ch);
end;
end;
until (length(s) > len) or (ch = #13);
end;
Procedure PortColor(f: byte);
begin
if (f < 16) and User.Ansi then
begin
TextColor(f);
Foreground := f;
ModemOnly := True;
if f < 8 then send(Esc+'[0m');
send(Esc+Fore[Foreground]+Back[BackGround]);
ModemOnly := False;
end;
end;
Procedure PortBackGround(b: byte);
begin
if (b < 8) and User.Ansi then
begin
TextBackGround(b);
Background := b;
ModemOnly := True;
send(Esc+'[0m');
send(Esc+Fore[Foreground]+Back[BackGround]);
ModemOnly := False;
end;
end;
Procedure ClrPortScr;
begin
ClrScr;
ModemOnly := True;
Send(Esc+'[2J');
ModemOnly := False;
end;
Procedure ClrPortEol;
begin
ClrEol;
ModemOnly := True;
If User.Ansi then Send(Esc+'[K');
ModemOnly := False;
end;
Procedure AutoAnsiDetect;
var ch: char;
j : longint;
begin
PurgeInBuffer;
User.Ansi := False;
if Online then
begin
ModemOnly := True;
Send(Esc+'[6n');
Send(Rep(#08,4));
ModemOnly := False;
Delay(1);
if PortPressed then
begin
Ch := ReadChar;
User.Ansi := Ch = 'R';
end;
end else User.Ansi := True;
end;
Procedure PortXY(x,y: byte);
begin
if not Online then
GotoXY(x,y)
else if User.Ansi then
begin
GotoXY(x,y);
ModemOnly := True;
Send(Esc+'['+ms(y)+';'+ms(x)+'H');
ModemOnly := False;
end else
begin
if y > WhereY then Send(Rep(#10,WhereY-y));
if x > WhereX then Send(Rep(#32,WhereX-x));
if x < WhereX then Send(Rep(#08,x-WhereX));
end;
end;
Procedure DisplayFile(Fname: string;
Stopkeys: CharSet;
PauseKeys: CharSet;
Var Ch : Char);
var f : file;
j : byte;
s : string;
nr : word;
Buf: array[1..10] of char;
IO : Byte;
Function HotKeyPressed: boolean;
Var Ch2: Char;
begin
HotKeyPressed := False;
if StopKeys <> [] then
if PortKeyPressed then
begin
Ch2 := Upcase(ReadChar);
if Ch2 in StopKeys then
begin
HotKeyPressed := True;
Ch := Ch2;
end;
end;
if PauseKeys <> [] then
if PortKeyPressed then
begin
Ch2 := Upcase(Readchar);
if Ch2 in PauseKeys then
begin
repeat until portkeypressed;
Ch2 := readchar;
end;
end;
end;
begin
if Fname <> '' then
begin
if Pos('.',Fname) > 0 then Delete(Fname,pos('.',Fname),4);
if User.Ansi then Fname := Fname + '.ANS' else Fname := Fname + '.ASC';
assign(f,Fname);
{$I-} reset(f,1); {$I+}
IO := IOresult;
if (IO <> 0) and User.Ansi then
begin
if User.Ansi then Fname := copy(Fname,1,pos('.',Fname))+'ASC';
{$I-} reset(f,1); {$I+}
IO := IOresult;
end;
If IO = 0 then
begin
ModemOnly := True;
repeat
s := '';
Blockread(f,Buf,10,nr);
For j := 1 to nr do
begin
Send(Buf[j]);
AnsiWrite(Buf[j]);
end;
Until (nr = 0) or HotKeyPressed;
ModemOnly := False;
Close(f);
end else writeln('Error: ',fname, ' not found');
end;
end;
Function PortX: byte;
begin
PortX := WhereX;
end;
Function PortY: byte;
begin
PortY := WhereY;
end;
Function WaitChar(Cset: CharSet): Char;
var ch: char;
begin
ch := #255;
repeat
if PortKeyPressed then Ch := ReadChar;
ch := Upcase(ch);
until ch in Cset;
WaitChar := Ch;
end;
Procedure HangUP;
var regs: registers;
begin
with Regs do
begin
Ah := $06;
Dx := Port;
Al := $00;
intr($14,regs);
end;
Halt;
end;
Procedure Chat(Full: Boolean);
Const InfoColor = 14;
SysopChat = 14;
UserChat = 3;
Var SysopScreen: Array[2..11] of String[80];
UserScreen : Array[13..22] of String[80];
NormalLine : String[80];
SysopX,SysopY: Byte;
UserX,UserY : Byte;
Ch : Char;
Procedure ScrollSysopScreen;
Var cnt: byte;
begin
For cnt := 2 to 6 do
SysopScreen[Cnt] := SysopScreen[Cnt+5];
For Cnt := 7 to 11 do
Fillchar(SysopScreen[Cnt],Sizeof(SysopScreen[Cnt]),0);
For Cnt := 11 downto 2 do
begin
PortXY(1,Cnt);
ClrPortEol;
if Cnt < 7 then
Sendln(SysopScreen[Cnt]);
end;
SysopY := 7;
end;
Procedure WrapSysopScreen;
Var cnt: byte;
begin
cnt := 81;
Repeat
dec(Cnt);
until (SysopScreen[SysopY-1][Cnt] = #32) or (Cnt = 1);
if cnt > 1 then
begin
SysopScreen[SysopY] := Copy(SysopScreen[SysopY-1],Cnt+1,80-Cnt);
Delete(SysopScreen[SysopY-1],Cnt,80-cnt);
PortXY(Cnt,SysopY-1);
Send(Rep(#32,81-Cnt));
PortXY(1,SysopY);
Send(SysopScreen[SysopY]);
end;
end;
Procedure ScrollUserScreen;
Var cnt: byte;
begin
For cnt := 13 to 17 do
UserScreen[Cnt] := UserScreen[Cnt+5];
For Cnt := 18 to 22 do
Fillchar(UserScreen[Cnt],Sizeof(UserScreen[Cnt]),0);
For Cnt := 22 downto 13 do
begin
PortXY(1,Cnt);
ClrPortEol;
if Cnt < 18 then
Sendln(UserScreen[Cnt]);
end;
UserY := 18;
end;
Procedure ClearSysopScreen;
var cnt : byte;
begin
for cnt := 2 to 11 do
Fillchar(SysopScreen[Cnt],sizeof(SysopScreen[cnt]),0);
For cnt := 11 downto 2 do
begin
PortXY(1,Cnt);
ClrPortEol;
end;
SysopY := 2;
end;
Procedure ClearUserScreen;
var cnt : byte;
begin
for cnt := 13 to 22 do
Fillchar(UserScreen[Cnt],sizeof(UserScreen[cnt]),0);
For cnt := 22 downto 13 do
begin
PortXY(1,Cnt);
ClrPortEol;
end;
UserY := 13;
end;
Procedure WrapUserScreen;
Var cnt: byte;
begin
cnt := 81;
Repeat
dec(Cnt);
until (UserScreen[UserY-1][Cnt] = #32) or (Cnt = 1);
if cnt > 1 then
begin
UserScreen[UserY] := Copy(UserScreen[UserY-1],Cnt+1,80-Cnt);
Delete(UserScreen[UserY-1],Cnt,80-cnt);
PortXY(Cnt,UserY-1);
Send(Rep(#32,81-Cnt));
PortXY(1,UserY);
Send(UserScreen[UserY]);
end;
end;
Procedure WordWrapNormal;
Var cnt: byte;
begin
cnt := 81;
Repeat
dec(Cnt);
until (NormalLine[Cnt] = #32) or (Cnt = 1);
if cnt > 1 then
begin
NormalLine := Copy(NormalLine,Cnt+1,80-Cnt);
PortXY(Cnt,WhereY);
Send(Rep(#32,81-Cnt));
Send(NormalLine);
end;
end;
Procedure RedrawScreen(Sysop: Boolean);
var cnt: byte;
begin
if Sysop then
begin
ModemOnly := True;
ClrScr;
TextColor(15);
TextBackGround(1);
ClrEol;
Write(#32+SysopName);
GotoXY(1,12);
ClrEol;
Write(#32+User.Name);
GotoXY(1,23);
ClrEol;
TextColor(14);
Write('Press Ctrl + R to re-draw screen and Ctrl + W to clear your screen');
TextBackGround(0);
GotoXY(1,2);
TextColor(14);
GotoXY(1,2);
For Cnt := 2 to SysopY do
Writeln(SysopScreen[Cnt]);
TextColor(3);
GotoXY(1,13);
For Cnt := 13 to UserY do
Writeln(UserScreen[Cnt]);
end else
begin
ClrPortScr;
PortColor(15);
PortBackGround(1);
ClrPortEol;
Send(#32+SysopName);
PortXY(1,12);
ClrPortEol;
Send(#32+User.Name);
PortXY(1,23);
ClrPortEol;
PortColor(14);
Send('Press Ctrl + R to re-draw screen and Ctrl + W to clear your screen');
PortBackGround(0);
PortXY(1,2);
PortColor(14);
PortXY(1,2);
For Cnt := 2 to SysopY do
Sendln(SysopScreen[Cnt]);
PortColor(3);
PortXY(1,13);
For Cnt := 13 to UserY do
Sendln(UserScreen[Cnt]);
end;
if Sysop then
PortXY(Length(SysopScreen[SysopY])+1,SysopY)
else
PortXY(Length(UserScreen[UserY])+1,UserY);
end;
Function ReadMChar: Char;
var regs: registers;
begin
CheckCarrier;
regs.AH := $02;
regs.DX := port;
intr($14,regs);
ReadMChar := chr(regs.AL);
end;
begin
Ch := #255;
PortColor(InfoColor);
PortBackGround(0);
Sendln('');
Sendln('');
Sendln('SysOp entering chat mode...');
if User.Ansi and Full then
begin
PortBackGround(0);
ClrPortScr;
PortColor(15);
PortBackGround(1);
ClrPortEol;
Send(#32+SysopName);
PortXY(1,12);
ClrPortEol;
Send(#32+User.Name);
PortXY(1,23);
ClrPortEol;
PortColor(14);
Send('Press Ctrl + R to re-draw screen and Ctrl + W to clear your screen');
PortBackGround(0);
PortXY(1,2);
SysopY := 2;
UserY := 13;
Fillchar(SysopScreen,sizeof(SysopScreen),0);
Fillchar(UserScreen ,sizeof(UserScreen) ,0);
Repeat
if KeyPressed then
begin
Ch := ReadKey;
if Ch = #0 then
begin
Ch := readkey;
case Ch of
#46: Chat(not LeftShift);
#35: HangUp;
#36: JumpToDos;
end;
end else
begin
if ForeGround <> SysopChat then PortColor(SysopChat);
PortXY(Length(SysopScreen[SysopY])+1,SysopY);
if (ch = #08) then
begin
if (Length(SysopScreen[SysopY]) = 0) and (SysopY > 2) then
begin
Dec(SysopY);
if Length(SysopScreen[SysopY]) = 80 then
begin
PortXY(80,SysopY);
Send(#32);
PortXY(80,SysopY);
end else
begin
PortXY(Length(SysopScreen[SysopY])+1,SysopY);
delete(SysopScreen[SysopY],length(SysopScreen[SysopY]),1);
Send(#08#32#08);
end;
end else if length(SysopScreen[SysopY]) > 0 then
begin
delete(SysopScreen[SysopY],length(SysopScreen[SysopY]),1);
Send(#08#32#08);
end;
end;
if (Ch > #27) and (Ch <> #255) Then
begin
SysopScreen[SysopY] := SysopScreen[SysopY] + ch;
Send(ch);
if Length(SysopScreen[SysopY]) = 80 then
begin
if SysopY = 11 then ScrollSysopScreen else
inc(SysopY);
if SysopScreen[SysopY-1][80] > #32 then WrapSysopScreen;
end;
end;
if Ch = #23 then
begin
ClearSysopScreen;
end;
if Ch = #18 then
RedrawScreen(True);
if Ch = #13 then
begin
if SysopY = 11 then ScrollSysopScreen else
Inc(SysopY);
PortXY(1,SysopY);
end;
end;
end;
if PortPressed then
begin
Ch := ReadMChar;
if ForeGround <> UserChat then PortColor(UserChat);
PortXY(Length(UserScreen[UserY])+1,UserY);
if (ch = #08) then
begin
if (Length(UserScreen[UserY]) = 0) and (UserY > 2) then
begin
Dec(UserY);
if Length(UserScreen[UserY]) = 80 then
begin
PortXY(80,UserY);
Send(#32);
PortXY(80,UserY);
end else
begin
PortXY(Length(UserScreen[UserY])+1,UserY);
delete(UserScreen[UserY],length(UserScreen[UserY]),1);
Send(#08#32#08);
end;
end else if length(UserScreen[UserY]) > 0 then
begin
delete(UserScreen[UserY],length(UserScreen[UserY]),1);
Send(#08#32#08);
end;
end;
if (ch = #0) then
begin
Ch := Readkey;
ch := #255;
end;
if (ch <> #08) and (ch <> #13) and (Ch > #27) and (Ch <> #255) Then
begin
UserScreen[UserY] := UserScreen[UserY] + ch;
Send(ch);
if Length(UserScreen[UserY]) = 80 then
begin
if UserY = 22 then ScrollUserScreen else
inc(UserY);
if UserScreen[UserY-1][80] > #32 then WrapUserScreen;
end;
end;
if Ch = #13 then
begin
if UserY = 22 then ScrollUserScreen else
Inc(UserY);
PortXY(1,UserY);
end;
if Ch = #18 then RedrawScreen(False);
if Ch = #23 then ClearUserScreen;
end;
until (ch = #27);
end else
begin
Sendln('Hi there, '+User.Name+' this is your Sysop.');
NormalLine := '';
Repeat
if KeyPressed then
begin
Ch := ReadKey;
if ForeGround <> SysopChat then PortColor(SysopChat);
if (ch = #08) and (length(NormalLine) > 0) then
begin
delete(NormalLine,length(NormalLine),1);
Send(#08#32#08);
end;
if (ch <> #08) and (ch <> #13) and (length(NormalLine) < 80) and
(ch > #31) and (ch < #127) then
begin
NormalLine := NormalLine + ch;
if Length(NormalLine) = 80 then WordWrapNormal;
Send(ch);
end;
if (Ch = #13) then
begin
Sendln('');
NormalLine := '';
end;
end;
if PortPressed then
begin
Ch := ReadMChar;
if ForeGround <> UserChat then PortColor(UserChat);
if (ch = #08) and (length(NormalLine) > 0) then
begin
delete(NormalLine,length(NormalLine),1);
Send(#08#32#08);
end;
if (ch <> #08) and (ch <> #13) and (length(NormalLine) < 80) and
(ch > #31) and (ch < #127) then
begin
NormalLine := NormalLine + ch;
if Length(NormalLine) = 80 then WordWrapNormal;
Send(ch);
end;
if (Ch = #13) then
begin
Sendln('');
NormalLine := '';
end;
if Ch = #27 then Ch := #255;
end;
Until Ch = #27;
end;
PortBackGround(0);
ClrPortScr;
PortColor(InfoColor);
Sendln('Chat mode ended.');
Sendln('');
end;
begin
_2warned := False;
_1warned := False;
_Iwarned := False;
User.Ansi := False;
port := 1;
foreground := 7;
background := 0;
ModemOnly := False;
_Countline := False;
_LineCount := 0;
_PauseCount := 0;
Stop := False;
_CheckTime := False;
ShowStatWin := True;
end.