Exemplo n.º 1
0
func init() {
	handle := dispatch.NewHandleConditions()
	//系统消息
	handle.Add(dispatch.HandleCondition{
		Condition: systemProto.IsValidID,
		H: dispatch.Handle{
			systemProto.ID_System_ConnectDBServerS2C: connectDBServerCallBack,
		},
	})
	//DB消息
	handle.Add(dispatch.HandleFuncCondition{
		Condition: dbProto.IsValidID,
		H: func(session *link.Session, msg []byte) {
			identification := binary.GetUint64LE(msg[2:10])
			var userSession *link.Session = global.GetSession(identification)
			if userSession == nil {
				return
			}
			dbMsgChan := userSession.State.(chan []byte)
			dbMsgChan <- msg
		},
	})

	//创建消息分派
	clientMsgDispatch = dispatch.NewDispatch(handle)
}
Exemplo n.º 2
0
func init() {
	handle := dispatch.NewHandleConditions()
	//系统消息处理
	handle.Add(dispatch.HandleCondition{
		Condition: systemProto.IsValidID,
		H: dispatch.Handle{
			systemProto.ID_System_ConnectWorldServerS2C: connectWorldServerCallBack,
		},
	})
	//游戏消息处理
	handle.Add(dispatch.HandleFuncCondition{
		Condition: gameProto.IsValidID,
		H: func(session *link.Session, msg []byte) {
			//发送到用户客户端
			msgIdentification := binary.GetUint64LE(msg[2:10])
			userSession := global.GetSession(msgIdentification)
			if userSession == nil {
				return
			}
			protos.Send(userSession, msg)
		},
	})

	//创建消息分派
	clientMsgDispatch = dispatch.NewDispatch(handle)
}
Exemplo n.º 3
0
func init() {
	//创建异步接收消息的Chans
	serverMsgReceiveChans = make([]dispatch.ReceiveMsgChan, 10)
	for i := 0; i < len(serverMsgReceiveChans); i++ {
		serverMsgReceiveChans[i] = make(chan dispatch.ReceiveMsg, 2048)
	}

	//创建DB同步数据消息分派
	serverMsgDispatch = dispatch.NewDispatchAsync(serverMsgReceiveChans,
		dispatch.HandleCondition{
			Condition: dbProto.IsValidSyncID,
			H: dispatch.Handle{
				systemProto.ID_System_ConnectDBServerC2S: connectDBServer,
				dbProto.ID_DB_User_LoginC2S:              userLogin,
			},
		},
	)

	//创建DB异步数据消息分派
	serverMsgDispatchAsync = dispatch.NewDispatch(
		dispatch.HandleCondition{
			Condition: dbProto.IsValidAsyncID,
			H: dispatch.Handle{
				dbProto.ID_DB_User_UpdateLastLoginTimeC2S: updateUserLastLoginTime,
			},
		},
	)
}
Exemplo n.º 4
0
func startGateway() {
	msgDispatch := dispatch.NewDispatch(
		dispatch.HandleFunc{
			H: transferProxy.SendToGameServer,
		},
	)

	addr := "0.0.0.0:" + gateway_port
	err := global.Listener("tcp", addr, global.PackCodecType_UnSafe,
		func(session *link.Session) {
			//将此Session记录在缓存内,消息回传时使用
			global.AddSession(session)
			//通知LoginServer用户上线
			transferProxy.SetClientSessionOnline(session)
			//添加session关闭时回调
			session.AddCloseCallback(session, func() {
				//通知LoginServer、GameServer用户下线
				transferProxy.SetClientSessionOffline(session.Id())
			})
		},
		msgDispatch,
	)

	checkError(err)
}
Exemplo n.º 5
0
func init() {
	//创建消息分派
	clientMsgDispatch = dispatch.NewDispatch(
		dispatch.Handle{
			systemProto.ID_System_ConnectLogServerS2C: connectLogServerCallBack,
		},
	)
}
Exemplo n.º 6
0
func init() {
	MsgDispatch = dispatch.NewDispatch(
		dispatch.Handle{
			gameProto.ID_UserLoginC2S:    login,
			gameProto.ID_GetUserInfoC2S:  getUserInfo,
			gameProto.ID_AgainConnectC2S: againConnect,
		},
	)
}
func init() {
	handle := dispatch.NewHandleConditions()
	//系统消息处理
	handle.Add(dispatch.HandleCondition{
		Condition: systemProto.IsValidID,
		H: dispatch.Handle{
			systemProto.ID_System_ConnectTransferServerC2S: connectTransferServer,
			systemProto.ID_System_ClientLoginSuccessC2S:    clientLoginSuccess,
		},
	})
	//游戏消息处理
	handle.Add(dispatch.HandleFuncCondition{
		Condition: gameProto.IsValidID,
		H: func(session *link.Session, msg []byte) {
			sendToGateServer(msg)
		},
	})

	//创建消息分派
	serverMsgDispatch = dispatch.NewDispatch(handle)
}
Exemplo n.º 8
0
func init() {
	handle := dispatch.NewHandleConditions()
	//系统消息处理
	handle.Add(dispatch.HandleCondition{
		Condition: systemProto.IsValidID,
		H: dispatch.Handle{
			systemProto.ID_System_ConnectWorldServerC2S:   connectWorldServer,
			systemProto.ID_System_ClientSessionOfflineC2S: setSessionOffline,
			systemProto.ID_System_ClientLoginSuccessC2S:   setClientLoginSuccess,
		},
	})
	//游戏消息处理
	handle.Add(dispatch.HandleFuncCondition{
		Condition: gameProto.IsValidID,
		H: func(session *link.Session, msg []byte) {
			dealGameMsg(msg)
		},
	})

	//创建消息分派
	serverMsgDispatch = dispatch.NewDispatch(handle)
}
func init() {
	handle := dispatch.NewHandleConditions()
	//系统消息处理
	handle.Add(dispatch.HandleCondition{
		Condition: systemProto.IsValidID,
		H: dispatch.Handle{
			systemProto.ID_System_ConnectTransferServerS2C: connectTransferServerCallBack,
			systemProto.ID_System_ClientSessionOnlineC2S:   setSessionOnline,
			systemProto.ID_System_ClientSessionOfflineC2S:  setSessionOffline,
			systemProto.ID_System_ClientLoginSuccessC2S:    setClientLoginSuccess,
		},
	})
	//LoginServer消息
	handle.Add(dispatch.HandleFuncCondition{
		Condition: gameProto.IsValidLoginID,
		H: func(session *link.Session, msg []byte) {
			dealGameMsg(msg)
		},
	})
	//GameServer消息
	handle.Add(dispatch.HandleFuncCondition{
		Condition: gameProto.IsValidGameID,
		H: func(session *link.Session, msg []byte) {
			dealGameMsg(msg)
		},
	})
	//WorldServer消息
	handle.Add(dispatch.HandleFuncCondition{
		Condition: gameProto.IsValidWorldID,
		H: func(session *link.Session, msg []byte) {
			worldProxy.SendGameMsgToServer(msg)
		},
	})

	//创建消息分派
	clientMsgDispatch = dispatch.NewDispatch(handle)
}