Skip to content
Snippets Groups Projects
Commit 814e1415 authored by dg's avatar dg
Browse files

talk

git-svn-id: http://svn.net-core.org/repos/t-engine4@2774 51575b47-30f0-44d4-a5cc-537603b46e54
parent 9fc2989a
No related branches found
No related tags found
No related merge requests found
...@@ -268,6 +268,9 @@ function _M:instanciate(mod, name, new_game, no_reboot) ...@@ -268,6 +268,9 @@ function _M:instanciate(mod, name, new_game, no_reboot)
-- And now run it! -- And now run it!
_G.game:run() _G.game:run()
-- Add user chat if needed
if mod.allow_userchat and _G.game.key then profile.chat:setupOnGame() end
-- Disable the profile if ungood -- Disable the profile if ungood
if mod.short_name ~= "boot" then if mod.short_name ~= "boot" then
if not hash_valid then if not hash_valid then
......
...@@ -23,6 +23,7 @@ local url = require "socket.url" ...@@ -23,6 +23,7 @@ local url = require "socket.url"
local ltn12 = require "ltn12" local ltn12 = require "ltn12"
local lanes = require "lanes" local lanes = require "lanes"
local Dialog = require "engine.ui.Dialog" local Dialog = require "engine.ui.Dialog"
local UserChat = require "engine.UserChat"
require "Json2" require "Json2"
------------------------------------------------------------ ------------------------------------------------------------
...@@ -72,6 +73,7 @@ end ...@@ -72,6 +73,7 @@ end
module(..., package.seeall, class.make) module(..., package.seeall, class.make)
function _M:init() function _M:init()
self.chat = UserChat.new()
self.generic = {} self.generic = {}
self.modules = {} self.modules = {}
self.evt_cbs = {} self.evt_cbs = {}
...@@ -376,11 +378,6 @@ function _M:eventGetNews(e) ...@@ -376,11 +378,6 @@ function _M:eventGetNews(e)
end end
end end
function _M:eventPushCode(e)
local f = loadstring(e.code)
if f then pcall(f) end
end
function _M:eventGetConfigs(e) function _M:eventGetConfigs(e)
local data = e.data:unserialize() local data = e.data:unserialize()
local module = e.module local module = e.module
...@@ -408,6 +405,15 @@ function _M:eventGetConfigs(e) ...@@ -408,6 +405,15 @@ function _M:eventGetConfigs(e)
if self.evt_cbs.GetConfigs then self.evt_cbs.GetConfigs(e) self.evt_cbs.GetConfigs = nil end if self.evt_cbs.GetConfigs then self.evt_cbs.GetConfigs(e) self.evt_cbs.GetConfigs = nil end
end end
function _M:eventPushCode(e)
local f = loadstring(e.code)
if f then pcall(f) end
end
function _M:eventChat(e)
self.chat:event(e)
end
--- Got an event from the profile thread --- Got an event from the profile thread
function _M:handleEvent(e) function _M:handleEvent(e)
e = e:unserialize() e = e:unserialize()
......
...@@ -46,3 +46,4 @@ You are an adventurer, set out to discover wonders, explore old places, and vent ...@@ -46,3 +46,4 @@ You are an adventurer, set out to discover wonders, explore old places, and vent
]] ]]
starter = "mod.load" starter = "mod.load"
profile_stats_fields = {"artifacts", "characters", "deaths", "uniques"} profile_stats_fields = {"artifacts", "characters", "deaths", "uniques"}
allow_userchat = true
...@@ -19,10 +19,12 @@ ...@@ -19,10 +19,12 @@
require "engine.class" require "engine.class"
local socket = require "socket" local socket = require "socket"
local UserChat = require "profile-thread.UserChat"
module(..., package.seeall, class.make) module(..., package.seeall, class.make)
function _M:init() function _M:init()
self.chat = UserChat.new(self)
end end
function _M:connected() function _M:connected()
...@@ -125,7 +127,9 @@ function _M:step() ...@@ -125,7 +127,9 @@ function _M:step()
local data = l:sub(5) local data = l:sub(5)
if code == "101" then if code == "101" then
local e = data:unserialize() local e = data:unserialize()
if e and e.e and self["push"..e.e] then self["push"..e.e](self, e) end if e and e.e:find("^Chat") then self.chat:event(e)
elseif e and e.e and self["push"..e.e] then self["push"..e.e](self, e)
end
end end
end end
end end
...@@ -148,6 +152,12 @@ function _M:run() ...@@ -148,6 +152,12 @@ function _M:run()
end end
end end
function _M:handleOrder(o)
o = o:unserialize()
if not self.sock and o.o ~= "Login" then return end -- Dont do stuff without a connection, unless we try to auth
if self["order"..o.o] then self["order"..o.o](self, o) end
end
-------------------------------------------------------------------- --------------------------------------------------------------------
-- Orders comming from the main thread -- Orders comming from the main thread
-------------------------------------------------------------------- --------------------------------------------------------------------
...@@ -251,30 +261,20 @@ function _M:orderSaveChardump(o) ...@@ -251,30 +261,20 @@ function _M:orderSaveChardump(o)
cprofile.pushEvent("e='SaveChardump' ok=true") cprofile.pushEvent("e='SaveChardump' ok=true")
end end
function _M:handleOrder(o) function _M:orderChatTalk(o)
o = o:unserialize() self:command("BRDC", o.channel, o.msg)
if not self.sock and o.o ~= "Login" then return end -- Dont do stuff without a connection, unless we try to auth self:read("200")
if self["order"..o.o] then self["order"..o.o](self, o) end
end end
-------------------------------------------------------------------- --------------------------------------------------------------------
-- Pushes comming from the push socket -- Pushes comming from the push socket
-------------------------------------------------------------------- --------------------------------------------------------------------
function _M:pushCode(o) function _M:pushCode(e)
if o.profile then if e.profile then
local f = loadstring(o.code) local f = loadstring(e.code)
if f then pcall(f) end
else
cprofile.pushEvent(string.format("e='PushCode' code=%q", o.code))
end
end
function _M:pushChatTalk(o)
if o.profile then
local f = loadstring(o.code)
if f then pcall(f) end if f then pcall(f) end
else else
cprofile.pushEvent(string.format("e='PushCode' code=%q", o.code)) cprofile.pushEvent(string.format("e='PushCode' code=%q", e.code))
end end
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment