Beispiel #1
0
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
}
Beispiel #2
0
func (a *Areas) createAppBak(bak share.CreateAppBak) {
	a.l.Lock()
	defer a.l.Unlock()
	appid := ""
	if bak.Res == "ok" {
		a.areas[bak.Id].Status = AREA_CREATED
		appid = bak.AppId
	} else {
		delete(a.areas, bak.Id)
	}

	log.LogMessage(bak, a)

	p := a.pending[bak.Id]
	var next *list.Element
	for e := p.Front(); e != nil; e = next {
		next = e.Next()
		mailbox := e.Value.(rpc.Mailbox)
		p.Remove(e)
		app := server.GetAppByName(mailbox.App)
		if app == nil {
			continue
		}
		app.Call(&mailbox, "AreaBridge.GetAreaBak", appid)
	}

	delete(a.pending, bak.Id)
}
Beispiel #3
0
func (d *DbBridge) RoleInUse(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	r := server.NewMessageReader(msg)
	serverid, err := r.ReadString()
	if server.Check(err) {
		return 0, nil
	}
	player := App.Players.GetPlayer(mailbox.Id)
	if player == nil {
		return 0, nil
	}

	if serverid == App.Name {
		server.Check(App.Players.SwitchPlayer(player))
		return 0, nil
	}

	app := server.GetAppByName(serverid)
	if app == nil {
		log.LogError(server.ErrAppNotFound)
		return 0, nil
	}

	app.Call(&mailbox, "Login.SwitchPlayer", player.Account)
	return 0, nil
}
Beispiel #4
0
func (a *Areas) GetArea(mailbox rpc.Mailbox, id string) error {
	a.l.Lock()
	defer a.l.Unlock()

	log.LogMessage("GetArea")
	app := server.GetAppByName(mailbox.App)
	if app == nil {
		return server.ErrAppNotFound
	}

	if areainfo, exist := a.areas[id]; exist {
		if areainfo.Status == AREA_CREATED {
			return app.Call(&mailbox, "AreaBridge.GetAreaBak", areainfo.AppId)
		} else {
			a.pending[id].PushBack(mailbox)
			return nil
		}
	}

	a.lastareaid++
	appid := fmt.Sprintf("area_%d", a.lastareaid)
	data, err := share.CreateAppMsg("area",
		id,
		appid,
		fmt.Sprintf(`{ "id":"%s", "host":"127.0.0.1", "port":0, "areaid":"%s"}`,
			appid,
			id),
		App.Name,
	)
	if err != nil {
		log.LogError(err)
		return app.Call(&mailbox, "AreaBridge.GetAreaBak", "")
	}

	err = App.SendToMaster(data)
	if err != nil {
		log.LogError(err)
		return app.Call(&mailbox, "AreaBridge.GetAreaBak", "")
	}

	ar := &area{}
	ar.AppId = appid
	ar.Status = AREA_CREATING
	a.areas[id] = ar
	l := list.New()
	l.PushBack(mailbox)
	a.pending[id] = l

	log.LogMessage(a)
	return nil
}
Beispiel #5
0
func (a *AreaBridge) areaRemovePlayer(player *BasePlayer, typ int) {
	area := server.GetAppByName(player.AreaId)
	if area == nil {
		player.SaveToDb(true)
		return
	}

	err := area.Call(&player.Mailbox, "BaseProxy.RemovePlayer", typ)
	if err != nil {
		player.SaveToDb(true)
		return
	}

}
Beispiel #6
0
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")
}
Beispiel #7
0
func (a *Account) Login(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	logindata := &c2s.Loginuser{}
	if server.Check(server.ParseProto(msg, logindata)) {
		return 0, nil
	}
	if logindata.GetPassword() == "123" {
		apps := server.GetAppByName("basemgr")
		if apps != nil {
			server.Check(apps.Call(&mailbox, "Session.GetBaseAndId", logindata.GetUser()))
			return 0, nil
		}
	} else {
		e := &s2c.Error{}
		e.ErrorNo = proto.Int32(share.ERROR_LOGIN_FAILED)
		server.MailTo(nil, &mailbox, "Login.Error", e)
	}

	return 0, nil
}
Beispiel #8
0
func (a *AreaBridge) checkPending(appid string) {
	if l, ok := a.pending[appid]; ok {
		ap := server.GetAppByName(appid)
		var next *list.Element
		for e := l.Front(); e != nil; e = next {
			next = e.Next()
			mb := e.Value.(rpc.Mailbox)
			l.Remove(e)
			player := App.Players.GetPlayer(mb.Id)
			if player == nil {
				continue
			}

			err := a.areaAddPlayer(ap, player)
			if err != nil {
				log.LogError(err)
			}
		}
	}
}
Beispiel #9
0
func (a *AreaBridge) enterArea(player *BasePlayer, areaid string) error {
	ap := server.GetAppByName(areaid)
	if ap == nil {
		if _, ok := a.pending[areaid]; ok {
			a.pending[areaid].PushBack(player.Mailbox)
			return nil
		} else {
			l := list.New()
			l.PushBack(player.Mailbox)
			a.pending[areaid] = l
			return nil
		}
	}
	if err := a.areaAddPlayer(ap, player); err != nil {
		log.LogError(err)
		return err
	}

	return nil
}