get Black_Pearl to read settings from cfg file
 

get Black_Pearl to read settings from cfg file

Started by Psycho_Chihuahua, 01 September, 2004, 12:42:50

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Psycho_Chihuahua

Hi
I got a small Prob here with Black_Pearl and hope to find the answer.

I've been trying to get the Bot to read its settings from a cfg file without luck.

Well the Functions work but the Bot:

a) Doens't register correctly to the hub
b) Only appears in Userlist when Userlist ist refreshed in the hubsoft after Users have entered
c) Doesn't appear correctly in the Userlist (only shows a Questionmark)

Ok the next 2 Post will show what i have so far


Oh yes ---> No Hubsoft Syntax Error messages at all
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

Psycho_Chihuahua

i've come this far...
Guard = {} 
sUserCount = frmHub:GetUsersCount()
sHubName = frmHub:GetHubName()
sHubDesc = frmHub:GetHubDescr()
sRedirect = frmHub:GetRedirectAddress()
sMaxUsers = frmHub:GetMaxUsers()
sMinShare = frmHub:GetMinShare()/(1024)
sCurrentShare = frmHub:GetCurrentShareAmount()/(1024^3)

ptokaxcommands = {
	op = 1, drop = 1, ban = 1, unban = 1, nickban = 1, getbanlist = 1,
	getinfo = 1, gag = 1, ungag = 1, banip = 1, ipinfo = 1, iprangeinfo = 1,
	userinfo = 1, clrtempban = 1, stat = 1 }

ptokax2commands = {
	clrpermban = 1, topic = 1, reloadtxt = 1 }

function Main() 
	frmHub:RegBot(BOTName)
assert(dofile("Data/Settings.cfg"),"settings file error")
	LoadTable(Guard,GuardianFile) 
	SendToAll("( >>>>  "..Version.." Started"..date(" the %d/%m-%Y at %X ").."  <<<< )")
	BOTNameInfo = "$MyINFO $ALL "..BOTName.." <++V:1.2 B_P,C:psycho_chihuahua> $ $GanjaLan(ThC)"..strchar( 1 ).."$johnnie242@bluewin.ch$" 
	SendToAll(BOTNameInfo)
end 

---------------- Vip-Reg Connected -----------------
function NewUserConnected(user)
if GuardianCheck==1 then 
	local acc,comp = BlockGuard(user.sIP)
	if acc then 
		user:SendData(denyMsg)
		user:SendData(BotName, "*** This is a private hub. You have no business here. - Dies ist ein privater Hub. Du hast hier nichts verloren. ***") 
		if notifyOps==1 then
			SendPmToOps(BotName,"*** "..user.sName.." - ( "..user.sIP.." ) from company ( "..comp.." ) tried to logg in! ***")
		end
		if banuser == 1 then
			user:SendData(banMsg)
			user:Ban() 
		else
			user:Disconnect()
		end
	end
end
	if user.iProfile == 2 then 
		SendToAll(BOTName, RandomVIPEntryMsg(user))
		user:SendData(BOTName, "Welcome to "..sHubName.." " ) 
	elseif user.iProfile == 3 then 
		SendToAll(BOTName, RandomRegEntryMsg(user))
		user:SendData(BOTName, "Welcome to "..sHubName.." " ) 
	end
end

--------- Vip-Reg Disconnected ---------

function UserDisconnected(user)
	if user.iProfile == 2 then 
		SendToAll(BOTName, RandomVIPExitMsg(user))
       elseif user.iProfile == 3 then 
		SendToAll(BOTName, RandomRegExitMsg(user))
	end
end

--------- Op Connected ---------

function OpConnected(user) 
	if user.iProfile == 0 then  
		user:SendData(BOTName, "Welcome to "..sHubName.." " ) 
		SendToAll(BOTName, RandomMasterEntryMsg(user))
       elseif user.iProfile == 1 then 
		user:SendData(BOTName, "Welcome to "..sHubName.." " )
		SendToAll(BOTName, RandomOPEntryMsg(user))
	end
end

--------- Op Disconnected ---------

function OpDisconnected(user) 
	if user.iProfile == 0 then  
		SendToAll(BOTName, RandomMasterExitMsg(user))
       elseif user.iProfile == 1 then 
		SendToAll(BOTName, RandomOPExitMsg(user))
	end 
end

