⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit_server_main.~pas

📁 这是Delphi开发的GPS系统的原代码势力程序
💻 ~PAS
📖 第 1 页 / 共 4 页
字号:
        TempNo := IntToHex(readbyte[y],2) + TempNo ;

      LogNum := 0 ;

      for I := 0 to High(ServerConnectionStatus) do
      with ServerConnectionStatus[I] do
      begin
        if (tcsRemoteAddress = Socket.RemoteAddress) and
           (tcsRemotePort = Socket.RemotePort) then
        begin
          tcsScreenName := TempNo ;
          //Break ;
        end ;
        if tcsScreenName = TempNo then Inc(LogNum ) ;
      end ;

      for i := 0 to HIGH(ServerConnectionStatus) do
      with ServerConnectionStatus[i] do
      begin
        if (tcsScreenName = TempNo) and (LogNum > 1) then
        begin
          for y := 0 to ChatServerSocket.Socket.ActiveConnections - 1 do
          begin
            if ChatServerSocket.Socket.Connections[y].RemotePort = tcsRemotePort then
            begin
              if ChatServerSocket.Socket.Connections[y].Connected then
              begin
                ChatServerSocket.Socket.Connections[y].Close ;
              end ;
            end ;
          end ;
        end ;
      end ;

      DisplayConnectionsInfo;

      for I := 0 to (ChatServerSocket.Socket.ActiveConnections - 1) do
      with ChatServerSocket.Socket.Connections[I] do
      begin
        if RemoteAddress  = ClientIP.Text  then
           if Connected then
           begin
             try
             SendText(CreateLoginList ); //Let the other users know that their list should be refreshed
             except  // }
               //for y := i to (ChatServerSocket.Socket.ActiveConnections - 1 ) do
               //begin
               //  if ChatServerSocket.Socket.Connections[y].RemoteAddress  = ClientIP.Text  then
               //     Socket.Close  ;
                    //SendText(CreateLoginList ) ;
               //end ;
               //break ;
             end ;
           end ;
      end;
      end
  else if (ReadByte[0] = $AA) or (ReadByte[0] = $BB) then
       begin
         if (ReadByte[15]-$33 <>$c1)and(ReadByte[14]-$33 <>$18) then
           begin
             for i := 0 to (ChatServerSocket.Socket.ActiveConnections - 1) do
             with ChatServerSocket.Socket.Connections[i] do
             begin
               if RemoteAddress  = ClientIP.Text then  //(ChatServerSocket.Socket.Connections[i].RemoteAddress  = ClientIP.Text ) then
               begin
                  SendBuf(ReadByte , DataLen ) ;
                  Break;
               end;
           end;    
         end;
       end
  else if ReadByte[0] = $ef then
       begin
               Data[0]  := $fe ;
               Data[1]  := $fe ;
               Data[2]  := $fe ;
               Data[3]  := $fe ;
               Data[4]  := $68 ;

               Data[5]  := $99 ;
               Data[6]  := $99 ;
               Data[7]  := $99 ;
               Data[8]  := $99 ;
               Data[9]  := $99 ;
               Data[9]  := $99 ;
               Data[10]  := $99 ;
               Data[11] := $68 ;
               Data[12] := $1 ;
               Data[13] := $2 ;

         if ReadByte[1] = $01 then
         begin
               Data[14] := $1e + $33 ;
               Data[15] := $90 + $33 ;

               y := 0 ;
               for n := 4 to 15 do
                   y := y + Data[n] ;

               Data[16] := y mod 256 ;
               Data[17] := $16 ;
              for i := 0 to ChatServerSocket.Socket.ActiveConnections - 1 do
                 begin
                  if ChatServerSocket.Socket.Connections[i].RemoteAddress <> clientip.Text then
                    ChatServerSocket.Socket.Connections[i].SendBuf(Data,18) ;
                 end ;

         end ;
         if ReadByte[1] = $02 then
         begin
               Data[14] := $2f + $33 ;
               Data[15] := $b6 + $33 ;

               y := 0 ;
               for n := 4 to 15 do
                   y := y + Data[n] ;

               Data[16] := y mod 256 ;
               Data[17] := $16 ;
              for i := 0 to ChatServerSocket.Socket.ActiveConnections - 1 do
                 begin
                  if ChatServerSocket.Socket.Connections[i].RemoteAddress <> clientip.Text then
                    ChatServerSocket.Socket.Connections[i].SendBuf(Data,18) ;
                 end ;
         end ;
         if ReadByte[1] = $03 then
         begin
               Data[14] := $3f + $33 ;
               Data[15] := $b6 + $33 ;

               y := 0 ;
               for n := 4 to 15 do
                   y := y + Data[n] ;

               Data[16] := y mod 256 ;
               Data[17] := $16 ;
              for i := 0 to ChatServerSocket.Socket.ActiveConnections - 1 do
                 begin
                  if ChatServerSocket.Socket.Connections[i].RemoteAddress <> clientip.Text then
                    ChatServerSocket.Socket.Connections[i].SendBuf(Data,18) ;
                 end ;
         end ;
       end
  else if ReadByte[0] = $ed then
       begin
        loginnumber:=0 ;
        timercount:=0 ;
         case ReadByte[1] of
         1 :  begin
               E901E ;
              end ;
         2 :  begin
                 E902E ;
              end ;
         3 :  begin
                 E911E ;
              end ;
         4 :  begin
                 E912E ;
             end ;
         5 :begin
                 E941E ;
               end ;
         6 :  begin
                 E942E ;
               end ;
         7 :  begin
                 E951E ;
               end ;
         8 :  begin
                 E952E ;
             end ;
         9 :  begin
                 EB61F ;
             end ;
         10 :  begin
                 EB33F ;
             end ;
         11 :  begin
                 EB34F ;
             end ;
         12 :  begin
                 E901E ;
             end ;
         13 :  begin
                 EB62F ;
             end ;
         14 :  begin
                 EB63F ;
             end ;
         end ;
       end
  else if (ReadByte[0] = $fe) and (ReadByte[1] = $fe) and (ReadByte[2] = $fe ) and (ReadByte[3] = $fe ) then
       begin
        TempMeter := IntToHex(readbyte[10],2) + IntToHex(readbyte[9],2) + IntToHex(readbyte[8],2) +
                      IntToHex(readbyte[7],2) + IntToHex(readbyte[6],2) + IntToHex(readbyte[5],2) ;
         for i := 0 to HIGH(serverconnectionstatus) do
         with ServerConnectionStatus[i] do
         begin
           if tcsScreenName = TempMeter then
           begin
             TempIP := tcsRemoteAddress ;
             TempSocket := tcsRemotePort ;
             for y := 0 to (ChatServerSocket.Socket.ActiveConnections - 1 ) do
             with ChatServerSocket.Socket.Connections[y] do
             begin
               if (RemoteAddress = TempIP) and (RemotePort = TempSocket) then
               begin
                 SendBuf(ReadByte ,DataLen ) ;
                 Break ;
               end ;
             end ;
             Break ;
           end ;
         end ;
       end
    // end ;
