model

package
v0.0.0-...-6f4ec31 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DEFAULT_VERSION = 1
View Source
const MESSAGE_FLAG_GROUP = 0x04

群组离线消息 MSG_OFFLINE使用

View Source
const MESSAGE_FLAG_SELF = 0x08

离线消息由当前登录的用户在当前设备发出

View Source
const MESSAGE_FLAG_TEXT = 0x01

消息标志 文本消息

View Source
const MESSAGE_FLAG_UNPERSISTENT = 0x02

消息不持久化

View Source
const MSG_ACK = 5
View Source
const MSG_AUTH_STATUS = 3
View Source
const MSG_AUTH_TOKEN = 15
View Source
const MSG_CUSTOMER = 24 //顾客->客服

persistent

View Source
const MSG_CUSTOMER_SERVICE_ = 23

persistent, deprecated

View Source
const MSG_CUSTOMER_SUPPORT = 25 //客服->顾客
View Source
const MSG_ENTER_ROOM = 18
View Source
const MSG_GROUP_IM = 8 //群聊IM
View Source
const MSG_GROUP_NOTIFICATION = 7 //群聊通知

persistent

View Source
const MSG_GROUP_SYNC_KEY = 35
View Source
const MSG_HEADER_SIZE = 12
View Source
const MSG_IM = 4

persistent

View Source
const MSG_LEAVE_ROOM = 19
View Source
const MSG_NOTIFICATION = 36

系统通知消息, unpersistent

View Source
const MSG_PING = 13
View Source
const MSG_PONG = 14
View Source
const MSG_PUBLISH = 132 //私聊消息
View Source
const MSG_PUBLISH_GROUP = 135 //广播给其他所有群聊服务器
View Source
const MSG_PUBLISH_ROOM = 138 //广播房间消息
View Source
const MSG_ROOM_IM = 20
View Source
const MSG_RST = 6

deprecated

View Source
const MSG_RT = 17
View Source
const MSG_SUBSCRIBE = 130 //在线请求

路由服务器消息

View Source
const MSG_SUBSCRIBE_ROOM = 136 //加入房间
View Source
const MSG_SYNC = 26 //同步消息

客户端->服务端

View Source
const MSG_SYNC_BEGIN = 27

服务端->客服端

View Source
const MSG_SYNC_END = 28
View Source
const MSG_SYNC_GROUP = 30 //同步超级群消息

客户端->服务端

View Source
const MSG_SYNC_GROUP_BEGIN = 31

服务端->客服端

View Source
const MSG_SYNC_GROUP_END = 32
View Source
const MSG_SYNC_GROUP_NOTIFY = 33

通知客户端有新消息

View Source
const MSG_SYNC_KEY = 34

客服端->服务端,更新服务器的synckey

View Source
const MSG_SYNC_NOTIFY = 29

通知客户端有新消息

View Source
const MSG_SYSTEM = 21

persistent

View Source
const MSG_UNREAD_COUNT = 22
View Source
const MSG_UNSUBSCRIBE = 131 //离线请求
View Source
const MSG_UNSUBSCRIBE_ROOM = 137 //离开房间
View Source
const MSG_VOIP_CONTROL = 64
View Source
const PLATFORM_ANDROID = 2
View Source
const PLATFORM_IOS = 1

平台号

View Source
const PLATFORM_WEB = 3
View Source
const SUBSCRIBE_HEATBEAT = 5 * 60

同redis的长链接保持5minute的心跳

Variables

View Source
var Message_creators map[int]MessageCreator = make(map[int]MessageCreator)
View Source
var Message_descriptions map[int]string = make(map[int]string)

Functions

func CreateAndStartGroup

func CreateAndStartGroup(redis_pool *redis.Pool, config config.ConfigBase)

func CreateGroup

func CreateGroup(db *sql.DB, appid int64, master int64, name string, super int8) int64

func DeleteGroup

func DeleteGroup(db *sql.DB, group_id int64) bool

func LoadAllGroup

func LoadAllGroup(db *sql.DB) (map[int64]*Group, error)