function DataArrival( user , data )

	if strsub(data, 1,1) == "<" then
		data=strsub(data,1,strlen(data)-1)
		s,e,cmd = strfind(data,"%b<>%s+(%S+)")
		if (cmd=="!help") then 
			if user.iProfile == nil then 
				SendUserhelp(user) 
				return 1 
			elseif user.iProfile == 0 then 
				SendMasterhelp(user) 
				return 1 
			elseif user.iProfile == 1 then 
				SendOpshelp(user) 
				return 1 
			elseif user.iProfile == 2 then 
				SendViphelp(user) 
				return 1 
			elseif user.iProfile == 3 then 
				SendReghelp(user) 
				return 1 
			elseif user.iProfile == 4 then 
				SendModeratorhelp(user) 
				return 1 
			end 
		elseif (cmd=="!lol") then 
			SendLol(user)
			return 1 
		elseif (cmd=="!rules") then 
			SendRules(user) 
			return 1 
		elseif (cmd=="!network") then 
			SendNetwork(user) 
			return 1 
		elseif (cmd=="!faq") then 
			SendFaq(user) 
			return 1 
		elseif (cmd=="!description") then 
			SendDescription(user) 
			return 1 
		elseif (cmd=="!showreg") then
			showreg(user)
			return 1
		elseif (cmd == "!myip" ) then
			user:SendData(BOTName,"Your Ip is: "..user.sIP)
			return 1
		elseif (cmd == "!myversion" ) then
			user:SendData(BOTName,"Your Client Version is: "..user.iVersion)
			return 1
		elseif (cmd == "!addreguser") then 
			if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then 
				return 0 
			elseif user.iProfile == nil then 
				user:SendPM(BOTName, "you are not allowed to use this command") 
			end 
		elseif (cmd == "!me") then 
			AddAChatter(sUser) 
			return 0 
		end
		local s, e, cmd, args = strfind(data, "^%b<> %!(%a+)%s*(.*)%|$")
		if s and ptokaxcommands[cmd] then
			if user.iProfile == 1 or user.iProfile == 0 or user.iProfile == 4 then 
				return 0
			elseif user.iProfile == nil then
				SendPM(BOTName, "you are not allowed to use this command") 
			end
			local s, e, cmd, args = strfind(data, "^%b<> %!(%a+)%s*(.*)%|$")
			if s and ptokax2commands[cmd] then
				if user.iProfile == 1 or user.iProfile == 4 then 
					return 0
				elseif user.iProfile == nil then
					SendPM(BOTName, "you are not allowed to use this command") 
				end
			elseif (cmd == "!restartscripts") and user.iProfile == 0 then 
				return 0 
			elseif (cmd == "!restart") and user.iProfile == 0 then 
				return 0 
			end
		end

	elseif strsub(data, 1,7) == "$MyINFO" then
		local _,_,openhubs = strfind( data , ".+H:(%d+)" );
         if OpenCheck == 1 then
		if ( openhubs ~= "0" ) then
			SendToNick( user.sName , "Du bist in einen oder mehreren Open Hubs. Dies verst?sst gegen unsere Regeln. Deshalb wird die Verbindung zur?ckgesetzt!" )
			user:Disconnect()
		end
	end
end
end
function RandomRegEntryMsg(user)
	local randomSeed = random(4)
	if randomSeed == 1 then 
		return user.sName.." rocks the hub with his presence." 
	elseif randomSeed == 2 then 
		return "Walking down the stairs "..user.sName.." enters the hub!" 
	elseif randomSeed == 3 then 
		return user.sName.." is about to get the party started ..." 
	elseif randomSeed == 4 then 
		return user.sName.." is happy to be a member of this cool hub!" 
	end
end

function RandomVIPEntryMsg(user)
	local randomSeed = random(4)
	if randomSeed == 1 then 
		return user.sName.." really adores this cool place." 
	elseif randomSeed == 2 then 
		return user.sName.."Drums are playing while "..user.sName.." enters the hub!" 
	elseif randomSeed == 3 then 
		return user.sName.." has finally found the fountain of youth ... through sharing...." 
	elseif randomSeed == 4 then 
		return user.sName.." is pooring drinks for all to enjoy his presence!" 
	end
end

function RandomOPEntryMsg(user)
	local randomSeed = random(7)
	if randomSeed == 1 then 
		return user.sName.." has entered the hub. Please give him a hand!" 
	elseif randomSeed == 2 then 
		return user.sName.." has entered the hub. Let's grab his slots!" 
	elseif randomSeed == 3 then 
		return user.sName.." tried to make a silence entrance but failed." 
	elseif randomSeed == 4 then 
		return "\r\n\r\n \\ ~ ~ //\r\n ( 0-0 )\r\n----oOO-------(_)--------------------------\r\nI "..user.sName.." I\r\n I Is watching you I\r\n-------------------oOO----------------------\r\n I__I__I\r\n I I I I\r\n nooO Ooo" 
	elseif randomSeed == 5 then 
		return "Please call my name, because i am "..user.sName.." !!!!!" 
	elseif randomSeed == 6 then 
		return "Please give him a big welcome! "..user.sName.." has entered the hub.!" 
	elseif randomSeed == 7 then 
		return "Here is "..user.sName..". Wow look at the move while he's walking in here!" 
	end
end

