Offline-Message-System lua problem

04/02/2016 01:07 tigerstefan#1
I have a little problem with Offline-Message-System lua function with this 2 functions:i tried this:
Code:
function find_player_by_name(name)
    return mysql_query("SELECT count(name) FROM player.player WHERE name = '"..name.."';")[1][1] > 0
end  
function get_playerid_by_playername(name)
    return mysql_query("SELECT id FROM player.player WHERE name = '"..name.."';").id[1]
end
And this:
Code:
function find_player_by_name(name)
    local a = mysql_query('SELECT COUNT(*) AS exist FROM player.player WHERE name="'..name..'"')
    if a.exist[1] == 1 then return true else return false end
end

function get_playerid_by_playername(name)
    local a = mysql_query('SELECT id FROM player.player WHERE name="'..name..'"')
    return a.id[1]
end
the mysql_query is this:
Code:
mysql_query = function(query)
   if not pre then
       local rt = io.open('CONFIG', 'r'):read('*all')
       pre = string.gsub(rt, '.+PLAYER_SQL:%s(%S+)%s(%S+)%s(%S+)%s(%S+).+', '-h%1 -u%2 -p%3 -D%4')
   end

   math.randomseed(os.time())

   local fi, t, out = 'mysql_data_'..math.random(10^9)+math.random(2^4,2^10),{},{}
   os.execute('mysql '..pre..' -e'..string.format('%q', query)..' > '..fi)

   for av in io.open(fi, 'r'):lines() do table.insert(t,split(av, '\t')) end; os.remove(fi);
   for i = 2, table.getn(t) do table.foreach(t[i],function(a, b)
       out[i-1]              = out[i-1] or {}
       out[i-1][a]           = tonumber(b) or b
       out[t[1][a]]          = out[t[1][a]] or {}
       out[t[1][a]][i-1]     = tonumber(b) or b
   end) end
   return out
end
the part in the quest that uses that functions in:
Code:
				local playerId = pc.get_player_id()  -- Nachricht an sich selbst schreiben lassen. ist meine PLAYER ID !!!!
				pc.change_money(-MESSAGES[playerId].MONEY)
				messagesystem_1.write_message(MESSAGES[playerId].ADDRESS, MESSAGES[playerId].NAME , MESSAGES[playerId].SUBJECT, MESSAGES[playerId].TEXT, MESSAGES[playerId].ITEM, MESSAGES[playerId].MONEY)
				messagesystem_1.reload_msg('POSTBOXOUT')
			elseif cmd[1] == 'NEWMESSAGE' then
				if not find_player_by_name(cmd[2]) then syschat'Dieser Spielername existiert nicht.' return end
				item_ = tonumber(cmd[5])
				pc.setqf('ITEMCOUNT',0)
				if item_ != -1 then
					item.select_cell(item_)
					local attr = {{item.get_attribute(0)}, {item.get_attribute(1)}, {item.get_attribute(2)}, {item.get_attribute(3)},{item.get_attribute(4)},{item.get_attribute(5)}, {item.get_attribute(6)}}
					local socket, itemVnum, itemCount = {item.get_socket(0), item.get_socket(1), item.get_socket(2),item.get_socket(3),item.get_socket(4),item.get_socket(5)}, item.get_vnum(), item.get_count() 
					if not messagesystem_1.item_can_send(itemVnum) then syschat'Dieses Item kann nicht versendet werden.' return end
					item_ = itemVnum.."#"..itemCount.."#"..socket[1].."#"..socket[2].."#"..socket[3].."#"..socket[4].."#"..socket[5].."#"..socket[6].."#"..attr[1][1].."#"..attr[1][2].."#"..attr[2][1].."#"..attr[2][2].."#"..attr[3][1].."#"..attr[3][2].."#"..attr[4][1].."#"..attr[4][2].."#"..attr[5][1].."#"..attr[5][2].."#"..attr[6][1].."#"..attr[6][2].."#"..attr[7][1].."#"..attr[7][2]
					pc.setqf('ITEMCOUNT', pc.count_item(itemVnum))
				end
				MESSAGES[pc.get_player_id()] = {
					['ADDRESS'] = get_playerid_by_playername(cmd[2]),
					['NAME'] = cmd[2],
					['SUBJECT'] = cmd[3],
					['TEXT'] = "",
					['MONEY'] = cmd[4],
					['ITEM'] =  item_,
				}
				cmdchat('MESSAGESYSTEM NEWMESSAGE_COMPLETE')
			elseif cmd[1] == 'TEXT' then
				MESSAGES[pc.get_player_id()].TEXT = MESSAGES[pc.get_player_id()].TEXT..cmd[2]
				cmdchat('MESSAGESYSTEM TEXT_COMPLETE')
			elseif cmd[1] == 'DELETE_MSG' then
				messagesystem_1.delete_msg(cmd[2],tonumber(cmd[3]))
			elseif cmd[1] == 'TAKE_ITEM' then
And the error i get is this:
Code:
SYSERR: Apr  2 00:28:04 :: RunState: LUA_ERROR: [string "messagesystem_1"]:8: attempt to index field `?' (a nil value)
SYSERR: Apr  2 00:28:04 :: WriteRunningStateToSyserr: LUA_ERROR: quest messagesystem_1.start click
I tried with mysql_query functions from source but no result....Other errors.
Any lua developer to help me?I think is from that 2 functions but i am not sure.It could be from the mysql_query function or the quest?
Another way to make it work?:confused::confused::confused:
04/03/2016 18:20 tigerstefan#2
No one?With a little knolage in lua?
04/11/2016 23:21 tigerstefan#3
Up
04/12/2016 09:23 IceFear#4
I don't know what the problem with the message system is, but if you execute the queries like that, you will will definetely have a problem with SQL injections.