コード例 #1
0
ファイル: casino.go プロジェクト: lsaint/casino
func GetPlayerBalance(players map[uint32]game.Player) (ret map[uint32]uint32) {
	l := len(players)
	if l == 0 {
		ret = make(map[uint32]uint32)
	} else {
		uids := make([]uint32, l)
		i := 0
		for _, player := range players {
			uids[i] = player.Uid
			i++
		}
		ret, _ = db.GetBalance(uids)
	}
	return
}
コード例 #2
0
ファイル: casino.go プロジェクト: lsaint/casino
func OnJoin(m game.JsonString, c net.Conn) {
	fmt.Println("OnJoin")
	uid := m.GetUid()
	rep := game.JoinRep{common.RET_FL, uid, 0, 0, "join"}

	r, ok := m.GetRound(Casino)
	if ok == false {
		game.SendMsg(c, rep)
		fmt.Println("OnJoin did not found round")
		return
	}

	pos := m.GetPos()
	rep.Pos, rep.Ret = pos, r.Join(game.Player{game.User{c, uid}, pos, ""})
	if rep.Ret == common.RET_OK {
		bal, _ := db.GetBalance([]uint32{uid})
		rep.Coin = bal[uid]
		r.Broadcast(rep)
	} else {
		game.SendMsg(c, rep)
	}
	fmt.Println("OnJoin rep:", rep)
}