function RandomMasterEntryMsg(user)
	local randomSeed = random(7)
	if randomSeed == 1 then 
		return user.sName.." needs some mistresses, please pm him if you want to ....!" 
	elseif randomSeed == 2 then 
		return user.sName.." has returned to the scene of the crime!" 
	elseif randomSeed == 3 then 
		return user.sName.." has entered to chat with all of you." 
	elseif randomSeed == 4 then 
		return "\r\n\r\n \\ ~ ~ //\r\n ( 0-0 )\r\n----oOO-------(_)--------------------------\r\nI "..user.sName.." I\r\n I Is looking at you I\r\n-------------------oOO----------------------\r\n I__I__I\r\n I I I I\r\n nooO Ooo" 
	elseif randomSeed == 5 then 
		return "Who is the man behind the curtains? Yes it is "..user.sName..".'" 
	elseif randomSeed == 6 then 
		return "Watch me throw slots at everybody because i am "..user.sName.." the big spender of this hub.!" 
	elseif randomSeed == 7 then 
		return "Here is "..user.sName.." !" 
	end
end

function RandomRegExitMsg(user)
	local randomSeed = random(3)
	if randomSeed == 1 then 
		return user.sName..", has left the hub and took all his available sluts........eh slots with him!" 
	elseif randomSeed == 2 then 
		return "Riding his harley, "..user.sName.." is now riding the freeway." 
	elseif randomSeed == 3 then 
		return user.sName.." has left the hub, and he's gonna be stinking drunk when he comes back." 
	end
end

function RandomVIPMsgExit(user)
	local randomSeed = random(3)
	if randomSeed == 1 then 
		return user.sName..", has left the hub!" 
	elseif randomSeed == 2 then 
		return "Circling on the parkinglot, "..user.sName.." is waiting for people to join him for a ride." 
	elseif randomSeed == 3 then 
		return user.sName.." has left the hub, shall he return?" 
	end
end

function RandomOPExitMsg(user)
	local randomSeed = random(7)
	if randomSeed == 1 then 
		return user.sName.." snaps his fingers and disappears like david copperfield ..." 
	elseif randomSeed == 2 then 
		return user.sName.." is gone for a ride on the storm ..." 
	elseif randomSeed == 3 then 
		return user.sName.." took his board and rides the waves now ..." 
	elseif randomSeed == 4 then 
		return user.sName.." has left the hub and is now howling to the moon!'" 
	elseif randomSeed == 5 then 
		return "'oh mama!', says "..user.sName.." and suddenly disappears out off sight ..." 
	elseif randomSeed == 6 then 
		return user.sName.." does a elvis presley imitation and has left the building!'" 
	elseif randomSeed == 7 then 
		return user.sName.." has left the hub, and is taking his absurdly huge share with him." 
	end
end

function RandomMasterExitMsg(user)
	local randomSeed = random(7)
	if randomSeed == 1 then 
		return user.sName.." waves his hand and slams the door behind him ..." 
	elseif randomSeed == 2 then 
		return user.sName.." has left this incredible cool place ..." 
	elseif randomSeed == 3 then 
		return user.sName.." has left the hub to check his e-mail ..." 
	elseif randomSeed == 4 then 
		return user.sName.." is chasing cats in the alley!'" 
	elseif randomSeed == 5 then 
		return "'oh mama!', says "..user.sName.." and left to powder his nose ..." 
	elseif randomSeed == 6 then 
		return user.sName.." is about to get to drunk to type, so he left the hub!'" 
	elseif randomSeed == 7 then 
		return user.sName.." has left the hub, to do some weirdo online game." 
	end
end

function DoRead(user)
	while 1 do 
		line = read() 
		if line == nil then break end
			user:SendPM(BOTName, line)
		end 
	readfrom() 
end

function showreg(user)
	user:SendPM(BOTName, "==> Regged users <==")
	user:SendPM(BOTName, "_______________________________")
	user:SendPM(BOTName, "??? Level\t==> Nick")
	user:SendPM(BOTName, "???????????????????????????????")
	local allprofiles = GetProfiles()
	local index, profile, index2, username, n
	for index, profile in allprofiles do
		if strlower(profile) ~= strlower("reg") then
			n = 0
			message = "??? "..profile.."\t==> "
			local users = GetUsersByProfile(profile)
			for index2, username in users do
				if not username or username == "" then
					message = nil
				elseif n < 3 then
					message = message..username.."\t"
					n = n + 1
				else
					user:SendPM(BOTName, message)
					message = "??? \t\t==> "..username.."\t"
					n = 1
				end
			end
			if message == "??? "..profile.."\t==> " then
				message = nil
			end
			user:SendPM(BOTName, message)
		end
	end
end
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

Psycho_Chihuahua

