Advertisement
akaMeltDown

Server.exe source code

Aug 27th, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 3.58 KB | None | 0 0
  1. unit Unit1;
  2.       {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.Win.ScktComp,
  8.   Vcl.ExtCtrls, IdHTTP;
  9.  
  10. type
  11.   TForm1 = class(TForm)
  12.     ServerSocket1: TServerSocket;
  13.     Memo1: TMemo;
  14.     iscon: TTimer;
  15.     CMDS: TTimer;
  16.     TrayIcon1: TTrayIcon;
  17.     procedure ServerSocket1ClientConnect(Sender: TObject;
  18.       Socket: TCustomWinSocket);
  19.     procedure ServerSocket1ClientDisconnect(Sender: TObject;
  20.       Socket: TCustomWinSocket);
  21.     procedure ServerSocket1ClientRead(Sender: TObject;
  22.       Socket: TCustomWinSocket);
  23.     procedure isconTimer(Sender: TObject);
  24.     procedure ServerSocket1ClientError(Sender: TObject;
  25.       Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  26.       var ErrorCode: Integer);
  27.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  28.     procedure FormCreate(Sender: TObject);
  29.   private
  30.     { Private declarations }
  31.   public
  32.     { Public declarations }
  33.     //showmessage(
  34.   end;
  35.  
  36. var
  37.   Form1: TForm1;
  38.  
  39. implementation
  40.  
  41. {$R *.dfm}
  42.  
  43. procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
  44.   Socket: TCustomWinSocket);
  45. begin
  46.     try
  47.     Socket.SendText('GiveInfo|');
  48.      trayicon1.BalloonTitle := 'Info!';
  49.       trayicon1.BalloonHint :=  'Received ->: Status 200';
  50.          TrayIcon1.ShowBalloonHint;
  51.   Except
  52.  
  53.   end;
  54. end;
  55.  
  56. procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
  57.   Socket: TCustomWinSocket);
  58. begin
  59.  
  60.   try
  61.    trayicon1.BalloonTitle := 'Info!';
  62.    trayicon1.BalloonHint := 'Received ->: Status 512';
  63.        TrayIcon1.ShowBalloonHint;
  64.   socket.Close;
  65.   Except
  66.  
  67.   end;
  68. end;
  69.  
  70. procedure TForm1.ServerSocket1ClientError(Sender: TObject;
  71.   Socket: TCustomWinSocket; ErrorEvent: TErrorEvent; var ErrorCode: Integer);
  72. begin
  73. Errorcode:= 0;
  74. end;
  75.  
  76. const
  77.  HTTP_RESPONSE_OK = 200;
  78.  
  79. function GetPage(aURL: string): string;
  80. var
  81.  Response: TStringStream;
  82.  HTTP: TIdHTTP;
  83. begin
  84.  Result := '';
  85.  Response := TStringStream.Create('');
  86.  try
  87.    HTTP := TIdHTTP.Create(nil);
  88.    try
  89.      HTTP.Get(aURL, Response);
  90.      if HTTP.ResponseCode = HTTP_RESPONSE_OK then begin
  91.        Result := Response.DataString;
  92.      end else begin
  93.        // TODO -cLogging: add some logging
  94.      end;
  95.    finally
  96.      HTTP.Free;
  97.    end;
  98.  finally
  99.    Response.Free;
  100.  end;
  101. end;
  102.  
  103. procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
  104.   Socket: TCustomWinSocket);
  105. Var
  106.   Data: string;
  107.   SL: TStringList;
  108. begin
  109.  SL := TStringList.Create;
  110.   SL.Delimiter := '|';
  111.   SL.StrictDelimiter := True;
  112.   Data := Socket.ReceiveText;
  113.   SL.DelimitedText := Data;
  114.  
  115.   if SL[0] = 'MyInfo' then
  116.   begin
  117.      trayicon1.BalloonTitle := 'Info!';
  118.      trayicon1.BalloonHint :=  'Received ->: ' + GetPage('api would go here');
  119.      TrayIcon1.ShowBalloonHint;
  120.     exit;
  121.   end;
  122.  
  123.   if SL[0] = 'Close' then
  124.   begin
  125.   trayicon1.BalloonTitle := 'Info!';
  126.  trayicon1.BalloonHint:= 'Received ->: ' + 'Bye :)';
  127.   TrayIcon1.ShowBalloonHint;
  128.     close;
  129.      exit;
  130.   end;
  131.  
  132. end;
  133.  
  134. procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  135. begin
  136.  
  137. end;
  138.  
  139. procedure TForm1.FormCreate(Sender: TObject);
  140. begin
  141. Hide();
  142.   WindowState := wsMinimized;
  143.  TrayIcon1.Visible := True;
  144.   TrayIcon1.Animate := True;
  145.   TrayIcon1.ShowBalloonHint;
  146. end;
  147.  
  148. procedure TForm1.isconTimer(Sender: TObject);
  149. begin
  150.    if self.ServerSocket1.Socket.Connected then
  151.    begin
  152.      exit;
  153.      CMDS.Enabled:= true;
  154.    end
  155.    else
  156.    begin
  157.  
  158.    end;
  159.  
  160. end;
  161.  
  162. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement