unit main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, FileCtrl,options,Registry,Winsock, ScktComp, IdBaseComponent,
IdComponent, IdTCPServer, Grids, IdTCPConnection, IdTCPClient, ComCtrls,shellapi;
type
mainRecord =
Packed Record
what:integer;
clientip:
string[250];
film1:
string[250];
vote:integer;
end;
type
iprec =
Packed Record
clientip:
string[100];
clienthost:
string[100];
end;
type
Tform1 =
class(TForm)
options: TButton;
Label1: TLabel;
filmliste: TFileListBox;
bsvcontr: TButton;
Label2: TLabel;
lIP: TLabel;
lHostname: TLabel;
Label3: TLabel;
stringgrid: TStringGrid;
Label4: TLabel;
Button2: TButton;
countvotebutton: TButton;
Edit1: TEdit;
serversock: TServerSocket;
procedure optionsClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure serverClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure bsvcontrClick(Sender: TObject);
procedure countvotebuttonClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure serversockClientWrite(Sender: TObject;
Socket: TCustomWinSocket);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
form1: Tform1;
ip,host:
string;
clientsactive:integer;
implementation
{$R *.DFM}
//ip funktion
function GetComputerNetName:
string;
var
buffer:
array[0..255]
of char;
size: dword;
begin
size := 256;
if GetComputerName(buffer, size)
then
Result := buffer
else
Result := '
';
end;
function GetLocalIPs:
string;
type
PPInAddr = ^PInAddr;
var
wsadata : TWSAData;
hostinfo : PHostEnt;
addr : PPInAddr;
begin
Result := '
';
if(WSAStartUp(MAKEWORD(1,1),wsadata) = 0)
then
try
hostinfo := gethostbyname(
nil);
if(hostinfo <>
nil)
then begin
addr := pointer(hostinfo^.h_addr_list);
while(addr^ <>
nil)
do begin
Result := Result + inet_ntoa(addr^^) + ^M^J;
inc(addr);
end;
end;
finally
WSACleanUp;
end;
end;
procedure Tform1.optionsClick(Sender: TObject);
begin
form2.showmodal;
end;
procedure Tform1.FormActivate(Sender: TObject);
var regist: TRegistry;
var ip:
string;
begin
clientsactive:=0;
//Stringgrid schreiben
stringgrid.cells[0,0]:='
Name';
stringgrid.cells[0,1]:='
IP';
stringgrid.cells[0,2]:='
Voted for:';
stringgrid.cells[1,0]:='
Client1';
//regestry lesen
{regist:=TRegistry.Create;
regist.RootKey:=HKEY_CURRENT_USER;
regist.OpenKey('Software\Reaper Productions\Vote Tool', true);
filmliste.directory:=regist.Readstring('direct');
regist.OpenKey('Software\Reaper Productions\Vote Tool\VLC', true);
vlcpath:=regist.readstring('vlcpa');
vlcname:=regist.readstring('vlcna');
regist.free;}
filmliste.mask:='
*.mpg;'+'
*.mpeg;'+'
*.avi;';
//ip addresse einlesen und ausgeben
ip:=GetLocalIPs;
host:=GetComputerNetName;
lhostname.caption :=host;
lip.caption:=
ip;
end;
procedure Tform1.serverClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var z:integer;
rec1:mainrecord;
begin
//filmliste
end;
procedure Tform1.bsvcontrClick(Sender: TObject);
begin
if serversock.Active
then
begin
bsvcontr.caption:='
Server ist offline';
serversock.active:=false;
serversock.socket.close;
end else begin
bsvcontr.caption:='
Server ist online';
serversock.Port:=628;
serversock.active:=true;
serversock.Open;
end;
end;
procedure Tform1.countvotebuttonClick(Sender: TObject);
var z,max,maxnr:integer;
voted,votecomm:
string;
votefeld:
array[1..100]
of Integer;
begin
//alles auf 0 setzen
max:=0;
maxnr:=0;
for z:=1
to 50
do
begin
votefeld[z]:=0;
end;
//filmvotes zählen
for z:=1
to (stringgrid.colcount-1)
do
begin
inc(votefeld[(strtoint(stringgrid.cells[z,2]))]);
end;
//maximum suchen
for z:=1
to (stringgrid.colcount-1)
do
begin
if votefeld[z]>max
then
begin
max:=votefeld[z];
maxnr:=z;
end;
end;
showmessage('
Der gevotete Film ist' +filmliste.items[maxnr]+'
('+inttostr(maxnr)
+'
) mit '+inttostr(max)+'
votes. Stream wird jetzt gestartet auf 239.239.239.1:1234');
filmliste.itemindex:=maxnr;
//stream starten
try
voted:=filmliste.directory+'
/'+filmliste.items[maxnr];
edit1.Text:=voted;
ShellExecute(Application.Handle, '
open' ,
PChar(vlcname),
Pchar('
-vvv '+voted+'
--sout udp://239.239.0.1 --ttl 1'),
PChar(vlcpath), sw_ShowNormal);
except
showmessage('
Befindet sich nicht auf dem Server Rechner deswegen kein stream möglich');
end;
end;
procedure Tform1.Button2Click(Sender: TObject);
var rec1:mainrecord;
begin
rec1.film1:=filmliste.items[0];
serversock.Socket.SendBuf(rec1,sizeof(rec1));
end;
procedure Tform1.serversockClientWrite(Sender: TObject;
Socket: TCustomWinSocket);
var rec1:iprec;
z:integer;
begin
serversock.Socket.ReceiveBuf(rec1,sizeof(rec1));
z:=1;
//serversock.socket.ActiveConnections;
stringgrid.cells[z,1]:=rec1.clientip;
stringgrid.cells[z,2]:=rec1.clienthost;
end;
end.