Esempio n. 1
0
func startLocalServer() {
	//连接DB
	db.Init()

	//连接Redis
	redisProxyErr := redisProxy.InitClient(cfg.GetValue("redis_ip"), cfg.GetValue("redis_port"))
	checkError(redisProxyErr)

	listener, err := link.Serve("tcp", "0.0.0.0:"+local_port, packet.New(
		binary.SplitByUint32BE, 1024, 1024, 1024,
	))
	checkError(err)

	listener.Serve(func(session *link.Session) {
		session.AddCloseCallback(session, func() {
			session.Close()
		})
		global.AddSession(session)

		var msg packet.RAW
		for {
			if err := session.Receive(&msg); err != nil {
				break
			}
			module.ReceiveMessage(session, msg)
		}
	})
}
Esempio n. 2
0
//初始化
func InitServer(port string) error {
	servers = make(map[string]*link.Session)
	asyncMsgs = list.New()

	db.Init()

	startSysDB()

	createRevGoroutines()

	listener, err := link.Serve("tcp", "0.0.0.0:"+port, packet.New(
		binary.SplitByUint32BE, 1024, 1024, 1024,
	))
	if err != nil {
		return err
	}

	listener.Serve(func(session *link.Session) {
		for {
			var msg packet.RAW
			if err := session.Receive(&msg); err != nil {
				break
			}

			msgID := binary.GetUint16LE(msg[:2])
			if systemProto.IsValidID(msgID) {
				//系统消息
				dealReceiveSystemMsgC2S(session, msg)
			} else if dbProto.IsValidAsyncID(msgID) {
				//异步DB消息
				asyncMsgs.PushBack(msg)
			} else {
				//同步DB消息
				useObj := revSyncMsgGoroutines[revSyncMsgGoroutineIndex]
				useObj.revMsgChan <- goroutineMsg{msg, session}
				revSyncMsgGoroutineIndex++
				if revSyncMsgGoroutineIndex == revSyncMsgGoroutineNum {
					revSyncMsgGoroutineIndex = 0
				}
			}
		}
	})

	return nil
}
Esempio n. 3
0
//初始化
func InitServer(port string) error {
	servers = make(map[string]*link.Session)

	//开启DB
	db.Init()

	//开启同步写入DB
	StartSysDB()

	//监听tcp连接
	addr := "0.0.0.0:" + port
	err := global.Listener("tcp", addr, global.PackCodecType_Safe,
		func(session *link.Session) {},
		serverMsgDispatch,
	)

	return err
}
Esempio n. 4
0
func startLocalServer() {
	//连接Redis
	redisProxyErr := redisProxy.InitClient(cfg.GetValue("redis_ip"), cfg.GetValue("redis_port"), cfg.GetValue("redis_pwd"))
	checkError(redisProxyErr)

	//开启DB
	db.Init()

	//开启同步DB数据到数据库
	dbProxy.StartSysDB()

	//开启客户端监听
	addr := "0.0.0.0:" + local_port
	err := global.Listener("tcp", addr, global.PackCodecType_UnSafe,
		func(session *link.Session) {
			global.AddSession(session)
		},
		gameProxy.MsgDispatch,
	)
	checkError(err)
}