func OnLogin(m game.JsonString, c net.Conn) { fmt.Println("OnLogin") uid, cid, t, name := m.GetUid(), m.GetCid(), m.GetTime(), m.GetName() diff := time.Now().Unix() - t if diff >= common.ENDURE_SEC || diff < 0 { rep := game.LoginRep{common.RET_TME, uid, 0, 0, 0, "login"} game.SendMsg(c, rep) return } award, lost := TimeCheck(uid) fmt.Println("time check", award, lost) bal, _ := db.ModifyBalance(uid, int32(award-lost)) //bal := mod_ret.Balance db.SetLoginTime(uid) db.SetName(uid, name) r, ok := m.GetRound(Casino) if ok == false { // 创建 r = &game.Round{0, make(map[uint32]game.User, common.MAX_USER), make(map[uint32]game.Player, common.MAX_PLAYER), 0} Casino[cid] = r } user := game.User{c, uid} ret := r.Login(user, cid) rep := game.LoginRep{ret, uid, award, lost, bal, "login"} if ret == common.RET_OK { r.Broadcast(rep) } else { game.SendMsg(c, rep) } fmt.Println("Login rep:", rep) }
func OnGiveCoin(m game.JsonString, c net.Conn) { fmt.Println("OnGiveCoin") coin, uid, tuid := m.GetCoin(), m.GetUid(), m.GetTargetUid() r, ok := m.GetRound(Casino) if ok == false { rep := game.GiveCoinRep{common.RET_FL, uid, tuid, coin, "give_coin"} game.SendMsg(c, rep) return } ret := common.RET_OK _, err1 := db.ModifyBalance(uid, -coin) _, err2 := db.ModifyBalance(tuid, coin) db.SetDayCounter(uid, -coin) db.SetDayCounter(tuid, coin) if err1 != nil || err2 != nil { ret = common.RET_FL } rep := game.GiveCoinRep{ret, uid, tuid, coin, "give_coin"} r.Broadcast(rep) }