func LoadGroupMember

func LoadGroupMember(db *sql.DB, group_id int64) (map[int64]int64, error)

func ReadHeader

func ReadHeader(buff []byte) (int, int, int, int, int)

func SendMessage

func SendMessage(conn io.Writer, msg *Message) error

func WriteHeader

func WriteHeader(len int32, seq int32, cmd byte, version byte, flag byte, buffer io.Writer)

func WriteMessage

func WriteMessage(w *bytes.Buffer, msg *Message)

Types

type AppGroupMemberID

type AppGroupMemberID struct {
	Appid int64
	Gid   int64
	Uid   int64
}

func (*AppGroupMemberID) FromData

func (id *AppGroupMemberID) FromData(buff []byte) bool

func (*AppGroupMemberID) ToData

func (id *AppGroupMemberID) ToData() []byte

type AppMessage

type AppMessage struct {
	Appid     int64
	Receiver  int64
	Msgid     int64
	Device_id int64
	Timestamp int64 //纳秒,测试消息从im->imr->im的时间
	Msg       *Message
}

func (*AppMessage) FromData

func (amsg *AppMessage) FromData(buff []byte) bool

func (*AppMessage) ToData

func (amsg *AppMessage) ToData() []byte

type AppRoomID

type AppRoomID struct {
	Appid   int64
	Room_id int64
}

func (*AppRoomID) FromData

func (id *AppRoomID) FromData(buff []byte) bool

func (*AppRoomID) ToData

func (id *AppRoomID) ToData() []byte

type AppRoute

type AppRoute struct {
	FnCreate func(appid int64) RouteBase //创建route
	// contains filtered or unexported fields
}

func NewAppRoute

func NewAppRoute() *AppRoute

路由管理

func (*AppRoute) AddRoute

func (app_route *AppRoute) AddRoute(route RouteBase)

将路由加入路由管理

func (*AppRoute) FindOrAddRoute

func (app_route *AppRoute) FindOrAddRoute(appid int64) RouteBase

根据id获取路由,不在路由中则创建路由加入路由管理,并返回创建的路由

func (*AppRoute) FindRoute

func (app_route *AppRoute) FindRoute(appid int64) RouteBase

根据id获取路由

func (*AppRoute) GetUsers

func (app_route *AppRoute) GetUsers() map[int64]IntSet

获取路由管理下的所有appid对应的用户id 的intset

type AppUserID

type AppUserID struct {
	Appid int64
	Uid   int64
}

func (*AppUserID) FromData

func (id *AppUserID) FromData(buff []byte) bool

func (*AppUserID) ToData

func (id *AppUserID) ToData() []byte

type AuthenticationStatus

type AuthenticationStatus struct {
	Status int32
}

func (*AuthenticationStatus) FromData

func (auth *AuthenticationStatus) FromData(buff []byte) bool

func (*AuthenticationStatus) ToData

func (auth *AuthenticationStatus) ToData() []byte

type AuthenticationToken

type AuthenticationToken struct {
	Token       string
	Platform_id int8
	Device_id   string
}

func (*AuthenticationToken) FromData

func (auth *AuthenticationToken) FromData(buff []byte) bool

func (*AuthenticationToken) ToData

func (auth *AuthenticationToken) ToData() []byte

type Command

type Command int

func (Command) String

func (cmd Command) String() string

type CustomerMessage

type CustomerMessage struct {
	Customer_appid int64 //顾客id所在appid
	Customer_id    int64 //顾客id
	Store_id       int64
	Seller_id      int64
	Timestamp      int32
	Content        string
}

func (*CustomerMessage) FromData

func (cs *CustomerMessage) FromData(buff []byte) bool

func (*CustomerMessage) ToData

func (cs *CustomerMessage) ToData() []byte

type Group

type Group struct {
	Gid   int64
	Appid int64
	Super bool //超大群
	// contains filtered or unexported fields
}

func NewGroup

func NewGroup(gid int64, appid int64, members map[int64]int64) *Group

func NewSuperGroup

func NewSuperGroup(gid int64, appid int64, members map[int64]int64) *Group

func (*Group) AddMember

func (group *Group) AddMember(uid int64, timestamp int)

修改成员,在副本修改,避免读取时的lock

func (*Group) GetMemberMute

func (group *Group) GetMemberMute(uid int64) bool

func (*Group) GetMemberTimestamp

func (group *Group) GetMemberTimestamp(uid int64) int

func (*Group) IsEmpty

func (group *Group) IsEmpty() bool

func (*Group) IsMember

func (group *Group) IsMember(uid int64) bool

func (*Group) Members

func (group *Group) Members() map[int64]int64

func (*Group) RemoveMember

func (group *Group) RemoveMember(uid int64)

func (*Group) SetMemberMute

func (group *Group) SetMemberMute(uid int64, mute bool)

type GroupManager

type GroupManager struct {
	// contains filtered or unexported fields
}

群聊房间管理

var Group_manager *GroupManager

func NewGroupManager

func NewGroupManager(redis_pool *redis.Pool, config config.ConfigBase) *GroupManager

func (*GroupManager) FindGroup

func (g *GroupManager) FindGroup(gid int64) *Group

func (*GroupManager) FindUserGroups

func (g *GroupManager) FindUserGroups(appid int64, uid int64) []*Group

func (*GroupManager) GetGroups

func (g *GroupManager) GetGroups() []*Group

func (*GroupManager) HandleCreate

func (g *GroupManager) HandleCreate(data string)

func (*GroupManager) HandleDisband

func (g *GroupManager) HandleDisband(data string)

func (*GroupManager) HandleMemberAdd

func (g *GroupManager) HandleMemberAdd(data string)

func (*GroupManager) HandleMemberRemove

func (g *GroupManager) HandleMemberRemove(data string)

func (*GroupManager) HandleMute

func (g *GroupManager) HandleMute(data string)

func (*GroupManager) HandleUpgrade

func (g *GroupManager) HandleUpgrade(data string)

func (*GroupManager) Ping

func (g *GroupManager) Ping()

func (*GroupManager) PingLoop

func (g *GroupManager) PingLoop()

func (*GroupManager) ReloadGroup

func (g *GroupManager) ReloadGroup() bool

func (*GroupManager) Run

func (g *GroupManager) Run()

func (*GroupManager) RunOnce

func (g *GroupManager) RunOnce() bool

func (*GroupManager) Start

func (g *GroupManager) Start()

type GroupNotification

type GroupNotification struct {
	Notification string
}

func (*GroupNotification) FromData

func (notification *GroupNotification) FromData(buff []byte) bool

func (*GroupNotification) ToData

func (notification *GroupNotification) ToData() []byte

type GroupSyncKey

type GroupSyncKey struct {
	Group_id int64
	Sync_key int64
}

func (*GroupSyncKey) FromData

func (id *GroupSyncKey) FromData(buff []byte) bool

func (*GroupSyncKey) ToData

func (id *GroupSyncKey) ToData() []byte

type IMMessage

type IMMessage struct {
	Sender    int64
	Receiver  int64
	Timestamp int32
	Msgid     int32
	Content   string
}

func (*IMMessage) FromData

func (im *IMMessage) FromData(version int, buff []byte) bool

func (*IMMessage) FromDataV0

func (im *IMMessage) FromDataV0(buff []byte) bool

func (*IMMessage) FromDataV1

func (im *IMMessage) FromDataV1(buff []byte) bool

func (*IMMessage) ToData

func (im *IMMessage) ToData(version int) []byte

func (*IMMessage) ToDataV0

func (message *IMMessage) ToDataV0() []byte

func (*IMMessage) ToDataV1

func (message *IMMessage) ToDataV1() []byte

type IMessage

type IMessage interface {
	ToData() []byte
	FromData(buff []byte) bool
}

type IVersionMessage

type IVersionMessage interface {
	ToData(version int) []byte
	FromData(version int, buff []byte) bool
}

type IgnoreMessage

type IgnoreMessage struct {
}

保存在磁盘中但不再需要处理的消息

func (*IgnoreMessage) FromData

