Пример #1
0
func (a *Account) CreatePlayer(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	args := &c2s.Create{}
	if server.Check(server.ParseProto(msg, args)) {
		return 0, nil
	}

	player := App.Players.GetPlayer(mailbox.Id)
	if player == nil {
		//角色没有找到
		return 0, nil
	}
	if player.State != STATE_LOGGED {
		log.LogWarning("player state not logged")
		return 0, nil
	}
	obj, err := App.CreateRole("Player", args)
	if err != nil {
		log.LogError(err)
		return 0, nil
	}

	save := share.GetSaveData(obj)
	server.Check(App.DbBridge.createRole(mailbox, obj, player.Account, args.GetName(), int(args.GetIndex()), save))
	App.Destroy(obj.GetObjId())
	return 0, nil
}
Пример #2
0
func (t *Thread) work(id int) {
	log.LogMessage(t.TAG, " thread work, id:", id)
	var start_time time.Time
	var delay time.Duration
	warninglvl := 50 * time.Millisecond
	for {
		select {
		case rpc := <-t.Queue[id]:
			log.LogMessage(t.TAG, " thread:", id, rpc.GetSrc(), " call:", rpc.GetMethod())
			start_time = time.Now()
			err := rpc.Call()
			if err != nil {
				log.LogError("rpc error:", err)
			}
			delay = time.Now().Sub(start_time)
			if delay > warninglvl {
				log.LogWarning("rpc call ", rpc.GetMethod(), " delay:", delay.Nanoseconds()/1000000, "ms")
			}
			err = rpc.Done()
			if err != nil {
				log.LogError("rpc error:", err)
			}
			rpc.Free()
			break
		default:
			if t.Quit {
				log.LogMessage(t.TAG, " thread ", id, " quit")
				return
			}
			time.Sleep(time.Millisecond)
		}
	}
}
Пример #3
0
func (a *Account) work(id int) {
	log.LogMessage("db work, id:", id)
	var start_time time.Time
	var delay time.Duration
	warninglvl := 50 * time.Millisecond
	for {
		select {
		case caller := <-a.queue[id]:
			log.LogMessage(caller.GetSrc(), " rpc call:", caller.GetMethod(), ", thread:", id)
			start_time = time.Now()
			err := caller.Call()
			if err != nil {
				log.LogError("rpc error:", err)
			}
			delay = time.Now().Sub(start_time)
			if delay > warninglvl {
				log.LogWarning("rpc call ", caller.GetMethod(), " delay:", delay.Nanoseconds()/1000000, "ms")
			}
			caller.Free()
			break
		default:
			if a.quit {
				return
			}
			time.Sleep(time.Millisecond)
		}
	}
}
Пример #4
0
func LoadFromConfig(id string, ent PropSeter) error {
	var f *csvparser
	var infos []string
	var fi string
	for fi, f = range cachefiles {
		if strings.HasPrefix(fi, "conf_") {
			continue
		}
		infos = f.Find(id)
		if infos != nil {
			break
		}
	}

	if infos == nil {
		return errors.New("config not found")
	}

	for k, hi := range f.heads {
		if hi.name == "Entity" || strings.HasSuffix(hi.name, "_script") {
			continue
		}
		err := SetProp(ent, hi.name, infos[k])
		if err != nil {
			log.LogWarning(err, ":", hi.name)
		}
	}

	return nil
}
Пример #5
0
func (rec *GlobalDataTestRec) Load(eq ExecQueryer, dbId uint64) error {

	rec.Rows = rec.Rows[:0]

	sql := "SELECT `r_testrec` FROM `tbl_globaldata` WHERE `id`=? LIMIT 1"
	r, err := eq.Query(sql, dbId)
	if err != nil {
		log.LogError("load record GlobalDataTestRec error:", err)
		return err
	}
	defer r.Close()
	if !r.Next() {
		log.LogError("load record GlobalDataTestRec error:", sql, dbId)
		return ErrSqlRowError
	}
	var json []byte
	if err = r.Scan(&json); err != nil {
		log.LogError("load record GlobalDataTestRec error:", err)
		return err
	}

	if json == nil || len(json) < 2 {
		log.LogWarning("load record GlobalDataTestRec error: nil")
		return nil
	}

	err = rec.Unmarshal(json)
	if err != nil {
		log.LogError("unmarshal record GlobalDataTestRec error:", err)
		return err
	}

	return nil
}
Пример #6
0
Файл: do.go Проект: 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
		}
	}
}
Пример #7
0
func (this *Config) load() {
	ids := helper.GetConfigIds("conf_configuration.csv")

	if len(ids) == 0 {
		log.LogWarning("conf_configuration.csv file load failed")
		return
	}

	this.configMap = make(map[string]*KeyVal, len(ids))

	for _, id := range ids {
		conf := &KeyVal{}

		if err := helper.LoadStructByFile("conf_configuration.csv", id, conf); err != nil {
			log.LogFatalf(err)
			continue
		}

		this.configMap[conf.UniqueName] = conf
	}

	log.LogMessage("conf_configuration.csv file load ok")

	ids = helper.GetConfigIds("conf_bp_ratio.csv")

	if len(ids) == 0 {
		log.LogWarning("conf_bp_ratio.csv file load failed")
		return
	}

	for _, id := range ids {
		conf := &KeyVal{}
		tmp := &PropRatio{}
		if err := helper.LoadStructByFile("conf_bp_ratio.csv", id, tmp); err != nil {
			log.LogFatalf(err)
			continue
		}

		conf.UniqueName = "bp_" + tmp.ID
		conf.Value = tmp.BTRatio
		this.configMap[conf.UniqueName] = conf
	}

	log.LogMessage("conf_bp_ratio.csv file load ok")

}
Пример #8
0
func CreateService(rs *Server, l net.Listener) {

	log.LogMessage("rpc start at:", l.Addr().String())
	for {
		conn, err := l.Accept()
		if nerr, ok := err.(net.Error); ok && nerr.Temporary() {
			log.LogWarning("TCP", "temporary Accept() failure - ", err.Error())
			runtime.Gosched()
			continue
		}
		if err != nil {
			log.LogWarning("rpc accept quit")
			break
		}
		//启动服务
		log.LogInfo("new rpc client,", conn.RemoteAddr())
		go rs.ServeConn(conn, MAX_BUF_LEN)
	}
}
Пример #9
0
func (a *Account) Push(r *rpc.RpcCall) bool {
	if !a.quit {
		mb := r.GetSrc()
		a.queue[int(mb.Uid)%a.pools] <- r // 队列满了,就会阻塞在这里
	} else {
		log.LogWarning("it's quit, drop the message")
	}

	return true
}
Пример #10
0
Файл: db.go Проект: mysll/flynet
func (d *DbBridge) UpdateUserInfo(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	r := server.NewMessageReader(msg)
	infos := share.UpdateUserBak{}
	if server.Check(r.ReadObject(&infos)) {
		return 0, nil
	}
	for _, info := range infos.Infos {
		if e := App.GetEntity(info.ObjId); e != nil {
			e.SetDbId(info.DBId)
			continue
		}

		log.LogWarning("update user info failed, object not found,", info.ObjId)
	}
	return 0, nil
}
Пример #11
0
func (a *Account) process(fname string, f func() error) error {

	atomic.AddInt32(&a.numprocess, 1)
	start := time.Now()
	err := f()
	if err != nil {
		log.LogError("db process error:", err)
	}
	delay := time.Now().Sub(start)
	if delay > time.Millisecond*10 {
		log.LogWarning("db process ", fname, " cost:", delay.Nanoseconds()/1000000, "ms")
	}
	atomic.AddInt32(&a.numprocess, -1)

	return err
}
Пример #12
0
Файл: do.go Проект: mysll/flynet
//事件遍历
func EventProcess(e *event.EventList) {
	var start_time time.Time
	var delay time.Duration
	for {
		evt := e.Pop()
		if evt == nil {
			break
		}
		start_time = time.Now()
		DoEvent(evt)
		delay = time.Now().Sub(start_time)
		if delay > warninglvl {
			log.LogWarning("DoEvent delay:", delay.Nanoseconds()/1000000, "ms")
		}
		busy = true
		e.FreeEvent(evt)
	}

}
Пример #13
0
func TCPServer(listener net.Listener, handler TCPHandler) {
	log.TraceInfo("TCP", "listening on ", listener.Addr().String())
	for {
		clientConn, err := listener.Accept()
		if err != nil {
			if nerr, ok := err.(net.Error); ok && nerr.Temporary() {
				log.LogWarning("TCP", "temporary Accept() failure - ", err.Error())
				runtime.Gosched()
				continue
			}
			// theres no direct way to detect this error because it is not exposed
			if !strings.Contains(err.Error(), "use of closed network connection") {
				log.LogError("listener.Accept() - ", err.Error())
			}
			break
		}
		go handler.Handle(clientConn)
	}

	log.TraceInfo("TCP", "closing ", listener.Addr().String())
}
Пример #14
0
func (a *Account) SelectUser(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	args := &c2s.Selectuser{}
	if server.Check(server.ParseProto(msg, args)) {
		return 0, nil
	}
	player := App.Players.GetPlayer(mailbox.Id)
	if player == nil {
		//角色没有找到
		return 0, nil
	}
	if player.State != STATE_LOGGED {
		log.LogWarning("player state not logged")
		return 0, nil
	}

	player.ChooseRole = args.GetRolename()
	err := App.DbBridge.selectUser(mailbox, player.Account, args.GetRolename(), int(args.GetRoleindex()))
	if err != nil {
		log.LogError(err)
	}

	return 0, nil
}
Пример #15
0
func LoadConfigByFile(file string, id string, ent PropSeter) error {
	var f *csvparser
	var infos []string
	var ok bool
	if f, ok = cachefiles[file]; !ok {
		return errors.New("config not found")
	}

	infos = f.Find(id)
	if infos == nil {
		return errors.New("config not found")
	}

	for k, hi := range f.heads {
		if hi.name == "Entity" || strings.HasSuffix(hi.name, "_script") {
			continue
		}
		err := SetProp(ent, hi.name, infos[k])
		if err != nil {
			log.LogWarning(err, ":", hi.name)
		}
	}
	return nil
}