Skip to content

Commit

Permalink
Merge pull request #6 from DaniElectra/matchmaking
Browse files Browse the repository at this point in the history
Remove Matchmaking notification hacks
  • Loading branch information
jonbarrow authored Apr 9, 2023
2 parents a28a436 + 994a112 commit dce7956
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions matchmaking/update_session_host.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package matchmaking

import (
"encoding/hex"
"fmt"
"strconv"
"time"

nex "github.com/PretendoNetwork/nex-go"
match_making "github.com/PretendoNetwork/nex-protocols-go/match-making"
"github.com/PretendoNetwork/nex-protocols-go/notifications"
)

func updateSessionHost(err error, client *nex.Client, callID uint32, gid uint32) {
Expand Down Expand Up @@ -44,21 +45,26 @@ func updateSessionHost(err error, client *nex.Client, callID uint32, gid uint32)

server.Send(responsePacket)

rmcMessage := nex.RMCRequest{}
rmcMessage.SetProtocolID(0xe)
rmcMessage := nex.NewRMCRequest()
rmcMessage.SetProtocolID(notifications.ProtocolID)
rmcMessage.SetCallID(0xffff0000 + callID)
rmcMessage.SetMethodID(0x1)
rmcMessage.SetMethodID(notifications.MethodProcessNotificationEvent)

hostpidString := fmt.Sprintf("%.8x", (client.PID()))
hostpidString = hostpidString[6:8] + hostpidString[4:6] + hostpidString[2:4] + hostpidString[0:2]
clientPidString := fmt.Sprintf("%.8x", (client.PID()))
clientPidString = clientPidString[6:8] + clientPidString[4:6] + clientPidString[2:4] + clientPidString[0:2]
gidString := fmt.Sprintf("%.8x", (gid))
gidString = gidString[6:8] + gidString[4:6] + gidString[2:4] + gidString[0:2]
oEvent := notifications.NewNotificationEvent()
oEvent.PIDSource = client.PID()
oEvent.Type = 4000 // Ownership changed
oEvent.Param1 = gid
oEvent.Param2 = client.PID()

data, _ := hex.DecodeString("0017000000" + hostpidString + "A00F0000" + gidString + clientPidString + "01000001000000")
rmcMessage.SetParameters(data)
rmcMessageBytes := rmcMessage.Bytes()
// https://github.com/kinnay/NintendoClients/issues/101
unixTime := time.Now()
oEvent.StrParam = strconv.FormatInt(unixTime.UnixMicro(), 10)

stream := nex.NewStreamOut(server)
oEventBytes := oEvent.Bytes(stream)
rmcMessage.SetParameters(oEventBytes)

rmcRequestBytes := rmcMessage.Bytes()

for _, pid := range GetRoomPlayersHandler(gid) {
if pid == 0 {
Expand All @@ -81,7 +87,7 @@ func updateSessionHost(err error, client *nex.Client, callID uint32, gid uint32)
messagePacket.SetSource(0xA1)
messagePacket.SetDestination(0xAF)
messagePacket.SetType(nex.DataPacket)
messagePacket.SetPayload(rmcMessageBytes)
messagePacket.SetPayload(rmcRequestBytes)

messagePacket.AddFlag(nex.FlagNeedsAck)
messagePacket.AddFlag(nex.FlagReliable)
Expand All @@ -97,7 +103,7 @@ func updateSessionHost(err error, client *nex.Client, callID uint32, gid uint32)
messagePacket.SetSource(0xA1)
messagePacket.SetDestination(0xAF)
messagePacket.SetType(nex.DataPacket)
messagePacket.SetPayload(rmcMessageBytes)
messagePacket.SetPayload(rmcRequestBytes)

messagePacket.AddFlag(nex.FlagNeedsAck)
messagePacket.AddFlag(nex.FlagReliable)
Expand Down

0 comments on commit dce7956

Please sign in to comment.