Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- PtokaX > AJAX Chat script
- -- version 1.0.2
- -- by deseven, 2010-2011
- -- main settings
- MysqlHost = "localhost"
- MysqlUser = "ajaxchat"
- MysqlPass = "ajaxchatpwd"
- MysqlDB = "ajaxchat"
- -- codepage and convertion settings
- UseIconv = true
- IconvFrom = "cp1251"
- IconvTo = "utf8//TRANSLIT"
- UseSetNames = true
- BadChars = {".","?","!","+","-",}
- function ChatArrival(user,data)
- Core.GetUserAllData(user)
- local s,e,chat = string.find(data,"^%b<>%s(.*)$")
- local when = os.date("%Y-%m-%d %H:%M:%S")
- local nick = user.sNick
- -- checking for BadChars
- for k,v in pairs(BadChars) do
- if string.sub(chat,1,1) == v then
- return
- end
- end
- -- preparing strings for bash
- -- welcome to the quotes' hell
- chat = string.sub(chat,1,-2)
- nick = string.gsub(nick,"\\","\\\\")
- nick = string.gsub(nick,"'","'\"\\'\"'")
- chat = string.gsub(chat,"\\","\\\\")
- chat = string.gsub(chat,"'","'\"\\'\"'")
- chat = string.gsub(chat,"|","|")
- chat = string.gsub(chat,"$","$")
- -- sending message to AJAX chat
- if UseSetNames == true then
- SendMsg = "echo 'SET NAMES utf8; INSERT INTO ajax_chat_messages (userName,dateTime,text,userID) VALUES ('\"'\"'"..nick.."'\"','\"'"..when.."'\"','\"'"..chat.."'\"','50000');\" "
- else
- SendMsg = "echo 'INSERT INTO ajax_chat_messages (userName,dateTime,text,userID) VALUES ('\"'\"'"..nick.."'\"','\"'"..when.."'\"','\"'"..chat.."'\"','50000');\" "
- end
- if UseIconv == true then
- SendMsg = SendMsg.."| iconv -f "..IconvFrom.." -t "..IconvTo.." | mysql -B -N -h "..MysqlHost.." -u"..MysqlUser.." -p"..MysqlPass.." "..MysqlDB
- else
- SendMsg = SendMsg.."| mysql -B -N -h "..MysqlHost.." -u"..MysqlUser.." -p"..MysqlPass.." "..MysqlDB
- end
- os.execute(SendMsg)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement