Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local secret="-snip-"
- local wi=infutil.wrap("webinterface")
- local ami=infutil.wrap("adventure map interface")
- local sc
- local function connect()
- if sc then
- wi.socket_close(sc)
- sc=nil
- end
- local e
- while not sc do
- e,sc=pcall(wi.socket_create,"localhost",1338)
- if not e then
- sc=nil
- end
- if not sc then
- sleep(5)
- end
- end
- wi.socket_setAutoFlush(sc,true)
- wi.socket_listen(sc)
- wi.socket_write(sc,secret.."\n")
- end
- connect()
- local function tell(txt,plr)
- if plr then
- ami.getPlayerByName(plr).sendChat(txt)
- else
- for k,v in pairs(ami.getPlayerUsernames()) do
- ami.getPlayerByName(v).sendChat(txt)
- end
- end
- end
- while true do
- local p={os.pullEvent()}
- if p[3]==sc then
- if p[1]=="socket_connectionClosed" then
- connect()
- elseif p[1]=="socket_line" then
- local dat=pt.d(p[4])
- if dat[1]=="say" then
- tell(unpack(dat,2))
- elseif dat[1]=="lua" then
- local e,r=loadstring(dat[2])
- if not e then
- wi.socket_write(sc,pt.c("lua_resp",false,r))
- else
- wi.socket_write(sc,pt.c("lua_resp",true,pcall(r)))
- end
- end
- end
- end
- if p[1]=="chat_message" or p[1]=="player_login" or p[1]=="player_logout" or p[1]=="player_respawn" or p[1]=="player_change_world" or p[1]=="chat_death" or p[1]=="modem_message" then
- wi.socket_write(sc,pt.c("event",unpack(p)).."\n")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement