Example #1
0
func HandleCI2(
	conn net.Conn,
	connection_data *structs.ConnData,
	packet_data *structs.PacketData,
	stringParts []string,
) error {
	if len(stringParts) != 2 {
		return nil
	}

	// I assume that's the classic anticheat
	// I have no idea if it is supposed to work, but I did it
	reason, err := strconv.Atoi(stringParts[1])
	if err != nil {
		return err
	}

	if reason == 50001 {
		connection_data.LastCI = time.Now()
	}

	if connection_data.IsUnclean {
		return nil
	}

	connection_data.IsUnclean = true

	// Write to database
	err = environment.Env.Database.Query(`
INSERT INTO 
	misago_ban(
		test,
		ban,
		reason_user,
		expires
	)
VALUES(
	?,
	?,
	?,
	?
)`, 0, connection_data.Username, "Cheat detected ("+stringParts[1]+")", time.Now().Add(time.Hour*24*14)).Run()
	if err != nil {
		return err
	}

	logger.Info(connection_data.Npid, " marked unclean for ", reason)

	if connection_data.ServerId != 0 {
		return utils.KickUser(connection_data.ServerId, connection_data.Npid, int64(reason))
	}

	return nil
}
Example #2
0
func HandleCI25(
	conn net.Conn,
	connection_data *structs.ConnData,
	packet_data *structs.PacketData,
	stringParts []string,
) error {

	// Parse the token
	detection_id, guid, err := parseToken25(stringParts)
	if err != nil {
		return err
	}

	logger.Infof("DETECTION FROM %s: %d", connection_data.Username, detection_id)

	// We already know that the user is unclean, don't waste time handling it.
	if connection_data.IsUnclean {
		return nil
	}

	// check the hwid for bans
	if isHWIDBanned(guid) {
		detection_id = 10100
	}

	// If reason equals NOT_DETECTED, then it's a check
	if detection_id == NOT_DETECTED || detection_id == 41009 {
		// Client is checked, allow it to connect
		connection_data.LastCI = time.Now()

		// Append the GUID
		err = AppendHWID(guid, structs.NpidToId(connection_data.Npid), false)
		if err != nil {
			return err
		}
	} else {
		// Set the connection to unclean
		connection_data.IsUnclean = true

		// Append the GUID
		err = AppendHWID(guid, structs.NpidToId(connection_data.Npid), true)
		if err != nil {
			return err
		}

		if environment.Env.Config.NP.AnticheatInstant {
			// Ban that user
			err = utils.BanUser(connection_data.Username, detection_id, time.Hour*24*14)
			if err != nil {
				return err
			}

			// Kick him!
			if connection_data.ServerId != 0 {
				err = utils.KickUser(connection_data.ServerId, connection_data.Npid, detection_id)
			}
		} else {
			// Add a delayed ban
			err = utils.AddDelayedBan(connection_data.Npid, detection_id, guid)
			if err != nil {
				return err
			}
		}
	}

	return nil
}