WIP: implement register

This commit is contained in:
jtieri 2021-09-16 00:26:26 -05:00
parent 0312dd2f1c
commit 24010da0e2
4 changed files with 84 additions and 1 deletions

View File

@ -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
}

View File

@ -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))
//}

View File

@ -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() {

View File

@ -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)
}
}