func (ignore *IgnoreMessage) FromData(buff []byte) bool

func (*IgnoreMessage) ToData

func (ignore *IgnoreMessage) ToData() []byte

type IntSet

type IntSet map[int64]struct{}

func NewIntSet

func NewIntSet() IntSet

func (IntSet) Add

func (set IntSet) Add(v int64)

func (IntSet) Clone

func (set IntSet) Clone() IntSet

func (IntSet) IsMember

func (set IntSet) IsMember(v int64) bool

func (IntSet) Remove

func (set IntSet) Remove(v int64)

type Message

type Message struct {
	Cmd     int
	Seq     int
	Version int
	Flag    int

	Body interface{}
}

func ReceiveClientMessage

func ReceiveClientMessage(conn io.Reader) *Message

接受客户端消息(external messages)

func ReceiveLimitMessage

func ReceiveLimitMessage(conn io.Reader, limit_size int, external bool) *Message

func ReceiveMessage

func ReceiveMessage(conn io.Reader) *Message

func ReceiveStorageSyncMessage

func ReceiveStorageSyncMessage(conn io.Reader) *Message

消息大小限制在1M

func (*Message) FromData

func (message *Message) FromData(buff []byte) bool

func (*Message) ToData

func (message *Message) ToData() []byte

type MessageACK

type MessageACK struct {
	Seq int32
}

func (*MessageACK) FromData

func (ack *MessageACK) FromData(buff []byte) bool

func (*MessageACK) ToData

func (ack *MessageACK) ToData() []byte

type MessageCreator

type MessageCreator func() IMessage

type MessageUnreadCount

type MessageUnreadCount struct {
	Count int32
}

func (*MessageUnreadCount) FromData

func (u *MessageUnreadCount) FromData(buff []byte) bool

func (*MessageUnreadCount) ToData

func (u *MessageUnreadCount) ToData() []byte

type RTMessage

type RTMessage struct {
	Sender   int64
	Receiver int64
	Content  string
}

func (*RTMessage) FromData

func (rt *RTMessage) FromData(buff []byte) bool

func (*RTMessage) ToData

func (message *RTMessage) ToData() []byte

type Room

type Room int64

func (*Room) FromData

func (room *Room) FromData(buff []byte) bool

func (*Room) RoomID

func (room *Room) RoomID() int64

func (*Room) ToData

func (room *Room) ToData() []byte

type RoomMessage

type RoomMessage struct {
	*RTMessage
}

type RouteBase

type RouteBase interface {
	GetAppID() int64
	GetUserIDs() IntSet
	ContainUserID(uid int64) bool
	IsUserOnline(uid int64) bool
	ContainRoomID(room_id int64) bool
	AddUserID(uid int64, online bool)
	RemoveUserID(uid int64)
	AddRoomID(room_id int64)
	RemoveRoomID(room_id int64)
}

type SubscribeMessage

type SubscribeMessage struct {
	Appid  int64
	Uid    int64
	Online int8 //1 or 0
}

func (*SubscribeMessage) FromData

func (sub *SubscribeMessage) FromData(buff []byte) bool

func (*SubscribeMessage) ToData

func (sub *SubscribeMessage) ToData() []byte

type SyncKey

type SyncKey struct {
	Sync_key int64
}

func (*SyncKey) FromData

func (id *SyncKey) FromData(buff []byte) bool

func (*SyncKey) ToData

func (id *SyncKey) ToData() []byte

type SystemMessage

type SystemMessage struct {
	Notification string
}

func (*SystemMessage) FromData

func (sys *SystemMessage) FromData(buff []byte) bool

func (*SystemMessage) ToData

func (sys *SystemMessage) ToData() []byte

type VOIPControl

type VOIPControl struct {
	// contains filtered or unexported fields
}

func (*VOIPControl) FromData

func (ctl *VOIPControl) FromData(buff []byte) bool

func (*VOIPControl) ToData

func (ctl *VOIPControl) ToData() []byte

type VersionMessageCreator

type VersionMessageCreator func() IVersionMessage

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL