//----------------------------------------------- connection close cleanup work
func close_work(sess *Session) {
	if sess.LoggedIn {
		hub_client.Logout(sess.User.Id)
		gsdb.UnregisterOnline(sess.User.Id)
		close(sess.MQ)

		// 未处理的IPC数据,重新放入db
		if len(sess.MQ) > 0 {
			log.Println("re-push ipcobject back to db")
		}

		for len(sess.MQ) > 0 {
			ipcobject := <-sess.MQ
			forward_tbl.Push(&ipcobject)
		}

		// 持久化逻辑#3: 离线时,刷入数据库
		_flush(sess)
	}
}
Exemple #2
0
//----------------------------------------------- cleanup work after disconnection
func close_work(sess *Session) {
	defer PrintPanicStack()
	if sess.Flag&SESS_LOGGED_IN == 0 {
		return
	}

	// must flush user data
	_flush(sess)

	// notify hub
	hub_client.Logout(sess.User.Id)

	// unregister online at this server
	gsdb.UnregisterOnline(sess.User.Id)

	// close MQ, and save the queue to db
	close(sess.MQ)
	for ipcobject := range sess.MQ {
		forward_tbl.Push(&ipcobject)
		NOTICE("re-pushed ipcobject back to db, userid:", sess.User.Id)
	}

	NOTICE(sess.User.Name, "disconnected from", sess.IP, "country:", geoip.Query(sess.IP))
}