mirror of
https://github.com/tiennm99/gomoku.git
synced 2026-05-31 16:16:58 +00:00
6e3670aec8
Import source files from ratel-online organization repos into monorepo structure for gomoku game development. Update README with project structure and credits for original authors.
53 lines
854 B
Go
53 lines
854 B
Go
package shell
|
|
|
|
import (
|
|
"github.com/ratel-online/client/ctx"
|
|
"github.com/ratel-online/client/model"
|
|
"github.com/ratel-online/client/util"
|
|
"github.com/ratel-online/core/log"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
type shell struct {
|
|
ctx *ctx.Context
|
|
addr string
|
|
name string
|
|
}
|
|
|
|
func New(addr, name string) *shell {
|
|
return &shell{
|
|
addr: addr,
|
|
name: name,
|
|
}
|
|
}
|
|
|
|
func (s *shell) Start() error {
|
|
name := util.RandomName()
|
|
if s.name != "" {
|
|
name = s.name
|
|
}
|
|
s.ctx = ctx.New(model.LoginRespData{
|
|
ID: time.Now().UnixNano(),
|
|
Name: name,
|
|
Score: 100,
|
|
Username: name,
|
|
Token: "aeiou",
|
|
})
|
|
net := "tcp"
|
|
if strings.HasSuffix(s.addr, "9998") {
|
|
net = "ws"
|
|
}
|
|
err := s.ctx.Connect(net, s.addr)
|
|
if err != nil {
|
|
log.Error(err)
|
|
return err
|
|
}
|
|
err = s.ctx.Auth()
|
|
if err != nil {
|
|
log.Error(err)
|
|
return err
|
|
}
|
|
return s.ctx.Listener()
|
|
}
|