diff --git a/habbgo/protocol/composers/handshake_composers.go b/habbgo/protocol/composers/handshake_composers.go new file mode 100644 index 0000000..91ad116 --- /dev/null +++ b/habbgo/protocol/composers/handshake_composers.go @@ -0,0 +1,71 @@ +package composers + +import ( + "github.com/jtieri/HabbGo/habbgo/protocol/packets" + "github.com/jtieri/HabbGo/habbgo/utils" + "strconv" +) + +// Used in ComposeSessionParams +const ( + registerCoppa = 0 // toggle conf_coppa or conf_strong_coppa_req by setting value > 0 or > 1 + voucherEnabled = 1 // Enables in-game vouchers when value is set > 0 + registerRequireParentEmail = 2 // Requires parent email when registering if value is set > 0 + registerSendParentEmail = 3 // conf_parent_email_request_reregistration + allowDirectMail = 4 // conf_allow_direct_mail + dateFormat = 5 // Sets the date formatter used across the client + partnerIntegrationEnabled = 6 // conf_partner_integration. Value is either 1 or 0 (enabled or disabled) + allowProfileEditing = 7 // Enables the in-game profile editor + trackingHeader = 8 // tracking_header - used in stats.tracking.javascript(?) + tutorialEnabled = 9 // Enables the in-game tutorial when value is set to 1 and disables it when 0 +) + +func ComposeHello() *packets.OutgoingPacket { + return packets.NewOutgoing(0) // Base64 Header @@ +} + +func ComposeCryptoParams() *packets.OutgoingPacket { + packet := packets.NewOutgoing(277) // Base64 Header DU + packet.WriteInt(0) // Toggles server->client encryption; 0=off | non-zero=on + return packet +} + +func ComposeEndCrypto() *packets.OutgoingPacket { + packet := packets.NewOutgoing(278) // Base 64 Header DV + return packet +} + +func ComposeSessionParams() *packets.OutgoingPacket { + packet := packets.NewOutgoing(257) // Base64 Header DA + + params := make(map[int]string, 10) + params[registerCoppa] = strconv.Itoa(0) + params[voucherEnabled] = strconv.Itoa(0) // TODO create config to enable if vouchers are enabled + params[registerRequireParentEmail] = strconv.Itoa(0) + params[registerSendParentEmail] = strconv.Itoa(0) + params[allowDirectMail] = strconv.Itoa(0) + params[dateFormat] = "dd-MM-yyyy" + params[partnerIntegrationEnabled] = strconv.Itoa(0) + params[allowProfileEditing] = strconv.Itoa(1) // TODO create config to enable if profile editing is enabled + params[trackingHeader] = "" + params[tutorialEnabled] = strconv.Itoa(0) // TODO check if player has finished tutorial then set appropriately + + packet.WriteInt(len(params)) + + for i, v := range params { + packet.WriteInt(i) + + if utils.IsNumber(v) { + num, _ := strconv.Atoi(v) + packet.WriteInt(num) + } else { + packet.WriteString(v) + } + } + return packet +} + +func ComposeLoginOk() *packets.OutgoingPacket { + packet := packets.NewOutgoing(3) // Base 64 Header @C + return packet +} diff --git a/habbgo/protocol/composers/player_composers.go b/habbgo/protocol/composers/player_composers.go new file mode 100644 index 0000000..31bebad --- /dev/null +++ b/habbgo/protocol/composers/player_composers.go @@ -0,0 +1,41 @@ +package composers + +import ( + "github.com/jtieri/HabbGo/habbgo/game/model/player" + "github.com/jtieri/HabbGo/habbgo/protocol/packets" + "strconv" +) + +func ComposeUserObj(player *player.Player) *packets.OutgoingPacket { + p := packets.NewOutgoing(5) // Base64 Header @E + + p.WriteString(strconv.Itoa(player.Details.Id)) // writeString userId + p.WriteString(player.Details.Username) // writeString name + p.WriteString(player.Details.Figure) // writeString figure + p.WriteString(string(player.Details.Sex)) // writeString sex + p.WriteString(player.Details.Motto) // writeString motto + p.WriteInt(player.Details.Tickets) // writeInt ph_tickets + p.WriteString(player.Details.PoolFigure) // writeString ph_figure + p.WriteInt(player.Details.Film) // writeInt photo_film + //p.WriteInt(directMail) + + return p +} + +func ComposeCreditBalance(credits int) *packets.OutgoingPacket { + p := packets.NewOutgoing(6) // Base64 Header @F + p.WriteString(strconv.Itoa(credits) + ".0") + return p +} + +func ComposeAvailableBadges() *packets.OutgoingPacket { + p := packets.NewOutgoing(229) // Base64 Header + + // writeInt num of badges + + // loop and writeString each badge id + + // writeInt chosenBadge + // writeInt visible + return p +} diff --git a/habbgo/utils/encoding/base64.go b/habbgo/protocol/encoding/base64.go similarity index 100% rename from habbgo/utils/encoding/base64.go rename to habbgo/protocol/encoding/base64.go diff --git a/habbgo/utils/encoding/vl64.go b/habbgo/protocol/encoding/vl64.go similarity index 100% rename from habbgo/utils/encoding/vl64.go rename to habbgo/protocol/encoding/vl64.go diff --git a/habbgo/server/protocol/handlers/handshake_handlers.go b/habbgo/protocol/handlers/handshake_handlers.go similarity index 55% rename from habbgo/server/protocol/handlers/handshake_handlers.go rename to habbgo/protocol/handlers/handshake_handlers.go index 23ab237..906c070 100644 --- a/habbgo/server/protocol/handlers/handshake_handlers.go +++ b/habbgo/protocol/handlers/handshake_handlers.go @@ -1,9 +1,10 @@ package handlers import ( + "github.com/jtieri/HabbGo/habbgo/database" "github.com/jtieri/HabbGo/habbgo/game/model/player" - "github.com/jtieri/HabbGo/habbgo/server/protocol/composers" - "github.com/jtieri/HabbGo/habbgo/server/protocol/packets" + "github.com/jtieri/HabbGo/habbgo/protocol/composers" + "github.com/jtieri/HabbGo/habbgo/protocol/packets" ) func HandleInitCrypto(player *player.Player, packet *packets.IncomingPacket) { @@ -11,7 +12,6 @@ func HandleInitCrypto(player *player.Player, packet *packets.IncomingPacket) { } func HandleGenerateKey(player *player.Player, packet *packets.IncomingPacket) { - // TODO send player.Session.Send(composers.ComposeEndCrypto()) } @@ -20,9 +20,23 @@ func HandleGetSessionParams(player *player.Player, packet *packets.IncomingPacke } func HandleSSO(player *player.Player, packet *packets.IncomingPacket) { + token := packet.ReadString() + // TODO if player login with token is success login, otherwise send LOCALISED ERROR & disconnect from server + if token == "" { + player.Service.Login() + } else { + + } } func HandleTryLogin(player *player.Player, packet *packets.IncomingPacket) { + username := packet.ReadString() + password := packet.ReadString() + if database.Login(player, username, password) { + player.Service.Login() + } else { + // TODO send LOCALISED ERROR + } } diff --git a/habbgo/protocol/handlers/player_handlers.go b/habbgo/protocol/handlers/player_handlers.go new file mode 100644 index 0000000..bb4a43c --- /dev/null +++ b/habbgo/protocol/handlers/player_handlers.go @@ -0,0 +1,19 @@ +package handlers + +import ( + "github.com/jtieri/HabbGo/habbgo/game/model/player" + "github.com/jtieri/HabbGo/habbgo/protocol/composers" + "github.com/jtieri/HabbGo/habbgo/protocol/packets" +) + +func HandleGetInfo(player *player.Player, packet *packets.IncomingPacket) { + player.Session.Send(composers.ComposeUserObj(player)) +} + +func HandleGetCredits(player *player.Player, packet *packets.IncomingPacket) { + player.Session.Send(composers.ComposeCreditBalance(player.Details.Credits)) +} + +func HandleGetAvailableBadges(player *player.Player, packet *packets.IncomingPacket) { + player.Session.Send(composers.ComposeAvailableBadges()) +} diff --git a/habbgo/server/protocol/packets/incoming.go b/habbgo/protocol/packets/incoming.go similarity index 97% rename from habbgo/server/protocol/packets/incoming.go rename to habbgo/protocol/packets/incoming.go index a91f21e..292ca66 100644 --- a/habbgo/server/protocol/packets/incoming.go +++ b/habbgo/protocol/packets/incoming.go @@ -2,7 +2,7 @@ package packets import ( "bytes" - "github.com/jtieri/HabbGo/habbgo/utils/encoding" + "github.com/jtieri/HabbGo/habbgo/protocol/encoding" ) // IncomingPacket represents a client->server packet. diff --git a/habbgo/server/protocol/packets/outgoing.go b/habbgo/protocol/packets/outgoing.go similarity index 97% rename from habbgo/server/protocol/packets/outgoing.go rename to habbgo/protocol/packets/outgoing.go index 8d489a6..93d9ad4 100644 --- a/habbgo/server/protocol/packets/outgoing.go +++ b/habbgo/protocol/packets/outgoing.go @@ -2,7 +2,7 @@ package packets import ( "bytes" - "github.com/jtieri/HabbGo/habbgo/utils/encoding" + "github.com/jtieri/HabbGo/habbgo/protocol/encoding" ) // OutgoingPacket represents a server->client packet. diff --git a/habbgo/server/protocol/composers/handshake_composers.go b/habbgo/server/protocol/composers/handshake_composers.go deleted file mode 100644 index fe44d8e..0000000 --- a/habbgo/server/protocol/composers/handshake_composers.go +++ /dev/null @@ -1,28 +0,0 @@ -package composers - -import "github.com/jtieri/HabbGo/habbgo/server/protocol/packets" - -func ComposeHello() *packets.OutgoingPacket { - return packets.NewOutgoing(0) // Base64 Header @@ -} - -func ComposeCryptoParams() *packets.OutgoingPacket { - packet := packets.NewOutgoing(277) // Base64 Header DU - packet.WriteInt(0) // Toggles server->client encryption; 0=off | non-zero=on - return packet -} - -func ComposeEndCrypto() *packets.OutgoingPacket { - packet := packets.NewOutgoing(278) // Base 64 Header DV - return packet -} - -func ComposeSessionParams() *packets.OutgoingPacket { - packet := packets.NewOutgoing(257) // Base64 Header DA - - // Map the param types to their values - // writeInt number of params - // iterate over the params & writeInt(paramiD) then writeInt for numeric values and writeString for strings - - return packet -} \ No newline at end of file