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)
-- And now run it!
_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
if mod.short_name ~= "boot" then
if not hash_valid then
......
......@@ -23,6 +23,7 @@ local url = require "socket.url"
local ltn12 = require "ltn12"
local lanes = require "lanes"
local Dialog = require "engine.ui.Dialog"
local UserChat = require "engine.UserChat"
require "Json2"
------------------------------------------------------------
......@@ -72,6 +73,7 @@ end
module(..., package.seeall, class.make)
function _M:init()
self.chat = UserChat.new()
self.generic = {}
self.modules = {}
self.evt_cbs = {}
......@@ -376,11 +378,6 @@ function _M:eventGetNews(e)
end
end
function _M:eventPushCode(e)
local f = loadstring(e.code)
if f then pcall(f) end
end
function _M:eventGetConfigs(e)
local data = e.data:unserialize()
local module = e.module
......@@ -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
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
function _M:handleEvent(e)
e = e:unserialize()
......
......@@ -46,3 +46,4 @@ You are an adventurer, set out to discover wonders, explore old places, and vent
]]
starter = "mod.load"
profile_stats_fields = {"artifacts", "characters", "deaths", "uniques"}
allow_userchat = true
......@@ -19,10 +19,12 @@
require "engine.class"
local socket = require "socket"
local UserChat = require "profile-thread.UserChat"
module(..., package.seeall, class.make)
function _M:init()
self.chat = UserChat.new(self)
end
function _M:connected()
......@@ -125,7 +127,9 @@ function _M:step()
local data = l:sub(5)
if code == "101" then
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
......@@ -148,6 +152,12 @@ function _M:run()
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
--------------------------------------------------------------------
......@@ -251,30 +261,20 @@ function _M:orderSaveChardump(o)
cprofile.pushEvent("e='SaveChardump' ok=true")
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
function _M:orderChatTalk(o)
self:command("BRDC", o.channel, o.msg)
self:read("200")
end
--------------------------------------------------------------------
-- Pushes comming from the push socket
--------------------------------------------------------------------
function _M:pushCode(o)
if o.profile then
local f = loadstring(o.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)
function _M:pushCode(e)
if e.profile then
local f = loadstring(e.code)
if f then pcall(f) end
else
cprofile.pushEvent(string.format("e='PushCode' code=%q", o.code))
cprofile.pushEvent(string.format("e='PushCode' code=%q", e.code))
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