Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.47 KB | None | 0 0
  1. -- PtokaX > AJAX Chat script
  2. -- version 2
  3. -- by deseven, 2010
  4.  
  5. -- settings
  6. BadChars = {".","?","!","+","-",}
  7. MysqlHost = "localhost"
  8. MysqlUser = "ajaxchat"
  9. MysqlPass = "ajaxchatpwd"
  10. MysqlDB = "ajaxchat"
  11. UseIconv = true
  12. IconvFrom = "cp1251"
  13. IconvTo = "utf8//TRANSLIT"
  14.  
  15. function ChatArrival(user,data)
  16.     Core.GetUserAllData(user)
  17.     if string.sub(data,1,1) ~= "<" then end
  18.     local s,e,chat = string.find(data,"^%b<>%s(.*)$")
  19.     local when = os.date("%Y-%m-%d %H:%M:%S")
  20.     local nick = user.sNick
  21.  
  22.     -- checking for BadChars
  23.     for k,v in pairs(BadChars) do
  24.         if chat == v then
  25.             return
  26.         end
  27.     end
  28.  
  29.     -- preparing strings for bash
  30.     -- welcome to the quotes' hell
  31.     chat = string.sub(chat, 1, -2)
  32.     nick = string.gsub(nick,"\\","\\\\")
  33.     nick = string.gsub(nick,"'","'\"\\'\"'")
  34.     chat = string.gsub(chat,"\\","\\\\")
  35.     chat = string.gsub(chat,"'","'\"\\'\"'")
  36.  
  37.     -- sending message to AJAX chat
  38.     SendMsg = "echo 'SET NAMES utf8; INSERT INTO ajax_chat_messages (userName,dateTime,text,userID) VALUES ('\"'\"'"..nick.."'\"','\"'"..when.."'\"','\"'"..chat.."'\"','50000');\" "
  39.     if UseIconv == true then
  40.         SendMsg = SendMsg.."| iconv -f "..IconvFrom.." -t "..IconvTo.." | mysql -B -N -h "..MysqlHost.." -u"..MysqlUser.." -p"..MysqlPass.." "..MysqlDB
  41.     else
  42.         SendMsg = SendMsg.."| mysql -B -N -h "..MysqlHost.." -u"..MysqlUser.." -p"..MysqlPass.." "..MysqlDB
  43.     end
  44.     os.execute(SendMsg)
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement