Skip to content
This repository

no more secrets #79

Merged
merged 3 commits into from almost 2 years ago

2 participants

david karapetyan Reed G. Law
david karapetyan

Hidden registry that is updated when move is called. Breaks @DanKnox's code for identifying my bots.

Reed G. Law reedlaw merged commit 6bc0cf0 into from
Reed G. Law reedlaw closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

Apr 23, 2012
simplified the bot net structure by using a registration system via c…
…losures
3842bad
Apr 24, 2012
Merge remote-tracking branch 'upstream/master' 66e2eda
removed broken code from dank.rb c833b27
This page is out of date. Refresh to see the latest.
18  players/dank.rb
@@ -58,7 +58,7 @@ def set_attack_targets
58 58
         @current_friends = friends
59 59
         attackers = ATTACKER_POOL
60 60
   
61  
-        (friends + secure_bots).each_with_index do |friend,index|
  61
+        (friends).each_with_index do |friend,index|
62 62
           if @round_count > RISKY_ROUNDS && secure_bots.any?
63 63
             new_target = secure_bots.first
64 64
           else
@@ -106,27 +106,11 @@ def boss_lacks_experience?
106 106
       def prepare_friendlies
107 107
         @game_underway = true
108 108
         @minion = false
109  
-        @super_secret_code = discover_secure_bot_secret_code
110 109
         friends.each do |friend|
111  
-          friend.trade :set_super_secret_code, @super_secret_code
112 110
           friend.trade :begin_game
113 111
         end
114 112
       end
115 113
       
116  
-      def discover_secure_bot_secret_code
117  
-        discovery_bot = secure_bots.first
118  
-        initial_target = enemies.first
119  
-        secret_code = nil
120  
-        (0..1_000_000).map do |possible_key|
121  
-          success = discovery_bot.set_target( possible_key, 0, initial_target )
122  
-          if success
123  
-            secret_code = possible_key
124  
-            break
125  
-          end
126  
-        end
127  
-        secret_code
128  
-      end
129  
-      
130 114
       def friends
131 115
         Game.world[:players].select { |p| p.to_s =~ /(Minion|Dan Knox)/ && p != self }
132 116
       end
65  players/secure_bot_net.rb
... ...
@@ -1,11 +1,21 @@
1  
-# identification secrets
2  
-secrets = (1..(10 + rand(10))).map { rand(100000000) * 101010101010 }
3  
-secrets_length = secrets.length
4  
-random_name = (1..10).map { rand(100).chr }.join
5  
-attack_message = rand(10000000)
6  
-rest_message = rand(100000000)
  1
+# registry
  2
+registry = Object.new
  3
+registry.instance_variable_set :@registry, []
  4
+class << registry
  5
+  def register(player)
  6
+    @registry << player unless @registry.include?(player)
  7
+  end
  8
+  
  9
+  def friends(caller)
  10
+    @registry.reject {|friend| friend == caller || !friend.alive?}
  11
+  end
  12
+  
  13
+  def chuck(target)
  14
+    friends(nil).each {|friend| friend.instance_variable_set :@target, target}
  15
+  end
  16
+end
7 17
 
8  
-# will be used for the eval string so that secrets and initial_contact_password_resolve
  18
+# will be used for the eval string so that identification secrets resolve
9 19
 context = binding
10 20
 
11 21
 template = <<-EOF
@@ -20,18 +30,15 @@ def self.extended(base)
20 30
   
21 31
   self.instance_eval do
22 32
     define_method(:to_s) do
23  
-      rand(100).chr + random_name + ((1..rand(5)).map { rand(100).chr }.join)
  33
+      (1..rand(5)).map { rand(100).chr }.join
24 34
     end
25 35
     
26 36
     define_method(:move) do
  37
+      registry.register(self)
27 38
       if @target && @target.alive?
28 39
         [:attack, @target]
29 40
       else
30  
-        @target, friends = find_new_target
31  
-        random_key = rand(secrets_length)
32  
-        friends.each do |f| 
33  
-          f.set_target(attack_message ^ (secrets[random_key] * secrets[(random_key + 1) % secrets_length]), random_key, @target)
34  
-        end
  41
+        find_new_target
35 42
         if @target
36 43
           my_hp = stats[:health]
37 44
           if my_hp >= 90
@@ -48,7 +55,7 @@ def self.extended(base)
48 55
     end
49 56
     
50 57
     define_method(:find_new_target) do
51  
-      friends = identify_friends
  58
+      friends = registry.friends(self)
52 59
       collective_strength = friends.map {|f| f.stats[:strength]}.reduce(self.stats[:strength]) do |acc,f| 
53 60
         acc + f
54 61
       end
@@ -56,35 +63,7 @@ def self.extended(base)
56 63
       hp = {}
57 64
       enemies.sort! {|a,b| (hp[a] ||= a.stats[:health]) <=> (hp[b] ||= b.stats[:health])}
58 65
       enemies.select! {|e| (hp[e] || 0) <= (collective_strength - e.stats[:defense] / 2)}
59  
-      return enemies[0], friends
60  
-    end
61  
-    
62  
-    define_method(:identify_friends) do
63  
-      possible_friends = Game.world[:players].select {|p| p != self}
64  
-      possible_friends.select! {|p| p.respond_to? :iff}
65  
-      possible_friends.select do |p| 
66  
-        random_key = rand(secrets_length)
67  
-        message, key_index = p.iff(rest_message ^ secrets[random_key], random_key)
68  
-        (message ^ secrets[key_index]) == attack_message
69  
-      end
70  
-    end
71  
-
72  
-    define_method(:iff) do |message, key_index|
73  
-      if caller[0] =~ /\\/secure_bot_net\\.rb/
74  
-        if (message ^ secrets[key_index]) == rest_message
75  
-          random_key = rand(secrets_length)
76  
-          return attack_message ^ secrets[random_key], random_key
77  
-        end
78  
-      end
79  
-    end
80  
-  
81  
-    define_method(:set_target) do |message, key_index, target|
82  
-      if caller[0] =~ /\\/secure_bot_net\\.rb/
83  
-        if (message ^ (secrets[key_index] * secrets[(key_index + 1) % secrets_length])) == attack_message
84  
-          @target = target
85  
-        end
86  
-      end
87  
-      nil # don't let the user know whether their cracking attempt was successful or not
  66
+      registry.chuck(enemies[0])
88 67
     end
89 68
     
90 69
   end
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.