Beispiel #1
0
func checkLogChan() {

	defer func() {
		if err := recover(); err != nil {
			log.Critical("logChan panic : %v", err)
			checkLogChan()
		}
	}()

	for log := range logChan {
		DB().Insert(log)
	}
}
Beispiel #2
0
func checkfinanceChan() {

	defer func() {
		if err := recover(); err != nil {
			log.Critical("financeChan panic : %v", err)
			checkfinanceChan()
		}
	}()

	for finance := range financeChan {
		DB().Insert(finance)
		//sql := "INSERT INTO g_role_finance_log SET roles_unique = ? , rfl_old_money = ? , rfl_new_money = ? , rfl_type = ? , rfl_mtype = ? , rfl_desc = ? , rfl_time = UNIX_TIMESTAMP() , rfl_static_type = ? "
		//DB().Exec(sql, finance.uid, finance.oldMoney, finance.newMoney, isAdd, finance.moneyType, finance.desc, finance.financeType)
	}
}
Beispiel #3
0
// 从客户端读取信息
func (this *Connect) PullFromClient() {

	for {
		defer func() {
			if err := recover(); err != nil {
				log.Critical("Panic occur. %v", err)
				this.Send(lineNum(), fmt.Sprintf("%v", err))
				this.PullFromClient()
			}
		}()

		var content []byte
		err := websocket.Message.Receive(this.Conn, &content)
		if err != nil {
			log.Info("Websocket Error: %v", err)
			playerMap.Delete(this.Uid, this)
			return
		}

		beginTime := time.Now()
		log.Info(" Begin ")

		// parse proto message
		this.Request, err = ParseContent(content)
		if err != nil {
			log.Error("Parse client request error. %v", err)
			this.Send(lineNum(), err)
			continue
		}

		if this.Request.GetCmdId() != LOGIN {
			if !this.verify(this.Request.GetTokenStr()) {
				continue
			}
		}

		this.Function(this.Request.GetCmdId())()

		execTime := time.Now().Sub(beginTime)
		if execTime.Seconds() > 0.1 {
			// slow log
			log.Warn("Slow Exec , time is %v second", execTime.Seconds())
		} else {
			log.Info("time is %v second", execTime.Seconds())
		}
	}
}
Beispiel #4
0
func httpConfirm(w http.ResponseWriter, r *http.Request) {

	defer func() {
		if err := recover(); err != nil {
			log.Critical("RPC Panic: %v", err)
		}
	}()

	orderId := r.FormValue("order_id")
	if orderId == "" {
		return
	}

	OrderData, err := models.Order.Order(orderId)
	if err != nil {
		return
	}

	conn := playerMap.Get(OrderData.Uid)

	var RoleData *models.RoleData
	if conn != nil && conn.Role != nil {
		RoleData = conn.Role
	} else {
		RoleData, err = models.Role.Role(OrderData.Uid)
		if err != nil {
			return
		}
	}

	// ----- 启动事务 -----
	if OrderData.Status != 1 {
		log.Warn("Order status not is '1' ORDERID: %s", orderId)
		return
	}

	Transaction, err := models.DB().Begin()
	if err != nil {
		log.Warn("%v", err)
		return
	}

	OrderData.Status = 2

	affected_rows, err := Transaction.Update(OrderData)
	if err != nil || affected_rows != 1 {
		Transaction.Rollback()
		log.Warn("%v", err)
		return
	}

	oldDiamond := RoleData.Diamond
	RoleData.Diamond += OrderData.Diamond
	RoleData.UnixTime = time.Now().Unix()

	_, err = Transaction.Update(RoleData)
	if err != nil {
		RoleData.Diamond = oldDiamond
		Transaction.Rollback()
		log.Warn("%v", err)
		return
	}

	// ----- 提交 -----
	if Transaction.Commit() != nil {
		RoleData.Diamond = oldDiamond
		Transaction.Rollback()
		log.Warn("%v", err)
		return
	}

	models.InsertSubDiamondFinanceLog(OrderData.Uid, models.FINANCE_BUY_DIAMOND, oldDiamond, RoleData.Diamond, fmt.Sprintf("orderId: %s", orderId))

	if conn != nil {
		*conn.Request.CmdId = 10121
		*conn.Request.CmdIndex = 10121
		conn.Send(StatusOK, &protodata.PaySuccessResponse{Role: roleProto(RoleData)})
	}
}