function BlockGuard(ip) 
	local _,_,a,b,c,d = strfind(ip, "(%d+)%.(%d+)%.(%d+)%.(%d+)") 
	if ( tonumber(a) and tonumber(b) and tonumber(c) and tonumber(d) ) then 
		local uip = ComputeIP(a)..ComputeIP(b)..ComputeIP(c)..ComputeIP(d)
		local ip1,ip2
		for r1,comp in Guard do
 			_,_,a,b,c,d,e,f,g,h = strfind(r1, "(%d+)%.(%d+)%.(%d+)%.(%d+)-(%d+)%.(%d+)%.(%d+)%.(%d+)") 
			ip1 = ComputeIP(a)..ComputeIP(b)..ComputeIP(c)..ComputeIP(d)
			ip2 = ComputeIP(e)..ComputeIP(f)..ComputeIP(g)..ComputeIP(h)
			if tonumber(uip) >= tonumber(ip1) and tonumber(uip) <= tonumber(ip2) then 
				return 1,comp
			end 
		end 
	end 
end 

function ComputeIP(num) 
 	num = tonumber(num)
	if (num < 10) then
		return num.."00"
	elseif (num < 100) then
		return num.."0"
	else
		return num
	end
end

function LoadTable(table,file) 
	local handle = openfile(file, "r") 
	if (handle) then 
		local line = read(handle) 
		while line do 
			s,e,comp,ip = strfind(line, "(.+):(%d+%.%d+%.%d+%.%d+-%d+%.%d+%.%d+%.%d+)") 
			table[ip]=comp
			line = read(handle) 
		end 
		closefile(handle) 
	end 
end

function SendOprules(user) 
	readfrom("Data/oprules.txt") 
	DoRead(user)
end

function SendRules(user) 
	readfrom("Data/rules.txt") 
	DoRead(user) 
end

function SendNetwork(user) 
	readfrom("Data/network.txt") 
	DoRead(user) 
end

function SendLol(user) 
	readfrom("Data/lol.txt") 
	DoRead(user)
end

function SendFaq(user) 
	readfrom("Data/faq.txt") 
	DoRead(user)
end

function SendDescription(user) 
	readfrom("Data/description.txt") 
	DoRead(user) 
end

function SendUserhelp(user) 
	readfrom("Data/userhelp.txt") 
	DoRead(user)  
end

function SendMasterhelp(user) 
	readfrom("Data/masterhelp.txt") 
	DoRead(user)  
end

function SendOpshelp(user) 
	readfrom("Data/opshelp.txt") 
	DoRead(user)  
end

function SendViphelp(user) 
	readfrom("Data/viphelp.txt") 
	DoRead(user) 
end

function SendReghelp(user) 
	readfrom("Data/reghelp.txt") 
	DoRead(user) 
end

function SendModeratorhelp(user) 
	readfrom("Data/moderatorhelp.txt") 
	DoRead(user) 
end
and in the Data/Settings.cfg i have
GuardianCheck = 1 
notifyOps = 1
banuser = 1
GuardianFile = "scripts/Data/guard/guarding.p2p"
denyMsg = "*** This is a private hub. You have no business here. - Dies ist ein privater Hub. Du hast hier nichts verloren." 
banMsg = "*** Your IP has been banned. - Deine IP wurde gebannt" 
OpenCheck = 1  -- 1=on/0=off
DisconnectMessage = "You are in one or more Open Hubs and that is against our Hubrules!"
BOTName ="Black_Pearl"
Version ="Black Pearl 1.2 - English"
Creators ="Troubadour, psycho_chihuahua"
PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

Psycho_Chihuahua

PtokaxWiki ?PtokaX Mirror + latest Libs

01100001011011000111001101101111001000000110101101101110011011110111011101101110001000000110000101110011001000000101010001101111011010110110111101101100011011110111001101101000

Troubadour

QuoteOriginally posted by Mutor
assert(dofile("Data/Settings.cfg"),"settings file error")

function Main() 
	frmHub:RegBot(BOTName)
	LoadTable(Guard,GuardianFile) 
	SendToAll("( >>>>  "..Version.." Started"..date(" the %d/%m-%Y at %X ").."  <<<< )")
	BOTNameInfo = "$MyINFO $ALL "..BOTName.." <++V:1.2 B_P,C:psycho_chihuahua> $ $GanjaLan(ThC)"..strchar( 1 ).."$johnnie242@bluewin.ch$" 
	SendToAll(BOTNameInfo)
end

could do it shorter like

dofile("Data/Settings.cfg");

Regards,
Troubadour
Regards,

Troubadour

** Guardian Forum **

hubaddy:   nederfun.no-ip.com

nErBoS

Hi,

Yes Troubadour, thats right, but the assert(file, msg) will popup a error on the editor with the message you want, will be easier to see why the script is bugging.

Best regards, nErBoS
--## nErBoS Spot ##--

SMF spam blocked by CleanTalk