187 lines
6.2 KiB
Lua
187 lines
6.2 KiB
Lua
|
|
local skynet = require "skynet"
|
||
|
|
local oo = require "Class"
|
||
|
|
local gameCmd = require "GameCmd"
|
||
|
|
local json =require "json"
|
||
|
|
local log = require "Log"
|
||
|
|
local sqlUrl = require "SqlUrl"
|
||
|
|
local errorInfo = require "ErrorInfo"
|
||
|
|
local serverId = tonumber(skynet.getenv "serverId")
|
||
|
|
local redisKeyUrl = require "RedisKeyUrl"
|
||
|
|
local clusterServer = require "ClusterServer"
|
||
|
|
local redeemManage = require "RedeemManage"
|
||
|
|
local mailManage = require "MailManage"
|
||
|
|
local serverManage = require "ServerManage"
|
||
|
|
local MultiServer = oo.class(clusterServer)
|
||
|
|
|
||
|
|
--初始化
|
||
|
|
function MultiServer:Init()
|
||
|
|
end
|
||
|
|
|
||
|
|
--跨天
|
||
|
|
function MultiServer:OnNewDay()
|
||
|
|
|
||
|
|
end
|
||
|
|
|
||
|
|
--1秒Timer
|
||
|
|
function MultiServer:On1SecTimer()
|
||
|
|
|
||
|
|
end
|
||
|
|
|
||
|
|
--5秒Timer
|
||
|
|
function MultiServer:On5SecTimer()
|
||
|
|
end
|
||
|
|
|
||
|
|
--接收集群数据
|
||
|
|
function MultiServer:ClusterRecv(...)
|
||
|
|
local cmd , c2sData = ...
|
||
|
|
local s2cData = {}
|
||
|
|
s2cData.code = errorInfo.Suc
|
||
|
|
|
||
|
|
if self.Center2All_ServerManageCmd == cmd then --中心服集群消息
|
||
|
|
serverManage:DoManageCmd( c2sData , s2cData )
|
||
|
|
elseif self.Center2All_SyncClusterInfo == cmd then
|
||
|
|
self:RecvSyncClusterInfo( c2sData )
|
||
|
|
elseif self.Center2All_SyncServerConfig == cmd then --同步服务器配置
|
||
|
|
self:RecvSyncServerConfig( c2sData )
|
||
|
|
elseif self.GameToMulti_GetRedeemBonus == cmd then --同步配置
|
||
|
|
self:RecvGetRedeemBonus( c2sData , s2cData )
|
||
|
|
elseif self.GameToMulti_GetMailList == cmd then
|
||
|
|
self:RecvGetMailList( c2sData , s2cData )
|
||
|
|
elseif self.GameToMulti_GetMailBonus == cmd then --同步配置
|
||
|
|
self:RecvGetMailBonus( c2sData )
|
||
|
|
else
|
||
|
|
log.info(string.format("集群服务器 消息接口 %d 不存在", cmd))
|
||
|
|
s2cData.code = errorInfo.ErrorCode.NoExistInterface
|
||
|
|
end
|
||
|
|
|
||
|
|
log.info("集群服务器 消息接口", cmd , "返回信息",s2cData.code)
|
||
|
|
return s2cData
|
||
|
|
end
|
||
|
|
|
||
|
|
--接收HTTP数据
|
||
|
|
function MultiServer:HttpRecv( c2sData , url , addr )
|
||
|
|
local s2cData = {}
|
||
|
|
s2cData.code = errorInfo.Suc
|
||
|
|
c2sData.addr = addr
|
||
|
|
|
||
|
|
if not self.isConnectCenterServer then
|
||
|
|
--断开了就不允许接收后台的邮件请请求
|
||
|
|
s2cData.code = errorInfo.ErrorCode.ServiceOffline
|
||
|
|
return s2cData
|
||
|
|
end
|
||
|
|
|
||
|
|
--验证管理员
|
||
|
|
if not self:CheckAdmin( c2sData , s2cData , url ) then
|
||
|
|
return s2cData
|
||
|
|
end
|
||
|
|
|
||
|
|
if "QueryRedeemList" == url then
|
||
|
|
self:QueryRedeemList( c2sData , s2cData )
|
||
|
|
elseif "RedeemManage" == url then
|
||
|
|
self:RedeemManage( c2sData , s2cData )
|
||
|
|
elseif "MailTemplate" == url then
|
||
|
|
self:MailTemplate( c2sData , s2cData )
|
||
|
|
elseif "MailManage" == url then
|
||
|
|
self:MailManage( c2sData , s2cData )
|
||
|
|
else
|
||
|
|
log.info(string.format("Http服务器 消息接口 %s 不存在", url))
|
||
|
|
s2cData.code = errorInfo.ErrorCode.NoExistInterface
|
||
|
|
end
|
||
|
|
log.info("Http服务器 消息接口 ",url ,"返回信息",s2cData.code)
|
||
|
|
return s2cData
|
||
|
|
end
|
||
|
|
|
||
|
|
--游戏服发来的获取邮件奖励
|
||
|
|
function MultiServer:RecvGetRedeemBonus( c2sData , s2cData )
|
||
|
|
redeemManage:GetBonus( c2sData , s2cData )
|
||
|
|
end
|
||
|
|
|
||
|
|
|
||
|
|
--游戏服发来的获取邮件奖励
|
||
|
|
function MultiServer:RecvGetMailList( c2sData , s2cData )
|
||
|
|
s2cData.mailList = mailManage:GetMailList()
|
||
|
|
end
|
||
|
|
|
||
|
|
--游戏服发来的获取邮件奖励
|
||
|
|
function MultiServer:RecvGetMailBonus( c2sData )
|
||
|
|
local mailId = c2sData.mailId
|
||
|
|
local userId = c2sData.userId
|
||
|
|
if not mailId or not userId then
|
||
|
|
return
|
||
|
|
end
|
||
|
|
mailManage:UpdateMailPlayerCount( mailId , userId )
|
||
|
|
end
|
||
|
|
|
||
|
|
--停止服务
|
||
|
|
function MultiServer:StopServer()
|
||
|
|
mailManage:SaveDB()
|
||
|
|
end
|
||
|
|
|
||
|
|
--检查管理员
|
||
|
|
function MultiServer:CheckAdmin( c2sData , s2cData , url )
|
||
|
|
local account = c2sData.account
|
||
|
|
local pwd = c2sData.password
|
||
|
|
if account and pwd then
|
||
|
|
local sql = string.format(sqlUrl.selectAdminFromAdministrators , account , pwd )
|
||
|
|
local queryData = skynet.server.db:Query( "game" , sql )
|
||
|
|
if #queryData > 0 then
|
||
|
|
log.info(string.format("操作请求 %s 管理员 %s 密码 %s 验证成功" ,url , account , pwd ))
|
||
|
|
return true
|
||
|
|
else
|
||
|
|
log.info(string.format("操作请求 %s 管理员 %s 密码 %s 验证失败" ,url , account , pwd ))
|
||
|
|
s2cData.code = errorInfo.ErrorCode.NoExistAdmin
|
||
|
|
return false
|
||
|
|
end
|
||
|
|
else
|
||
|
|
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
||
|
|
return false
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
--查询兑换码
|
||
|
|
function MultiServer:QueryRedeemList( c2sData , s2cData )
|
||
|
|
redeemManage:QueryRedeemList( c2sData , s2cData )
|
||
|
|
end
|
||
|
|
|
||
|
|
--兑换码管理
|
||
|
|
function MultiServer:RedeemManage( c2sData , s2cData )
|
||
|
|
if redeemManage.OpType_Add == c2sData.opType then
|
||
|
|
redeemManage:Add( c2sData , s2cData )
|
||
|
|
elseif redeemManage.OpType_Modify == c2sData.opType then
|
||
|
|
redeemManage:Modify( c2sData , s2cData )
|
||
|
|
elseif redeemManage.OpType_Delete == c2sData.opType then
|
||
|
|
redeemManage:Delete( c2sData , s2cData )
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
--邮件模板
|
||
|
|
function MultiServer:MailTemplate( c2sData , s2cData )
|
||
|
|
if mailManage.OpType_Add == c2sData.opType then
|
||
|
|
mailManage:AddTemplate( c2sData , s2cData )
|
||
|
|
elseif mailManage.OpType_Modify == c2sData.opType then
|
||
|
|
mailManage:ModifyTemplate( c2sData , s2cData )
|
||
|
|
elseif mailManage.OpType_Delete == c2sData.opType then
|
||
|
|
mailManage:DeleteTemplate( c2sData , s2cData )
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
--邮件管理
|
||
|
|
function MultiServer:MailManage( c2sData , s2cData )
|
||
|
|
--验证登陆接口参数
|
||
|
|
if nil == c2sData then
|
||
|
|
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
||
|
|
return s2cData
|
||
|
|
end
|
||
|
|
|
||
|
|
if mailManage.OpType_Add == c2sData.opType then
|
||
|
|
mailManage:AddMail( c2sData , s2cData )
|
||
|
|
elseif mailManage.OpType_Modify == c2sData.opType then
|
||
|
|
mailManage:ModifyMail( c2sData , s2cData )
|
||
|
|
elseif mailManage.OpType_Delete == c2sData.opType then
|
||
|
|
mailManage:DeleteMail( c2sData , s2cData )
|
||
|
|
end
|
||
|
|
end
|
||
|
|
|
||
|
|
skynet.server.multiServer = MultiServer
|
||
|
|
return MultiServer
|