home *** CD-ROM | disk | FTP | other *** search
- program KickGreedUsers;
-
- {
- This simple script detects and places to kick list
- those connected to your system users, who has
- no shared resources. Script kicks user immidiately if
- it has no shared resources and adds it to kicklist if
- found that user tried to connect more than CountBeforeKickList times.
- Script also automatically remove from kicklist those users who
- share resources
- It also writes 'Greed guy' to custom comment of host, if it is empty
- }
-
- //How many times user can connect without shared
- //resources before it will be added to kicklist
- const CountBeforeKickList=3;
-
-
- //Script will set this string to host's custom comment
- //of placed to kicklist users if it is blank
- const GreedComment='Greed guy';
-
-
- //Text that will be sent via net send to user that was added to kick list
- //If empty then message will not be sent
- const NetSendText='';
- //const NetSendText='Greed guys not allowed! Please share some usefull resources before using my resources.';
-
-
-
- var e,v1,v2,cnt,i:integer;
- lst,ksl:TStringList;
- s:string;
- hst:TNVHost;
- begin
- hst:=TNVHost.Create;
- lst:=TStringList.Create;
- ksl:=TStringList.Create;
- ksl.CaseSensitive:=false;
- repeat
- e:=WaitEvent(v1,v2);
- if (e=NMNP_ALERT) and ((v1 and $ffff)=NVALERT_NETWATCHER) and ((v1 and NVALERTMASK_CANCEL)=0) and (v2<>0)then
- begin
- hst.GETHOST(v2,0);
- if hst.id<>0 then
- begin
- NVWatcher.ControlListEnum(1,ksl);
- if ksl.IndexOf(hst.hname)=-1 then
- begin
- cnt:=StrToIntDef(hst.GetMetaVar('greedcnt'),0);
- hst.GetResList(false,lst);
- if lst.Count>0 then
- for i:=lst.Count-1 downto 0 do
- begin
- s:=lst.Strings[i];
- if length(s)>0 then
- begin
- if s[length(s)]='$' then lst.Delete(i);
- end;
- end;
-
- if lst.Count=0 then hst.GetResList(true,lst);
- if lst.Count=0 then
- begin
- NVWatcher.KickHost(hst.hname);
- cnt:=cnt+1;
- hst.SetMetaVar('greedcnt',IntToStr(cnt));
- if cnt>CountBeforeKickList then
- begin
- NVWatcher.ControlListPut(0,hst.hname);
- if hst.GetMetaVar('cdesc')='' then
- begin
- hst.SetMetaVar('cdesc',GreedComment);
- Action(NVACTION_SETSTATE,hst.id);
- end;
- if length(NetSendText)<>0 then NetSend('',hst.hname,NetSendText,true,false,false);
- end;
- end else
- begin
- if cnt>CountBeforeKickList then NVWatcher.ControlListDel(0,hst.hname);
- hst.SetMetaVar('greedcnt','');
- if hst.GetMetaVar('cdesc')=GreedComment then
- begin
- hst.SetMetaVar('cdesc','');
- Action(NVACTION_SETSTATE,hst.id);
- end;
- end;
- end;
- end;
- end;
- until e=0;
- hst.Free;
- lst.Free;
- ksl.Free;
- end.
-