actor.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package dev
  2. import (
  3. "f1-game/internal/code"
  4. nameActor "f1-game/internal/name/actor"
  5. nameRemote "f1-game/internal/name/remote"
  6. "f1-game/internal/pb"
  7. "f1-game/nodes/center/internal/db"
  8. "strings"
  9. "github.com/cherry-game/cherry/net/parser/pomelo"
  10. )
  11. type (
  12. actor struct {
  13. pomelo.ActorBase
  14. //workerSize int64
  15. }
  16. )
  17. func NewActor() *actor {
  18. return &actor{}
  19. }
  20. func (p *actor) AliasID() string {
  21. return nameActor.Dev
  22. }
  23. func (p *actor) OnInit() {
  24. p.Remote().Register(nameRemote.Dev_Register, p.register)
  25. p.Remote().Register(nameRemote.Dev_Auth, p.auth)
  26. }
  27. // register 注册开发者帐号
  28. func (p *actor) register(req *pb.DevRegister) int32 {
  29. var (
  30. accountName = req.AccountName
  31. password = req.Password
  32. )
  33. if strings.TrimSpace(accountName) == "" || strings.TrimSpace(password) == "" {
  34. return code.AccountInputParamsError
  35. }
  36. if len(accountName) < 3 || len(accountName) > 18 {
  37. return code.AccountNameLenError
  38. }
  39. if len(password) < 3 || len(password) > 18 {
  40. return code.AccountPasswordLenShort
  41. }
  42. return db.DevAccountRegister(accountName, password, req.Ip)
  43. }
  44. // auth 帐号验证
  45. func (p *actor) auth(req *pb.DevRegister) (*pb.I64, int32) {
  46. var (
  47. accountName = req.AccountName
  48. password = req.Password
  49. )
  50. devAccount, _ := db.DevAccountWithName(accountName)
  51. if devAccount == nil || devAccount.Password != password {
  52. return nil, code.AccountSDKAuthFail
  53. }
  54. return &pb.I64{Value: devAccount.AccountID}, code.OK
  55. }