PtokaX forum

Development Section => Your Developing Problems => Topic started by: nErBoS on 15 May, 2004, 00:45:05

Title: Script PMs...
Post by: nErBoS on 15 May, 2004, 00:45:05
Hi,

Question...

Does SendPmToNick or user:SendPM() by pass in the DataArrival() ??? I have tried to block PMs from Bots and no success, made a fullsearch data and it seens not to pass. Can anyone explain why ??

Best regards, nErBoS
Title:
Post by: NotRabidWombat on 15 May, 2004, 02:00:18
Outgoing script messages do not have a loopback. So SendPM does bypass.

Having them loopback adds a complexity to scripts.
Do you send to all scripts or just the ones in order? Do you send it to the originating script?
It could also result in an infinite loop of sending messages.

-NotRabidWombat
Title:
Post by: nErBoS on 15 May, 2004, 14:35:38
Hi,

The script in cause...

Code: [Select]
--Requested by Bladerunneruk
--Made by nErBoS

sBot = "The Hider"

hide = {}
hidesv = "hide.dat"

function Main()
frmHub:RegBot(sBot)
frmHub:EnableFullData(1)
LoadFromFile(hidesv)
RefreshHide()
end

function OnExit()
SaveToFile(hidesv , hide , "hide")
end

function OpDisconnect(user, data)
if (user.iProfile == 0) then
hide[user.sName] = nil
frmHub:UnregBot(user.sName)
end
end

function DataArrival(user, data)
if (strsub(data,1,1) == "<" or strsub(data,1,5+strlen(sBot)) == "$To: "..sBot) then
data = strsub(data,1,strlen(data)-1)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == "!hide" and user.iProfile == 0) then
if (hide[user.sName] == nil) then
hide[user.sName] = 1
frmHub:UnregBot(user.sName)
user:SendPM(sBot, "You are now hide from the user list")
else
user:SendPM(sBot, "You are already hide from the user list")
end
return 1
elseif (cmd == "!unhide" and user.iProfile == 0) then
if (hide[user.sName] ~= nil) then
hide[user.sName] = nil
frmHub:RegBot(user.sName)
user:SendPM(sBot, "You are now back to the user list")
else
user:SendPM(sBot, "You are not hide from the Hub")
end
return 1
end
end
if (strsub(data,1,12) == "$GetNickList") then
RefreshHide()
end
if (strsub(data,1,5) == "$To: ") then
local s,e,usr = strfind(data, "$To:%s+(%S+)")
if (hide[usr] ~= nil) then
return 1
end
end
end

function RefreshHide()
local usr,aux
for usr, aux in hide do
frmHub:UnregBot(usr)
end
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";
sTmp = ""

sTmp = sTmp..sTab..sTableName.." = {\n"

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end

sTmp = sTmp..",\n"
end

sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

This script will block any PM if the user chooses to hide, but the others script PM are by passing.

Best regards, nErBoS
Title: Block PM's - Riding on the back of insanity
Post by: Stravides on 17 May, 2004, 16:47:44
Ok to piggyback on the back of this thread..

I want to be able to block all users PM's

UNLESS it is OP - User or User to OP
is that possible ?

Code: [Select]
Pseudo code

if [B]dataarrival is pm [/B]  then
if [B]user an operator[/B] ,
permit PM
else [B](if user not operator )[/B]
  if [B]to = operator [/B]  
permit
else
Block PM
end
end
end

Title:
Post by: nErBoS on 17 May, 2004, 22:58:32
Hi,

Yes its possible, just do this...

Code: [Select]
if (strsub(data,1,5) == "$To: ") then
if (not user.bOperator) then
local s,e,usr = strfind(data, "$To:%s+(%S+)")
if (GetItemByName(usr) ~= nil and not GetItemByName(usr).bOperator) then
return 1
end
end
end

Best regards, nErBoS
Title:
Post by: jiten on 29 September, 2004, 21:15:02
hi there nErBoS.
just wanted to ask you something about this hider.
i've tried this one and Phatty's Lance Hider.
the problem is that both of them have bugs.

this one gives the nick taken error, when i try to reconnect, even after doing the !unhide command. so, i always have to restart the hub, to reconnect again.

On ther other hand, Phatty's Lance Hider doesn't give the nick taken error, but, when i hide myself from the userlist, i always reappear after some minutes, and can't stay "invisible" like with yours.

is there a solution for this?
thanks.

jiten
Title:
Post by: nErBoS on 29 September, 2004, 22:31:16
Hi,

My script have some bad inputs, but its has been made one i don't recall who made it, just search in the "Resquest Script" section. Can you post the script of phatty that you use.

Best regards, nErBoS
Title:
Post by: jiten on 29 September, 2004, 22:49:45
here it's:

--Lance Evol v1.01
--Hider Bot, this one does not give the nick taken error ;)
--Written by Phatty 12th December 2k3
--little update today ehmm today issss 14th april 2k4

Bot = "?bot?" ;
Hidden = {}

function NewUserConnected(user)
   if Hidden == nil then
      return 1;   else
      for i,v in Hidden do
         user:SendData( "$Quit "..i ) ;
      end;
   end;
