1. Andrew Godwin
  2. myne

Commits

Andrew Godwin  committed de1e8cb

IPBans

  • Participants
  • Parent commits c43536f
  • Branches default

Comments (0)

Files changed (3)

File myne/plugins/adminblocks.py

View file
     
     def canBreakAdminBlocks(self):
         "Shortcut for checking permissions."
-        return (not self.client.world.admin_blocks) or self.client.isOp()
+        if self.client.world:
+            return (not self.client.world.admin_blocks) or self.client.isOp()
+        else:
+            return False
     
     def sendAdminBlockUpdate(self):
         "Sends a packet that updates the client's admin-building ability"

File myne/plugins/kickban.py

View file
         "ban": "commandBan",
         "ipban": "commandIpban",
         "unban": "commandUnban",
+        "unipban": "commandUnipban",
         "reason": "commandReason",
+        "ipreason": "commandIpreason",
     }
 
     @admin_only
     @admin_only
     @only_username_command
     def commandIpban(self, username, params=[]):
-        "/ipban username reason - Ban a user from this server."
-        return
-        if self.client.factory.isIpBanned(username):
-            self.client.sendServerMessage("%s is already banned." % username)
+        "/ipban username reason - Ban a user's IP from this server."
+        ip = self.client.factory.usernames[username].transport.getPeer().host
+        if self.client.factory.isIpBanned(ip):
+            self.client.sendServerMessage("IP %s is already banned." % ip)
         else:
             if not params:
                 self.client.sendServerMessage("Please give a reason.")
             else:
-                self.client.factory.addIpBan(username, " ".join(params))
+                self.client.factory.addIpBan(ip, " ".join(params))
                 if username in self.client.factory.usernames:
                     self.client.factory.usernames[username].sendError("You were banned!")
     
             self.client.sendServerMessage("%s unbanned." % username)
     
     @admin_only
+    @only_string_command("IP")
+    def commandUnipban(self, ip):
+        "/unipban ip - Removes the ban on the ip."
+        if not self.client.factory.isIpBanned(ip):
+            self.client.sendServerMessage("%s is not banned." % ip)
+        else:
+            self.client.factory.removeIpBan(ip)
+            self.client.sendServerMessage("%s unbanned." % ip)
+    
+    @admin_only
     @only_username_command
     def commandReason(self, username):
         "/reason username - Gives the reason a user was banned."
             self.client.sendServerMessage("%s is not banned." % username)
         else:
             self.client.sendServerMessage("Reason: %s" % self.client.factory.banReason(username))
+    
+    @admin_only
+    @only_string_command("IP")
+    def commandIpreason(self, ip):
+        "/ipreason username - Gives the reason an IP was banned."
+        if not self.client.factory.isIpBanned(ip):
+            self.client.sendServerMessage("%s is not banned." % ip)
+        else:
+            self.client.sendServerMessage("Reason: %s" % self.client.factory.ipBanReason(ip))
     

File myne/server.py

View file
     def banReason(self, username):
         return self.banned[username.lower()]
     
+    def addIpBan(self, ip, reason):
+        self.ipbanned[ip] = reason
+    
+    def removeIpBan(self, ip):
+        del self.ipbanned[ip]
+    
+    def ipBanReason(self, ip):
+        return self.ipbanned[ip]
+    
     def world_exists(self, world_id):
         "Says if the world exists (even if unbooted)"
         return os.path.isdir("worlds/%s/" % world_id)