Skip to content

Commit f6b8dc7

Browse files
committed
feat: match and datagram handling
1 parent 9125dac commit f6b8dc7

File tree

8 files changed

+141
-4
lines changed

8 files changed

+141
-4
lines changed

client.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"errors"
66
"sync"
77

8+
"github.com/Sirupsen/logrus"
89
"github.com/faceit/go-steam"
910
"github.com/faceit/go-steam/protocol/gamecoordinator"
10-
"github.com/Sirupsen/logrus"
1111
"github.com/golang/protobuf/proto"
1212
devents "github.com/paralin/go-dota2/events"
1313
// gcmm "github.com/paralin/go-dota2/protocol/dota_gcmessages_common_match_management"
@@ -93,6 +93,9 @@ func (d *Dota2) buildHandlerMap() {
9393
uint32(gcm.EDOTAGCMsg_k_EMsgGCChatMessage): d.handleChatMessage,
9494
uint32(gcm.EDOTAGCMsg_k_EMsgGCOtherJoinedChannel): d.handleJoinedChannel,
9595
uint32(gcm.EDOTAGCMsg_k_EMsgGCOtherLeftChannel): d.handleLeftChannel,
96+
uint32(gcm.EDOTAGCMsg_k_EMsgGCToClientSteamDatagramTicket): d.handleSteamDatagramTicket,
97+
uint32(gcsm.EGCBaseClientMsg_k_EMsgGCPingRequest): d.handlePingRequest,
98+
uint32(gcm.EDOTAGCMsg_k_EMsgGCToClientMatchSignedOut): d.handleMatchSignedOut,
9699
}
97100
}
98101

@@ -157,7 +160,8 @@ func (d *Dota2) HandleGCPacket(packet *gamecoordinator.GCPacket) {
157160
}
158161
}
159162