end;

OpConnected = NewUserConnected

function DataArrival(user, data)
   if(strsub(data, 1, 5) == "$Quit") then
      if Hidden[user.sName] == 1 then
         Hidden[user.sName] = nil;
      end
   elseif strsub(data, 1, 1) == "<" then
      local data=strsub(data,1,strlen(data)-1)
      local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
      
      if cmd == "!hide" and user.bOperator then
         SendToAll( "$Quit "..user.sName )
         Hidden[user.sName] = 1;
      return 1

      elseif cmd == "!unhide" and user.bOperator then
         SendToAll( "$Hello "..user.sName )
         Hidden[user.sName] = nil;
      return 1
      end;
   end;
end;
Title:
Post by: nErBoS on 30 September, 2004, 00:00:27
Hi,

Here is the script improved...

Code: [Select]
--Lance Evol v1.01
--Hider Bot, this one does not give the nick taken error ;)
--Written by Phatty 12th December 2k3
--little update today ehmm today issss 14th april 2k4
--Update on Saving Table by nErBoS
--User still hide by refresh list by nErBoS

Bot = "?bot?" ;
Hidden = {}
fHidden = "hidden.dat"

--## Configuration ##--

uLaterPtokax = 0 -- Choose 0 if your Ptokax Version is 0.3.3.0 or higher
-- Choose 1 if your Ptokax Version is lower then 0.3.3.0

--## END ##--

function Main()
frmHub:EnableFullData(1)
LoadFromFile(fHidden)
end

function OnExit()
SaveToFile(fHidden , Hidden , "Hidden")
end

function NewUserConnected(user)
if (Hidden[user.sName] ~= nil) then
SendToAll("$Quit "..user.sName)
end
if Hidden ~= nil then
for i,v in Hidden do
user:SendData("$Quit "..i)
end
end
return 1
end

OpConnected = NewUserConnected

function DataArrival(user, data)
if(strsub(data, 1, 5) == "$Quit") then
if Hidden[user.sName] == 1 then
Hidden[user.sName] = nil
if (uLaterPtokax == 1) then
OnExit()
end
end
elseif strsub(data, 1, 1) == "<" then
local data=strsub(data,1,strlen(data)-1)
local s,e,cmd = strfind(data,"%b<>%s+(%S+)")
if cmd == "!hide" and user.bOperator then
SendToAll( "$Quit "..user.sName )
Hidden[user.sName] = 1
if (uLaterPtokax == 1) then
OnExit()
end
return 1
elseif cmd == "!unhide" and user.bOperator then
SendToAll( "$Hello "..user.sName )
Hidden[user.sName] = nil
if (uLaterPtokax == 1) then
OnExit()
end
return 1
end
elseif strsub(data, 1, 8) == "$GetINFO" then
local s,e,who = strfind(data, "%$GetINFO%s+(%S+)")
if (Hidden[who] ~= nil) then
user:SendData("$Quit "..who )
return 1
end
end
end

function Serialize(tTable, sTableName, sTab)
assert(tTable, "tTable equals nil");
assert(sTableName, "sTableName equals nil");

assert(type(tTable) == "table", "tTable must be a table!");
assert(type(sTableName) == "string", "sTableName must be a string!");

sTab = sTab or "";
sTmp = ""

sTmp = sTmp..sTab..sTableName.." = {\n"

for key, value in tTable do
local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);

if(type(value) == "table") then
sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
else
local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
end

sTmp = sTmp..",\n"
end

sTmp = sTmp..sTab.."}"
return sTmp
end

function SaveToFile(file , table , tablename)
writeto(file)
write(Serialize(table, tablename))
writeto()
end

function LoadFromFile(file)
if (readfrom(file) ~= nil) then
readfrom(file)
dostring(read("*all"))
readfrom()
end
end

It only fails when the user connect or reconnects, but the OP only have to use the Hide command and all will be fixed.

Best regards, nErBoS
Title:
Post by: nErBoS on 30 September, 2004, 03:17:31
Hi,

Mutor by using RegBot() and UnregBot() you will get the same error from my older script "Your nick is already taken". Its better to use $Quit as fake info.

Best regards, nErBoS
Title:
Post by: nErBoS on 30 September, 2004, 13:54:44
Hi.

I have just tried out, try to hide yourself then refresh the userlist then unhide your self, then reconnect (i have tried that with your script and "The nick you are using is reserved for someone other. Change your nick and get back again.")

Best regards, nErBoS
Title:
Post by: Herodes on 30 September, 2004, 17:49:38
Yeah I've been having the same problems with this  (http://board.univ-angers.fr/thread.php?threadid=2564&boardid=11)....

I solved the problem with what u describe nErBoS but then I got another one .. so no real solution here I am afraid ...
Title:
Post by: nErBoS on 30 September, 2004, 20:37:09
Hi,

Ok you have the problem because you use the RegBot and UnregBot(), try only to use "$Quit" and "$Hello", the only parts that is still missing on the script above edit by me is when the user reconnects it won't hide (since the user is in the hide table).

Best regards, nErBoS