home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2007 April / PCpro_2007_04.ISO / files / dsl / NVinst.exe / Scripts / NetWatcher / KickGreedUsers.nvs < prev   
Encoding:
Text File  |  2007-02-10  |  2.6 KB  |  96 lines

  1. program KickGreedUsers;
  2.  
  3. {
  4. This simple script detects and places to kick list
  5. those connected to your system users, who has
  6. no shared resources. Script kicks user immidiately if
  7. it has no shared resources and adds it to kicklist if
  8. found that user tried to connect more than CountBeforeKickList times.
  9. Script also automatically remove from kicklist those users who
  10. share resources
  11. It also writes 'Greed guy' to custom comment of host, if it is empty
  12. }
  13.  
  14. //How many times user can connect without shared
  15. //resources before it will be added to kicklist
  16. const CountBeforeKickList=3;
  17.  
  18.  
  19. //Script will set this string to host's custom comment
  20. //of placed to kicklist users if it is blank
  21. const GreedComment='Greed guy';
  22.  
  23.  
  24. //Text that will be sent via net send to user that was added to kick list
  25. //If empty then message will not be sent
  26. const NetSendText='';
  27. //const NetSendText='Greed guys not allowed! Please share some usefull resources before using my resources.';
  28.  
  29.  
  30.  
  31. var e,v1,v2,cnt,i:integer;
  32.     lst,ksl:TStringList;
  33.     s:string;
  34.     hst:TNVHost;
  35. begin
  36. hst:=TNVHost.Create;
  37. lst:=TStringList.Create;
  38. ksl:=TStringList.Create;
  39. ksl.CaseSensitive:=false;
  40. repeat
  41.  e:=WaitEvent(v1,v2);
  42.  if (e=NMNP_ALERT) and ((v1 and $ffff)=NVALERT_NETWATCHER) and ((v1 and NVALERTMASK_CANCEL)=0) and (v2<>0)then
  43.   begin
  44.   hst.GETHOST(v2,0);
  45.   if hst.id<>0 then
  46.    begin
  47.    NVWatcher.ControlListEnum(1,ksl);
  48.    if ksl.IndexOf(hst.hname)=-1 then
  49.     begin
  50.     cnt:=StrToIntDef(hst.GetMetaVar('greedcnt'),0);
  51.     hst.GetResList(false,lst);
  52.     if lst.Count>0 then
  53.     for i:=lst.Count-1 downto 0 do
  54.      begin
  55.      s:=lst.Strings[i];
  56.      if length(s)>0 then
  57.       begin
  58.       if s[length(s)]='$' then lst.Delete(i);
  59.       end;
  60.      end;
  61.  
  62.     if lst.Count=0 then hst.GetResList(true,lst);
  63.     if lst.Count=0 then
  64.      begin
  65.      NVWatcher.KickHost(hst.hname);
  66.      cnt:=cnt+1;
  67.      hst.SetMetaVar('greedcnt',IntToStr(cnt));
  68.      if cnt>CountBeforeKickList then
  69.       begin
  70.       NVWatcher.ControlListPut(0,hst.hname);
  71.       if hst.GetMetaVar('cdesc')='' then
  72.        begin
  73.        hst.SetMetaVar('cdesc',GreedComment);
  74.        Action(NVACTION_SETSTATE,hst.id);
  75.        end;
  76.       if length(NetSendText)<>0 then NetSend('',hst.hname,NetSendText,true,false,false);
  77.       end;
  78.      end else
  79.      begin
  80.      if cnt>CountBeforeKickList then NVWatcher.ControlListDel(0,hst.hname);
  81.      hst.SetMetaVar('greedcnt','');
  82.      if hst.GetMetaVar('cdesc')=GreedComment then
  83.       begin
  84.       hst.SetMetaVar('cdesc','');
  85.       Action(NVACTION_SETSTATE,hst.id);
  86.       end;
  87.      end;
  88.     end;
  89.    end;
  90.   end;
  91. until e=0;
  92. hst.Free;
  93. lst.Free;
  94. ksl.Free;
  95. end.
  96.