end;

procedure TForm_Server_Main.ChatServerSocketClientWrite(Sender: TObject; Socket: TCustomWinSocket);
var
  X : TListItem;
begin
  X := lvServerActivity.Items.Add;
  X.Caption := '客户连接 ';
  X.SubItems.Add(Socket.RemoteHost);
  X.SubItems.Add(Socket.RemoteAddress);
  X.SubItems.Add(IntToStr(Socket.RemotePort));
  X.SubItems.Add(FormatDateTime(StatusDateTimeFormat, Now));
end;

procedure TForm_Server_Main.ChatServerSocketListen(Sender: TObject; Socket: TCustomWinSocket);
var
  X : TListItem;
begin
  X := lvServerActivity.Items.Add;
  X.Caption := '侦听...';
  X.SubItems.Add(Socket.LocalHost);
  X.SubItems.Add(Socket.LocalAddress);
  X.SubItems.Add(IntToStr(Socket.LocalPort));
  X.SubItems.Add(FormatDateTime(StatusDateTimeFormat, Now));
end;

procedure TForm_Server_Main.btnClearServerSocketLogClick(Sender: TObject);
begin
  DisplayConnectionsInfo;
  lvServerActivity.Items.Clear;
  memo1.Clear;
end;

procedure TForm_Server_Main.edSendKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var
  I, J : Integer;
