Esempio n. 1
0
// A very basic TCP client, for testing purposes
func main() {
	trn := terrain.New()

	ctx := message.NewClientContext()
	ctx.Terrain = trn
	ctx.Clock = clock.NewService()

	hdlr := handler.New(ctx)

	tlsConfig, err := crypto.GetClientTlsConfig()
	if err != nil {
		log.Println("WARN: could not load TLS config")
	}

	var c net.Conn
	if tlsConfig != nil {
		c, err = tls.Dial("tcp", "127.0.0.1:9999", tlsConfig)
	} else {
		c, err = net.Dial("tcp", "127.0.0.1:9999")
	}

	if err != nil {
		panic("Dial: " + err.Error())
	}

	reader := bufio.NewReader(c)
	clientIO := &message.IO{
		Reader: reader,
		Writer: c,
	}

	go hdlr.Listen(clientIO)

	/*err = builder.SendPing(clientIO.Writer)
	if err != nil {
		panic("SendPing: " + err.Error())
	}*/

	err = builder.SendLogin(clientIO.Writer, "root", "root")
	if err != nil {
		panic("SendLogin: "******"Hello World!")
	if err != nil {
		panic("SendChatSend: " + err.Error())
	}*/

	/*err = c.Close()
	if err != nil {
		panic("Close: " + err.Error())
	}*/
}
Esempio n. 2
0
func New(srv *server.Server, timeSrv *timeserver.Server) *Engine {
	// Create a new context
	ctx := message.NewServerContext()

	// Create the engine
	e := &Engine{
		ctx:     ctx,
		srv:     srv,
		timeSrv: timeSrv,
		auth:    auth.NewService(),
		clock:   clock.NewService(),
		entity:  entity.NewService(),
		action:  action.NewService(),
		terrain: terrain.New(),
		config:  game.DefaultConfig(),

		clients:        make(map[int]*server.Client),
		brdStop:        make(chan bool),
		listenStop:     make(chan bool),
		listenTimeStop: make(chan bool),
	}

	// Set config
	if timeSrv != nil {
		e.config.TimeServerPort = uint16(timeSrv.Port())
	}

	// Populate context
	ctx.Auth = e.auth
	ctx.Entity = e.entity.Frontend()
	ctx.Action = e.action.Frontend()
	ctx.Terrain = e.terrain
	ctx.Clock = e.clock
	ctx.Config = e.config

	// Initialize engine submodules
	e.mover = NewMover(e)

	// Set callbacks
	e.auth.LoginCallback = func(session *message.Session) {
		entity := session.Entity

		// Populate entity
		// TODO: default values are hardcoded
		entity.Position.BX = 20
		entity.Position.BY = 20
		entity.Type = game.PlayerEntity
		entity.Sprite = game.PlayerSprite
		entity.Attributes[game.HealthAttr] = game.Health(1000)
		entity.Attributes[game.CooldownOneAttr] = game.Cooldown(0)
	}

	return e
}
Esempio n. 3
0
func NewTerrain(el *js.Object) *Terrain {
	t := &Terrain{*terrain.New(), canvas.New(el)}
	t.Reset(1)
	return t
}