Example #1
0
func (p *PlayerList) ClearDeleted() {
	for session, pl := range p.players {
		if pl.Deleted {
			pl.DeletePlayer()
			delete(p.players, session)
			log.LogDebug("delete player:", session)
			log.LogDebug("remain players:", p.Count())
		}
	}
}
Example #2
0
File: do.go Project: mysll/flynet
//进程rpc处理
func RpcProcess(ch chan *rpc.RpcCall) {
	var start_time time.Time
	var delay time.Duration
	for {
		select {
		case call := <-ch:
			if call.IsThreadWork() {
				busy = true
			} else {
				log.LogDebug(call.GetSrc(), " rpc call:", call.GetMethod())
				start_time = time.Now()
				err := call.Call()
				if err != nil {
					log.LogError(err)
				}
				delay = time.Now().Sub(start_time)
				if delay > warninglvl {
					log.LogWarning("rpc call ", call.GetMethod(), " delay:", delay.Nanoseconds()/1000000, "ms")
				}
				err = call.Done()
				if err != nil {
					log.LogError(err)
				}
				call.Free()
				busy = true
			}

		default:
			return
		}
	}
}
Example #3
0
func (a *Account) Login(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	args := &c2s.Enterbase{}
	if server.Check(server.ParseProto(msg, args)) {
		return 0, nil
	}
	if App.Login.checkClient(args.GetUser(), args.GetKey()) {
		if pl := App.Players.AddPlayer(mailbox.Id); pl != nil {
			log.LogMessage("add player:", mailbox)
			pl.Account = args.GetUser()
			pl.State = STATE_LOGGED
			if args.GetRolename() != "" {
				pl.ChooseRole = args.GetRolename()
				server.Check(App.DbBridge.selectUser(mailbox, pl.Account, args.GetRolename(), int(args.GetRoleindex())))
				return 0, nil
			}
			server.Check(App.DbBridge.getUserInfo(mailbox, args.GetUser()))
			return 0, nil
		}
		log.LogError("player add failed", mailbox)
		return 0, nil
	} else {
		log.LogDebug(args.GetUser(), args.GetKey())
		err := &s2c.Error{}
		err.ErrorNo = proto.Int32(share.ERROR_LOGIN_FAILED)
		server.Check(server.MailTo(nil, &mailbox, "Login.Error", err))
		return 0, nil
	}
}
Example #4
0
func (k *Kernel) AddScheduler(s Scheduler) {
	if s == nil {
		return
	}
	schedulerid++
	s.SetSchedulerID(schedulerid)
	scheduler[schedulerid] = s
	log.LogDebug("add scheduler:", schedulerid)
}
Example #5
0
//移除一个客户端连接
func (cl *ClientList) Remove(session int64) {
	cl.l.Lock()
	if cn, ok := cl.clients[session]; ok {
		delete(cl.clients, session)
		log.LogDebug("remove client node, ", cn.Addr)
		cn.Close()
	}
	cl.l.Unlock()
}
Example #6
0
func (p *PlayerList) AddPlayer(mailbox rpc.Mailbox, data *EntityInfo) *AreaPlayer {
	if _, dup := p.players[mailbox.Uid]; dup {
		log.LogError("player already added,", mailbox)
		return nil
	}

	ent, err := App.CreateFromArchive(data,
		map[string]interface{}{
			"mailbox": mailbox,
			"base":    rpc.Mailbox{App: mailbox.App},
			"sync":    true})
	if err != nil {
		log.LogError(err)
		return nil
	}

	nameinter, err := ent.Get("Name")
	if err != nil {
		log.LogError(err)
		App.Destroy(ent.GetObjId())
		return nil
	}
	name := nameinter.(string)
	if _, dup := p.namelist[name]; dup {
		log.LogError("player name conflict")
		App.Destroy(ent.GetObjId())
		return nil
	}

	pl := &AreaPlayer{}
	pl.Mailbox = mailbox
	pl.Base = rpc.Mailbox{App: mailbox.App}
	pl.Name = name
	pl.Entity = ent
	pl.Deleted = false
	pl.Quit = false
	p.players[mailbox.Uid] = pl
	p.namelist[name] = mailbox
	cell := App.GetCell(1)
	if w, ok := ent.(inter.Watcher); ok {
		w.SetRange(2)
	}

	pl.Cell = cell
	App.PlaceObj(
		cell.scene,
		ent,
		Vector3{
			util.RandRangef(0, cell.width),
			0,
			util.RandRangef(0, cell.height)},
		0)

	log.LogDebug("Add player:", mailbox)
	return pl
}
Example #7
0
func (k *Kernel) RemoveScheduler(s Scheduler) {
	if s == nil {
		return
	}
	if _, exist := scheduler[s.GetSchedulerID()]; exist {
		delete(scheduler, s.GetSchedulerID())
		log.LogDebug("remove scheduler:", s.GetSchedulerID(), " total:", len(scheduler))
		s.SetSchedulerID(-1)
	}
}
Example #8
0
func (a *AOI) RemoveObject(id ObjectID, typ int) bool {
	if v, ok := a.watchers[typ]; ok {
		if _, ok := v[id.Index]; !ok {
			return false
		}
		delete(v, id.Index)
		log.LogDebug("aoi remove object:", id)
		return true
	}
	return false
}
Example #9
0
//清理删除的对象
func (f *Factory) ClearDelete() {
	delcount := 0
	var next *list.Element
	for ele := f.deletes.Front(); ele != nil; ele = next {
		next = ele.Next()
		f.realDestroy(ele.Value.(int32))
		f.deletes.Remove(ele)
		delcount++
	}
	if delcount > 0 {
		log.LogDebug("deleted objects:", delcount, ",remain objects:", len(f.objects))
	}
}
Example #10
0
func (p *PlayerList) RemovePlayer(session int64) bool {
	if pl, exist := p.players[session]; exist && !pl.Deleted {
		status := server.GetAppByType("status")
		if status != nil {
			status.Call(nil, "PlayerList.UpdatePlayer", pl.Account, pl.ChooseRole, "")
		}

		pl.Deleted = true
		pl.State = STATE_DELETING
		log.LogDebug("Remove player:", pl.ChooseRole, " session:", session)
		return true
	}

	return false
}
Example #11
0
func (p *PlayerList) RemovePlayer(mailbox rpc.Mailbox) bool {
	if pl, exist := p.players[mailbox.Uid]; exist && !pl.Deleted {
		if pl.Cell != nil {
			err := App.RemoveChild(pl.Cell.scene, pl.Entity)
			if err != nil {
				log.LogError(err)
			}
		}
		pl.Deleted = true
		pl.State = STATE_DELETING
		log.LogDebug("Remove player:", mailbox)
		return true
	}

	return false
}
Example #12
0
func (client *Client) input() {
	var err error
	for err == nil {
		message, err := client.codec.ReadMessage()
		if err != nil &&
			!strings.Contains(err.Error(), "An existing connection was forcibly closed by the remote host") &&
			!strings.Contains(err.Error(), "use of closed network connection") {
			log.LogError(client.codec.GetAddress(), err)
			break
		}

		ar := util.NewLoadArchiver(message.Header)
		seq, err := ar.ReadUInt64()
		client.mutex.Lock()
		call := client.pending[seq]
		delete(client.pending, seq)
		client.mutex.Unlock()

		switch {
		case call == nil:
		default:
			call.Reply = message
			client.queue <- call
			log.LogDebug("response replyed, seq:", seq)
		}
	}
	// Terminate pending calls.
	client.mutex.Lock()
	client.shutdown = true
	closing := client.closing
	if err == io.EOF {
		if closing {
			err = ErrShutdown
		} else {
			err = io.ErrUnexpectedEOF
		}
	}
	for _, call := range client.pending {
		call.Error = err
		call.done()
	}
	client.mutex.Unlock()

	log.LogMessage("quit read loop")

}
Example #13
0
func (a *AOI) AddObject(id ObjectID, typ int) bool {
	if v, ok := a.watchers[typ]; ok {
		if _, ok := v[id.Index]; ok {
			return false
		}
		v[id.Index] = id
		return true
	}

	w := make(map[int32]ObjectID, 100)

	w[id.Index] = id
	a.watchers[typ] = w

	log.LogDebug("aoi add object:", id)
	return true
}
Example #14
0
func (client *Client) send(call *Call) error {
	var seq uint64
	if !call.noreply {
		// Register this call.
		client.mutex.Lock()
		if client.shutdown || client.closing {
			call.Error = ErrShutdown
			return ErrShutdown
		}
		client.seq++
		seq = client.seq
		client.pending[seq] = call
		client.mutex.Unlock()
	}

	// Encode and send the request.
	err := client.codec.WriteRequest(&client.sending, seq, call)
	if err != nil {
		call.Error = err
		if !call.noreply {
			client.mutex.Lock()
			delete(client.pending, seq)
			client.mutex.Unlock()
		}

		call.done()
		return err
	}

	if call.noreply {
		call.done()
	} else {
		log.LogDebug("request async call:", call.ServiceMethod, ", seq:", seq)
	}

	return err
}
Example #15
0
File: base.go Project: mysll/flynet
func (b *BaseApp) OnSceneTeleported(mailbox rpc.Mailbox, result bool) {
	log.LogDebug("teleport to scene, result:", result)
}
Example #16
0
func (k *Kernel) RemoveSchedulerById(id int32) {
	if _, exist := scheduler[id]; exist {
		delete(scheduler, id)
		log.LogDebug("remove scheduler:", id, " total:", len(scheduler))
	}
}