PtokaX forum

Development Section => Your Developing Problems => Topic started by: Themaster on 11 January, 2005, 08:09:01

Title: past in a script
Post by: Themaster on 11 January, 2005, 08:09:01
have a little problem 2 past this script i made a standalone...
i can't get in 2 my script...

Bot = "UserLog"

UserInfo = {}

sOffline = "UserLog.lst"

-- New User Connected --
function NewUserConnected(user,data)
LogInfo(user)
end

function Main()
   frmHub:RegBot(Bot)
   LoadFromFile(sOffline)
end

function OnExit()
   SaveToFile(sOffline, UserInfo , "UserInfo")
end

function DataArrival(user, data)
if (strsub(data, 1, 1) == "<" ) then
      local data=strsub(data,1,strlen(data)-1)
      local _,_,cmd=strfind(data, "%b<>%s+(%S+)")
      local Commands = (UserCommands(user, data, cmd))
      return Commands
   elseif (strsub(data,1,4) == "$To:") then
      data = strsub(data,1,-2);
      local s,e,whoTo,from,arg = strfind(data,"%$To:%s+(%S+)%s+From:%s+(%S+)%s+%$%b<>%s+(.*)")
      local s,e,cmd = strfind(arg,"(%S+)")
      if (whoTo == Bot) then
      UserCommands(user,data,cmd)
      end
   end
end

function UserCommands(user,data,cmd)
   if cmd == "+log" then
     UserLog(user,data)
      return 1
   end
end

function UserLog(user,data)
   local s,e,arg = strfind(data,"%b<>%s+%S+%s+(%S+)")
  -- dofile(sOffline)
   if UserInfo[arg] then
   local msg = "\r\n\r\n"
      msg = msg .."\t"..strrep("-=",40).."\r\n"
      msg = msg .."\t\tThe user Name are:\t\t"..arg.."\r\n"
      msg = msg .."\t\tThe user Ip are:\t\t"..UserInfo[arg].IP.."\r\n"
      msg = msg .."\t\tThe user Profile are:\t\t"..UserInfo[arg].PROFILE.."\r\n"
      msg = msg .."\t\tUser are Seen:\t\t"..UserInfo[arg].Seen.."\r\n"
      msg = msg .."\t\tUserInfo :\t\t"..UserInfo[arg].MYINFO.."\r\n"
      msg = msg .."\r\n"
   user:SendPM(Bot, msg)
   end
end

-- Log Users Info --
function LogInfo(user)
-- LoadFromFile(sOffline)
   UserInfo[user.sName] = {["IP"]=user.sIP,["PROFILE"]=user.iProfile,["MYINFO"]=user.sMyInfoString,["Seen"]=date("%m/%d/%y"),}
   SaveToFile(sOffline, UserInfo , "UserInfo")
return 1
end

-- Serialize --
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"); -- THE BUG WAS IN HERE
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.."}\r\n"
return sTmp
end

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

function LoadFromFile(file)
readfrom(file)
dostring(read("*all"))
readfrom()
end

it work's as a stanalone..so please help me 2 fix it