From 24010da0e2a93c7de2ef259d3d8fed286384529d Mon Sep 17 00:00:00 2001 From: jtieri <37750742+jtieri@users.noreply.github.com> Date: Thu, 16 Sep 2021 00:26:26 -0500 Subject: [PATCH] WIP: implement register --- .../protocol/composers/register_composers.go | 21 ++++++++ habbgo/protocol/handlers/register_handlers.go | 54 +++++++++++++++++++ habbgo/server/router.go | 8 +++ habbgo/server/scheduler.go | 2 +- 4 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 habbgo/protocol/composers/register_composers.go create mode 100644 habbgo/protocol/handlers/register_handlers.go diff --git a/habbgo/protocol/composers/register_composers.go b/habbgo/protocol/composers/register_composers.go new file mode 100644 index 0000000..7d0bdd1 --- /dev/null +++ b/habbgo/protocol/composers/register_composers.go @@ -0,0 +1,21 @@ +package composers + +import "github.com/jtieri/HabbGo/habbgo/protocol/packets" + +func DATE(date string) *packets.OutgoingPacket { + p := packets.NewOutgoing(163) // Base64 Header - Bc + p.Write(date) + return p +} + +func APPROVENAMEREPLY(approveCode int) *packets.OutgoingPacket { + p := packets.NewOutgoing(36) + p.WriteInt(approveCode) + return p +} + +func PASSWORD_APPROVED(errorCode int) *packets.OutgoingPacket { + p := packets.NewOutgoing(282) // Base64 Header - DZ + p.WriteInt(errorCode) + return p +} diff --git a/habbgo/protocol/handlers/register_handlers.go b/habbgo/protocol/handlers/register_handlers.go new file mode 100644 index 0000000..76d4c9e --- /dev/null +++ b/habbgo/protocol/handlers/register_handlers.go @@ -0,0 +1,54 @@ +package handlers + +import ( + "github.com/jtieri/HabbGo/habbgo/date" + "github.com/jtieri/HabbGo/habbgo/game/player" + "github.com/jtieri/HabbGo/habbgo/protocol/composers" + "github.com/jtieri/HabbGo/habbgo/protocol/packets" + "github.com/jtieri/HabbGo/habbgo/text" + "strings" +) + +const ( + OK = 0 + TOOLONG = 1 + TOOSHORT = 2 + UNACCEPTABLE = 3 + ALREADYRESERVED = 4 +) + +// checkName takes in a proposed username and returns an integer representing the approval status of the given name +func checkName(username string) int { + allowedChars := "1234567890qwertyuiopasdfghjklzxcvbnm_-+=?!@:.,$" // TODO make this a config option + switch { + //TODO add case for username already being taken + case len(username) > 16: + return TOOLONG + case len(username) < 1: + return TOOSHORT + case !text.ContainsAllowedChars(strings.ToLower(username), allowedChars) || strings.Contains(username, " "): + return UNACCEPTABLE + case strings.Contains(strings.ToUpper(username), "MOD-"): + return UNACCEPTABLE + default: + return OK + } +} + +func GDATE(p *player.Player, packet *packets.IncomingPacket) { + p.Session.Send(composers.DATE(date.GetCurrentDate())) +} + +func APPROVENAME(p *player.Player, packet *packets.IncomingPacket) { + name := text.Filter(packet.ReadString()) + p.Session.Send(composers.APPROVENAMEREPLY(checkName(name))) +} + +//func APPROVE_PASSWORD(p *player.Player, packet *packets.IncomingPacket) { +// username := packet.ReadString() +// password := packet.ReadString() +// +// errorCode := 0 +// +// p.Session.Send(composers.PASSWORD_APPROVED(errorCode)) +//} diff --git a/habbgo/server/router.go b/habbgo/server/router.go index 0b65cb2..99c59b8 100644 --- a/habbgo/server/router.go +++ b/habbgo/server/router.go @@ -19,6 +19,7 @@ func RegisterHandlers() (r *Router) { r = &Router{RegisteredPackets: make(map[int]func(p *player.Player, packet *packets.IncomingPacket))} r.RegisterHandshakeHandlers() + r.RegisterRegistrationHandlers() r.RegisterPlayerHandlers() r.RegisterNavigatorHandlers() @@ -34,6 +35,13 @@ func (r *Router) RegisterHandshakeHandlers() { r.RegisteredPackets[181] = handlers.GetSessionParams r.RegisteredPackets[204] = handlers.SSO r.RegisteredPackets[4] = handlers.TryLogin + r.RegisteredPackets[207] = handlers.SECRETKEY +} + +func (r *Router) RegisterRegistrationHandlers() { + // r.RegisteredPackets[9] = GETAVAILABLESETS + r.RegisteredPackets[49] = handlers.GDATE + r.RegisteredPackets[42] = handlers.APPROVENAME // 42 - APPROVENAME } func (r *Router) RegisterPlayerHandlers() { diff --git a/habbgo/server/scheduler.go b/habbgo/server/scheduler.go index 13534e3..b9af24d 100644 --- a/habbgo/server/scheduler.go +++ b/habbgo/server/scheduler.go @@ -16,7 +16,7 @@ func Handle(p *player.Player, packet *packets.IncomingPacket) { handler(p, packet) } else { if GetConfig().Server.Debug { - logger.PrintUnkownPacket(p.Session.Address(), packet) + logger.PrintUnknownPacket(p.Session.Address(), packet) } }