func (s *Session) GetBaseAndId(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) { r := server.NewMessageReader(msg) user, err := r.ReadString() if server.Check(err) { return 0, nil } s.l.Lock() defer s.l.Unlock() s.serial++ if s.serial < 0 { s.serial = 0 } bases := server.GetAppIdsByType("base") sort.Sort(sort.StringSlice(bases)) if len(bases) > 0 { idx := s.serial % len(bases) baseid := bases[idx] s.id++ if base := server.GetAppByName(baseid); base != nil { server.Check(base.Call(&mailbox, "Login.AddClient", user)) return 0, nil } log.LogError(server.ErrNotFoundApp) return 0, nil } log.LogError(server.ErrNotFoundApp) return 0, nil }
func GetLogin() (host string, port int, err error) { App.l.Lock() defer App.l.Unlock() App.serial++ if App.serial < 0 { App.serial = 0 } ls := server.GetAppIdsByType("login") sort.Sort(sort.StringSlice(ls)) if len(ls) > 0 { idx := App.serial % len(ls) a := server.GetAppByName(ls[idx]) return a.ClientHost, a.ClientPort, nil } return "", 0, errors.New("not found login") }