| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package simplematch
- import (
- "bet24.com/log"
- privateroom "bet24.com/servers/micros/privateroom/proto"
- "fmt"
- )
- type matchroom struct {
- RoomNo int
- Users []int
- Status int
- mi *matchinstance
- Winners []int
- }
- func newMatchRoom(roomNo int, mi *matchinstance) *matchroom {
- ret := new(matchroom)
- ret.RoomNo = roomNo
- ret.mi = mi
- return ret
- }
- func (mr *matchroom) addUser(userId int) {
- for i := 0; i < len(mr.Users); i++ {
- if mr.Users[i] == userId {
- log.Release("simplematch.matchroom[%d] addUser %d already exist", mr.RoomNo, userId)
- return
- }
- }
- mr.Users = append(mr.Users, userId)
- }
- func (mr *matchroom) removeUser(userId int) {
- for i := 0; i < len(mr.Users); i++ {
- if mr.Users[i] == userId {
- mr.Users = append(mr.Users[:i], mr.Users[i+1:]...)
- return
- }
- }
- log.Release("simplematch.matchroom[%d] removeUser %d not exist", mr.RoomNo, userId)
- }
- func (mr *matchroom) isEnded() bool {
- return mr.Status == privateroom.PrivateRoomStatus_Ended
- }
- func (mr *matchroom) isStarted() bool {
- return mr.Status >= privateroom.PrivateRoomStatus_Playing
- }
- func (mr *matchroom) dump() {
- if mr == nil {
- return
- }
- var users string
- for i := 0; i < len(mr.Users); i++ {
- users = fmt.Sprintf("%s%d:%d;", users, mr.Users[i], mr.mi.getUserScore(mr.Users[i]))
- }
- if len(mr.Winners) > 0 {
- users = fmt.Sprintf("%s winners:%v", users, mr.Winners)
- }
- log.Release(" RoomNo[%d] Status[%d] Users[%s]", mr.RoomNo, mr.Status, users)
- }
- func (mr *matchroom) isValidUsers(users []int) bool {
- for _, v := range users {
- if !mr.isUserExist(v) {
- log.Release("matchroom.isValidUsers %d not exist in", v)
- return false
- }
- }
- return true
- }
- func (mr *matchroom) isUserExist(userId int) bool {
- for _, v := range mr.Users {
- if v == userId {
- return true
- }
- }
- return false
- }
- func (mr *matchroom) setWinners(winners []int) {
- mr.Winners = winners
- }
|