// Returns a function used for alerting users that another user, within visible range, has changed position
func movedFun(tId uint, usr *user.U) func(mNS, mEW float64, e interface{}) {
	return func(mNS, mEW float64, e interface{}) {
		oUsr := e.(*user.U)
		if !usr.Equiv(oUsr) {
			broadcastSend(tId, msgdef.SMovedOp, usr, oUsr)
		}
	}
}
// Deletes usr from tree at the given coords
func deleteUsr(mNS, mEW float64, usr *user.U, tree quadtree.T) {
	v := quadtree.PointViewP(mNS, mEW)
	pred := func(_, _ float64, e interface{}) bool {
		oUsr := e.(*user.U)
		return usr.Equiv(oUsr)
	}
	tree.Del(v, pred)
}
// Returns a function used for alerting users that another user has been added to the system
func initLocFun(tId uint, usr *user.U) func(mNS, mEW float64, e interface{}) {
	return func(mNS, mEW float64, e interface{}) {
		oUsr := e.(*user.U)
		if !usr.Equiv(oUsr) {
			broadcastSend(tId, msgdef.SVisibleOp, usr, oUsr)
			broadcastSend(tId, msgdef.SVisibleOp, oUsr, usr)
		}
	}
}
Beispiel #4
0
func processReg(tId uint, idMsg *msgdef.CIdMsg, usr *user.U) func() error {
	return func() error {
		if idMsg.Op != msgdef.CAddOp {
			return errors.New("Incorrect op-code for id registration: " + string(idMsg.Op))
		}
		if err := idMsg.Validate(); err != nil {
			return err
		}
		usr.Id = idMsg.Id
		if err := idMap.Add(usr.Id, usr); err != nil {
			return err
		}
		logutil.Registered(tId, usr.Id)
		return nil
	}
}