mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 19:17:38 +08:00
feature OtherClientStatusChangedEvent.
This commit is contained in:
parent
b8e1d54fe3
commit
37b077e610
@ -195,6 +195,26 @@ type (
|
||||
UClientType int64 `jceId:"5"`
|
||||
}
|
||||
|
||||
SvcReqMSFLoginNotify struct {
|
||||
AppId int64 `jceId:"0"`
|
||||
Status byte `jceId:"1"`
|
||||
Tablet byte `jceId:"2"`
|
||||
Platform int64 `jceId:"3"`
|
||||
Title string `jceId:"4"`
|
||||
Info string `jceId:"5"`
|
||||
ProductType int64 `jceId:"6"`
|
||||
ClientType int64 `jceId:"7"`
|
||||
InstanceList []InstanceInfo `jceId:"8"`
|
||||
}
|
||||
|
||||
InstanceInfo struct {
|
||||
AppId int32 `jceId:"0"`
|
||||
Tablet byte `jceId:"1"`
|
||||
Platform int64 `jceId:"2"`
|
||||
ProductType int64 `jceId:"3"`
|
||||
ClientType int64 `jceId:"4"`
|
||||
}
|
||||
|
||||
PushMessageInfo struct {
|
||||
FromUin int64 `jceId:"0"`
|
||||
MsgTime int64 `jceId:"1"`
|
||||
@ -746,6 +766,27 @@ func (pkt *OnlineInfo) ReadFrom(r *JceReader) {
|
||||
pkt.UClientType = r.ReadInt64(5)
|
||||
}
|
||||
|
||||
func (pkt *SvcReqMSFLoginNotify) ReadFrom(r *JceReader) {
|
||||
pkt.InstanceList = []InstanceInfo{}
|
||||
pkt.AppId = r.ReadInt64(0)
|
||||
pkt.Status = r.ReadByte(1)
|
||||
pkt.Tablet = r.ReadByte(2)
|
||||
pkt.Platform = r.ReadInt64(3)
|
||||
pkt.Title = r.ReadString(4)
|
||||
pkt.Info = r.ReadString(5)
|
||||
pkt.ProductType = r.ReadInt64(6)
|
||||
pkt.ClientType = r.ReadInt64(7)
|
||||
r.ReadSlice(&pkt.InstanceList, 8)
|
||||
}
|
||||
|
||||
func (pkt *InstanceInfo) ReadFrom(r *JceReader) {
|
||||
pkt.AppId = r.ReadInt32(0)
|
||||
pkt.Tablet = r.ReadByte(1)
|
||||
pkt.Platform = r.ReadInt64(2)
|
||||
pkt.ProductType = r.ReadInt64(3)
|
||||
pkt.ClientType = r.ReadInt64(4)
|
||||
}
|
||||
|
||||
func (pkt *SvcRespPushMsg) ToBytes() []byte {
|
||||
w := NewJceWriter()
|
||||
w.WriteJceStructRaw(pkt)
|
||||
|
@ -69,6 +69,11 @@ type (
|
||||
List []*FriendInfo
|
||||
}
|
||||
|
||||
OtherClientStatusChangedEvent struct {
|
||||
Client *OtherClientInfo
|
||||
Online bool
|
||||
}
|
||||
|
||||
GroupMuteEvent struct {
|
||||
GroupCode int64
|
||||
OperatorUin int64
|
||||
|
@ -31,6 +31,7 @@ type eventHandlers struct {
|
||||
groupNotifyHandlers []func(*QQClient, INotifyEvent)
|
||||
friendNotifyHandlers []func(*QQClient, INotifyEvent)
|
||||
offlineFileHandlers []func(*QQClient, *OfflineFileEvent)
|
||||
otherClientStatusChangedHandlers []func(*QQClient, *OtherClientStatusChangedEvent)
|
||||
groupMessageReceiptHandlers sync.Map
|
||||
}
|
||||
|
||||
@ -118,6 +119,10 @@ func (c *QQClient) OnReceivedOfflineFile(f func(*QQClient, *OfflineFileEvent)) {
|
||||
c.eventHandlers.offlineFileHandlers = append(c.eventHandlers.offlineFileHandlers, f)
|
||||
}
|
||||
|
||||
func (c *QQClient) OnOtherClientStatusChanged(f func(*QQClient, *OtherClientStatusChangedEvent)) {
|
||||
c.eventHandlers.otherClientStatusChangedHandlers = append(c.eventHandlers.otherClientStatusChangedHandlers, f)
|
||||
}
|
||||
|
||||
func (c *QQClient) OnLog(f func(*QQClient, *LogEvent)) {
|
||||
c.eventHandlers.logHandlers = append(c.eventHandlers.logHandlers, f)
|
||||
}
|
||||
@ -371,6 +376,17 @@ func (c *QQClient) dispatchOfflineFileEvent(e *OfflineFileEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *QQClient) dispatchOtherClientStatusChangedEvent(e *OtherClientStatusChangedEvent) {
|
||||
if e == nil {
|
||||
return
|
||||
}
|
||||
for _, f := range c.eventHandlers.otherClientStatusChangedHandlers {
|
||||
cover(func() {
|
||||
f(c, e)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (c *QQClient) dispatchLogEvent(e *LogEvent) {
|
||||
if e == nil {
|
||||
return
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
|
||||
func init() {
|
||||
decoders["StatSvc.GetDevLoginInfo"] = decodeDevListResponse
|
||||
decoders["StatSvc.SvcReqMSFLoginNotify"] = decodeLoginNotifyPacket
|
||||
decoders["RegPrxySvc.getOffMsg"] = decodeOfflineMsgResponse
|
||||
decoders["RegPrxySvc.PushParam"] = decodePushParamPacket
|
||||
}
|
||||
@ -194,3 +195,53 @@ func decodePushParamPacket(c *QQClient, _ uint16, payload []byte) (interface{},
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// StatSvc.SvcReqMSFLoginNotify
|
||||
func decodeLoginNotifyPacket(c *QQClient, _ uint16, payload []byte) (interface{}, error) {
|
||||
request := &jce.RequestPacket{}
|
||||
request.ReadFrom(jce.NewJceReader(payload))
|
||||
data := &jce.RequestDataVersion2{}
|
||||
data.ReadFrom(jce.NewJceReader(request.SBuffer))
|
||||
reader := jce.NewJceReader(data.Map["SvcReqMSFLoginNotify"]["QQService.SvcReqMSFLoginNotify"][1:])
|
||||
notify := &jce.SvcReqMSFLoginNotify{}
|
||||
notify.ReadFrom(reader)
|
||||
if notify.Status == 1 {
|
||||
found := false
|
||||
for _, oc := range c.OnlineClients {
|
||||
if oc.AppId == notify.AppId {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
allowedClients, _ := c.GetAllowedClients()
|
||||
for _, ac := range allowedClients {
|
||||
t := ac
|
||||
if ac.AppId == notify.AppId {
|
||||
c.OnlineClients = append(c.OnlineClients, t)
|
||||
c.dispatchOtherClientStatusChangedEvent(&OtherClientStatusChangedEvent{
|
||||
Client: t,
|
||||
Online: true,
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if notify.Status == 2 {
|
||||
rmi := -1
|
||||
for i, oc := range c.OnlineClients {
|
||||
if oc.AppId == notify.AppId {
|
||||
rmi = i
|
||||
}
|
||||
}
|
||||
if rmi != -1 {
|
||||
rmc := c.OnlineClients[rmi]
|
||||
c.OnlineClients = append(c.OnlineClients[:rmi], c.OnlineClients[rmi+1:]...)
|
||||
c.dispatchOtherClientStatusChangedEvent(&OtherClientStatusChangedEvent{
|
||||
Client: rmc,
|
||||
Online: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user