unit GUI;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ScktComp, uHash;
type
TFenster =
class(TForm)
TextAus: TMemo;
TextEin: TMemo;
ListBoxOn: TListBox;
PanelAn: TPanel;
Status: TMemo;
LabeledEditName: TLabeledEdit;
LabeledEditPW: TLabeledEdit;
ButtonOn: TButton;
ClientSocket: TClientSocket;
CheckBoxNew: TCheckBox;
Timer: TTimer;
PanelSever: TPanel;
ComboBoxServer: TComboBox;
ButtonStart: TButton;
CheckBoxFH: TCheckBox;
procedure ShowApplication;
procedure vCO(text:
string);
procedure vPW(text:
string);
procedure vLI(text:
string);
procedure vTE(text:
string);
procedure ButtonOnClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ClientSocketDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocketConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure TimerTimer(Sender: TObject);
procedure ClientSocketError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure LabeledEditNameKeyPress(Sender: TObject;
var Key: Char);
procedure LabeledEditPWKeyPress(Sender: TObject;
var Key: Char);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
procedure TextEinKeyPress(Sender: TObject;
var Key: Char);
procedure ButtonStartClick(Sender: TObject);
procedure TextAusChange(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Fenster: TFenster;
NName:
String;
CO:
String;
pw:
string;
implementation
{$R *.dfm}
procedure TFenster.ButtonOnClick(Sender: TObject);
var hash:
String;
begin
if (LabeledEditName.Text<>'
')
and (pw<>'
')
then
begin
hash:=uHash.hash(PW,19,2141);
pw:='
';
if CheckBoxNew.Checked
then
ClientSocket.Socket.SendText('
NE'+LabeledEditName.Text+'
|'+hash+'
|'+CO)
else
ClientSocket.Socket.SendText('
AN'+LabeledEditName.Text+'
|'+hash+'
|'+CO);
LabeledEditPW.Text:='
';
end
else
showmessage('
Type in name and password!');
end;
procedure TFenster.FormCreate(Sender: TObject);
begin
randomize;
pw:='
';
end;
procedure TFenster.ClientSocketDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
ClientSocket.Socket.SendText('
LO'+CO);
ClientSocket.Active:=false;
close;
SHowmessage('
You are offline!'+#10+#13+'
Server is gone!');
end;
procedure TFenster.ClientSocketConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Status.Lines.Add('
Welcome, please type in your name and password!');
ButtonOn.Enabled:=true;
end;
procedure TFenster.ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
var merke,Kopf, Text:
String;
begin
merke:=Socket.ReceiveText;
Kopf:=merke[1]+merke[2];
Text:=copy(merke,3,length(merke)-2);
if Kopf ='
PW'
then
vPW(text);
if Kopf = '
CO'
then
vCO(text);
if Kopf = '
LI'
then
vLI(text);
if Kopf = '
TE'
then
vTE(text);
if Kopf = '
LO'
then
close;
end;
procedure TFenster.vPW(text:
string);
begin
if text='
OK'
then
begin
NName:=LabeledEditName.Text;
ClientSocket.Socket.SendText('
ON'+NName+'
|'+CO);
PanelAn.Hide;
TextEin.SetFocus;
end
else
begin
Status.Lines.Add('
Invalid password');
Status.Lines.Add('
Access denided');
LabeledEditPW.Text:='
';
pw:='
';
end;
end;
procedure TFenster.vLI(text:
string);
var na:
string;
begin
ListBoxOn.Clear;
while length(text)>0
do
begin
na:=copy(text,1,pos('
|',text)-1);
delete(text,1,pos('
|',text));
ListBoxOn.Items.Add(na);
end;
end;
procedure TFenster.vCO(text:
string);
begin
CO:=text;
end;
procedure TFenster.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if alphablendvalue<247
then
AlphaBlendValue:=AlphaBlendValue+10
else
alphablendvalue:=255;
end;
procedure TFenster.TimerTimer(Sender: TObject);
begin
if not Fenster.Active
then
if AlphaBlendValue>10
then
AlphaBlendValue:=AlphaBlendValue-2
else
if alphablendvalue<247
then
AlphaBlendValue:=AlphaBlendValue+10
else
alphablendvalue:=255;
end;
procedure TFenster.ClientSocketError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
case ErrorCode
of
10061 :
begin
ErrorCode:=0;
showmessage('
Sever not found!'+#10+#13+'
Please, try again later!');
close;
end;
end;
end;
procedure TFenster.LabeledEditNameKeyPress(Sender: TObject;
var Key: Char);
begin
case key
of
char(vk_return) :
begin
key:=#0;
LabeledEditPW.SetFocus;
end;
'
|' : key:=#0;
else
end;
end;
procedure TFenster.LabeledEditPWKeyPress(Sender: TObject;
var Key: Char);
var i, anzahl : integer;
begin
anzahl:=random(3);
for i:=0
to anzahl
do
LabeledEditPW.Text:=LabeledEditPW.Text+'
*';
case key
of
chr(vk_return) :
begin
ButtonOnClick(Sender);
key:=#0;
end;
chr(vk_back) :
begin
LabeledEditPW.Text:='
';
pw:='
';
key:=#0;
end;
else
pw:=pw+key;
key:=#0;
end;
end;
procedure TFenster.FormClose(Sender: TObject;
var Action: TCloseAction);
var FileName, m1,m2,m3 :
string;
begin
FileName:='
D'+DateToStr(date)+'
T';
m1:=timetostr(time);
m2:=copy(m1,1,pos('
:',m1)-1);
delete(m1,1,pos('
:',m1));
m2:=m2+'
-';
m3:=copy(m1,1,pos('
:',m1)-1);
delete(m1,1,pos('
:',m1));
m2:=m2+m3+'
-'+m1;
FileNAme:=FileName+m2;
if DirectoryExists('
Verlauf')
then
begin
TextAus.Lines.SaveToFile('
Verlauf\'+FileName+'
.vlf');
end
else
begin
MkDir('
Verlauf');
TextAus.Lines.SaveToFile('
Verlauf\'+FileName+'
.vlf');
end;
ClientSocket.Active:=false;
end;
procedure TFenster.TextEinKeyPress(Sender: TObject;
var Key: Char);
var text :
string;
begin
if key = chr(13)
then
begin
key:=#0;
text:=TextEin.Lines.Text;
TextEin.Clear;
if lowercase(text) = '
exit'
then
close;
ClientSocket.Socket.SendText('
TE'+text+'
|'+CO);
end;
end;
procedure TFenster.vTE(text:
string);
begin
TextAus.Lines.Add(text);
end;
procedure TFenster.ButtonStartClick(Sender: TObject);
begin
ClientSocket.Host:=ComboBoxServer.Text;
try
ClientSocket.Active:=true;
except
end;
PanelSever.Visible:=false;
end;
end.