Advertisement
deseven

sendchat.lua

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