HomeServer/lualib-src/Server-main/AllServer/GameServer/GameServer.lua
2024-11-20 15:41:37 +08:00

778 lines
48 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local skynet = require "skynet"
local oo = require "Class"
local gameCmd = require "GameCmd"
local json =require "json"
local sqlUrl = require "SqlUrl"
local log = require "Log"
local dataType = require "DataType"
local errorInfo = require "ErrorInfo"
local serverId = tonumber(skynet.getenv "serverId")
local clusterServer = require "ClusterServer"
local socket = require "skynet.socket"
local pb = require "pb"
local playerCenter = require "PlayerCenter"
local playerRecord = require "PlayerRecord"
local redeem = require "Redeem"
local mail = require "Mail"
local announcement = require "Announcement"
local house = require "House"
local generalShop = require "GeneralShop"
local decorateShop = require "DecorateShop"
local clothesShop = require "ClothesShop"
local petClothesShop = require "PetClothesShop"
local plantShop = require "PlantShop"
local coffeeShop = require "CoffeeShop"
local flowerShop = require "FlowerShop"
local styleShop = require "StyleShop"
local guGuShop = require "GuGuShop"
local lottery = require "Lottery"
local flowerpot = require "Flowerpot"
local bag = require "Bag"
local used = require "Used"
local accountServer = require "AccountServer"
local serverManage = require "ServerManage"
local defense = require "Defense"
local gashapon = require "Gashapon"
local weather = require "Weather"
local msgTips = require "MsgTips"
local gm = require "Gm"
local personal = require "Personal"
local pet = require "Pet"
local levelTask = require "LevelTask"
local dailyTask = require "DailyTask"
local achieveTask = require "AchieveTask"
local friend = require "Friend"
local illustration = require "Illustration"
local flowerShop = require "FlowerShop"
local ad = require "AD"
local extraRevenue = require "ExtraRevenue"
local guide = require "Guide"
local map = require "Map"
local questionnaire = require "Questionnaire"
local dyeworkshop = require "DyeWorkShop"
local store = require "Store"
local passCheck = require "PassCheck"
local design = require "Design"
local audit = require "Audit"
local signIn = require "SignIn"
local playerLand = require "PlayerLand"
--local backpack = require "Backpack"
local GameServer = oo.class(clusterServer)
GameServer.per5MinTotalLoginCount = 300 --每5分钟连接数
--初始化
function GameServer:Init()
self.lastLoginCount = 0
self.preLoginUser = {}
self.serverInfo.playerCount ={}
self.serverInfo.playerCount.playing = 0
self.serverInfo.playerCount.offline = 0
self.serverInfo.pre5MinLoginCount = 0
self.serverInfo.loginCount = 0
self.serverInfo.needPlayerCount = 0
self.last5MinTotalLoginCount = 0
--预登陆玩家
for i = 1, 100, 1 do
local account = "womei"..i
if not self.preLoginUser[ account ] then
self.preLoginUser[ account ] = {}
end
self.preLoginUser[ account ].platform = "Apple"
self.preLoginUser[ account ].loginAccount = account
self.preLoginUser[ account ].loginToken = "123456"
end
if 100 == serverId then
--skynet.newservice("debug_console",9099)
end
end
--跨天
function GameServer:OnNewDay()
end
--1秒Timer
function GameServer:On1SecTimer()
end
--5秒Timer
function GameServer:On5SecTimer()
self:StatData()
end
--接收集群数据
function GameServer:ClusterRecv(...)
local cmd , c2sData = ...
local s2cData = {}
s2cData.code = errorInfo.Suc
s2cData.data = {}
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.Center2All_WebMsg == cmd then --Web消息
self:WebMsg( c2sData )
elseif self.Route2Game_QueryUserOnline == cmd then --路由服集群消息
self:RecvQueryUserOnline( c2sData , s2cData )
elseif self.Route2Game_UserLoginToken == cmd then
self:RecvUserLoginToken( c2sData )
elseif self.Pay2Game_AddPayInfo == cmd then
self:AddPayInfo( c2sData , s2cData)
else
log.info(string.format("集群服务器 消息接口 %d 不存在", cmd))
s2cData.code = errorInfo.ErrorCode.NoExistInterface
end
log.info(string.format("集群服 执行命令 %d 返回消息状态 %d " , cmd , s2cData.code))
return s2cData
end
--接收客户端TCP数据
function GameServer:TcpRecv( c2sData , s2cData)
function Do()
if pb.enum("MsgType","CMD_C2S_UserLogin") == c2sData.cmd then --用户登陆游戏
local t1 = skynet.GetTime()
self:UserLogin( c2sData , s2cData )
log.info(string.format("登陆请求运行时间 %d", skynet.GetTime() - t1))
elseif pb.enum("MsgType","CMD_C2S_UserExit") == c2sData.cmd then --用户登陆游戏
else
local t1 = skynet.GetTime()
c2sData.userId = playerCenter:GetUserIDForSocketId( c2sData.socketId )
if nil == c2sData.userId then
log.info("该 sokcet 已经不存在,发来的消息不处理", c2sData.socketId )
s2cData.code = errorInfo.ErrorCode.NoExistSocketId
return
end
local player = playerCenter:GetPlayer( c2sData.userId )
if not playerCenter:IsPlaying( c2sData.userId ) then
--除了登陆,断线后不接收任何消息
s2cData.code = errorInfo.ErrorCode.UserOffline
return
end
playerCenter:Ping( c2sData.userId )
player.basicInfo.lastGameTime = skynet.GetTime()
if self.curServerConfig.IsDetailLog then
log.info(string.format("玩家 %d cmd %d 请求", c2sData.userId , c2sData.cmd))
else
log.info(string.format("玩家 %d cmd %d 请求", c2sData.userId , c2sData.cmd))
end
--线上版本需要严格检测消息类型
if skynet.server.gameConfig:IsOnline() then
if pb.enum("MsgType","CMD_C2S_Ping") ~= c2sData.cmd and pb.enum("MsgType","CMD_C2S_Archive") ~= c2sData.cmd
and pb.enum("MsgType","CMD_C2S_ServerTime") ~= c2sData.cmd then
s2cData.code = errorInfo.ErrorCode.MsgTypeError
log.info(string.format("玩家 %d 存档版本无法走服务器逻辑", c2sData.userId))
return
elseif pb.enum("MsgType","CMD_C2S_Archive") == c2sData.cmd then
s2cData.code = errorInfo.ErrorCode.MsgTypeError
log.info(string.format("玩家 %d 服务器版本无法走存档逻辑", c2sData.userId))
return
end
end
if pb.enum("MsgType","CMD_C2S_Ping") == c2sData.cmd then --用户Ping
self:Ping( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_Archive") == c2sData.cmd then --存档
self:Archive( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_ServerTime") == c2sData.cmd then --获取服务器时间
self:ServerTime( player , c2sData , s2cData )
--elseif pb.enum("MsgType","CMD_C2S_MoneyChange") == c2sData.cmd then --货币变化
-- player:MoneyChangeMsg()
elseif pb.enum("MsgType","CMD_C2S_MsgTipsConfirm") == c2sData.cmd then --消息提示完成
skynet.server.msgTips:Confirm( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FinishGuide") == c2sData.cmd then --完成新手引导
skynet.server.guide:FinishGuide( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_GMCmd") == c2sData.cmd then --GM命令
--skynet.server.gm:Cmd( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_GMAddGoods") == c2sData.cmd then --GM商品命令
--skynet.server.gm:AddGoods( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_BagSort") == c2sData.cmd then --背包排序
skynet.server.bag:Sort( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_BagShow") == c2sData.cmd then --背包展现
skynet.server.bag:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_BagClick") == c2sData.cmd then --背包点击
skynet.server.bag:Click( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_HouseShow") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_MoveHome ) then --房子展示
skynet.server.house:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_HouseBuy") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_MoveHome ) then --房子购买
skynet.server.house:Buy( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_HouseMove") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_MoveHome ) then --搬家
skynet.server.house:Move( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_HouseBuyScheme") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_MoveHome ) then --购买方案
skynet.server.house:BuyScheme( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_HouseSwitchScheme") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_MoveHome ) then --切换方案
skynet.server.house:SwitchScheme( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_HouseSchemeName") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_MoveHome ) then --修改方案名称
skynet.server.house:SchemeName( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_HousePutFurniture") == c2sData.cmd then --房屋摆放家具
skynet.server.house:PutFurniture( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_HouseDecorate") == c2sData.cmd then --装修房间
skynet.server.house:Decorate( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_HouseUnlockArea") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_MoveHome ) then --解锁房间区域
skynet.server.house:UnlockArea( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_ShopShow") == c2sData.cmd then --通用商店展示
skynet.server.generalShop:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_ShopRefresh") == c2sData.cmd then --通用商店刷新
skynet.server.generalShop:Refresh( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_ShopBuy") == c2sData.cmd then --通用商店购买
skynet.server.generalShop:Buy( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_DecorateShopShow") == c2sData.cmd then --装修商店展示
skynet.server.decorateShop:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_DecorateShopRefresh") == c2sData.cmd then --装修商店刷新
skynet.server.decorateShop:Refresh( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_DecorateShopBuy") == c2sData.cmd then --装修商店购买
skynet.server.decorateShop:Buy( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_ClothesShopShow") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Clothing ) then --服饰商店展示
skynet.server.clothesShop:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_ClothesShopRefresh") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Clothing ) then --服饰商店刷新
skynet.server.clothesShop:Refresh( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_ClothesShopBuy") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Clothing ) then --服饰商店购买
skynet.server.clothesShop:Buy( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PetClothesShopShow") == c2sData.cmd then --宠物服饰商店展示
skynet.server.petClothesShop:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PetClothesShopRefresh") == c2sData.cmd then --宠物服饰商店刷新
skynet.server.petClothesShop:Refresh( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PetClothesShopBuy") == c2sData.cmd then --宠物服饰商店购买
skynet.server.petClothesShop:Buy( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PlantShopShow") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Plant ) then --植物商店展示
skynet.server.plantShop:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PlantShopManage") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Plant ) then --植物商店管理
skynet.server.plantShop:Manage( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_LevelTaskShow") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_LevelTask ) then --等级任务列表显示
skynet.server.levelTask:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_LevelTaskAccomplish") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_LevelTask ) then --等级任务完成
skynet.server.levelTask:Accomplish( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_DailyTaskShow") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_DailyTask ) then --每日任务列表显示
skynet.server.dailyTask:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_DailyTaskOneAccomplish") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_DailyTask ) then --每日任务完成
skynet.server.dailyTask:OneAccomplish( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_DailyTaskAllAccomplish") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_DailyTask ) then --每日任务完成
skynet.server.dailyTask:AllAccomplish( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_AchieveTaskShow") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_AchieveTask ) then --成就任务列表显示
skynet.server.achieveTask:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_AchieveTaskAccomplish") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_AchieveTask ) then --成就任务完成
skynet.server.achieveTask:Accomplish( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_UsedShow") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Used ) then --闲菜展示
skynet.server.used:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_UsedBuy") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Used )then --闲菜购买
skynet.server.used:Buy( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_UsedRefresh") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Used )then --闲菜刷新
skynet.server.used:Refresh( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_UsedSell") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Used )then --闲菜出售
skynet.server.used:Sell( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_UsedLogisticsShow") == c2sData.cmd then --闲菜物流展示
skynet.server.used:LogisticsShow( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_UsedLogistics") == c2sData.cmd then --闲菜物流
skynet.server.used:Logistics( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_UsedStorageShow") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Used )then --闲菜查看仓库
skynet.server.used:StorageShow( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_UsedSellAccelerate") == c2sData.cmd then --闲菜物流
skynet.server.used:SellAccelerate( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PersonalShow") == c2sData.cmd then --个人特征展示
skynet.server.personal:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PersonalChange") == c2sData.cmd then --个人特征改变
skynet.server.personal:Change( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PersonalRename") == c2sData.cmd then --个人特征重新改名
skynet.server.personal:Rename( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PetShow") == c2sData.cmd then --宠物特征展示
skynet.server.pet:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PetChange") == c2sData.cmd then --宠物特征改变
skynet.server.pet:Change( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PetUnlock") == c2sData.cmd then --宠物解锁
skynet.server.pet:Unlock( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PetRename") == c2sData.cmd then --宠物改名
skynet.server.pet:Rename( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_IllustrationShow") == c2sData.cmd then --图鉴展示
skynet.server.illustration:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_IllustrationAward") == c2sData.cmd then --图鉴领奖
skynet.server.illustration:Award( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FlowerpotShow") == c2sData.cmd then --花盆展示信息
skynet.server.flowerpot:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FlowerpotPlant") == c2sData.cmd then --花盆种植
skynet.server.flowerpot:Plant( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FlowerpotShovel") == c2sData.cmd then --花盆铲除
skynet.server.flowerpot:Shovel( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FlowerpotFertilize") == c2sData.cmd then --花盆施肥
skynet.server.flowerpot:Fertilize( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FriendMsgList") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Friend) then --朋友圈消息列表
skynet.server.friend:MsgList( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FriendMsgDetail") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Friend ) then --朋友圈消息详情
skynet.server.friend:MsgDetail( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FriendMsgClient") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Friend ) then --朋友圈客户端发送消息
skynet.server.friend:MsgClient( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FriendMsgAddFriend") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Friend ) then --朋友圈消息添加好友
skynet.server.friend:AddFriend( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FriendMsgGetGift") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Friend ) then --朋友圈消息获取礼物
skynet.server.friend:GetGift( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FriendMsgEnterScene") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Friend ) then --朋友圈消息进入场景
skynet.server.friend:EnterScene( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FriendMsgLeaveScene") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Friend ) then --朋友圈消息离开场景
skynet.server.friend:LeaveScene( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FriendListShow") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Friend ) then --好友列表展示
skynet.server.friend:ListShow( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FriendGiftBag") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Friend ) then --礼物背包
skynet.server.friend:GiftBag( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FriendGiftGive") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Friend ) then --赠送礼物
skynet.server.friend:GiftGive( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FriendNewsShow") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Friend ) then --友圈动态
skynet.server.friend:NewsShow( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FriendLikeNews") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Friend ) then --友圈点赞
skynet.server.friend:LikeNews( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FriendInteract") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Friend ) then --友圈互动
skynet.server.friend:Interact( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FriendFavorabilityChange") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Friend ) then --友圈互动
skynet.server.friend:Interact( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_GiftBoxShow") == c2sData.cmd then --礼盒展示
--skynet.server.giftBox:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_GiftBoxPrize") == c2sData.cmd then --礼盒领奖
--skynet.server.giftBox:Prize( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_GashaponShow") == c2sData.cmd then --扭蛋展示
skynet.server.gashapon:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_GashaponLottery") == c2sData.cmd then --扭蛋抽奖
skynet.server.gashapon:Lottery( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_GashaponGainPrize") == c2sData.cmd then --扭蛋获取奖品
skynet.server.gashapon:GainPrize( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_ADWatch") == c2sData.cmd then --观看广告
skynet.server.ad:Watch( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_ExtraRevenue") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_Hang ) then --额外收益(在线+离线)
skynet.server.extraRevenue:Start( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_MailHistory") == c2sData.cmd then --邮件领取历史
skynet.server.mail:History( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_MailAward") == c2sData.cmd then --邮件奖励
skynet.server.mail:Award( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_ReadMail") == c2sData.cmd then --邮件读取
skynet.server.mail:Read( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_DeleteReadMail") == c2sData.cmd then --删除已读邮件
skynet.server.mail:DeleteRead( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_MailAllAward") == c2sData.cmd then --一键领取邮件奖励
skynet.server.mail:AllAward( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_RedeemHistory") == c2sData.cmd then --兑换码领取历史
skynet.server.redeem:History( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_RedeemAward") == c2sData.cmd then --兑换码领取奖励
skynet.server.redeem:Award( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_CoffeeMergeShow") == c2sData.cmd then --咖啡合成界面展示
skynet.server.coffeeShop:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_CoffeeMergeSupplyClick") == c2sData.cmd then --咖啡供货盒点击
skynet.server.coffeeShop:SupplyClick( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_CoffeeMergeSupplyShow") == c2sData.cmd then --咖啡供货盒展示
skynet.server.coffeeShop:SupplyShow( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_CoffeeMergeSort") == c2sData.cmd then --咖啡排序
skynet.server.coffeeShop:Sort( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_CoffeeMergeAttempt") == c2sData.cmd then --咖啡合成
skynet.server.coffeeShop:Merge( player , c2sData , s2cData )
--elseif pb.enum("MsgType","CMD_C2S_CoffeeMergeCurrency") == c2sData.cmd then --咖啡货币
-- skynet.server.coffeeShop:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_CoffeeSupplierReplenish") == c2sData.cmd then --咖啡原料补充
skynet.server.coffeeShop:Replenish( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_CoffeeResearch") == c2sData.cmd then --咖啡研发
skynet.server.coffeeShop:Research( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_CoffeeIllustrationShow") == c2sData.cmd then --咖啡图鉴展示
skynet.server.coffeeShop:IllustrationShow( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_CoffeeIllustrationPrize") == c2sData.cmd then --咖啡图鉴领取
skynet.server.coffeeShop:IllustrationPrize( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FlowerShopShow") == c2sData.cmd then --花店内容展示
skynet.server.flowerShop:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FlowerShopBuy") == c2sData.cmd then --花店展示区购买
skynet.server.flowerShop:Buy( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FlowerShopRecycle") == c2sData.cmd then --花店回收区售卖
skynet.server.flowerShop:Recycle( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FlowerShelfShow") == c2sData.cmd then --花店货架展示
skynet.server.flowerShop:ShelfShow( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FlowerShelfBuy") == c2sData.cmd then --花店货架购买
skynet.server.flowerShop:ShelfBuy( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_StylingRoomMiniGameShow") == c2sData.cmd then --造型间寻物展示
skynet.server.styleShop:GridShow( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_StylingRoomMiniGameRefresh") == c2sData.cmd then --造型间寻物刷新
skynet.server.styleShop:GridRefresh( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_StylingRoomMiniGameClick") == c2sData.cmd then --造型间寻物点击
skynet.server.styleShop:GridClick( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_StylingRoomMiniGameEnergyRefill") == c2sData.cmd then --造型间寻物剪刀回复
skynet.server.styleShop:RestoreEnergy( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_StylingRoomMiniGameEnergyShow") == c2sData.cmd then --造型间寻物剪刀展示
skynet.server.styleShop:EnergyShow( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_StylingDesignRoomShow") == c2sData.cmd then --每次进入造型间的时候需要显示
skynet.server.styleShop:RoomShow( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_StylingDesignRoomAttempt") == c2sData.cmd then --造型间设计
skynet.server.styleShop:RoomAttempt( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_StylingDesignRewardPrize") == c2sData.cmd then --造型间奖励领取
skynet.server.styleShop:RoomReward( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_GuGuShopShow") == c2sData.cmd then --咕咕市集数据展示
skynet.server.guGuShop:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_GuGuShopBuy") == c2sData.cmd then --咕咕市集购买
skynet.server.guGuShop:Buy( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_MapShowLoc") == c2sData.cmd then --外出地点展示
skynet.server.map:ShowLoc( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_MapLocEnter") == c2sData.cmd then --进入外出地点
skynet.server.map:EntryLoc( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_MapShowNPCDetail") == c2sData.cmd then --NPC详情
skynet.server.map:MapShowNPCDetail( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_AnnouncementHistory") == c2sData.cmd then --公告历史
skynet.server.announcement:History( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_QuestionnaireShow") == c2sData.cmd then --问卷调查显示
skynet.server.questionnaire:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_QuestionnaireSubmit") == c2sData.cmd then --问卷调查提交
skynet.server.questionnaire:Submit( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PassCheckRewardShow") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_PassCheck ) then --通行证奖励显示
skynet.server.passCheck:RewardShow( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PassCheckRewardGet") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_PassCheck ) then --通行证奖励获取
skynet.server.passCheck:RewardGet( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PassCheckRewardAllGet") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_PassCheck ) then --通行证奖励一键获取
skynet.server.passCheck:RewardAllGet( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PassCheckTaskShow") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_PassCheck ) then --通行证任务显示
skynet.server.passCheck:TaskShow( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PassCheckTaskGet") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_PassCheck ) then --通行证奖励获取
skynet.server.passCheck:TaskGet( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FurDyeShow") == c2sData.cmd then --染色工坊显示
skynet.server.dyeworkshop:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FurDyeAttempt") == c2sData.cmd then --染色工坊染色
skynet.server.dyeworkshop:Attempt( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FurDyeSlotPrize") == c2sData.cmd then --染色工坊领取
skynet.server.dyeworkshop:Prize( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FurDyeSlotSpeedUp") == c2sData.cmd then --染色工坊加速
skynet.server.dyeworkshop:SpeedUp( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_FurDyeSlotUnlock") == c2sData.cmd then --染色空间解锁
skynet.server.dyeworkshop:Unlock( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_DesignShow") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_DesignHouse ) then --设计抽奖展示
skynet.server.design:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_DesignLottery") == c2sData.cmd and player:IsUnlockSystem( dataType.UnlockSystem_DesignHouse ) then --设计抽奖
skynet.server.design:Lottery( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_StoreShow") == c2sData.cmd then --商城展示
skynet.server.store:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_StoreBuy") == c2sData.cmd then --商城购买
skynet.server.store:Buy( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_SignInShow") == c2sData.cmd then --常规签到显示
skynet.server.signIn:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_SignInGet") == c2sData.cmd then --常规签到获取
skynet.server.signIn:Get( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_SignInSumGet") == c2sData.cmd then --常规签到累签获取
skynet.server.signIn:SumGet( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PlayerLandCheck") == c2sData.cmd then --新人签到检查
skynet.server.playerLand:Check( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PlayerLandShow") == c2sData.cmd then --新人签到显示
skynet.server.playerLand:Show( player , c2sData , s2cData )
elseif pb.enum("MsgType","CMD_C2S_PlayerLandGet") == c2sData.cmd then --新人签到获取
skynet.server.playerLand:Get( player , c2sData , s2cData )
else
--正在游戏中不接收其它消息
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
return
end
--存档版本刷新TIPS
skynet.server.msgTips:Refresh( player )
if self.curServerConfig.IsDetailLog then
log.info(string.format("玩家 %d cmd %d 返回code %d 运行时间 %d", c2sData.userId , s2cData.cmd or 0 , s2cData.code , skynet.GetTime() - t1))
else
log.info(string.format("玩家 %d cmd %d 返回code %d 运行时间 %d", c2sData.userId , s2cData.cmd or 0, s2cData.code , skynet.GetTime() - t1))
end
end
end
local isDo,callData = pcall( Do )
local sendMsg,sendLen = 0,0
if not isDo then
log.info("GameServer 内部错误",callData )
s2cData.code = errorInfo.ErrorCode.InnerError
self:SendErrorInfoToCenter( s2cData.code , "内部错误")
end
end
--接收用户登陆TOKEN
function GameServer:RecvUserLoginToken( c2sData )
log.info(string.format("游戏服接收路由服Token信息 平台 %s 帐号 %s Token %s", c2sData.platform , c2sData.loginAccount , c2sData.loginToken))
local platform = c2sData.platform
local loginAccount = c2sData.loginAccount
local loginToken = c2sData.loginToken
if not self.preLoginUser[ loginAccount ] then
self.preLoginUser[ loginAccount ] = {}
end
self.preLoginUser[ loginAccount ].platform = platform
self.preLoginUser[ loginAccount ].loginAccount = loginAccount
self.preLoginUser[ loginAccount ].loginToken = loginToken
self.preLoginUser[ loginAccount ].lastUpdateTime = skynet.GetTime() --上一次更新时间
end
--接收用户登陆TOKEN
function GameServer:AddPayInfo( c2sData , s2cData)
local account = c2sData.account
local storeId = c2sData.storeId
local count = math.abs(c2sData.count)
if not skynet.server.playerCenter:IsExistPlayerForAccount( account ) then
s2cData.code = errorInfo.ErrorCode.NoExistUser
else
local player = skynet.server.playerCenter:GetPlayerForAccount( account )
if not player then
s2cData.code = errorInfo.ErrorCode.NoExistUser
else
if 7 == storeId then --通行证开启VIP礼包
skynet.server.passCheck:Pay( player , storeId )
log.info(string.format("玩家 %s 开始发放充值礼包1 %d", player.userId , storeId))
else
local isGive = true
--if 8 == storeId then
--skynet.server.design:Pay( player , storeId )
--isGive = false
---log.info(string.format("玩家 %s 开始发放充值礼包2 %d", player.userId , storeId))
--else
skynet.server.design:Pay( player , storeId )
skynet.server.store:Pay( player , storeId )
isGive = false
log.info(string.format("玩家 %s 开始发放充值礼包3 %d", player.userId , storeId))
--end
if isGive then
--直接发货
local cfgStorePack = skynet.server.gameConfig:GetCurCfg( "StorePack" , storeId )
if not cfgStorePack then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
else
for i = 1, count , 1 do
player:GiveReward( cfgStorePack.rewardId )
end
end
end
end
--通知客户端
local data = {}
data.storeId = storeId
data.count = count
self:SendMsgToUser( player.userId , "CMD_S2C_PayInfo" , data )
log.info(string.format("玩家 %s 成功发放充值礼包 %d", player.userId , storeId))
end
end
end
--Web消息
function GameServer:WebMsg( c2sData )
log.info("后台发来的消息 ",skynet.server.common:TableToString(c2sData))
--if "GMCmd" == c2sData.gameMessage or "GMAddGoods" == c2sData.gameMessage then
skynet.server.gm:WebMsg( c2sData )
--end
end
--查询用户登陆状态
function GameServer:RecvQueryUserOnline( c2sData , s2cData )
s2cData.isExistPlayer = playerCenter:IsExistPlayer( c2sData.platform , c2sData.loginAccount )
end
--用户登陆游戏
function GameServer:UserLogin( c2sData , s2cData )
local t1 = skynet.GetTime()
local socketId = c2sData.socketId
c2sData.data = assert(pb.decode("C2SUserLogin", c2sData.data ))
--对必要的参数检查
if not c2sData.data.platform or not c2sData.data.loginAccount or not c2sData.data.loginToken then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
return s2cData
end
local loginAccount = c2sData.data.loginAccount
log.info(string.format("玩家 %s 平台 %s 登陆请求 Token %s 硬件码 %s",c2sData.data.loginAccount , c2sData.data.platform , c2sData.data.loginToken , c2sData.data.hardwareCode ))
--检查预登陆信息,不存在就不能登陆
if not self.preLoginUser[ loginAccount ] then
s2cData.code = errorInfo.ErrorCode.NoExistPreLogin
log.info(string.format("玩家 %s 不存在预登陆信息", loginAccount))
return s2cData
end
--检查预登陆玩家是否有效
local isExist = false
for k, v in pairs(self.preLoginUser) do
if c2sData.data.platform == v.platform and c2sData.data.loginAccount == v.loginAccount and c2sData.data.loginToken == v.loginToken then
isExist = true
break
end
end
if not isExist then
s2cData.code = errorInfo.ErrorCode.VerifyTokenFailed
log.info(string.format("玩家 %s 预登陆不匹配", loginAccount))
return s2cData
end
if not string.find(loginAccount,"womei") then
self.preLoginUser[ loginAccount ] = nil
end
--从帐号模块获取数据
accountServer:UserLoginGame(c2sData , s2cData)
local userData = {}
if errorInfo.Suc == s2cData.code then
local playerData = json:decode(s2cData.data.playerData)
playerCenter:UserEnter( c2sData , playerData )
userData = playerCenter:GetLoginInfo( playerData )
if not userData then
s2cData.code = errorInfo.ErrorCode.NoExistUser
userData ={}
end
log.info(string.format("玩家 %s 登陆游戏成功", loginAccount))
else
log.info(string.format("玩家 %s 登陆游戏失败", loginAccount))
end
self.serverInfo.loginCount = self.serverInfo.loginCount + 1
s2cData.code = s2cData.code
s2cData.cmd = pb.enum("MsgType","CMD_S2C_UserLogin")
s2cData.data = assert(pb.encode("S2CUserLogin", userData))
end
--PING消息
function GameServer:Ping( player , c2sData , s2cData )
playerCenter:Ping( c2sData.userId )
local data = {}
s2cData.cmd = pb.enum("MsgType","CMD_S2C_Ping")
s2cData.data = assert(pb.encode("S2CPing", data))
end
--存档
function GameServer:Archive( player , c2sData , s2cData )
local socketId = c2sData.socketId
local userId = c2sData.userId
c2sData.data = assert(pb.decode("C2SArchive", c2sData.data ))
--对必要的参数检查
if nil == c2sData.data.opType then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
return s2cData
end
log.info("玩家存档操作",skynet.server.common:TableToString(c2sData.data))
local userCurLevel = tonumber(player.gameData.archiveLevel) --获取当前等级
local isCoverArchive = false --是否覆盖存档
log.info("读取档接收玩家等级 " , c2sData.data.level , userCurLevel)
if 1 == c2sData.data.opType and ( 0 == c2sData.data.level or c2sData.data.level >= userCurLevel ) then
isCoverArchive = true
player.gameData.archiveLevel = c2sData.data.level
log.info(string.format("玩家 %d 原等级 %s 新等级 %s", userId , userCurLevel , c2sData.data.level))
end
local data = {}
if 1 == c2sData.data.opType and c2sData.data.gameData and isCoverArchive then --保存
log.info(string.format("玩家 %d 覆盖存档", userId ))
player.archiveData = c2sData.data.gameData
playerCenter:UpdateIntervalSave( userId )
elseif 2 == c2sData.data.opType then --读取
log.info(string.format("玩家 %d 读取存档", userId ))
data.gameData = player.archiveData
elseif 3 == c2sData.data.opType then --清档
log.info(string.format("玩家 %d 存档置空", userId ))
player.archiveData ="{}"
player.gameData.level = 0
else
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
return s2cData
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_Archive")
s2cData.data = assert(pb.encode("S2CArchive", data))
end
--服务器时间
function GameServer:ServerTime( player , c2sData , s2cData )
local data = {}
data.serverTime = skynet.GetTime()
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ServerTime")
s2cData.data = assert(pb.encode("S2CServerTime", data))
end
--客户端连接断开
function GameServer:UserOffline( socketId )
local userId = playerCenter:GetUserIDForSocketId( socketId )
playerCenter:UserOffline( userId )
end
--向用户发送消息
function GameServer:SendMsgToUser( userId , cmd , userData )
--命令进行裁剪组装一下
local cmdName = string.sub(cmd, 9)
cmdName= "S2C"..cmdName
local socketId = playerCenter:GetSocketIdForUserID( userId )
if -1 == socketId then
return
end
local c2sData = {}
c2sData.code = errorInfo.Suc
c2sData.cmd = assert(pb.enum("MsgType",cmd))
c2sData.data = assert(pb.encode(cmdName, userData))
c2sData = assert(pb.encode("S2CMsgData", c2sData))
return skynet.call( "TcpSocket", "lua", cmd , socketId , c2sData )
end
--是否停止服务器
function GameServer:StopServer()
local playerList = skynet.server.playerCenter:GetPlayerList()
local c2sData ={}
local s2cData ={}
for userId, value in pairs( playerList ) do
log.info("玩家" ,userId, "服务器强制关闭,已被服务器下线")
accountServer:SavePlayerToDB( value.player , false )
end
end
--统计数据
function GameServer:StatData()
if skynet.GetTime() - self.last5MinTotalLoginCount >= self.per5MinTotalLoginCount then
skynet.server.mail:RefreshMailList()
skynet.server.announcement:RefreshAnnouncementList()
self.serverInfo.pre5MinLoginCount = self.serverInfo.loginCount - self.lastLoginCount
self.lastLoginCount = self.serverInfo.loginCount
self.last5MinTotalLoginCount = skynet.GetTime()
log.info(string.format("5分钟共有 %d 次登陆 , 当前总登陆次数 %d",self.serverInfo.pre5MinLoginCount, self.serverInfo.loginCount))
end
self.serverInfo.playerCount = playerCenter:GetPlayerCount()
end
skynet.server.gameServer = GameServer
return GameServer