www.pudn.com > Roulette.rar > ClientInterpreter.pas


unit ClientInterpreter; 
{Tlt logic layer} 
interface 
uses Classes, SConnect, TltConst, ExtCtrls; 
type 
  TrltClientInterpreter = class(TDataBlockInterpreter) 
    function DoCustomAction(Action: Integer; const Data: IDataBlock): Boolean; override; 
  public 
    {Receiving Calls} 
    procedure DoGetServerInfo(const Data: IDataBlock); 
    procedure DoGetCurrentRoundNo(const Data: IDataBlock); 
    procedure DoSetCountDown(const Data: IDataBlock); 
    {Sending Calls} 
    function CallGetServerInfo : TServerInfo; 
    function CallGetCurrentRoundNo: integer; 
    {Sendto Client} 
    procedure CallSetCountDown; 
 
  end; 
 
 
 
 
implementation 
uses ScktCnst, rltClient; 
 
 
{ TTltInterpreter } 
 
function TrltClientInterpreter.CallGetServerInfo: TServerInfo; 
var 
  Data: IDataBlock; 
  Size : integer; 
  s : TServerInfo; 
begin 
  Data := TDataBlock.Create as IDataBlock; 
  Data.Signature := CallSig or asGetServerInfo; 
  Data := FSendDataBlock.Send(Data, True); 
  Data.Read(size, sizeof(size)); 
  Data.Read(s,Size); 
  Result := s; 
//  Result := ReadVariant(Flags, Data); 
end; 
 
function TrltClientInterpreter.CallGetCurrentRoundNo: integer; 
var 
  Data: IDataBlock; 
  Size : integer; 
  s : integer; 
begin 
  Data := TDataBlock.Create as IDataBlock; 
  Data.Signature := CallSig or asGetCurrentRoundNo; 
  Data := FSendDataBlock.Send(Data, True); 
  Data.Read(size, sizeof(size)); 
  Data.Read(s,Size); 
  Result := s; 
//  Result := ReadVariant(Flags, Data); 
end; 
 
 
function TrltClientInterpreter.DoCustomAction(Action: Integer; 
  const Data: IDataBlock): Boolean;  
begin 
  case (Action and asMask) of 
    asGetServerInfo: DoGetServerInfo(Data); 
    asGetCurrentRoundNo : DoGetCurrentRoundNo(Data); 
 
    //client 
    asSetCountDown : DoSetCountDown(Data); 
  else 
    Result := false; 
  end; 
end; 
 
procedure TrltClientInterpreter.DoGetServerInfo(const Data: IDataBlock); 
var 
  ServerInfo : TServerInfo; 
  VarSize : integer; 
begin 
  Data.Clear; 
  try 
    ServerInfo.ServerVer :='1.0'; 
  finally 
  end; 
  VarSize := sizeof(ServerInfo); 
  Data.Write(VarSize, sizeof(integer)); 
  Data.Write(ServerInfo, VarSize); 
  Data.Signature := ResultSig or asGetServers; 
  FSendDataBlock.Send(Data, False); 
end; 
 
procedure TrltClientInterpreter.DoGetCurrentRoundNo(const Data: IDataBlock); 
var 
  VarSize : integer; 
begin 
  Data.Clear; 
  WriteVariant(rltManager.CurrentRoundNo, Data); 
  Data.Signature := ResultSig or asGetServers; 
  FSendDataBlock.Send(Data, False); 
end; 
 
 
procedure TrltClientInterpreter.CallSetCountDown; 
var 
  Data: IDataBlock; 
  Size : integer; 
  s : integer; 
begin 
  Data := TDataBlock.Create as IDataBlock; 
  WriteVariant(rltManager.CountDown, Data); 
  Data.Signature := CallSig or asSetCountDown; 
  Data := FSendDataBlock.Send(Data, True); 
end; 
 
procedure TrltClientInterpreter.DoSetCountDown(const Data: IDataBlock); 
var 
  VarSize : integer; 
  VarFlag : TVarFlag; 
begin 
 
  // Client. := ReadVariant(VarFlag, Data); 
end; 
 
end.