begin
  if Key = VK_RETURN then
  begin
    if (ChatServerSocket.Active) and (cbBroadcastMessage.Checked) then
      ServerBrodcastMessage
    else if (ChatServerSocket.Active) then //Server specific message
      for I := 0 to High(ServerConnectionStatus) do
      begin
        //Send message only to those selected
        if (ServerConnectionStatus[I].tcsServerPrivateMsg) then
        begin
          //Find the user to send message
          for J := 0 to (ChatServerSocket.Socket.ActiveConnections - 1) do
          begin
            with ChatServerSocket.Socket.Connections[J] do
            begin
              if (ServerConnectionStatus[I].tcsRemoteAddress = RemoteAddress) and
               (ServerConnectionStatus[I].tcsRemotePort = RemotePort) then
               begin
                 if (Connected) then SendText( edSend.Text );
                 Break;
               end
            end;
          end;
        end;
      end;
    memReceive.Lines.Append('Server Admin: ' + edSend.Text + #13#10);
    edSend.Text := '';
  end;
end;

procedure TForm_Server_Main.sgServerConnectionsDblClick(Sender: TObject);
var
  I : Integer;
begin
{  I := sgServerConnections.Row - 1;
  if (sgServerConnections.Row <> 0) then
    with ServerConnectionStatus[I] do
    begin
      if (tcsServerPrivateMsg) then
        begin
          tcsServerPrivateMsg := False;
          sgServerConnections.Cells[0,sgServerConnections.Row] := '';
        end
      else
        begin
          tcsServerPrivateMsg := True;
          sgServerConnections.Cells[0,sgServerConnections.Row] := '(Selected)';
        end;
    end;  }
end;

procedure TForm_Server_Main.ChatServerSocketThreadEnd(Sender: TObject; Thread: TServerClientThread);
begin
//
end;

procedure TForm_Server_Main.ChatServerSocketThreadStart(Sender: TObject; Thread: TServerClientThread);
begin
//
end;

procedure TForm_Server_Main.ChatServerSocketGetSocket(Sender: TObject; Socket: Integer; var ClientSocket: TServerClientWinSocket);
begin
//
end;

procedure TForm_Server_Main.ChatServerSocketGetThread(Sender: TObject; ClientSocket: TServerClientWinSocket; var SocketThread: TServerClientThread);
begin
//
end;

procedure TForm_Server_Main.ChatServerSocketAccept(Sender: TObject; Socket: TCustomWinSocket);
begin
//
end;

procedure TForm_Server_Main.DisplayConnectionsInfo;
var
  I : Integer;
begin
  with ChatServerSocket do
  begin
    if (Length(ServerConnectionStatus) >= 1) then
      sgServerConnections.RowCount := Length(ServerConnectionStatus) + 1
    else
      sgServerConnections.RowCount := 2;
    sgServerConnections.FixedRows := 1;
    with sgServerConnections do
    begin
      for I := 0 to High(ServerConnectionStatus) do
      begin
        Cells[1 ,I+1] := '';
        Cells[2 ,I+1] := '';
        Cells[3 ,I+1] := '';
        Cells[4 ,I+1] := '';
        Cells[5 ,I+1] := '';
        Cells[7 ,I+1] := '';
        Cells[8 ,I+1] := '';
        Cells[0 ,I+1] := '';
        with ServerConnectionStatus[I] do
        begin
          if tcsScreenName <> 'Empty' then
             begin
                Cells[1 ,I+1] := IntToStr(tcsActiveConnections);
                Cells[2 ,I+1] := tcsScreenName;
                Cells[3 ,I+1] := tcsLocalHost;
                Cells[4 ,I+1] := tcsLocalAddress;
                Cells[5 ,I+1] := IntToStr(tcsLocalPort);
                Cells[7 ,I+1] := tcsRemoteAddress;
                Cells[8 ,I+1] := IntToStr(tcsRemotePort);
                if (tcsServerPrivateMsg) then
                  Cells[0 ,I+1] := '(Selected)'
                else
                  Cells[0 ,I+1] := '';
             end;
        end;
      end; //end for I
    end; //end with sgServerConnections
  end; //end with ServerSocket
end;

procedure TForm_Server_Main.ServerBrodcastMessage;
var
  I : Integer;
begin
  with ChatServerSocket.Socket do
  begin
    for I := 0 to (ActiveConnections - 1) do
      Connections[I].SendText(edSend.Text + #13#10);
    memReceive.Lines.Append(edSend.Text + #13#10);
  end;
end;

procedure TForm_Server_Main.AddConnectionsInfo(ClientInfo : TServerConnectionStatus);
var
  I, X     : Integer;
  AddToSCS : Boolean;
begin
  //Search for an empty slot in the ServerConnectionStatus array
  AddToSCS := True;
  for I := 0 to High(ServerConnectionStatus) do
  begin
    if (ServerConnectionStatus[I].tcsScreenName = 'Empty') then
      begin
        AddToSCS := False;
        Break;
      end;
  end;

  if (AddToSCS) then //An empty slot was not found so add one and use it
    begin
      SetLength(ServerConnectionStatus, Length(ServerConnectionStatus) + 1);
      X := High(ServerConnectionStatus);
    end
  else
    X := I;
  //Add the new connection information
  with ServerConnectionStatus[X] do
  begin
    tcsActiveConnections := X;
    tcsScreenName        := ClientInfo.tcsScreenName;
    tcsLocalHost         := ClientInfo.tcsLocalHost;
    tcsLocalAddress      := ClientInfo.tcsLocalAddress;
    tcsLocalPort         := ClientInfo.tcsLocalPort;
//    tcsRemoteHost        := ClientInfo.tcsRemoteHost;
    tcsRemoteAddress     := ClientInfo.tcsRemoteAddress;
    tcsRemotePort        := ClientInfo.tcsRemotePort;
    tcsServerPrivateMsg  := False;
    tcsSocketHandle      := ClientInfo.tcsSocketHandle;
    tcsServerSocketHWND  := ClientInfo.tcsServerSocketHWND;
  end;
end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -