Skip to content

Commit

Permalink
feat: handle session and party
Browse files Browse the repository at this point in the history
  • Loading branch information
paralin committed Jan 30, 2018
1 parent f6b8dc7 commit d619532
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
9 changes: 7 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/golang/protobuf/proto"
devents "github.com/paralin/go-dota2/events"
// gcmm "github.com/paralin/go-dota2/protocol/dota_gcmessages_common_match_management"
bgcm "github.com/paralin/go-dota2/protocol/base_gcmessages"
gccm "github.com/paralin/go-dota2/protocol/dota_gcmessages_common"
gcm "github.com/paralin/go-dota2/protocol/dota_gcmessages_msgid"
gcsdkm "github.com/paralin/go-dota2/protocol/gcsdk_gcmessages"
Expand Down Expand Up @@ -96,6 +97,8 @@ func (d *Dota2) buildHandlerMap() {
uint32(gcm.EDOTAGCMsg_k_EMsgGCToClientSteamDatagramTicket): d.handleSteamDatagramTicket,
uint32(gcsm.EGCBaseClientMsg_k_EMsgGCPingRequest): d.handlePingRequest,
uint32(gcm.EDOTAGCMsg_k_EMsgGCToClientMatchSignedOut): d.handleMatchSignedOut,
uint32(bgcm.EGCBaseMsg_k_EMsgGCInvitationCreated): d.handleGcInvitationCreated,
uint32(gcm.EDOTAGCMsg_k_EMsgDestroyLobbyResponse): nil,
}
}

Expand Down Expand Up @@ -155,8 +158,10 @@ func (d *Dota2) HandleGCPacket(packet *gamecoordinator.GCPacket) {
return
}

if err := handler(packet); err != nil {
le.WithError(err).Warn("error handling gc msg")
if handler != nil {
if err := handler(packet); err != nil {
le.WithError(err).Warn("error handling gc msg")
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions client_party.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
package dota2

import (
"github.com/faceit/go-steam/protocol/gamecoordinator"
"github.com/paralin/go-dota2/events"
bgcm "github.com/paralin/go-dota2/protocol/base_gcmessages"
)

// LeaveParty attempts to leave the current party.
func (d *Dota2) LeaveParty() {
d.write(uint32(bgcm.EGCBaseMsg_k_EMsgGCLeaveParty), &bgcm.CMsgLeaveParty{})
}

// handleGcInvitationCreated handles game coordinator invitation created.
func (d *Dota2) handleGcInvitationCreated(packet *gamecoordinator.GCPacket) error {
eve := &events.InvitationCreated{}
if err := d.unmarshalBody(packet, &eve.CMsgInvitationCreated); err != nil {
return err
}

d.emit(eve)
return nil
}
2 changes: 1 addition & 1 deletion client_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (d *Dota2) handleClientWelcome(packet *gamecoordinator.GCPacket) error {
return err
}

d.le.Debugf("welcome: %v", welcome)
d.le.Debug("received GC welcome")
for _, cache := range welcome.GetUptodateSubscribedCaches() {
d.RequestCacheSubscriptionRefresh(cache.GetOwnerSoid())
}
Expand Down
10 changes: 10 additions & 0 deletions events/invite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package events

import (
bgcm "github.com/paralin/go-dota2/protocol/base_gcmessages"
)

// InvitationCreated is fired when the
type InvitationCreated struct {
bgcm.CMsgInvitationCreated
}

0 comments on commit d619532

Please sign in to comment.