Exemplo n.º 1
0
// ClientLive method for accept new connection from socket
func ClientLive(buffers Buffers, conf core.Config, c net.Conn) {
	defer core.ErrorNetworkHandler(c)

	buffer := bytes.NewBuffer([]byte{})
	player := entitie.NewPlayer(c)
	newPill := pill.NewPill()

	for getBytes := range buffers.GetReadChannel() {
		buffer.Reset()
		buffer.Write(getBytes)

		log.WithField("bytes", fmt.Sprintf("% x", buffer.Bytes())).Info("Print message from client")

		if buffer.Len() <= 2 {
			buffers.GetWriteChannel() <- []byte{0x00, 0x02}
			continue
		}

		opcodes, err := newPill.Decrypt(buffer.Bytes(), player)
		if err != nil {
			log.WithError(err).Panic("Error in pill decrypt")
		}

		if opcodes != nil {
			for _, opcode := range opcodes {
				pillEncrypt, err := newPill.Encrypt(newPill.GetPill(opcode), player)
				if err != nil {
					log.WithError(err).Error("Error in pill encrypt")
				}

				buffers.GetWriteChannel() <- pillEncrypt
			}
		}
	}
}
Exemplo n.º 2
0
// WriteHandler method for write bytes to socket in loop from channel
func (b *Buffers) WriteHandler(c net.Conn) {
	defer core.ErrorNetworkHandler(c)

	// Write one packet for client with time.Now()
	newPill := pill.NewPill()
	packet, err := newPill.Encrypt(newPill.GetPill(pill.DateOpcode), &entitie.Player{})
	if err != nil {
		log.WithError(err).Error("Error in pill encrypt")
	}

	c.Write(packet)

	for v := range b.WriteChannel {
		c.Write(v)
	}
}
Exemplo n.º 3
0
// WriteHandler method for write bytes to socket in loop from channel
func (b *Buffers) WriteHandler(c net.Conn) {
	defer core.ErrorNetworkHandler(c)

	// Write one packet for client with time.Now()
	pillInit := pill.NewPill()
	packet, err := pillInit.Encrypt(pillInit.SetOpcode(940).GetOutcomingCrumb())
	if err != nil {
		log.WithError(err).Error("Error in pill encrypt")
	}

	c.Write(packet)

	for v := range b.WriteChannel {
		c.Write(v)
	}
}
Exemplo n.º 4
0
// ClientLive method for accept new connection from socket
func ClientLive(buffers Buffers, conf core.Config, c net.Conn) {
	defer core.ErrorNetworkHandler(c)

	buffer := bytes.NewBuffer([]byte{})
	player := entitie.NewPlayer(c)
	pillInit := pill.NewPill()

	for getBytes := range buffers.GetReadChannel() {
		buffer.Write(getBytes)

		if conf.Base.Test {
			log.Panic("Client is break =_=")
		} else {
			log.WithField("bytes", fmt.Sprintf("% x", buffer.Bytes())).Info("Print message from client")

			if buffer.Len() >= 8 {
				opcodes, err := pillInit.Decrypt(buffer.Bytes(), *player)
				if err != nil {
					log.WithError(err).Panic("Error in pill decrypt")
				}

				if opcodes != nil {
					for _, v := range opcodes {
						pillEncrypt, err := pillInit.Encrypt(pillInit.SetOpcode(v).GetOutcomingCrumb())
						if err != nil {
							log.WithError(err).Error("Error in pill encrypt")
						}

						buffers.GetWriteChannel() <- pillEncrypt
					}
				}
			} else {
				buffers.GetWriteChannel() <- []byte{0x00, 0x02}
			}
		}

		buffer.Reset()
	}
}