{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, SysUtils, CustApp
{ you can add units after this }
, crt, Graph
;
type
StringArray= Array of String;
{ TLNETServer }
TLNETServer = class(TCustomApplication)
protected
procedure DoRun; override;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure WriteHelp; virtual;
procedure RunOnce();
private
RanOnce: Boolean;
end;
//procedure updateText(newText: String);
{ TLNETServer }
var
address: String;
port: Integer;
currentInputString: String;
currentChar: Char;
consolelog: StringArray;
cmdBuffer: StringArray;
//Console Procedures
procedure removeLine(Y: tcrtcoord);
var
I: Integer;
begin
GotoXY(WindMinX, Y);
for I := WindMinX to WindMaxX do
begin
GotoXY(I, Y);
Write(' ');
end;
end;
procedure updateLog();
var
I: Integer;
logIndex: Integer;
currentRow: Integer;
maxRow: Integer;
begin
if Length(consolelog) > 0 then
begin
maxRow := WindMaxY - 1;
for I := maxRow downto WindMinY do
begin
logIndex := maxRow - I;
if logIndex >= Low(consolelog) then
begin
GotoXY(WindMinX,I);
Write(consolelog[logIndex]);
end;
end;
end;
end;
procedure logMessage(msg: String);
begin
SetLength(consolelog,Length(consolelog)+1);
consolelog[High(consolelog)] := msg;
updateLog();
end;
procedure updateText(newText: String);
begin
GotoXY(WindMinX,WindMaxY);
DelLine;
Write(newText);
end;
procedure checkKeyInput();
begin
if KeyPressed then
begin
currentChar := ReadKey;
if currentChar = #0 then
begin
currentChar := ReadKey;
//WriteLn('SPECIAL KEY: '+inttostr(Ord(currentChar)));
end
else
begin
if (Ord(currentChar) < 32) and (Ord(currentChar) <> 0) then
begin
case Ord(currentChar) of
8: begin
if Length(currentInputString) > 0 then
Delete(currentInputString,Length(currentInputString)-1,1);
updateText(currentInputString);
end;
13: begin
ClrScr;
//WriteLn('Command: '+currentInputString);
logMessage(currentInputString);
currentInputString := '';
updateText(currentInputString);
end
else
begin
Write(Char(7));
updateText(currentInputString);
end;
end;
end
else
begin
currentInputString := currentInputString + currentChar;
//WriteLn('NORMAL KEY: '+inttostr(Ord(currentChar))+' ('+currentChar+')');
updateText(currentInputString);
end;
end;
end;
end;
procedure TLNETServer.DoRun;
var
ErrorMsg: String;
begin
// quick check parameters
ErrorMsg:=CheckOptions('ha:p:','help address: port:');
if ErrorMsg<>'' then begin
WriteLn(ErrorMsg);
ShowException(Exception.Create(ErrorMsg));
Terminate;
Exit;
end;
// parse parameters
if HasOption('h', 'help') then begin
WriteHelp;
Terminate;
Exit;
end;
if HasOption('a', 'address') then begin
writeln('found option address(a) with argument '+GetOptionValue('a','address'));
readln;
end;
if RanOnce = false then
RunOnce();
if HasOption('p', 'port') then begin
writeln('found option port(p) with argument '+GetOptionValue('p','port'));
ReadLn;
end;
{ add your program here }
checkKeyInput();
// stop program loop
//Terminate;
end;
constructor TLNETServer.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException:=True;
end;
destructor TLNETServer.Destroy;
begin
inherited Destroy;
end;
procedure TLNETServer.WriteHelp;
begin
{ add your help code here }
writeln('Usage: ', ExeName, ' -h');
end;
procedure TLNETServer.RunOnce;
begin
WriteLn(inttostr(WindMinX));
ReadLn;
ClrScr;
GotoXY(WindMinX,1);
Write('ConsoleApplication.Size: '+inttostr(ConsoleApplication.Size));
GotoXY(WindMinX,2);
Write('Graph.getMaxX: '+inttostr(Graph.GetMaxX));
GotoXY(WindMinX,3);
Write('crt.WindMinX: '+inttostr(crt.WindMinX));
GotoXY(WindMinX,4);
Write('crt.WindMinY: '+inttostr(crt.WindMinY));
GotoXY(WindMinX,5);
Write('crt.WindMaxX: '+inttostr(crt.WindMaxX));
GotoXY(WindMinX,6);
Write('crt.WindMaxY: '+inttostr(crt.WindMaxY));
Read;
//crt.ClrScr();
GotoXY(1,3);
//Sleep(1000);
Write(' ');
removeLine(3);
Read;
{
ClrScr;
GotoXY(10,10);
Write('10,10');
GotoXY(70,20);
Write('70,20');
GotoXY(1,22);
Write('lol'); }
RanOnce := true;
end;
var
Application: TLNETServer;
begin
Application:=TLNETServer.Create(nil);
Application.Title:='lNetServer';
Application.Run;
Application.Free;
end.