Commits

Andrew Godwin  committed d95c330

Add physics limiting

  • Participants
  • Parent commits 6c8d9bf

Comments (0)

Files changed (3)

File myne/plugins/physcontrol.py

     def commandPhysics(self, onoff):
         "/physics on|off - Enables or disables physics in this world."
         if onoff == "on":
-            self.client.world.physics = True
-            self.client.sendWorldMessage("This world now has physics enabled.")
+            if self.client.world.physics:
+                self.client.sendWorldMessage("Physics is already on here.")
+            else:
+                if self.client.factory.numberWithPhysics() >= self.client.factory.physics_limit:
+                    self.client.sendWorldMessage("There are already %s worlds with physics on (the max)." % self.client.factory.physics_limit)
+                else:
+                    self.client.world.physics = True
+                    self.client.sendWorldMessage("This world now has physics enabled.")
         else:
-            self.client.world.physics = False
-            self.client.sendWorldMessage("This world now has physics disabled.")
+            if not self.client.world.physics:
+                self.client.sendWorldMessage("Physics is already off here.")
+            else:
+                self.client.world.physics = False
+                self.client.sendWorldMessage("This world now has physics disabled.")
     
     @op_only
     @on_off_command

File myne/server.py

         self.duplicate_logins = self.config.getboolean("server", "duplicate_logins")
         self.verify_names = self.config.getboolean("server", "verify_names")
         self.control_password = self.config.get("server", "control_password")
+        self.physics_limit = self.config.getint("server", "physics_limit")
         
         # Parse IRC section
         if self.config.has_section("irc"):
         # Create a default world, if there isn't one.
         if not os.path.isdir("worlds/default"):
             logging.log(logging.INFO, "Generating default world...")
-            sx, sy, sz = 256, 64, 256
-            grass_to = (sy // 2) - 1
+            sx, sy, sz = 96, 160, 32
+            grass_to = (sy // 2)
             world = World.create(
                 "worlds/default",
                 sx, sy, sz, # Size
                 sx//2,grass_to+2, sz//2, 0, # Spawn
-                ([BLOCK_DIRT]*(grass_to-1) + [BLOCK_GRASS] + [BLOCK_AIR]*(sy-grass_to)) # Levels
+                [BLOCK_ROCK]*sy#([BLOCK_DIRT]*(grass_to-1) + [BLOCK_GRASS] + [BLOCK_AIR]*(sy-grass_to)) # Levels
             )
             logging.log(logging.INFO, "Generated.")
         
         logging.log(logging.INFO, "Loaded %s discrete archives." % len(self.archives))
         reactor.callLater(300, self.loadArchives)
     
+    def numberWithPhysics(self):
+        "Returns the number of worlds with physics enabled."
+        return len([world for world in self.worlds.values() if world.physics])
+    
     def isAdmin(self, username):
         return username.lower() in self.admins
     

File server.conf.example

 name: The Archives
 description: Experimental Multi-World Server
 greeting: Welcome! Type /help for information about use of this server,\nor /random to be taken to a random world.\nMore information is at http://archives.aeracode.org/
+physics_limit: 4
 
 [plugins]
 core: