rejetto forum

NEW code

Guest · 1 · 3113

0 Members and 1 Guest are viewing this topic.

VIP

  • Guest
can anyone familiar with delphi look at my code and make sure it is proper, and covers all aspects needed.
This is going to be a modification to HFS to allow only 1 download at a time with 5 queues which are automatically filled with the user's IP on attempt to download the file... then taken to the queues page to show stats on queues etc...
heres the code so far:

//TO DO:
//
//User queue timeout (inactivity)/ deletion ~ after specified amount of time if in queue1 (permitted download slot)
//
//function to Keep one "download" session open for browsing when queues are not full(check limitsExceeded2()
//    before allowing user to start download)
//
//function to check if the file they are requesting is not .html or just
//browsing around isrealfile()
//
//Need code to add user to queues upon file request
//   if checkopenqueues() is true (noone is queued) call queueuser() and proceed with download
//   if checkopenqueues() is false (someone is queued already) call queueuser() and cancel download request... then take them to (conn.reply.body:=getQueuesPage();// shows queued users and how much of the download has been completed)
//
//Create new template interface for conn.reply.body:=getQueuesPage();

//Completed:
// function limitsExceeded2():boolean;
//   =(leave one browsing slot open),FUNCTION
// function sortqueues();
//   =(function to sort the queues),FUNCTION
// if checkopenqueues() then
//   =(on full queues.. show queue list template),MODIFIED CODE in the HE_CONNECTED section
// function checkopenqueues():boolean;
//   =(function to check if any queue slot is open),FUNCTION
// function Onqueues():boolean;
//   =(function to check if user is any queue slot),FUNCTION
// function queueuser();
//   =(function to add user to the first open queue slot),FUNCTION
// HE_GOT:
//   =(modified logging code to remove user from queue once a "real file" has been downloaded),MODIFIED CODE
//////////////////////////////////////////////////////////////////////////Modified NEW code to allow 1 slot for browsing (called from the retrieve file function)
//need to alter code to do this check before sending a file to the user
//full server (2)
  function limitsExceeded2():boolean;
  begin
  result:=(maxConnections>0) and (srv.conns.count > maxConnections-1) and !isrealfile()// ensure that one browsing slot is open and file requested isn't !isrealfile() =is not a real file (IS an .html or whatever.. not a mp3.. avi.. txt.. ETC ETC)
    or (maxConnectionsIP>0)
      and (countConnectionsByIP(conn.address)>maxConnectionsIP) and !isrealfile();
  end; // limitsExceeded

//////////////////////////////////////////////////////////////////////////Modified NEW code to allow 1 slot for browsing (called from the retrieve file function)
//need to alter code to do this check before sending a file to the user
//full server (2)
  function sortqueues();
  begin
if queue1 == 0 then // checks to see if user is queued
       begin

   if queue2 != 0 then
       begin
   queue1 = queue2;
   queue2 = 0;
      end;
   else if queue2 == 0 then
       begin
      if queue3 != 0 then
          begin
      queue2 = queue3;
      queue3 = 0;
         end;
      else if queue3 == 0 then
          begin
         if queue4 != 0 then
             begin
         queue3 = queue4;
         queue4 = 0;
            end;
         else if queue4 == 0 then
             begin
            if queue5 != 0 then
                begin
            queue4 = queue5;
            queue5 = 0;
               end;
           end;
        end;
   end;
     end;
if queue2 == 0 then
       begin
   if queue3 != 0 then
       begin
   queue2 = queue3;
   queue2 = 0;
      end;
   else if queue3 == 0 then
       begin
      if queue4 != 0 then
          begin
      queue3 = queue4;
      queue4 = 0;
         end;
      else if queue4 == 0 then
          begin
         if queue5 != 0 then
             begin
         queue4 = queue5;
         queue5 = 0;
            end;
        end;
     end;
end;
end;
if queue3 == 0 then
       begin
   if queue4 != 0 then
       begin
   queue3 = queue4;
   queue4 = 0;
      end;
   else if queue4 == 0 then
       begin
      if queue5 != 0 then
          begin
      queue4 = queue5;
      queue5 = 0;
         end;
     end;
end;
      end;
if queue4 == 0 then
       begin
   if queue5 != 0 then
       begin
   queue4 = queue5;
   queue5 = 0;
      end;
end;
  end; // END THE SORTING FUNCTION



//////////////////////////////////////////////////////////////////////////New denial of serving for full queues (in the HE_CONNECTED)
if checkopenqueues() then
       begin
      data.refusing:='limits exceeded';
        conn.reply.mode:=HRM_VIEWQUEUES;// not 100% sure about this yet... (modified ban code)
      conn.reply.body:=getQueuesPage();// shows queued users and how much of the download has been completed
      exit;
      end;


//////////////////////////////////////////////////////////////////////////New function
//// CHECK TO SEE IF at least 1 QUEUE IS OPEN
  function checkopenqueues():boolean;
  begin
result:=(queue1 == 0) or (queue2 == 0) or (queue3 == 0) or (queue4 == 0) or (queue5 == 0);

end;

//////////////////////////////////////////////////////////////////////////New function
//// CHECK TO SEE IF USER IS QUEUED
  function Onqueues():boolean;
  begin
result:=(queue1 == conn.address) or (queue2 == conn.address) or (queue3 == conn.address) or (queue4 == conn.address) or (queue5 == conn.address);

end;

//////////////////////////////////////////////////////////////////////////New function
//// Adds user to QUEUE
  function queueuser();
  begin
if queue1 == 0 then // checks to see if user is queued
       begin
   queue1 = conn.address; // remove them from queues
   sortqueues(); // puts the queues in order (no 1 2 4 queued... but 3 and 5 unqueued)... will leave 1,2 alone... then move 4 down etc...)
      end;
else if queue2 == 0 then
       begin
   queue2 = conn.address;
   sortqueues();
      end;
else if queue3 == 0 then
       begin
   queue3 = conn.address;
   sortqueues();
      end;
else if queue4 == 0 then
       begin
   queue4 = conn.address;
   sortqueues();
      end;
else if queue5 == 0 then
       begin
   queue5 = conn.address;
   sortqueues();
      end;
  end;

//////////////////////////////////////////////////////////////////////////Modified code to the logging section
// variables to be added =  queue1... through queue5 (global strings)

//NEED TO ADD CODE TO MAKE SURE IT IS A FILE THAT HE RECIEVED (not just browsing)
//if isrealfile()

//when the user recieves a file, checks queues to remove them

case eventID of
    HE_GOT: // modified HE_GOT:
   begin
    add(' '+intToStr(conn.bytesGot)+' bytes');
if queue1 == conn.address then // checks to see if user is queued
       begin
   queue1 = 0; // remove them from queues
   sortqueues(); // puts the queues in order (no 1 2 4 queued... but 3 and 5 unqueued)... will leave 1,2 alone... then move 4 down etc...)
      end;
if queue2 == conn.address then
       begin
   queue2 = 0;
   sortqueues();
      end;
if queue3 == conn.address then
       begin
   queue3 = 0;
   sortqueues();
      end;
if queue4 == conn.address then
       begin
   queue4 = 0;
   sortqueues();
      end;
if queue5 == conn.address then
       begin
   queue5 = 0;
   sortqueues();
      end;

end;// end modified HE_GOT

/// OBSOLETE CODE /// OBSOLETE CODE /// OBSOLETE CODE /// OBSOLETE CODE
/// OBSOLETE CODE /// OBSOLETE CODE /// OBSOLETE CODE /// OBSOLETE CODE
/// OBSOLETE CODE /// OBSOLETE CODE /// OBSOLETE CODE /// OBSOLETE CODE

HE_REQUESTED:
       add(' '+method2str[conn.request.method]+decodeURL(conn.request.url));
// begin{
if queue1 == conn.address then // checks to see if user is queued and starting their download
       begin
   queue1started = TRUE;
      end;
if queue2 == conn.address then
       begin
   queue2started = TRUE;
      end;
if queue3 == conn.address then
       begin
   queue3started = TRUE;
      end;
if queue4 == conn.address then
       begin
   queue4started = TRUE;
      end;
if queue5 == conn.address then
       begin
   queue5started = TRUE;
      end;
//end;} //(end queue check)
    end;

//////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////New denial of serving for full server(2) and non queued user (add user to queues)
if !Onqueues() and limitsExceeded2() then
       begin
   sortqueues(); // puts the queues in order (no 1 2 4 queued... but 3 and 5 unqueued)... will leave 1,2 alone... then move 4 down etc...)
   if checkopenqueues() then // looks through queues to see if any are open (boolean)
          begin
      queueuser(); // calls function to add user to the first open queue
      end;
      data.refusing:='limits exceeded';
        conn.reply.mode:=HRM_VIEWQUEUES;// not 100% sure about this yet... (modified ban code)
      conn.reply.body:=getQueuesPage();// shows queued users and how much of the download has been completed
      exit;
      end;

/// END OBSOLETE CODE /// END OBSOLETE CODE /// END OBSOLETE CODE /// END OBSOLETE CODE
/// END OBSOLETE CODE /// END OBSOLETE CODE /// END OBSOLETE CODE /// END OBSOLETE CODE
/// END OBSOLETE CODE /// END OBSOLETE CODE /// END OBSOLETE CODE /// END OBSOLETE CODE