unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, userlist, ScktComp, StdCtrls, ExtCtrls, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP, Menus, ComCtrls, ClipBrd;
// *********************************************
// ******** TForm1 *****************************
// *********************************************
type
TForm1 =
class(TForm)
Server: TServerSocket;
HTTP: TIdHTTP;
ListBox1: TListBox;
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
ListBox2: TListBox;
Splitter1: TSplitter;
PopupMenu1: TPopupMenu;
Kick1: TMenuItem;
Ban1: TMenuItem;
N1: TMenuItem;
MSGTOUser1: TMenuItem;
FILETOUser1: TMenuItem;
N2: TMenuItem;
INFOFROMUser1: TMenuItem;
Button3: TButton;
speichern: TSaveDialog;
StatusBar1: TStatusBar;
PopupMenu2: TPopupMenu;
CopyText1: TMenuItem;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ServerClientConnect(Sender: TObject; Socket: TCustomWinSocket);
procedure ServerClientDisconnect(Sender: TObject; Socket: TCustomWinSocket);
procedure Edit1KeyPress(Sender: TObject;
var Key: Char);
procedure ServerClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure ServerClientError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure Button3Click(Sender: TObject);
procedure PopupMenu1Popup(Sender: TObject);
procedure PopupMenu2Popup(Sender: TObject);
procedure CopyText1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Userliste: TUserlist;
uid: integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
HTTP.Get('
http://www.*******/adminip.php?action=reactivate');
// Onlineupdate siehe extra hinweis unten
ListBox1.Items.Add('
*** Online-Update wurde durchgeführt! ***');
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if (Server.Active)
then
begin
Server.Close;
ListBox1.Items.Add('
*** Server wurde beendet! ***');
Button2.Caption := '
Start Server';
ListBox2.Clear;
Userliste.Clear;
uid := 1;
end else begin
Server.Open;
ListBox1.Items.Add('
*** Server wurde gestartet! ***');
Button2.Caption := '
Stop Server';
ListBox2.Clear;
Userliste.Clear;
uid := 1;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
if (speichern.Execute)
then // Abspeichern des Server-Chat-Log's in eine Datei
ListBox1.Items.SaveToFile(speichern.FileName);
end;
procedure TForm1.CopyText1Click(Sender: TObject);
begin
Clipboard.AsText := ListBox1.Items[ListBox1.ItemIndex];
// eine kleine Kopierfunktion um zeilen aus dem Server-Chat-Log rauszukopieren
end;
procedure TForm1.Edit1KeyPress(Sender: TObject;
var Key: Char);
begin
if (key=#13)
then // wenn "Enter" dann mache folgendes
begin
Userliste.Broadcast('
Server: '+Edit1.Text,Server);
// das was im Servereditfeld eingegeben wird wird hier an alle user geschickt
ListBox1.Items.Add('
*** Server: '+Edit1.Text+'
***');
// und hier wird es dem server selber ausgegeben
Edit1.Clear;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Userliste := TUserlist.Create;
Userliste.Clear;
uid := 1;
end;
procedure TForm1.PopupMenu1Popup(Sender: TObject);
var x:
string;
begin
if (ListBox2.ItemIndex >= 0)
then
begin
x := ListBox2.Items[ListBox2.ItemIndex];
Popupmenu1.Items[0].Visible := True;
Popupmenu1.Items[1].Visible := True;
Popupmenu1.Items[3].Visible := True;
Popupmenu1.Items[4].Visible := True;
Popupmenu1.Items[6].Visible := True;
Popupmenu1.Items[0].Caption := '
KICK '+x;
Popupmenu1.Items[1].Caption := '
BAN '+x;
Popupmenu1.Items[3].Caption := '
MSG TO '+x;
Popupmenu1.Items[4].Caption := '
FILE TO '+x;
Popupmenu1.Items[6].Caption := '
INFO FROM '+x;
end else begin
Popupmenu1.Items[0].Visible := False;
Popupmenu1.Items[1].Visible := False;
Popupmenu1.Items[3].Visible := False;
Popupmenu1.Items[4].Visible := False;
Popupmenu1.Items[6].Visible := False;
end;
end;
procedure TForm1.PopupMenu2Popup(Sender: TObject);
var x:
string;
begin
if (ListBox1.ItemIndex >= 0)
then
begin
x := ListBox1.Items[ListBox1.ItemIndex];
Popupmenu2.Items[0].Visible := True;
end else begin
Popupmenu2.Items[0].Visible := False;
end;
end;
procedure TForm1.ServerClientConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
Userliste.Adduser('
User'+inttostr(uid),Socket.RemoteAddress,IntToStr(Socket.RemotePort),ListBox2);
Userliste.Broadcast('
JOIN User'+inttostr(uid)+'
('+Socket.RemoteHost+'
:'+IntToStr(Socket.RemotePort)+'
)',Server);
ListBox1.Items.Add('
*** User Connected: User'+inttostr(uid)+'
('+Socket.RemoteHost+'
:'+IntToStr(Socket.RemotePort)+'
) ***');
inc(uid);
StatusBar1.Panels[1].Text := IntToStr(Userliste.Count);
end;
procedure TForm1.ServerClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
var xname:
string;
begin
try
xname := Userliste.GetUsernamebyid(Socket.RemoteAddress+'
:'+IntToStr(Socket.RemotePort));
Userliste.Broadcast('
QUIT '+xname+'
('+Socket.RemoteHost+'
:'+IntToStr(Socket.RemotePort)+'
)',Server);
ListBox1.Items.Add('
*** User Disconnected: '+xname+'
('+Socket.RemoteHost+'
:'+IntToStr(Socket.RemotePort)+'
) ***');
finally
Userliste.Deleteuser(Socket.RemoteAddress, IntToStr(Socket.RemotePort),ListBox2);
StatusBar1.Panels[1].Text := IntToStr(Userliste.Count);
end;
end;
procedure TForm1.ServerClientError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
ListBox1.Items.Add('
*** ERROR: ('+IntToStr(ErrorCode)+'
) ***');
end;
procedure TForm1.ServerClientRead(Sender: TObject; Socket: TCustomWinSocket);
var sr,xu, meta:
string;
begin
xu := Userliste.GetUsernamebyid(Socket.RemoteAddress+'
:'+IntTostr(Socket.RemotePort));
sr := Socket.ReceiveText;
if ((sr[1] = '
/')
AND (sr[2] = '
s')
AND (sr[3] = '
a')
AND (sr[4] = '
y'))
then // der say befehl sendet text an alle user
begin
Userliste.BroadCast(xu+'
: '+Copy(sr,6,length(sr)-5),Server);
ListBox1.Items.Add('
*** '+xu+'
: '+Copy(sr,6,length(sr)-5)+'
***');
end;
if ((sr[1] = '
/')
AND (sr[2] = '
n')
AND (sr[3] = '
a')
AND (sr[4] = '
m')
AND (sr[5] = '
e'))
then // mit /name ändert man den namen
begin
meta := Userliste.ChangeNickName(xu,Copy(sr,7,length(sr)-6),Server,ListBox2);
if (meta <&gt; '
')
then
Userliste.Sendtextto('
INFO',Socket.RemoteAddress,IntToStr(Socket.RemotePort),meta,Server)
else
ListBox1.Items.Add('
*** Namensänderung: '+xu+'
=&gt; '+Copy(sr,7,length(sr)-6)+'
***');
end;
end;
end.