~iks279/tremuadmin/main

« back to all changes in this revision

Viewing changes to tremulog.rb

  • Committer: Maxime N. Sadrieh (iKs)
  • Date: 2008-02-22 12:35:31 UTC
  • Revision ID: sadriehmaxime@gmail.com-20080222123531-zy8aold2lo2mx54z
Factorized the Regex escaping algorithm

Show diffs side-by-side

added added

removed removed

Lines of Context:
287
287
 
288
288
        # Unless specified the argument passed is a correct Regex pattern, we create a regex, escaping the strings and add wildcards and options
289
289
        unless regex
 
290
                # For simple arguments having no special format, we simply add /.*/ on each side
 
291
                for argument in [:team, :structure, :newname, :victim, :weapon, :text]
 
292
                        variables[argument] = Regexp.new('.*?' + Regexp.escape(variables[argument]) + '.*?', 'i') unless variables[argument].nil?
 
293
                end
 
294
                # For more formatted arguments, we define a specific Regex for each
290
295
                name = Regexp.new('.*?' + Regexp.escape(name) + '.*?', 'i') unless name.nil?
291
296
                ip = Regexp.new(Regexp.escape(ip) + '(\.?\d\d?\d?)*?') unless ip.nil?
292
297
                guid = Regexp.new('[A-F0-9]*?' + Regexp.escape(guid)) unless guid.nil?
293
 
                variables[:team] = Regexp.escape(variables[:team], 'i') unless variables[:team].nil?
294
 
                variables[:structure] = Regexp.new('.*?' + Regexp.escape(variables[:structure]) + '.*?', 'i') unless variables[:structure].nil?
295
 
                variables[:newname] = Regexp.new('.*?' + Regexp.escape(variables[:newname]) + '.*?', 'i') unless variables[:newname].nil?
296
 
                variables[:victim] = Regexp.new('.*?' + Regexp.escape(variables[:victim]) + '.*?', 'i') unless variables[:victim].nil?
297
 
                variables[:weapon] = Regexp.new('.*?' + Regexp.escape(variables[:weapon]) + '.*?', 'i') unless variables[:weapon].nil?
298
298
                variables[:field] = Regexp.new(Regexp.escape(variables[:field]) + 's?', 'i') unless variables[:field].nil?
299
 
                variables[:text] = Regexp.new('.*?' + Regexp.escape(variables[:text]) + '.*?', 'i') unless variables[:text].nil?
300
299
        end
301
300
 
302
301
        # Get the logs (whether the passed filename or the log itself on stdin)and call the class passing it as an argument