160-
// Pong responds to a Ping.
161-
func (d *Dota2) Pong() {
163+
// handlePingRequest handles an incoming ping request from the gc.
164+
func (d *Dota2) handlePingRequest(packet *gamecoordinator.GCPacket) error {
162165
d.write(uint32(gcsm.EGCBaseClientMsg_k_EMsgGCPingResponse), &gcsdkm.CMsgGCClientPing{})
166+
return nil
163167
}

client_datagram.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package dota2
2+
3+
import (
4+
"github.com/faceit/go-steam/protocol/gamecoordinator"
5+
"github.com/faceit/go-steam/steamid"
6+
"github.com/paralin/go-dota2/events"
7+
gcccm "github.com/paralin/go-dota2/protocol/dota_gcmessages_client_match_management"
8+
gcm "github.com/paralin/go-dota2/protocol/dota_gcmessages_msgid"
9+
)
10+
11+
// RequestSteamDatagramTicket requests a steam datagram ticket.
12+
func (d *Dota2) RequestSteamDatagramTicket(serverID steamid.SteamId) {
13+
steamID := serverID.ToUint64()
14+
d.write(uint32(gcm.EDOTAGCMsg_k_EMsgClientToGCRequestSteamDatagramTicket), &gcccm.CMsgClientToGCRequestSteamDatagramTicket{
15+
ServerSteamId: &steamID,
16+
})
17+
}
18+
19+
// handleSteamDatagramTicket handles an incoming steam datagram ticket.
20+
func (d *Dota2) handleSteamDatagramTicket(packet *gamecoordinator.GCPacket) error {
21+
ev := &events.SteamDatagramTicket{}
22+
if err := d.unmarshalBody(packet, &ev.CMsgGCToClientSteamDatagramTicket); err != nil {
23+
return err
24+
}
25+
26+
d.emit(ev)
27+
return nil
28+
}

client_lobby.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func (d *Dota2) LaunchLobby() {
3333
}
3434

3535
// LeaveCreateLobby attempts to leave any current lobby and creates a new one.
36-
func (d *Dota2) LeaveCreateLobby(ctx context.Context, details *gcccm.CMsgPracticeLobbySetDetails) error {
36+
func (d *Dota2) LeaveCreateLobby(ctx context.Context, details *gcccm.CMsgPracticeLobbySetDetails, destroyOldLobby bool) error {
3737
cacheCtr, err := d.cache.GetContainerForTypeID(uint32(cso.Lobby))
3838
if err != nil {
3939
return err
@@ -57,6 +57,12 @@ func (d *Dota2) LeaveCreateLobby(ctx context.Context, details *gcccm.CMsgPractic
5757
}
5858

5959
le.Debug("attempting to leave lobby")
60+
if destroyOldLobby && lob.GetLeaderId() == d.client.SteamId().ToUint64() {
61+
d.DestroyLobby()
62+
}
63+
if lob.GetState() != gcmm.CSODOTALobby_UI {
64+
d.AbandonLobby()
65+
}
6066
d.LeaveLobby()
6167
} else {
6268
wasInNoLobby = true
@@ -78,6 +84,11 @@ func (d *Dota2) LeaveLobby() {
7884
d.write(uint32(gcm.EDOTAGCMsg_k_EMsgGCPracticeLobbyLeave), &gcccm.CMsgPracticeLobbyLeave{})
7985
}
8086

87+
// AbandonLobby abandons the current lobby.
88+
func (d *Dota2) AbandonLobby() {
89+
d.write(uint32(gcm.EDOTAGCMsg_k_EMsgGCAbandonCurrentGame), &gcccm.CMsgAbandonCurrentGame{})
90+
}
91+
8192
// DestroyLobby attempts to destroy the lobby.
8293
func (d *Dota2) DestroyLobby() {
8394
d.write(uint32(gcm.EDOTAGCMsg_k_EMsgDestroyLobbyRequest), &gccm.CMsgDOTADestroyLobbyRequest{})

client_lobby_members.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package dota2
2+
3+
import (
4+
"github.com/faceit/go-steam/steamid"
5+
bgcm "github.com/paralin/go-dota2/protocol/base_gcmessages"
6+
gcccm "github.com/paralin/go-dota2/protocol/dota_gcmessages_client_match_management"
7+
gcm "github.com/paralin/go-dota2/protocol/dota_gcmessages_msgid"
8+
)
9+
10+
// LobbyKickPlayer kicks a player from the lobby by account ID.
11+
func (d *Dota2) LobbyKickPlayer(playerID steamid.SteamId) {
12+
accountID := playerID.GetAccountId()
13+
d.write(uint32(gcm.EDOTAGCMsg_k_EMsgGCPracticeLobbyKick), &gcccm.CMsgPracticeLobbyKick{
14+
AccountId: &accountID,
15+
})
16+
}
17+
18+
// LobbyInvitePlayer attempts to invite a player to the current lobby.
19+
func (d *Dota2) LobbyInvitePlayer(playerID steamid.SteamId) {
20+
steamID := playerID.ToUint64()
21+
d.write(uint32(bgcm.EGCBaseMsg_k_EMsgGCInviteToLobby), &bgcm.CMsgInviteToLobby{
22+
SteamId: &steamID,
23+
})
24+
}

client_lobby_slot.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package dota2
2+
3+
import (
4+
"github.com/faceit/go-steam/steamid"
5+
gcccm "github.com/paralin/go-dota2/protocol/dota_gcmessages_client_match_management"
6+
gcm "github.com/paralin/go-dota2/protocol/dota_gcmessages_msgid"
7+
"github.com/paralin/go-dota2/protocol/dota_shared_enums"
8+
)
9+
10+
// LobbyJoinTeam switches team in a lobby.
11+
func (d *Dota2) LobbyJoinTeam(team dota_shared_enums.DOTA_GC_TEAM, slot uint32) {
12+
d.write(uint32(gcm.EDOTAGCMsg_k_EMsgGCPracticeLobbySetTeamSlot), &gcccm.CMsgPracticeLobbySetTeamSlot{
13+
Team: &team,
14+
Slot: &slot,
15+
})
16+
}
17+
18+
// LobbySetSlotBotDifficulty sets the difficulty of a slot to a given bot difficulty.
19+
func (d *Dota2) LobbySetSlotBotDifficulty(team dota_shared_enums.DOTA_GC_TEAM, slot uint32, botDifficulty dota_shared_enums.DOTABotDifficulty) {
20+
d.write(uint32(gcm.EDOTAGCMsg_k_EMsgGCPracticeLobbySetTeamSlot), &gcccm.CMsgPracticeLobbySetTeamSlot{
21+
Team: &team,
22+
Slot: &slot,
23+
BotDifficulty: &botDifficulty,
24+
})
25+
}
26+
27+
// LobbyKickPlayerFromTeam kicks a player from whatever team they are on.
28+
func (d *Dota2) LobbyKickPlayerFromTeam(player steamid.SteamId) {
29+
accountID := player.GetAccountId()
30+
d.write(uint32(gcm.EDOTAGCMsg_k_EMsgGCPracticeLobbyKickFromTeam), &gcccm.CMsgPracticeLobbyKickFromTeam{
31+
AccountId: &accountID,
32+
})
33+
}

client_match.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package dota2
2+
3+
import (
4+
"github.com/faceit/go-steam/protocol/gamecoordinator"
5+
"github.com/paralin/go-dota2/events"
6+
)
7+
8+
// handleMatchSignedOut handles an incoming steam datagram ticket.
9+
func (d *Dota2) handleMatchSignedOut(packet *gamecoordinator.GCPacket) error {
10+
ev := &events.MatchSignedOut{}
11+
if err := d.unmarshalBody(packet, &ev.CMsgGCToClientMatchSignedOut); err != nil {
12+
return err
13+
}
14+
15+
d.emit(ev)
16+
return nil
17+
}

events/datagram.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package events
2+
3+
import (
4+
gcccm "github.com/paralin/go-dota2/protocol/dota_gcmessages_client_match_management"
5+
)
6+
7+
// SteamDatagramTicket contains an incoming steam datagram ticket.
8+
type SteamDatagramTicket struct {
9+
gcccm.CMsgGCToClientSteamDatagramTicket
10+
}

events/match.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package events
2+
3+
import (
4+
gccm "github.com/paralin/go-dota2/protocol/dota_gcmessages_client"
5+
)
6+
7+
// MatchSignedOut is emitted when the match signout event arrives from the GC.
8+
type MatchSignedOut struct {
9+
gccm.CMsgGCToClientMatchSignedOut
10+
}

0 commit comments

Comments
 (0)