本文整理汇总了Golang中server.Check函数的典型用法代码示例。如果您正苦于以下问题:Golang Check函数的具体用法?Golang Check怎么用?Golang Check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Check函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RecvLetter
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: AddPlayerBak
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: SyncPlayer
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: CreateRoleBack
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: Login
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: GetBaseAndId
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: RoleInUse
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: ExecSql
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: CreatePlayer
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: QuerySql
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: UpdateRow
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: QueryLetter
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: UpdatePlayer
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: DeleteLetter
//删除信件
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: SendSystemLetter
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
}