-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from shutterbug2000/subscription-protocol
Add Subscription Protocol
- Loading branch information
Showing
9 changed files
with
371 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Package subscription implements the Subscription NEX protocol | ||
package subscription | ||
|
||
import ( | ||
"fmt" | ||
|
||
nex "github.com/PretendoNetwork/nex-go" | ||
"github.com/PretendoNetwork/nex-protocols-go/globals" | ||
) | ||
|
||
// CreateMySubscriptionData sets the CreateMySubscriptionData handler function | ||
func (protocol *SubscriptionProtocol) CreateMySubscriptionData(handler func(err error, client *nex.Client, callID uint32, unk uint64, content []byte)) { | ||
protocol.createMySubscriptionDataHandler = handler | ||
} | ||
|
||
func (protocol *SubscriptionProtocol) handleCreateMySubscriptionData(packet nex.PacketInterface) { | ||
if protocol.createMySubscriptionDataHandler == nil { | ||
fmt.Println("[Warning] SubscriptionProtocol::CreateMySubscriptionData not implemented") | ||
go globals.RespondError(packet, ProtocolID, nex.Errors.Core.NotImplemented) | ||
return | ||
} | ||
|
||
client := packet.Sender() | ||
request := packet.RMCRequest() | ||
|
||
callID := request.CallID() | ||
parameters := request.Parameters() | ||
|
||
parametersStream := nex.NewStreamIn(parameters, protocol.Server) | ||
unk, err := parametersStream.ReadUInt64LE() | ||
if err != nil { | ||
go protocol.createMySubscriptionDataHandler(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), client, callID, 0, nil) | ||
return | ||
} | ||
|
||
//This is done since the server doesn't need to care about the data here (it's game-specific), so we just pass it along to store however the handler wants | ||
content := parametersStream.ReadRemaining() | ||
go protocol.createMySubscriptionDataHandler(nil, client, callID, unk, content) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Package subscription implements the Subscription NEX protocol | ||
package subscription | ||
|
||
import ( | ||
"fmt" | ||
|
||
nex "github.com/PretendoNetwork/nex-go" | ||
"github.com/PretendoNetwork/nex-protocols-go/globals" | ||
) | ||
|
||
// GetActivePlayerSubscriptionData sets the GetActivePlayerSubscriptionData handler function | ||
func (protocol *SubscriptionProtocol) GetActivePlayerSubscriptionData(handler func(err error, client *nex.Client, callID uint32)) { | ||
protocol.getActivePlayerSubscriptionDataHandler = handler | ||
} | ||
|
||
func (protocol *SubscriptionProtocol) handleGetActivePlayerSubscriptionData(packet nex.PacketInterface) { | ||
if protocol.getActivePlayerSubscriptionDataHandler == nil { | ||
fmt.Println("[Warning] SubscriptionProtocol::GetActivePlayerSubscriptionData not implemented") | ||
go globals.RespondError(packet, ProtocolID, nex.Errors.Core.NotImplemented) | ||
return | ||
} | ||
|
||
client := packet.Sender() | ||
request := packet.RMCRequest() | ||
|
||
callID := request.CallID() | ||
|
||
go protocol.getActivePlayerSubscriptionDataHandler(nil, client, callID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Package subscription implements the Subscription NEX protocol | ||
package subscription | ||
|
||
import ( | ||
"fmt" | ||
|
||
nex "github.com/PretendoNetwork/nex-go" | ||
"github.com/PretendoNetwork/nex-protocols-go/globals" | ||
) | ||
|
||
// GetFriendSubscriptionData sets GetFriendSubscriptionData Unk1 handler function | ||
func (protocol *SubscriptionProtocol) GetFriendSubscriptionData(handler func(err error, client *nex.Client, callID uint32)) { | ||
protocol.getFriendSubscriptionDataHandler = handler | ||
} | ||
|
||
func (protocol *SubscriptionProtocol) handleGetFriendSubscriptionData(packet nex.PacketInterface) { | ||
if protocol.getFriendSubscriptionDataHandler == nil { | ||
fmt.Println("[Warning] SubscriptionProtocol::GetFriendSubscriptionData not implemented") | ||
go globals.RespondError(packet, ProtocolID, nex.Errors.Core.NotImplemented) | ||
return | ||
} | ||
|
||
client := packet.Sender() | ||
request := packet.RMCRequest() | ||
|
||
callID := request.CallID() | ||
|
||
go protocol.getFriendSubscriptionDataHandler(nil, client, callID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Package subscription implements the Subscription NEX protocol | ||
package subscription | ||
|
||
import ( | ||
"fmt" | ||
|
||
nex "github.com/PretendoNetwork/nex-go" | ||
"github.com/PretendoNetwork/nex-protocols-go/globals" | ||
) | ||
|
||
// GetPrivacyLevels sets the GetPrivacyLevels handler function | ||
func (protocol *SubscriptionProtocol) GetPrivacyLevels(handler func(err error, client *nex.Client, callID uint32)) { | ||
protocol.getPrivacyLevelsHandler = handler | ||
} | ||
|
||
func (protocol *SubscriptionProtocol) handleGetPrivacyLevels(packet nex.PacketInterface) { | ||
if protocol.getPrivacyLevelsHandler == nil { | ||
fmt.Println("[Warning] SubscriptionProtocol::GetPrivacyLevels not implemented") | ||
go globals.RespondError(packet, ProtocolID, nex.Errors.Core.NotImplemented) | ||
return | ||
} | ||
|
||
client := packet.Sender() | ||
request := packet.RMCRequest() | ||
|
||
callID := request.CallID() | ||
|
||
go protocol.getPrivacyLevelsHandler(nil, client, callID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Package subscription implements the Subscription NEX protocol | ||
package subscription | ||
|
||
import ( | ||
"fmt" | ||
|
||
nex "github.com/PretendoNetwork/nex-go" | ||
"github.com/PretendoNetwork/nex-protocols-go/globals" | ||
) | ||
|
||
// GetSubscriptionData sets the GetSubscriptionData handler function | ||
func (protocol *SubscriptionProtocol) GetSubscriptionData(handler func(err error, client *nex.Client, callID uint32, pids []uint32)) { | ||
protocol.getSubscriptionDataHandler = handler | ||
} | ||
|
||
func (protocol *SubscriptionProtocol) handleGetSubscriptionData(packet nex.PacketInterface) { | ||
if protocol.getSubscriptionDataHandler == nil { | ||
fmt.Println("[Warning] SubscriptionProtocol::GetSubscriptionData not implemented") | ||
go globals.RespondError(packet, ProtocolID, nex.Errors.Core.NotImplemented) | ||
return | ||
} | ||
|
||
client := packet.Sender() | ||
request := packet.RMCRequest() | ||
|
||
callID := request.CallID() | ||
parameters := request.Parameters() | ||
|
||
parametersStream := nex.NewStreamIn(parameters, protocol.Server) | ||
pids, err := parametersStream.ReadListUInt32LE() | ||
if err != nil { | ||
go protocol.getSubscriptionDataHandler(nil, client, callID, nil) | ||
} | ||
|
||
go protocol.getSubscriptionDataHandler(nil, client, callID, pids) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Package subscription implements the Subscription NEX protocol | ||
package subscription | ||
|
||
import ( | ||
"fmt" | ||
|
||
nex "github.com/PretendoNetwork/nex-go" | ||
"github.com/PretendoNetwork/nex-protocols-go/globals" | ||
) | ||
|
||
// GetTargetSubscriptionData sets the GetTargetSubscriptionData handler function | ||
func (protocol *SubscriptionProtocol) GetTargetSubscriptionData(handler func(err error, client *nex.Client, callID uint32)) { | ||
protocol.getTargetSubscriptionDataHandler = handler | ||
} | ||
|
||
func (protocol *SubscriptionProtocol) handleGetTargetSubscriptionData(packet nex.PacketInterface) { | ||
if protocol.getTargetSubscriptionDataHandler == nil { | ||
fmt.Println("[Warning] SubscriptionProtocol::GetTargetSubscriptionData not implemented") | ||
go globals.RespondError(packet, ProtocolID, nex.Errors.Core.NotImplemented) | ||
return | ||
} | ||
|
||
client := packet.Sender() | ||
request := packet.RMCRequest() | ||
|
||
callID := request.CallID() | ||
|
||
go protocol.getTargetSubscriptionDataHandler(nil, client, callID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Package subscription implements the Subscription NEX protocol | ||
package subscription | ||
|
||
import ( | ||
"fmt" | ||
|
||
nex "github.com/PretendoNetwork/nex-go" | ||
"github.com/PretendoNetwork/nex-protocols-go/globals" | ||
) | ||
|
||
const ( | ||
// ProtocolID is the protocol ID for the Subscription protocol | ||
ProtocolID = 0x75 | ||
|
||
// MethodCreateMySubscriptionData is the method ID for the method CreateMySubscriptionDataID | ||
MethodCreateMySubscriptionData = 0x1 | ||
|
||
// MethodUpdateMySubscriptionData is the method ID for the method UpdateMySubscriptionData | ||
MethodUpdateMySubscriptionData = 0x2 | ||
|
||
// MethodClearMySubscriptionData is the method ID for the method ClearMySubscriptionDataID | ||
MethodClearMySubscriptionData = 0x3 | ||
|
||
// MethodAddTarget is the method ID for the method AddTarget | ||
MethodAddTarget = 0x4 | ||
|
||
// MethodDeleteTarget is the method ID for the method DeleteTarget | ||
MethodDeleteTarget = 0x5 | ||
|
||
// MethodClearTarget is the method ID for the method ClearTarget | ||
MethodClearTarget = 0x6 | ||
|
||
// MethodGetFriendSubscriptionData is the method ID for the method GetFriendSubscriptionData | ||
MethodGetFriendSubscriptionData = 0x7 | ||
|
||
// MethodGetTargetSubscriptionData is the method ID for the method GetTargetSubscriptionData | ||
MethodGetTargetSubscriptionData = 0x8 | ||
|
||
// MethodGetActivePlayerSubscriptionData is the method ID for the method GetActivePlayerSubscriptionData | ||
MethodGetActivePlayerSubscriptionData = 0x9 | ||
|
||
// MethodGetSubscriptionData is the method ID for the method GetSubscriptionData | ||
MethodGetSubscriptionData = 0xA | ||
|
||
// MethodReplaceTargetAndGetSubscriptionData is the method ID for the method ReplaceTargetAndGetSubscriptionData | ||
MethodReplaceTargetAndGetSubscriptionData = 0xB | ||
|
||
// MethodSetPrivacyLevel is the method ID for the method SetPrivacyLevel | ||
MethodSetPrivacyLevel = 0xC | ||
|
||
// MethodGetPrivacyLevel is the method ID for the method GetPrivacyLevel | ||
MethodGetPrivacyLevel = 0xD | ||
|
||
// MethodGetSubscriptionUserFriendList is the method ID for the method GetSubscriptionUserFriendList | ||
MethodGetSubscriptionUserFriendList = 0xE | ||
|
||
// MethodGetPrivacyLevels is the method ID for the method GetPrivacyLevels | ||
MethodGetPrivacyLevels = 0xF | ||
) | ||
|
||
// SubscriptionProtocol handles the Subscription nex protocol | ||
type SubscriptionProtocol struct { | ||
Server *nex.Server | ||
createMySubscriptionDataHandler func(err error, client *nex.Client, callID uint32, unk uint64, content []byte) | ||
updateMySubscriptionDataHandler func(err error, client *nex.Client, callID uint32, unk uint32, content []byte) | ||
getFriendSubscriptionDataHandler func(err error, client *nex.Client, callID uint32) | ||
getTargetSubscriptionDataHandler func(err error, client *nex.Client, callID uint32) | ||
getActivePlayerSubscriptionDataHandler func(err error, client *nex.Client, callID uint32) | ||
getSubscriptionDataHandler func(err error, client *nex.Client, callID uint32, pids []uint32) | ||
replaceTargetAndGetSubscriptionDataHandler func(err error, client *nex.Client, callID uint32) | ||
getPrivacyLevelsHandler func(err error, client *nex.Client, callID uint32) | ||
} | ||
|
||
// Setup initializes the protocol | ||
func (protocol *SubscriptionProtocol) Setup() { | ||
protocol.Server.On("Data", func(packet nex.PacketInterface) { | ||
request := packet.RMCRequest() | ||
|
||
if ProtocolID == request.ProtocolID() { | ||
switch request.MethodID() { | ||
case MethodCreateMySubscriptionData: | ||
go protocol.handleCreateMySubscriptionData(packet) | ||
case MethodUpdateMySubscriptionData: | ||
go protocol.handleUpdateMySubscriptionData(packet) | ||
case MethodGetFriendSubscriptionData: | ||
go protocol.handleGetFriendSubscriptionData(packet) | ||
case MethodGetTargetSubscriptionData: | ||
go protocol.handleGetTargetSubscriptionData(packet) | ||
case MethodGetActivePlayerSubscriptionData: | ||
go protocol.handleGetActivePlayerSubscriptionData(packet) | ||
case MethodGetSubscriptionData: | ||
go protocol.handleGetSubscriptionData(packet) | ||
case MethodReplaceTargetAndGetSubscriptionData: | ||
go protocol.handleReplaceTargetAndGetSubscriptionData(packet) | ||
case MethodGetPrivacyLevels: | ||
go protocol.handleGetPrivacyLevels(packet) | ||
default: | ||
go globals.RespondError(packet, ProtocolID, nex.Errors.Core.NotImplemented) | ||
fmt.Printf("Unsupported Subscription method ID: %#v\n", request.MethodID()) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
// NewSubscriptionProtocol returns a new SubscriptionProtocol | ||
func NewSubscriptionProtocol(server *nex.Server) *SubscriptionProtocol { | ||
protocol := &SubscriptionProtocol{Server: server} | ||
|
||
protocol.Setup() | ||
|
||
return protocol | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Package subscription implements the Subscription NEX protocol | ||
package subscription | ||
|
||
import ( | ||
"fmt" | ||
|
||
nex "github.com/PretendoNetwork/nex-go" | ||
"github.com/PretendoNetwork/nex-protocols-go/globals" | ||
) | ||
|
||
// ReplaceTargetAndGetSubscriptionData sets the ReplaceTargetAndGetSubscriptionData handler function | ||
func (protocol *SubscriptionProtocol) ReplaceTargetAndGetSubscriptionData(handler func(err error, client *nex.Client, callID uint32)) { | ||
protocol.replaceTargetAndGetSubscriptionDataHandler = handler | ||
} | ||
|
||
func (protocol *SubscriptionProtocol) handleReplaceTargetAndGetSubscriptionData(packet nex.PacketInterface) { | ||
if protocol.replaceTargetAndGetSubscriptionDataHandler == nil { | ||
fmt.Println("[Warning] SubscriptionProtocol::ReplaceTargetAndGetSubscriptionData not implemented") | ||
go globals.RespondError(packet, ProtocolID, nex.Errors.Core.NotImplemented) | ||
return | ||
} | ||
|
||
client := packet.Sender() | ||
request := packet.RMCRequest() | ||
|
||
callID := request.CallID() | ||
|
||
go protocol.replaceTargetAndGetSubscriptionDataHandler(nil, client, callID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Package subscription implements the Subscription NEX protocol | ||
package subscription | ||
|
||
import ( | ||
"fmt" | ||
|
||
nex "github.com/PretendoNetwork/nex-go" | ||
"github.com/PretendoNetwork/nex-protocols-go/globals" | ||
) | ||
|
||
// UpdateMySubscriptionData sets the UpdateMySubscriptionData handler function | ||
func (protocol *SubscriptionProtocol) UpdateMySubscriptionData(handler func(err error, client *nex.Client, callID uint32, unk uint32, content []byte)) { | ||
protocol.updateMySubscriptionDataHandler = handler | ||
} | ||
|
||
func (protocol *SubscriptionProtocol) handleUpdateMySubscriptionData(packet nex.PacketInterface) { | ||
if protocol.updateMySubscriptionDataHandler == nil { | ||
fmt.Println("[Warning] SubscriptionProtocol::UpdateMySubscriptionData not implemented") | ||
go globals.RespondError(packet, ProtocolID, nex.Errors.Core.NotImplemented) | ||
return | ||
} | ||
|
||
client := packet.Sender() | ||
request := packet.RMCRequest() | ||
|
||
callID := request.CallID() | ||
parameters := request.Parameters() | ||
|
||
parametersStream := nex.NewStreamIn(parameters, protocol.Server) | ||
unk, err := parametersStream.ReadUInt32LE() | ||
if err != nil { | ||
go protocol.updateMySubscriptionDataHandler(fmt.Errorf("Failed to read param from parameters. %s", err.Error()), client, callID, 0, nil) | ||
return | ||
} | ||
|
||
//This is done since the server doesn't need to care about the data here (it's game-specific), so we just pass it along to store however the handler wants | ||
content := parametersStream.ReadRemaining() | ||
go protocol.updateMySubscriptionDataHandler(nil, client, callID, unk, content) | ||
} |