INTERNAL_COMM_D = {}
setmetatable(INTERNAL_COMM_D, {__index = _G})
local _ENV = INTERNAL_COMM_D
local cookie_map = {}
local TIMEOUT = 15
local function timer_handle()
local cur_time = os.time()
for k, v in pairs(cookie_map) do
if v["begin_time"] + TIMEOUT <= cur_time then
cookie_map[k] = nil
local callback, arg = v["callback"], v["arg"]
if type(callback) == "function" then
if arg then
callback(arg, -2)
else
callback(-2)
end
end
end
end
end
function notify_internal_result(cookie, ...)
local oper = cookie_map[tostring(cookie)]
if not oper then
do return end
end
local ret = 2
cookie_map[tostring(cookie)] = nil
local callback = oper["callback"]
local callback_arg = oper["arg"]
if type(callback) == "function" then
if callback_arg then
callback(callback_arg, ret, ...)
else
callback(ret, ...)
end
end
end
function send_room_raw_message(room_name, user_rid, record, net_data)
local cookie = 0
if is_table(record) and sizeof(record) ~= 0 then
cookie = new_cookie()
local new_record = { begin_time = os.time(), callback = record[1], arg = record[2] }
cookie_map[tostring(cookie)] = new_record
end
local channel = string.format(CREATE_ROOM_MSG_CHANNEL_USER, room_name, user_rid, cookie)
REDIS_D.run_publish(channel, net_data)
end
function send_room_message(room_name, user_rid, record, msg, ...)
local net_msg = pack_message(msg, ...)
if not net_msg then
return
end
send_room_raw_message(room_name, user_rid, record, net_msg:get_data())
del_message(net_msg)
end
function send_server_raw_message(server_id, user_rid, record, net_data)
local cookie = 0
if is_table(record) and sizeof(record) ~= 0 then
cookie = new_cookie()
local new_record = { begin_time = os.time(), callback = record[1], arg = record[2] }
cookie_map[tostring(cookie)] = new_record
end
local channel = string.format(CREATE_SERVER_MSG_USER, server_id, user_rid, cookie)
REDIS_D.run_publish(channel, net_data)
end
function send_server_message(server_id, user_rid, record, msg, ...)
server_id = tonumber(server_id)
local net_msg = pack_message(msg, ...)
if not net_msg then
return
end
send_server_raw_message(server_id, user_rid, record, net_msg:get_data())
del_message(net_msg)
end
function get_cookie_map()
return cookie_map
end
function create()
set_timer(1000, timer_handle, nil, true)
if SERVER_TYPE == SERVER_LOGIC or STANDALONE then
REDIS_D.add_subscribe_channel(string.format(REDIS_SERVER_MSG_USER, SERVER_ID))
REDIS_D.add_subscribe_channel(string.format(REDIS_RESPONE_SERVER_INFO, SERVER_ID))
end
end
create()