My Art =]
 

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

My Art =]

Started by Corayzon, 19 June, 2004, 04:52:53

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Corayzon

cslave 1.0 DataArrival function

function DataArrival(tUser, sData)

	local _,_, sCmd, sArgs = strfind(sData, "(%S+)%s*(.*)|")
	-- SendToAll(tUser.sName .. " -> " .. (sCmd or "none") .. " - " .. (sArgs or "none") .. "|") -- debug line for testing

	if tSysCommands[sCmd] ~= nil and strsub(sData, 1, strlen(sBot) + 5) ~= "$To: " .. sBot then
		return tSysCommands[sCmd]["Func"](tUser, sArgs)

	elseif strsub(sData, 1, strlen(tUser.sName) + 2) == "<" .. tUser.sName .. ">" or strsub(sData, 1, strlen(sBot) + 5) == "$To: " .. sBot then
		local _,_, sMessage = strfind(sData, "%b<>%s+(.*)|")
		if tPrefixs[strsub(sMessage, 1, 1)] == 1 then
			sCmd = getCommand(sMessage)
			if tCommands[sCmd] then
				if getUserLevel(tUser) <= tCommands[sCmd].iLevel then
					local tArgs = buildArgTable(sMessage, tCommands[sCmd].iArgs)
					local iReturn = tCommands[sCmd]["Func"](tUser, tArgs)
					if (tCommands[sCmd].bReturn or iReturn) and (tCommands[sCmd].bReturn ~= 0) then return 1 else return end
				else
					return 1
				end
			else
				return 1 -- :: Hide incorrect commands
			end
		else
			 return  -- :: Let through hub chat
		end
	else
		tUser:Disconnect() -- :: Kill user on bad send (hacked or spammer client)
	end
end

noza

NotRabidWombat

"if sData == "<" .. tUser.sName .. "> !!|" then tUser:SendPM(sBot, "Welcome to cSlave 1.0") end"

Why can't "!!" be part of tCommands?

"SendToAll(tUser.sName .. " -> " .. (sCmd or "none") .. " - " .. (sArgs or "none") .. "|")"

Probably want to comment the debug line ;-)

"local iReturn = tSysCommands[sCmd]["Func"](tUser, sArgs)
if iReturn then return 1 else return end"

You can return another functions return, so this becomes:
return tSysCommands[sCmd]["Func"](tUser, sArgs);

Other than that this is an excellent example of how a DataArrival should look like :-)

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

Corayzon

*** points taken and updated to above

NotRabidWombat

If you change:
local _,_, sCmd, sArgs = strfind(sData, "(%S+) (.*)")
to
local _,_, sCmd, sArgs = strfind(sData, "(%S+)%s*(.*)|")

You *should* no longer need:
if sCmd == nil then _,_, sCmd = strfind(sData, "(.*)|") end

You could also use: (%S+)%s?(.*)|
? - means 0 or 1 occurences
Or: ^(%S+)%s*(.*)|$
^ - anchor to beginning of string
$ - anchor to end of string
These may or may not improve the efficiency of the regex since it will understand you are trying to break up the whole string.

-NotRabidWombat


I like childish behavior. Maybe this post will be deleted next.

Corayzon

NotRabidWombat, allways here to set my strait =], what would i do without ya, ehehe

*** updated to above

noza

SMF spam blocked by CleanTalk