Help! want a smoother way!
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Help! want a smoother way!

Started by NightLitch, 14 March, 2004, 21:36:59

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

NightLitch

Hey guys, have tried many things know, but are back to this shit again if elseif etc. instead of for a,b in table do or i = 1,getn(table) etc.

plz help me shorten this elseif etc. to maybe a smoother way, plz.

function NewUserConnected(curUser)
	local tmp1 = NK[curUser.sName]
	local tmp2 = IP[curUser.sIP]
	if tmp2 then
		if tmp2[1] and not tmp2[2] then IP[curUser.sIP]={tmp2[1],curUser.sName}
		elseif tmp2[2] and not tmp2[3] then IP[curUser.sIP]={tmp2[1],tmp2[2],curUser.sName}
		elseif tmp2[3] and not tmp2[4] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],curUser.sName}
		elseif tmp2[4] and not tmp2[5] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],tmp2[4],curUser.sName}
		elseif tmp2[5] and not tmp2[6] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],tmp2[4],tmp2[5],curUser.sName}
		elseif tmp2[6] and not tmp2[7] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],tmp2[4],tmp2[5],tmp2[6],curUser.sName}
		elseif tmp2[7] and not tmp2[8] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],tmp2[4],tmp2[5],tmp2[6],tmp2[7],curUser.sName}
		elseif tmp2[8] and not tmp2[9] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],tmp2[4],tmp2[5],tmp2[6],tmp2[7],tmp2[8],curUser.sName}
		elseif tmp2[9] and not tmp2[10] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],tmp2[4],tmp2[5],tmp2[6],tmp2[7],tmp2[8],tmp2[9],curUser.sName}
		elseif tmp2[10] and not tmp2[11] then IP[curUser.sIP]={tmp2[1],tmp2[2],tmp2[3],tmp2[4],tmp2[5],tmp2[6],tmp2[7],tmp2[8],tmp2[9],tmp2[10],curUser.sName}
		end
	else
		IP[curUser.sIP]={curUser.sName}
	end
	if tmp1 then
		if tmp1[1] and not tmp1[2] then NK[curUser.sName]={tmp1[1],curUser.sIP}
		elseif tmp1[2] and not tmp1[3] then NK[curUser.sName]={tmp1[1],tmp1[2],curUser.sIP}
		elseif tmp1[3] and not tmp1[4] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],curUser.sIP}
		elseif tmp1[4] and not tmp1[5] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],tmp1[4],curUser.sIP}
		elseif tmp1[5] and not tmp1[6] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],tmp1[4],tmp1[5],curUser.sIP}
		elseif tmp1[6] and not tmp1[7] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],tmp1[4],tmp1[5],tmp1[6],curUser.sIP}
		elseif tmp1[7] and not tmp1[8] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],tmp1[4],tmp1[5],tmp1[6],tmp1[7],curUser.sIP}
		elseif tmp1[8] and not tmp1[9] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],tmp1[4],tmp1[5],tmp1[6],tmp1[7],tmp1[8],curUser.sIP}
		elseif tmp1[9] and not tmp1[10] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],tmp1[4],tmp1[5],tmp1[6],tmp1[7],tmp1[8],tmp1[9],curUser.sIP}
		elseif tmp1[10] and not tmp1[11] then NK[curUser.sName]={tmp1[1],tmp1[2],tmp1[3],tmp1[4],tmp1[5],tmp1[6],tmp1[7],tmp1[8],tmp1[9],tmp1[10],curUser.sIP}
		end
	else
		NK[curUser.sName]={curUser.sIP}
	end

		SaveToFile(IP , "IP", F)
		SaveToFile(NK , "NK", N)
end

it is a Database that stores info on how many ip per nick and nick per ip.

/NL
//NL

tezlo

NK[user.sName] = NK[user.sName] or {}
tinsert(NK[user.sName], user.sIP)
..

NightLitch

QuoteOriginally posted by tezlo
NK[user.sName] = NK[user.sName] or {}
tinsert(NK[user.sName], user.sIP)
..

could you do an ex. if I not understand it right. gonna try.

/NL
//NL

NightLitch

back to the beginning it feels like with tables, suck...

help Tezlo:

function NewUserConnected(curUser)

	IP[curUser.sIP] = IP[curUser.sIP] or {} 
	tinsert(IP[curUser.sIP], curUser.sName) 

	NK[curUser.sName] = NK[curUser.sName] or {} 
	tinsert(NK[curUser.sName], curUser.sIP) 

	SaveToFile(IP , "IP", F)
	SaveToFile(NK , "NK", N)
end

just by this I get double's:
IP = {
	["127.0.0.1"] = {
		[1] = "[Local]Sabin",
		[2] = "[Local]Sabin",
		["n"] = 2,
	},
}

NK = {
	["[Local]Sabin"] = {
		[1] = "127.0.0.1",
		[2] = "127.0.0.1",
		["n"] = 2,
	},
}

plz help

/NL
//NL

NightLitch

plz some help... getting nuts...

/NL
//NL

[NL]Pur

can't you write a check that looks if the ip already excist under a username. and then it shouldn't be added.

NightLitch

QuoteOriginally posted by [NL]Pur
can't you write a check that looks if the ip already excist under a username. and then it shouldn't be added.

have tried and no luck in that, then it will not write anyting. but maybe have something.

else help help...
//NL

NightLitch

here is my solusion, tell me if it's totaly messed up.

IP[curUser.sIP] = IP[curUser.sIP] or {}
	local check =""
	for ip,table in IP do
		for n,nick in table do
			if curUser.sName==nick then
				check="1"
			end
		end
	end
	if check=="" then
		tinsert(IP[curUser.sIP], curUser.sName)
	end
//NL

NightLitch

here is the complete solusion for my problem above i hope, if not, then tell me Tezlo.

function NewUserConnected(curUser)
	IP[curUser.sIP] = IP[curUser.sIP] or {}
	local ch1,temp ="",IP[curUser.sIP]
	if temp then
		for n,nick in temp do
			if curUser.sName==nick then
				ch1="1"
			end
		end
	end
	if ch1=="" then tinsert(IP[curUser.sIP], curUser.sName) end
	NK[curUser.sName] = NK[curUser.sName] or {}
	local ch2,temp ="",NK[curUser.sName]
	if temp then
		for n,ip in temp do
			if curUser.sIP==ip then
				ch2="1"
			end
		end
	end
	if ch2=="" then tinsert(NK[curUser.sName], curUser.sIP) end
	SaveToFile(IP , "IP", F)
	SaveToFile(NK , "NK", N)
end

/NL
//NL

SMF spam blocked by CleanTalk