コード例 #1
0
ファイル: db_raw.go プロジェクト: mysll/flynet
func (this *Database) RecvLetter(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var uid uint64
	var serial_no uint64
	var callback string
	var callbackparams share.DBParams

	if server.Check(server.ParseArgs(msg, &uid, &serial_no, &callback, &callbackparams)) {
		return 0, nil
	}

	letter, err := this.recvLetterBySerial(uid, serial_no)
	if err != nil {
		log.LogError(err)
		return share.ERR_REPLY_FAILED, nil
	}

	if callback == "_" {
		return 0, nil
	}
	callbackparams["result"] = false
	if letter != nil {
		callbackparams["result"] = true
		callbackparams["letter"] = letter
	}

	server.Check(server.MailTo(nil, &mailbox, callback, callbackparams))
	return 0, nil
}
コード例 #2
0
ファイル: area.go プロジェクト: mysll/flynet
func (a *AreaBridge) AddPlayerBak(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	r := server.NewMessageReader(msg)
	res, err := r.ReadString()
	if server.Check(err) {
		return 0, nil
	}
	if res == "ok" {
		player := App.Players.GetPlayer(mailbox.Id)
		if player == nil {
			log.LogFatalf("can not be nil")
			return 0, nil
		}

		if player.State != STATE_ENTERAREA { //可能客户端已经断开了,则让玩家下线
			player.Leave()
			return 0, nil
		}

		player.EnterScene()
		return 0, nil
	} else {
		err := &s2c.Error{}
		err.ErrorNo = proto.Int32(share.ERROR_ROLE_ENTERAREA_ERROR)
		server.Check(server.MailTo(nil, &mailbox, "error", err))
		return 0, nil
	}

}
コード例 #3
0
ファイル: sync.go プロジェクト: mysll/flynet
func (s *Sync) SyncPlayer(src rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	r := server.NewMessageReader(msg)
	infos := make(map[string]interface{})
	if server.Check(r.ReadObject(&infos)) {
		return 0, nil
	}
	mb := infos["mailbox"].(rpc.Mailbox)
	info := infos["data"].(*EntityInfo)
	playerid := info.ObjId
	player := App.GetEntity(playerid)
	if player == nil || player.ObjType() != PLAYER {
		log.LogError("sync player player not found", playerid)
		return 0, nil
	}
	for k := range s.childs {
		delete(s.childs, k)
	}
	for k := range s.newobj {
		delete(s.newobj, k)
	}
	s.getAllChilds(player)
	s.sync(info)
	for k := range s.childs { //剩余的表示需要删除
		App.Destroy(k)
	}

	server.Check(server.MailTo(&mb, &src, "BaseProxy.SyncPlayerBak", s.newobj))
	return 0, nil
}
コード例 #4
0
ファイル: db.go プロジェクト: mysll/flynet
func (d *DbBridge) CreateRoleBack(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	r := server.NewMessageReader(msg)
	errstr, err := r.ReadString()
	if server.Check(err) {
		return 0, nil
	}
	if errstr != "ok" {
		server.Check(server.Error(nil, &mailbox, "Role.Error", share.ERROR_CREATE_ROLE_ERROR))
		return 0, nil
	}

	player := App.Players.GetPlayer(mailbox.Id)
	if player == nil {
		log.LogError("player not found, id:", mailbox.Id)
		//角色没有找到
		return 0, nil
	}

	if player.State != STATE_LOGGED {
		log.LogError("player state not logged")
		return 0, nil
	}

	server.Check(d.getUserInfo(mailbox, player.Account))
	return 0, nil
}
コード例 #5
0
ファイル: account.go プロジェクト: mysll/flynet
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
	}
}
コード例 #6
0
ファイル: session.go プロジェクト: mysll/flynet
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
}
コード例 #7
0
ファイル: db.go プロジェクト: mysll/flynet
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
}
コード例 #8
0
ファイル: db_raw.go プロジェクト: mysll/flynet
func (this *Database) ExecSql(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var sqlstr string
	var callback string
	var callbackparams share.DBParams

	if server.Check(server.ParseArgs(msg, &sqlstr, &callback, &callbackparams)) {
		return 0, nil
	}

	sqlconn := db.sql
	var r sql.Result
	var err error

	app := server.GetAppById(mailbox.App)
	if app == nil {
		log.LogError(server.ErrAppNotFound)
		return 0, nil
	}

	if r, err = sqlconn.Exec(sqlstr); err != nil {
		log.LogError("sql:", sqlstr)
		server.Check(app.Call(nil, callback, callbackparams, 0, err.Error()))
		return 0, nil
	}

	eff, _ := r.RowsAffected()
	server.Check(app.Call(nil, callback, callbackparams, eff, ""))
	return 0, nil
}
コード例 #9
0
ファイル: account.go プロジェクト: mysll/flynet
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
}
コード例 #10
0
ファイル: db_raw.go プロジェクト: mysll/flynet
func (this *Database) QuerySql(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var sqlstr string
	var callback string
	var callbackparams share.DBParams

	if server.Check(server.ParseArgs(msg, &sqlstr, &callback, &callbackparams)) {
		return 0, nil
	}

	sqlconn := db.sql
	var r *sql.Rows
	var err error

	app := server.GetAppById(mailbox.App)
	if app == nil {
		log.LogError(server.ErrAppNotFound)
		return 0, nil
	}

	if r, err = sqlconn.Query(sqlstr); err != nil {
		log.LogError(err)
		return 0, nil
	}
	defer r.Close()
	var cols []string
	cols, err = r.Columns()
	if err != nil {
		server.Check(app.Call(nil, callback, callbackparams, []share.DBRow{share.DBRow{"error": []byte(err.Error())}}))
		return 0, nil
	}

	result := make([]interface{}, len(cols))
	for k := range result {
		result[k] = new([]byte)
	}

	arrresult := make([]share.DBRow, 0, 100)
	for r.Next() {

		err = r.Scan(result...)
		if err != nil {
			log.LogError("sql:", sqlstr)
			server.Check(app.Call(nil, callback, callbackparams, []share.DBRow{share.DBRow{"error": []byte(err.Error())}}))
			return 0, nil
		}

		mapresult := make(share.DBRow, len(cols))
		for k, v := range cols {
			mapresult[v] = *result[k].(*[]byte)
		}
		arrresult = append(arrresult, mapresult)
		if len(arrresult) == 100 {
			break
		}
	}

	server.Check(app.Call(nil, callback, callbackparams, arrresult))
	return 0, nil
}
コード例 #11
0
ファイル: db_raw.go プロジェクト: mysll/flynet
func (this *Database) UpdateRow(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var tbl string
	var values map[string]interface{}
	var condition string
	var callback string
	var callbackparams share.DBParams

	if server.Check(server.ParseArgs(msg, &tbl, &values, &condition, &callback, &callbackparams)) {
		return 0, nil
	}

	sqlconn := db.sql
	var r sql.Result
	var err error

	app := server.GetAppById(mailbox.App)
	if app == nil {
		log.LogError(server.ErrAppNotFound)
		return 0, nil
	}

	if condition != "" {
		condition = fmt.Sprintf("WHERE %s", condition)
	}

	args := make([]interface{}, 0, len(values))
	var sql bytes.Buffer
	sql.WriteString("UPDATE `")
	sql.WriteString(tbl)
	sql.WriteString("` SET")
	split := " "
	for k, v := range values {
		sql.WriteString(split)
		split = ", "
		sql.WriteString("`")
		sql.WriteString(k)
		sql.WriteString("`")
		sql.WriteString("=?")
		args = append(args, v)
	}
	sqlstr := fmt.Sprintf("%s %s", sql.String(), condition)
	if r, err = sqlconn.Exec(sqlstr, args...); err != nil {
		log.LogError("sql:", sqlstr)
		if callback == "_" {
			log.LogError(err)
			return 0, nil
		}
		server.Check(app.Call(nil, callback, callbackparams, 0, err.Error()))
		return 0, nil
	}
	if callback == "_" {
		return 0, nil
	}
	eff, _ := r.RowsAffected()
	server.Check(app.Call(nil, callback, callbackparams, eff, ""))
	return 0, nil
}
コード例 #12
0
ファイル: db_raw.go プロジェクト: mysll/flynet
func (this *Database) QueryLetter(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var uid uint64
	var callback string
	var callbackparams share.DBParams

	if server.Check(server.ParseArgs(msg, &uid, &callback, &callbackparams)) {
		return 0, nil
	}

	count, _ := this.queryLetter(uid)
	callbackparams["count"] = count
	server.Check(server.MailTo(nil, &mailbox, callback, callbackparams))
	return 0, nil
}
コード例 #13
0
ファイル: playerlist.go プロジェクト: mysll/flynet
func (pl *PlayerList) UpdatePlayer(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	r := server.NewMessageReader(msg)
	account, err := r.ReadString()
	if server.Check(err) {
		return 0, nil
	}
	role_name, err := r.ReadString()
	if server.Check(err) {
		return 0, nil
	}
	base_id, err := r.ReadString()
	if server.Check(err) {
		return 0, nil
	}

	if base_id == "" {
		if acc, ok := pl.accounts[account]; ok {
			pl := acc.GetPlayInfo(role_name)
			if pl != nil {
				delete(acc.roles, account)
				log.LogMessage("remove ", account, ",", role_name)
			}
		}

		return 0, nil
	}

	if acc, ok := pl.accounts[account]; ok {
		p := acc.GetPlayInfo(role_name)
		if p != nil {
			log.LogMessage("update ", account, ",", role_name, " base:", base_id)
			p.BaseId = base_id
			return 0, nil
		}

		p = &PlayerInfo{role_name, base_id}
		acc.roles[role_name] = p
		log.LogMessage("add ", account, ",", role_name, " base:", base_id)
		return 0, nil
	}

	p := &PlayerInfo{role_name, base_id}
	acc := &AccountInfo{}
	acc.roles = make(map[string]*PlayerInfo, MAX_ROLES)
	acc.roles[role_name] = p
	pl.accounts[account] = acc
	log.LogMessage("add ", account, ",", role_name, " base:", base_id)
	return 0, nil
}
コード例 #14
0
ファイル: letter_logic.go プロジェクト: mysll/flynet
//删除信件
func (l *LetterSystem) DeleteLetter(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	args := &c2s.Reqoperatemail{}
	if server.Check(server.ParseProto(msg, args)) {
		return 0, nil
	}
	p := App.Players.GetPlayer(mailbox.Id)
	if p == nil {
		log.LogError("player not found, id:", mailbox.Id)
		//角色没有找到
		return 0, nil
	}
	player := p.Entity.(*entity.Player)

	if len(args.Mails) == 0 {
		return 0, nil
	}

	for _, sno := range args.Mails {
		row := player.MailBox_r.FindSerial_no(uint64(sno))
		if row == -1 {
			return 0, nil
		}
		player.MailBox_r.Del(row)
	}
	return 0, nil
}
コード例 #15
0
ファイル: db_raw.go プロジェクト: mysll/flynet
func (this *Database) SendSystemLetter(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var source_name string
	var recvacc, recvrole string
	var typ int32
	var title, content, appendix string
	var callback string
	var callbackparams share.DBParams
	if server.Check(server.ParseArgs(msg, &source_name, &recvacc, &recvrole, &typ, &title, &content, &appendix, &callback, &callbackparams)) {
		return 0, nil
	}

	var roleid uint64
	if recvacc == "" && recvrole == "" {
		roleid = 0
	} else {
		var err error
		roleid, err = GetRoleUid(recvacc, recvrole)
		if err != nil {
			callbackparams["result"] = false
			callbackparams["err"] = "role not found"
			if callback != "_" {
				server.Check(server.MailTo(nil, &mailbox, callback, callbackparams))
			}
			log.LogError(err)
			return 0, nil
		}
	}

	serial_no, err := this.systemLetter(source_name, roleid, recvacc, recvrole, typ, title, content, appendix)
	if err != nil {
		if callback != "_" {
			callbackparams["result"] = false
			callbackparams["err"] = err.Error()
			server.Check(server.MailTo(nil, &mailbox, callback, callbackparams))
		}
		log.LogError(err)
		return 0, nil
	}

	if callback != "_" {
		callbackparams["result"] = true
		callbackparams["serial_no"] = serial_no
		server.Check(server.MailTo(nil, &mailbox, callback, callbackparams))
	}
	return 0, nil

}
コード例 #16
0
ファイル: task_logic.go プロジェクト: mysll/flynet
func (t *TaskLogic) Submit(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	args := &c2s.Reqreceivetask{}
	if server.Check(server.ParseProto(msg, args)) {
		return 0, nil
	}
	p := App.Players.GetPlayer(mailbox.Id)
	if p == nil || p.Entity == nil {
		log.LogError("player not found")
		return 0, nil
	}
	player := p.Entity.(*entity.Player)

	taskid := args.GetTaskid()

	server.Check(App.tasksystem.Submit(player, taskid))
	return 0, nil
}
コード例 #17
0
ファイル: login.go プロジェクト: mysll/flynet
func (l *Login) SwitchPlayer(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
	}
	serial := rand.Int31()
	log.LogMessage("client serial:", serial)
	l.Cached[user] = cacheUser{serial, time.Now()}

	ret := &s2c.Loginsucceed{}
	ret.Host = proto.String(App.ClientHost)
	ret.Port = proto.Int32(int32(App.ClientPort))
	ret.Key = proto.Int32(serial)
	server.Check(server.MailTo(nil, &mailbox, "Login.SwitchBase", ret))
	return 0, nil
}
コード例 #18
0
ファイル: account.go プロジェクト: mysll/flynet
func (a *Account) SavePlayer(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	r := server.NewMessageReader(msg)
	var data share.UpdateUser
	if server.Check(r.ReadObject(&data)) {
		return 0, nil
	}
	if data.SaveData.Data == nil {
		log.LogError("save data is nil")
		return 0, nil
	}

	sqlconn := db.sql
	base := rpc.NewMailBox(0, 0, mailbox.App)
	infos := make([]share.ObjectInfo, 0, 128)
	if err := UpdateItem(sqlconn, data.SaveData.Data.DBId, data.SaveData.Data); err != nil {
		log.LogError(err)
		server.Check(server.MailTo(&mailbox, &base, "DbBridge.SavePlayerBak", err.Error()))
		return 0, nil
	}

	if data.Type == share.SAVETYPE_OFFLINE {
		_, err := db.sql.Exec("UPDATE `role_info` SET `status`=?, `serverid`=?, `scene`=?, `scene_x`=?, `scene_y`=?, `scene_z`=?, `scene_dir`=?, `roleinfo`=? WHERE `account`=? and `rolename`=?",
			0,
			"",
			data.Scene, data.X, data.Y, data.Z, data.Dir,
			data.SaveData.RoleInfo,
			data.Account,
			data.Name,
		)
		if err != nil {
			log.LogError(err)
			server.Check(server.MailTo(&mailbox, &base, "DbBridge.SavePlayerBak", err.Error()))
			return 0, nil
		}

		server.Check(server.MailTo(&mailbox, &base, "DbBridge.SavePlayerBak", "ok"))
		return 0, nil
	}

	bakinfo := share.UpdateUserBak{}
	bakinfo.Infos = infos
	server.Check(server.MailTo(&mailbox, &base, "DbBridge.UpdateUserInfo", bakinfo))
	return 0, nil
}
コード例 #19
0
ファイル: account.go プロジェクト: mysll/flynet
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
}
コード例 #20
0
ファイル: account.go プロジェクト: mysll/flynet
func (a *Account) GetUserInfo(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	reader := server.NewMessageReader(msg)
	account, err := reader.ReadString()
	if server.Check(err) {
		return 0, nil
	}

	s := db.sql
	r, err := s.Query(`SELECT rolename, roleindex, roleinfo, locktime, locked 
FROM role_info
WHERE account=? and deleted =0`, account)
	if err != nil {
		log.LogError(err)
		return 0, nil
	}
	defer r.Close()

	var rolename string
	var roleindex int32
	var roleinfo string
	var locktime mysql.NullTime
	var locked int

	info := &s2c.RoleInfo{}
	info.UserInfo = make([]*s2c.Role, 0, 4)
	for r.Next() {
		err = r.Scan(&rolename, &roleindex, &roleinfo, &locktime, &locked)
		if err != nil {
			log.LogError(err)
			return 0, nil
		}
		if locked == 0 {
			role := &s2c.Role{}
			role.Name = proto.String(rolename)
			role.Index = proto.Int32(roleindex)
			role.Roleinfo = proto.String(roleinfo)

			info.UserInfo = append(info.UserInfo, role)
		}
	}
	server.Check(server.MailTo(nil, &mailbox, "Role.RoleInfo", info))
	return 0, nil
}
コード例 #21
0
ファイル: db.go プロジェクト: mysll/flynet
func (d *DbBridge) SelectUserBak(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	r := server.NewMessageReader(msg)
	save := share.LoadUserBak{}
	if server.Check(r.ReadObject(&save)) {
		return 0, nil
	}
	db := server.GetAppByType("database")
	info := share.ClearUser{save.Account, save.Name}
	player := App.Players.GetPlayer(mailbox.Id)
	if player == nil {
		log.LogError("player not found, id:", mailbox.Id)
		db.Call(&mailbox, "Account.ClearPlayerStatus", info)
		//角色没有找到
		return 0, nil
	}

	if player.State != STATE_LOGGED {
		log.LogError("player state not logged")
		db.Call(&mailbox, "Account.ClearPlayerStatus", info)
		player.Leave()
		return 0, nil
	}

	if save.Data == nil {
		db.Call(&mailbox, "Account.ClearPlayerStatus", info)
		server.Check(server.Error(nil, &mailbox, "Login.Error", share.ERROR_SELECT_ROLE_ERROR))
		return 0, nil
	}

	err := player.LoadPlayer(save)
	if server.Check(err) {
		db.Call(&mailbox, "Account.ClearPlayerStatus", info)
		return 0, nil
	}

	status := server.GetAppByType("status")
	if status != nil {
		status.Call(&mailbox, "PlayerList.UpdatePlayer", player.Account, player.ChooseRole, App.Name)
	}
	//App.AreaBridge.getArea(mailbox, save.Scene) //这里会自动加入场景
	return 0, nil
}
コード例 #22
0
ファイル: db_raw.go プロジェクト: mysll/flynet
func (this *Database) Count(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var tbl string
	var condition string
	var callback string
	var callbackparams share.DBParams

	if server.Check(server.ParseArgs(msg, &tbl, &condition, &callback, &callbackparams)) {
		return 0, nil
	}

	sqlconn := db.sql
	var r *sql.Rows
	var err error
	app := server.GetAppById(mailbox.App)
	if app == nil {
		log.LogError(server.ErrAppNotFound)
	}

	if condition != "" {
		condition = fmt.Sprintf("WHERE %s", condition)
	}
	sqlstr := fmt.Sprintf("SELECT COUNT(*) FROM `%s` %s LIMIT 1", tbl, condition)
	if r, err = sqlconn.Query(sqlstr); err != nil {
		log.LogError("sql:", sqlstr)
		return 0, nil
	}
	defer r.Close()
	if !r.Next() {
		server.Check(app.Call(nil, callback, -1))
		return 0, nil
	}

	var count int32
	if err = r.Scan(&count); err != nil {
		log.LogError(err)
		server.Check(app.Call(nil, callback, -1))
		return 0, nil
	}

	server.Check(app.Call(nil, callback, callbackparams, count))
	return 0, nil
}
コード例 #23
0
ファイル: account.go プロジェクト: mysll/flynet
func (a *Account) ClearStatus(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
	}

	server.Check2(db.sql.Exec("UPDATE `role_info` SET `status`=?, `serverid`=? WHERE `status`=? and `serverid`=?", 0, "", 1, serverid))
	log.LogMessage("clear server:", serverid)
	return 0, nil
}
コード例 #24
0
ファイル: playerlist.go プロジェクト: mysll/flynet
func (pl *PlayerList) GetPlayerBase(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	r := server.NewMessageReader(msg)
	account, err := r.ReadString()
	if server.Check(err) {
		return 0, nil
	}
	role_name, err := r.ReadString()
	if server.Check(err) {
		return 0, nil
	}
	callback, err := r.ReadString()
	if server.Check(err) {
		return 0, nil
	}

	app := server.GetAppById(mailbox.App)
	if app == nil {
		server.Check(server.ErrAppNotFound)
		return 0, nil
	}

	if acc, ok := pl.accounts[account]; ok {
		pl := acc.GetPlayInfo(role_name)
		if pl != nil {
			server.Check(app.Call(&mailbox, callback, account, role_name, pl.BaseId))
			return 0, nil
		}
	}

	server.Check(app.Call(&mailbox, callback, account, role_name, ""))
	return 0, nil
}
コード例 #25
0
ファイル: db_raw.go プロジェクト: mysll/flynet
func (this *Database) DeleteRow(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var tbl string
	var condition string
	var callback string
	var callbackparams share.DBParams

	if server.Check(server.ParseArgs(msg, &tbl, &condition, &callback, &callbackparams)) {
		return 0, nil
	}

	sqlconn := db.sql
	var r sql.Result
	var err error
	app := server.GetAppById(mailbox.App)
	if app == nil {
		log.LogError(server.ErrAppNotFound)
		return 0, nil
	}

	if condition != "" {
		condition = fmt.Sprintf(" WHERE %s", condition)
	}

	sqlstr := fmt.Sprintf("DELETE FROM `%s`%s", tbl, condition)
	if r, err = sqlconn.Exec(sqlstr); err != nil {
		log.LogError("sql:", sqlstr)
		if callback != "_" {
			server.Check(app.Call(nil, callback, callbackparams, 0, err.Error()))
			return 0, nil
		}
	}

	if callback == "_" {
		return 0, nil
	}

	eff, _ := r.RowsAffected()
	server.Check(app.Call(nil, callback, callbackparams, eff, ""))
	return 0, nil
}
コード例 #26
0
ファイル: db_raw.go プロジェクト: mysll/flynet
func (this *Database) LookLetter(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var uid uint64
	var callback string
	var callbackparams share.DBParams

	if server.Check(server.ParseArgs(msg, &uid, &callback, &callbackparams)) {
		return 0, nil
	}

	letters, err := this.lookLetter(uid)
	if err != nil {
		log.LogError(err)
		return 0, nil
	}

	callbackparams["result"] = false
	if letters != nil {
		callbackparams["result"] = true
		callbackparams["letters"] = letters
	}

	server.Check(server.MailTo(nil, &mailbox, callback, callbackparams))
	return 0, nil
}
コード例 #27
0
ファイル: account.go プロジェクト: mysll/flynet
func (a *Account) ClearPlayerStatus(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	r := server.NewMessageReader(msg)
	var info share.ClearUser
	if server.Check(r.ReadObject(&info)) {
		return 0, nil
	}

	sqlconn := db.sql
	_, err := sqlconn.Exec("UPDATE `role_info` SET `status`=?, `serverid`=? WHERE `account`=? and `rolename`=?", 0, "", info.Account, info.Name)
	if err != nil {
		log.LogError(err)
		return 0, nil
	}
	log.LogMessage("player clear status,", info.Name)
	return 0, nil
}
コード例 #28
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
}
コード例 #29
0
ファイル: db_raw.go プロジェクト: mysll/flynet
func (this *Database) SaveObject(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var object share.DbSave
	var callbackparams share.DBParams
	if server.Check(server.ParseArgs(msg, &object, &callbackparams)) {
		return share.ERR_ARGS_ERROR, nil
	}

	reply = server.CreateMessage(callbackparams)
	sqlconn := db.sql

	err := SaveItem(sqlconn, true, object.Data.DBId, object.Data)

	if err != nil {
		return share.ERR_REPLY_FAILED, reply
	}

	return share.ERR_REPLY_SUCCEED, reply
}
コード例 #30
0
ファイル: db_raw.go プロジェクト: mysll/flynet
func (this *Database) Log(mailbox rpc.Mailbox, msg *rpc.Message) (errcode int32, reply *rpc.Message) {
	var log_name string
	var log_source, log_type int32
	var log_content, log_comment string

	if server.Check(server.ParseArgs(msg, &log_name, &log_source, &log_type, &log_content, &log_comment)) {
		return 0, nil
	}

	sqlconn := db.sql
	uid, err := sqlconn.GetUid("serial_no")
	if err != nil {
		log.LogError(err)
		return 0, nil
	}
	sql := fmt.Sprintf("INSERT INTO `log_data`(`serial_no`, `log_time`,`log_name`, `log_source`, `log_type`, `log_content`, `log_comment`) VALUES(?,?,?,?,?,?,?)")
	server.Check2(sqlconn.Exec(sql, uid, time.Now().Format(util.TIME_LAYOUT), log_name, log_source, log_type, log_content, log_comment))
	return 0, nil
}