Пример #1
1
func OnActive(m game.JsonString, c net.Conn) {
	//fmt.Println("OnActive")
	uid, cid := m.GetUid(), m.GetCid()
	_, exist := ticker.Active[cid]
	if exist {
		ticker.Active[cid][uid] = time.Now().Unix()
	} else {
		ticker.Active[cid] = map[uint32]int64{uid: time.Now().Unix()}
	}
}
Пример #2
0
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)
}
Пример #3
0
func OnUserList(m game.JsonString, c net.Conn) {
	fmt.Println("OnUserList")
	uid, cid := m.GetUid(), m.GetCid()

	rep := game.UserListRep{}
	rep.Ret = common.RET_OK
	rep.Uid = uid
	rep.Cid = cid

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

	rep.Status = r.Status
	rep.Op = "user_list"
	rep.UserList = make([]game.UserRep, 0) //+

	ubl := GetPlayerBalance(r.Players)
	for _, player := range r.Players {
		ur := game.UserRep{player.Uid, player.Pos, ubl[player.Uid]}
		rep.UserList = append(rep.UserList, ur)
	}
	for _, user := range r.Users {
		ur := game.UserRep{user.Uid, 0, 0}
		rep.UserList = append(rep.UserList, ur)
	}

	game.SendMsg(c, rep)
	fmt.Println("OnUserList rep:", rep)
}
Пример #4
0
func OnSendChlInvite(m game.JsonString, c net.Conn) {
	fmt.Println("OnSendChlInvite")
	go func() {
		conn, err := net.Dial("tcp", "127.0.0.1:37771")
		if err != nil {
			fmt.Println("conn invite proxy err")
		} else {
			msg := game.ProxyInvite{"Doinvite", m.GetRootChlId(), m.GetCid()}
			game.SendMsg(conn, msg)
		}
	}()
}
Пример #5
0
func OnLogout(m game.JsonString, c net.Conn) {
	fmt.Println("OnLogout")
	uid, cid := m.GetUid(), m.GetCid()
	r, ok := m.GetRound(Casino)
	if ok {
		uid := m.GetUid()
		r.Logout(uid)
	}
	_, ok = ticker.Active[cid]
	if ok {
		delete(ticker.Active[cid], uid)
	}
	db.SetLogoutTime(uid)

	rep := game.LogoutRep{0, uid, "logout"}
	r.Broadcast(rep)
	fmt.Println("OnLogout rep:", rep)
}