unit mice_main;
interface
uses SysUtils,
ScktComp;
type
TMainApp =
class
private
public
procedure procMain;
procedure procError(intErrorID: integer);
procedure procParseCommandline(strRaw:
string);
function funcRunServer: integer;
end;
var MainApp : TMainApp;
ServerSocket: TServerSocket;
implementation
procedure TMainApp.procError(intErrorID: integer);
var strErrorMessage:
string;
begin
case intErrorID
of
0: strErrorMessage := '
error during server start'
else
strErrorMessage := '
unknown error';
end;
writeln('
! err: ['+inttostr(intErrorID)+'
] '+strErrorMessage);
end;
procedure TMainApp.procMain;
var intErr: integer;
begin
TMainApp.Create;
writeln('
> run mice');
intErr := funcRunServer;
if intErr <> 0
then procError(intErr)
else writeln('
> socket opened');
end;
function TMainApp.funcRunServer: integer;
begin
ServerSocket := TServerSocket.Create(
nil);
ServerSocket.Port := 1234;
ServerSocket.Open;
result := 0;
end;
procedure TMainApp.procParseCommandline(strRaw:
string);
var strCommand, strResult:
string;
begin
if pos(#32, strRaw)<>0
then
strCommand := LowerCase(copy(strRaw,0,pos(#32, strRaw)-1))
else strCommand := LowerCase(copy(strRaw,0,length(strRaw)));
if strCommand = '
info'
then
strResult := '
multi interface chat engine - (c) 2005 Michael Pawlik'
else if strCommand = '
send'
then
if ServerSocket.Active
then
ServerSocket.Socket.Connections[0].SendText('
test ^^')
else strResult := '
server is not active'
else if strCommand = '
status'
then
if ServerSocket.Active
then strResult := '
server is active on port '+inttostr(ServerSocket.Port)
else strResult := '
server is not active'
else if strCommand = '
open'
then
if not(ServerSocket.Active)
then begin
ServerSocket.Open;
strResult := '
socket opened'
end else
strResult := '
server is already active'
else if strCommand = '
close'
then
if ServerSocket.Active
then begin
ServerSocket.Close;
strResult := '
socket closed'
end else
strResult := '
server is not active'
else if strCommand = '
exit'
then
strResult := '
shutting down'
else strResult := '
unknown command: '+strCommand;
writeln('
> '+strResult);
end;
end.