local skynet = require "skynet" local s = require "service" local tools = require "tools" local cjson = require "cjson" --玩家列表 local players = {} --用户详情列表 local playersInfo = { user_folder_nums = {}, user_file_type_nums = {} } --玩家类 function mgrplayer() local m = { playerid = nil, node = nil, agent = nil, status = nil, gate = nil, } return m end --登录 s.resp.login = function(fd,msg_body) msg_body = cjson.decode(msg_body) if msg_body.account == nil then return tools.response(fd,200,cjson.encode({code=1001,msg = "账号不能为空"})) end if msg_body.password == nil then return tools.response(fd,200,cjson.encode({code=1002,msg = "密码不能为空"})) end local isok,user_data = skynet.call("dbmgr","lua","on_recv","verify",msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=1003,msg = "账号密码错误!"})) end -- if msg_body.account~="123456" or msg_body.password~="abc" then -- end local index = 0 if players[user_data.id] ~=nil then index = players[user_data.id].index+1 end local token = tools.tokenEncode(cjson.encode({user_id=user_data.id,index=index})) local myTable = {code =10000, msg = "登录成功!", data = {user_id=user_data.id,user_name=user_data.name,group_id=user_data.group_id,permit_id=user_data.permit_id,token=token}} local jsonStr = cjson.encode(myTable) players[user_data.id] = {index = index} return tools.response(fd,200,jsonStr) end s.resp.account_is_other_user_login = function(source,user_id,index) if not players[user_id] then players[user_id] = {index = index} return false end if players[user_id].index~=index then return true end return false end --注册 s.resp.register = function(fd,msg_body) msg_body = cjson.decode(msg_body) local isok,user_data = skynet.call("dbmgr","lua","on_recv","select_user_by_account",msg_body.account) if isok then return tools.response(fd,200,string.format("用户 %s 已存在",msg_body.account)) end isok = skynet.call("dbmgr","lua","on_recv","add_new_user",msg_body) if not isok then return tools.response(fd,200,"创建失败!") end return tools.response(fd,200,cjson.encode({code=10000,msg = "创建成功!"})) end --用户新建文件夹 s.resp.new_folder = function(fd,msg_body,user_data) skynet.error("new_folder",msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if not user_id then return tools.response(fd,200,cjson.encode({code=9001,msg = "缺少user_id"})) end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"category_name","type","classification_id"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: '%s'.", key)})) end local is_public = 0 if msg_body.is_public ~=nil then is_public = msg_body.is_public end msg_body["is_public"] = is_public local isok = skynet.call("dbmgr","lua","on_recv","new_folder",{ user_id=user_id, folder_name=msg_body.category_name, classification_id = msg_body.classification_id, folder_type=msg_body.type, is_public=msg_body.is_public} ,fd) end --获取资源文件夹列表 s.resp.folder_list = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,100,"user_id==nil folder_list !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"type","page","count","classification_id"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end local is_public = 0 if msg_body.is_public ~=nil then is_public = msg_body.is_public end isok = skynet.call("dbmgr","lua","on_recv","folder_list",{user_id = user_id, type=msg_body.type, is_public=is_public, page=msg_body.page, count = msg_body.count, classification_id = msg_body.classification_id} ,fd) end --获取文件夹内的所有资源 s.resp.folder_res_list = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,100,"user_id==nil folder_res_list !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"folder_id","page","count"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end local is_public = 0 if msg_body.is_public ~=nil then is_public = msg_body.is_public end local duration = nil if msg_body.duration ~=nil then duration = msg_body.duration end isok = skynet.call("dbmgr","lua","on_recv","folder_res_list",{ folder_id = msg_body.folder_id, user_id = user_id, is_public=is_public, page=msg_body.page, count = msg_body.count, duration = duration} ,fd) end --重命名资源 s.resp.reset_res_name = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,100,"user_id==nil reset_res_name !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"folder_id","file_id","name"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end local is_public = 0 if msg_body.is_public ~=nil then is_public = msg_body.is_public end isok = skynet.call("dbmgr","lua","on_recv","reset_res_name",{ folder_id = msg_body.folder_id, file_id = msg_body.file_id, name = msg_body.name, is_public=is_public, user_id = user_id} ) if not isok then return tools.response(fd,200,cjson.encode({code=10001,msg = "--重命名资源失败"})) end return tools.response(fd,200,cjson.encode({code=10000,msg = "重命名资源成功"})) end --重命名文件夹 s.resp.reset_folder_name = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,100,"user_id==nil reset_folder_name !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"folder_id","name"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end local is_public = 0 if msg_body.is_public ~=nil then is_public = msg_body.is_public end isok = skynet.call("dbmgr","lua","on_recv","reset_folder_name",{ folder_id = msg_body.folder_id, name = msg_body.name, is_public=is_public, user_id = user_id} ) if not isok then return tools.response(fd,200,cjson.encode({code=10001,msg = "--重命名资源失败"})) end return tools.response(fd,200,cjson.encode({code=10000,msg = "重命名资源成功"})) end --搜索 s.resp.search_res = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,100,"user_id==nil search_res !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"search_content","type","is_public","page","count","classification_id"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end local is_public = 0 if msg_body.is_public ~=nil then is_public = msg_body.is_public end isok = skynet.call("dbmgr","lua","on_recv","search_res",{ type = msg_body.type, search_content = msg_body.search_content, is_public=is_public, page = msg_body.page, count = msg_body.count, classification_id = msg_body.classification_id, user_id = user_id} ,fd) end --删除资源 s.resp.delete_res = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,200,"user_id==nil delete_res !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"file_id_list","is_public"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end local is_public = 0 if msg_body.is_public ~=nil then is_public = msg_body.is_public end isok = skynet.call("dbmgr","lua","on_recv","delete_res",{ file_id_list = msg_body.file_id_list, is_public=is_public, user_id = user_id} ) if not isok then return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!",data={}})) end return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!",data={}})) end --删除文件夹 s.resp.delete_folder = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,200,"user_id==nil delete_folder !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"folder_id_list","is_public"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end local is_public = 0 if msg_body.is_public ~=nil then is_public = msg_body.is_public end isok = skynet.call("dbmgr","lua","on_recv","delete_folder",{ folder_id_list = msg_body.folder_id_list, is_public=is_public, user_id = user_id} ) if not isok then return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!",data={}})) end return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!",data={}})) end --获取指定类型所有文件 s.resp.get_file_list_by_type = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,200,"user_id==nil get_file_list_by_type !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"type","page","count"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end local duration = nil if msg_body.duration ~=nil then duration = msg_body.duration end isok = skynet.call("dbmgr","lua","on_recv","get_file_list_by_type",{ type = msg_body.type, count = msg_body.count, page = msg_body.page, user_id = user_id, duration = duration} ,fd) end --新建模板 s.resp.create_template = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,200,"user_id==nil create_template !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"project_name","book_name","ratio","video_stype","subtitles","subtitles_audio","video_nums","video_crop_time"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end local error_info = "" isok,error_info = skynet.call("dbmgr","lua","on_recv","check_template_isRight", msg_body) if not isok then return tools.response(fd,200,error_info) end -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{ -- duration = 0, -- type = 1, -- limit = 1, -- user_id = user_id} -- ) -- if not isok then -- return tools.response(fd,200,cjson.encode({code=10001,msg = "新建模板失败,片头资源不足!"})) -- end -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{ -- duration = 0, -- type = 3, -- limit = 1, -- user_id = user_id} -- ) -- if not isok then -- return tools.response(fd,200,cjson.encode({code=10001,msg = "新建模板失败,片尾资源不足"})) -- end -- local subtitles_audio_duration = 0 -- if msg_body.template_info ~=nil and msg_body.template_info~="" then -- local template_info = cjson.decode(msg_body.template_info) -- if template_info.subtitles_audio_duration~=nil then -- subtitles_audio_duration = tonumber(template_info.subtitles_audio_duration) -- end -- end -- local duration = msg_body.video_crop_time + 5 -- local limit = math.floor(subtitles_audio_duration/duration) -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{ -- duration = duration, -- type = 2, -- limit =limit , -- user_id = user_id} -- ) -- if not isok then -- return tools.response(fd,200,cjson.encode({code=10001,msg = "正片资源不足"})) -- end -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{ -- duration = 0, -- type = 4, -- limit = 1, -- user_id = user_id} -- ) -- if not isok then -- return tools.response(fd,200,cjson.encode({code=10001,msg = "BGM音效资源不足!"})) -- end isok = skynet.call("dbmgr","lua","on_recv","create_template",msg_body,fd) if not isok then return tools.response(fd,200,cjson.encode({code=10001,msg = "新建模板失败"})) end return tools.response(fd,200,cjson.encode({code=10000,msg = "新建模板成功"})) end -- 获取模板列表 s.resp.get_template_list = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,200,"user_id==nil get_template_list !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"video_stype","page","count"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end isok = skynet.call("dbmgr","lua","on_recv","get_template_list",msg_body,fd) end --删除模板 s.resp.delete_template = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,200,"user_id==nil get_template_list !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"template_id_list"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end isok = skynet.call("dbmgr","lua","on_recv","delete_template",msg_body,fd) if not isok then return tools.response(fd,200,cjson.encode({code=10001,msg = "删除模板失败"})) end return tools.response(fd,200,cjson.encode({code=10000,msg = "删除模板成功"})) end --保存/修改模板 s.resp.save_template = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,200,"user_id==nil save_template !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"template_id","project_name","book_name","ratio","video_stype","subtitles","subtitles_audio","video_nums","video_crop_time","template_info"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end isok = skynet.call("dbmgr","lua","on_recv","save_template",msg_body,fd) if not isok then return tools.response(fd,200,cjson.encode({code=10001,msg = "修改模板失败"})) end return tools.response(fd,200,cjson.encode({code=10000,msg = "修改模板成功"})) end --模板搜索 s.resp.search_template = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,200,"user_id==nil search_template !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"video_stype","search_content","page","count"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end isok = skynet.call("dbmgr","lua","on_recv","search_template",msg_body,fd) end --根据模板ID获取模板信息 s.resp.get_template_info_by_id = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,200,"user_id==nil get_template_info_by_id !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"template_id"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end isok = skynet.call("dbmgr","lua","on_recv","get_template_info_by_id",msg_body,fd) end --生成视频 s.resp.generate_video = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,200,"user_id==nil generate_video !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"template_id"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end isok = skynet.call("dbmgr","lua","on_recv","generate_video",msg_body,fd) end --获取生成视频文件夹列表 s.resp.get_generate_video_folder_list = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,100,"user_id==nil get_generate_video_folder_list !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"page","count","video_stype"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end local is_public = 0 if msg_body.is_public ~=nil then is_public = msg_body.is_public end isok = skynet.call("dbmgr","lua","on_recv","get_generate_video_folder_list",{user_id = user_id, page=msg_body.page, count = msg_body.count, video_stype=msg_body.video_stype} ,fd) end --获取文件夹内的生成视频 s.resp.get_video_list_by_folder_id = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,100,"user_id==nil get_video_list_by_folder_id !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"folder_id","page","count"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end local is_public = 0 if msg_body.is_public ~=nil then is_public = msg_body.is_public end local duration = nil if msg_body.duration ~=nil then duration = msg_body.duration end isok = skynet.call("dbmgr","lua","on_recv","get_video_list_by_folder_id",{ folder_id = msg_body.folder_id, user_id = user_id, page=msg_body.page, count = msg_body.count} ,fd) end --删除生成视频文件夹 s.resp.delete_generate_video_folder = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,200,"user_id==nil delete_generate_video_folder !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"folder_id_list"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end isok = skynet.call("dbmgr","lua","on_recv","delete_generate_video_folder",{ folder_id_list = msg_body.folder_id_list, user_id = user_id} ) if not isok then return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!",data={}})) end return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!",data={}})) end --删除生成视频 s.resp.delete_generate_video = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,200,"user_id==nil delete_generate_video !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"generate_video_id_list"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end local is_public = 0 if msg_body.is_public ~=nil then is_public = msg_body.is_public end isok = skynet.call("dbmgr","lua","on_recv","delete_generate_video",{ file_id_list = msg_body.generate_video_id_list, user_id = user_id} ) if not isok then return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!"})) end return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!"})) end --重命名生成视频文件夹的名字 s.resp.reset_generate_video_folder_name = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,100,"user_id==nil reset_generate_video_folder_name !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"folder_id","file_id"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end isok = skynet.call("dbmgr","lua","on_recv","reset_generate_video_folder_name",{ folder_id = msg_body.folder_id, file_id = msg_body.file_id, user_id = user_id} ) if not isok then return tools.response(fd,200,cjson.encode({code=10001,msg = "重命名生成视频文件夹的名字失败"})) end return tools.response(fd,200,cjson.encode({code=10000,msg = "重命名生成视频文件夹的名字成功"})) end --生成视频搜索 s.resp.search_generate_video_file = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,100,"user_id==nil reset_generate_video_folder_name !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"page","count","video_stype","search_content"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end isok = skynet.call("dbmgr","lua","on_recv","search_generate_video_file",{ search_content = msg_body.search_content, page = msg_body.page, count = msg_body.count, video_stype = msg_body.video_stype},fd ) end --检测指定类型文件是否够数量 s.resp.checkNumsByType = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,100,"user_id==nil checkNumsByType !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"type","limit"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{ duration = msg_body.duration, type = msg_body.type, limit = msg_body.limit, user_id = user_id} ) if not isok then return tools.response(fd,200,cjson.encode({code=10001,msg = "条件不足"})) end return tools.response(fd,200,cjson.encode({code=10000,msg = "条件成立"})) end --修改密码 s.resp.reset_password = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id if user_id==nil then return tools.response(fd,100,"user_id==nil reset_password !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"new_pw","sure_pw"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end if msg_body.new_pw~=msg_body.sure_pw then return tools.response(fd,200,cjson.encode({code=9002,msg ="两次密码不一致!"})) end isok = skynet.call("dbmgr","lua","on_recv","reset_password",{ new_pw = msg_body.new_pw, sure_pw = msg_body.sure_pw, user_id = user_id} ) if not isok then return tools.response(fd,200,cjson.encode({code=10001,msg = "修改密码失败!"})) end return tools.response(fd,200,cjson.encode({code=10000,msg = "修改密码成功!"})) end s.resp.update_generate_video_custom = function(fd,msg_body,user_data) msg_body = cjson.decode(msg_body) if type(user_data) ~= "table" then return tools.response(fd, 200, "token error!") end local user_id = user_data.user_id -- tools.dump(msg_body) if user_id==nil then return tools.response(fd,100,"user_id==nil update_generate_video_custom !") end msg_body["user_id"] = user_id local isok ,key = tools.checkData({"data"},msg_body) if not isok then return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)})) end isok = skynet.call("dbmgr","lua","on_recv","update_generate_video_custom",{ data = msg_body.data, user_id = user_id} ) if not isok then return tools.response(fd,200,cjson.encode({code=10001,msg = "更新失败!"})) end return tools.response(fd,200,cjson.encode({code=10000,msg = "更新成功!"})) end --更新用户所有的文件数 s.resp.update_user_folder_list_nums = function(user_id) skynet.fork(function() local count = skynet.call("dbmgr","lua","on_recv","get_user_folder_list_nums",{ user_id = user_id} ) playersInfo.user_folder_nums[user_id] = count end) end --更新用户指定类型的数量 s.resp.update_user_file_count_by_type = function(user_id,file_type) skynet.fork(function() local key = user_id.."_"..file_type local count = skynet.call("dbmgr","lua","on_recv","get_user_file_count_by_type",{ user_id = user_id, file_type = file_type} ) playersInfo.user_file_type_nums[key] = count end) end --获取用户所有的文件数 s.resp.get_user_folder_list_nums = function(user_id) if playersInfo.user_folder_nums[user_id]~=nil then return playersInfo.user_folder_nums[user_id] else local count = skynet.call("dbmgr","lua","on_recv","get_user_folder_list_nums",{ user_id = user_id} ) playersInfo.user_folder_nums[user_id] = count return count end end --获取用户指定类型的数量 s.resp.get_user_file_count_by_type = function(user_id,file_type) local key = user_id.."_"..file_type if playersInfo.user_file_type_nums[key]~=nil then return playersInfo.user_file_type_nums[key] else local count = skynet.call("dbmgr","lua","on_recv","get_user_file_count_by_type",{ user_id = user_id, file_type = file_type} ) playersInfo.user_file_type_nums[key] = count return count end end --踢掉 s.resp.kick = function(fd,msg_body,user_data) end s.resp.on_recv = function (source, fd, msg_id, msg_body,user_data) skynet.error("接收一条客户端消息 ",msg_id,user_data) local func = string.gsub(msg_id, '/', '') if func ~= "login" then if not s.resp.account_is_other_user_login(source,user_data.user_id,user_data.index) then else skynet.error("用户被挤掉",user_data.user_id) return tools.response(fd,200,cjson.encode({code=999,msg = "您的账号被其他用户登录!"})) end end if s.resp[func] ~=nil then return s.resp[func](fd,msg_body,user_data) end return tools.response(fd,200,string.format("接口 %s 不存在",func)) end s.start(...)