128 lines
4.1 KiB
Lua
128 lines
4.1 KiB
Lua
local skynet = require "skynet"
|
||
local oo = require "Class"
|
||
local pb = require "pb"
|
||
local log = require "Log"
|
||
local errorInfo = require "ErrorInfo"
|
||
local dataType = require "DataType"
|
||
local redisKeyUrl = require "RedisKeyUrl"
|
||
local Group = oo.class()
|
||
|
||
Group.ShowType_JoinList = 1 --加入列表
|
||
Group.ShowType_GroupInfo = 2 --家园信息
|
||
|
||
Group.IdentityType_Leader = 1 --园长
|
||
Group.IdentityType_ViceLeader = 2 --副园长
|
||
Group.IdentityType_Member = 3 --成员
|
||
|
||
Group.JoinType_Freedom = 1 --自由加入
|
||
Group.JoinType_Approve = 2 --审批加入
|
||
|
||
--[[
|
||
{"group",
|
||
{
|
||
{"isAdd", false , "是否加入家园" } ,
|
||
{"data", {} , "消息提示数据" } ,
|
||
{"reward", {} , "红点奖励" } ,
|
||
} ,
|
||
"消息提示" } ,
|
||
]]
|
||
|
||
--[[
|
||
Group
|
||
家园ID , 家园名称、家园宣言、家园徽章、加入家园方式(自由加入和审批加入)、加入等级限制
|
||
|
||
|
||
|
||
]]
|
||
function Group:Init()
|
||
end
|
||
|
||
--家园显示
|
||
function Group:Show( player , c2sData , s2cData )
|
||
c2sData.data = assert(pb.decode("C2SGroupShow", c2sData.data ))
|
||
local data = {}
|
||
local curGroup = player.gameData.group
|
||
if curGroup.isAdd then
|
||
data.showType = self.ShowType_JoinList
|
||
data.joinInfo = {}
|
||
else
|
||
data.showType = self.ShowType_GroupInfo
|
||
data.groupInfo = {}
|
||
end
|
||
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupShow")
|
||
s2cData.data = assert(pb.encode("S2CGroupShow", data))
|
||
end
|
||
|
||
--家园创建
|
||
function Group:Create( player , c2sData , s2cData )
|
||
c2sData.data = assert(pb.decode("C2SGroupCreate", c2sData.data ))
|
||
local data = {}
|
||
local curGroup = player.gameData.group
|
||
|
||
local name = c2sData.data.name
|
||
local declaration = c2sData.data.declaration
|
||
local badgeId = c2sData.data.badgeId
|
||
local joinType = c2sData.data.joinType
|
||
local minJoinLevel = c2sData.data.minJoinLevel
|
||
|
||
if not name or not declaration or not badgeId or not joinType or not minJoinLevel then
|
||
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
||
elseif 0 ~= #curGroup.id then
|
||
s2cData.code = errorInfo.ErrorCode.AlreadyExistGroup
|
||
else
|
||
while true do
|
||
local randId = skynet.server.common:RandID( 10 ) --生成10位随机ID
|
||
local redisKey = string.format( redisKeyUrl.GameServerGroupInfo , randId )
|
||
if not skynet.server.redis:exists( redisKey) then
|
||
curGroup.id = randId
|
||
skynet.server.redis:hmset( redisKey , "name" , name ,"declaration" , declaration ,"badgeId" , badgeId ,"joinType" , joinType ,"minJoinLevel" , minJoinLevel )
|
||
end
|
||
end
|
||
end
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupCreate")
|
||
s2cData.data = assert(pb.encode("S2CGroupCreate", data))
|
||
end
|
||
|
||
--家园加入
|
||
function Group:Join( player , c2sData , s2cData )
|
||
c2sData.data = assert(pb.decode("C2SGroupJoin", c2sData.data ))
|
||
local data = {}
|
||
local curGroup = player.gameData.group
|
||
|
||
local id = c2sData.data.id
|
||
if not id or 10 ~= #id then
|
||
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
||
elseif 0 ~= #curGroup.id then
|
||
s2cData.code = errorInfo.ErrorCode.AlreadyExistGroup
|
||
else
|
||
local redisKey = string.format( redisKeyUrl.GameServerGroupInfo , id )
|
||
if not skynet.server.redis:exists( redisKey) then
|
||
s2cData.code = errorInfo.ErrorCode.NoExistGroup
|
||
else
|
||
|
||
end
|
||
end
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupJoin")
|
||
s2cData.data = assert(pb.encode("S2CGroupJoin", data))
|
||
end
|
||
|
||
--家园创建
|
||
function Group:test( player , c2sData , s2cData )
|
||
c2sData.data = assert(pb.decode("C2SGroupCreate", c2sData.data ))
|
||
local data = {}
|
||
local id = c2sData.data.id
|
||
if not id then
|
||
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
||
else
|
||
end
|
||
s2cData.cmd = pb.enum("MsgType","CMD_S2C_GroupCreate")
|
||
s2cData.data = assert(pb.encode("S2CGroupCreate", data))
|
||
end
|
||
|
||
--获取能加入的家园列表
|
||
function Group:GetJoinList( player )
|
||
end
|
||
|
||
skynet.server.group = Group
|
||
return Group |