Beispiel #1
0
// 解析内部数据包
func UnpackageData(body []byte) (PkgHead, []byte, InnerPkgTail, error) {
	p := bytes.NewReader(body)
	head := PkgHead{}
	tail := InnerPkgTail{}
	var jsonStr []byte

	err := binary.Read(p, binary.BigEndian, &head)
	if err != nil {
		return head, nil, tail, errors.New("read pkghead error!!!", err, body)
	}

	if int(head.PkgLen)+SIZEOF_INNERTAIL != len(body) {
		return head, nil, tail, errors.New("data package len error!!!", head.PkgLen, len(body))
	}

	jsonStr = make([]byte, int(head.PkgLen)-SIZEOF_PKGHEAD)
	if err := binary.Read(p, binary.BigEndian, &jsonStr); err != nil {
		return head, nil, tail, errors.New("read pkgbody error!!!", err, body)
	}

	if err := binary.Read(p, binary.BigEndian, &tail); err != nil {
		return head, nil, tail, errors.New("read pkgtail error!!!", err, body)
	}

	return head, jsonStr, tail, nil
}
Beispiel #2
0
func (this *DataPackage) Unpackage(body []byte) error {
	p := bytes.NewReader(body)

	err := binary.Read(p, binary.BigEndian, &this.Head)
	if err != nil {
		return errors.New("read pkghead error!!!", err, body)
	}

	if int(this.Head.PkgLen)+SIZEOF_INNERTAIL != len(body) {
		return errors.New("data package len error!!!", this.Head.PkgLen, len(body))
	}

	this.Body = make([]byte, int(this.Head.PkgLen)-SIZEOF_PKGHEAD)
	if err := binary.Read(p, binary.BigEndian, &this.Body); err != nil {
		return errors.New("read pkgbody error!!!", err, body)
	}

	if err := binary.Read(p, binary.BigEndian, &this.Tail); err != nil {
		return errors.New("read pkgtail error!!!", err, body)
	}

	return nil

}
Beispiel #3
0
func RedisAddTeamMember(tid, uid uint64) error {
	count := RedisTeamMemberCount(tid)
	if int(count) >= MAX_MEMBER_NUM_TEAM {
		return errors.New("team member too many")
	}
	userKey := fmt.Sprintf("%s%d", SET_TEAM_MEMBER, tid)
	val := fmt.Sprintf("%d", uid)

	redis.RedisSAdd(userKey, val)

	//member version
	val = fmt.Sprintf("%d", time.Now().Unix())
	userKey = fmt.Sprintf("%s%d", KEY_TEAM_MEMBER_VER, tid)
	redis.RedisSet(userKey, val)

	userKey = fmt.Sprintf("%s%d", SET_USERS_TEAM, uid)
	val = fmt.Sprintf("%d", tid)
	redis.RedisSAdd(userKey, val)

	return nil
}
Beispiel #4
0
func GetNextTeamId(uid uint64) (uint64, error) {
	// lock uid
	c := common.MongoCollection(TEAM_DB, TEAM_INFO_TABLE)
	ti := &TeamInfo{}
	// 先找一个无效的组id,相当于被删除的组
	if err := c.Find(bson.M{"uid": uid, "teamtype": TEAM_TYPE_INVALID}).One(ti); err != nil && err != mgo.ErrNotFound {
		return 0, errors.As(err, uid)
	}
	// 若没有无效组,查找已有最大组id
	if err := c.Find(bson.M{"uid": uid}).Sort("-teamid").One(ti); err != nil {
		if err == mgo.ErrNotFound {
			// 没有组,从1计数
			return uint64(int(uid)*MAX_NUM_TEAM + 1), nil
		}
		return 0, errors.As(err, uid)
	}
	// 判断是否超过用户组上限
	if int(ti.TeamId)%MAX_NUM_TEAM >= MAX_NUM_TEAM_USER {
		return 0, errors.New("user create team too many", uid)
	}

	return ti.TeamId + 1, nil
}
Beispiel #5
0
		"nickname": this.Name,
		"fid":      this.Image,
		"tel":      this.Tel,
		"email":    this.Email,
		"enable":   this.Enable,
		"v":        this.V,
	})
}

type CSVerInfo struct {
	CsId uint64 `json:"csid,omitempty"`
	V    int    `json:"v,omitempty"`
}

var (
	ERROR_NONE              = errors.New("0") // 无错误
	ERROR_UNKNOWN           = errors.New("1") // 未知错误
	ERROR_SERVER_BUSY       = errors.New("2") // 服务器繁忙
	ERROR_CLIENT_BUG        = errors.New("3") // 客户端请求数据包异常
	ERROR_OUT_OF_REACH      = errors.New("4") // 未能到达,权限不够(如金币不足,或无法查看私照)
	ERROR_TOUCH_TOP         = errors.New("5") // 已到达最大值(如周边用户已全部拉取完成)
	ERROR_NO_DATA           = errors.New("6") // 无可用数据返回
	ERROR_TIMEOUT           = errors.New("7") // 已过期
	ERROR_OUT               = errors.New("8") // 要求离开
	ERROR_ACCOUNT           = errors.New("9") // 注册帐号已存在
	IN_BLACKLIST            = errors.New("10")
	NOT_WHITELIST           = errors.New("11")
	ERR_CID                 = errors.New("12")
	ERR_APPKEY              = errors.New("13") //13 AppKey错误
	ERR_CODE_LOGIN_CONFLICT = errors.New("14") //14 自动登录失败
	ERR_CODE_ERR_PKG        = errors.New("30") //包错误
Beispiel #6
0
	"database/sql"

	"github.com/gosexy/db"
	_ "github.com/gosexy/db/mysql"

	"sirendaou.com/duserver/common/errors"
	//"sirendaou.com/duserver/common/syslog"
)

const (
	mysql_conn_max_num = 10
	mysql_conn_min_num = 1
)

var (
	ErrNoRows = errors.New("mysql select have no record!!!")
)

type MysqlManager struct {
	dbCh  chan *sql.DB
	count int
}

var g_mysql *MysqlManager = nil

func Init(host, dbname, user, passwd string, count int) {
	if count > mysql_conn_max_num {
		count = mysql_conn_max_num
	} else if count < mysql_conn_min_num {
		count = mysql_conn_min_num
	}