Пример #1
0
func (i *IncomingAuth) Packet(db *database.Database) (func(netes network.Netes), func(player *entitie.Player) []int) {
	handler := func(netes network.Netes) {
		netes.ReadString(&i.Key)
		netes.ReadString(&i.Login)
		netes.ReadString(&i.Password)
		netes.ReadString(&i.MAC)
		netes.ReadUint16(&i.IsCheat)
		netes.ReadUint16(&i.ClientVersion)

		return
	}

	process := func(player *entitie.Player) []int {
		if player.Error != nil {
			// Here was gopher...
		}

		user, err := db.User().GetByName(i.Login)
		if err != nil {
			player.Error = &support.PlayerIsNotFound

			return []int{support.OP_SERVER_LOGIN}
		}

		encryptPassword, err := crypt.EncryptPassword(strings.ToUpper(user.Password[:24]), player.Time)
		if err != nil {
			player.Error = &support.CustomError{0, err}

			return []int{support.OP_SERVER_LOGIN}
		}

		if encryptPassword != i.Password {
			player.Error = &support.PasswordIncorrect

			return []int{support.OP_SERVER_LOGIN}
		}

		if user.IsActive {
			player.Error = &support.PlayerInGame

			return []int{support.OP_SERVER_LOGIN}
		}

		user.IsActive = true
		err = user.Update(user.ID)
		if err != nil {
			player.Error = &support.CustomError{0, err}

			return []int{support.OP_SERVER_LOGIN}
		}

		player.ID = user.ID

		return []int{support.OP_SERVER_LOGIN}
	}

	return handler, process
}
Пример #2
0
func (i *IncomingExit) Packet(db *database.Database) (func(netes network.Netes), func(player *entitie.Player) []int) {
	handler := func(netes network.Netes) {
		return
	}

	process := func(player *entitie.Player) []int {
		user := db.User()
		user.IsActive = false
		err := user.Update(player.ID)
		if err != nil {
			player.Error = &support.CustomError{0, err}
		}

		player.Buffers.GetEC() <- struct{}{}

		return nil
	}

	return handler, process
}