Skip to content

Commit

Permalink
Fixes a few bugs and finally updating the trunk.
Browse files Browse the repository at this point in the history
-All: Code cleanup.
-archives.py: Corrected a bug which prevented it from reading the correct file (finally!)
-console.py: Added spec command, and fixed error which have possibly prevented /gc from working correctly, fixed pluginload/unload bit
-constants.py: Moved blocklist (which used to belong to plugins/blockinfo.py) to this file.
-decorators.py: Renaming only_username_command back to username_command. I will fix this later.
-irc_client.py: Removed factory reference when calling Credits
-blb.py: Now /bfb cleans up self.client.total as it should
-blockinfo.py: Combining /binfo and /binfoend, moved blocklist to constants.py
-core.py: Advanced error reporting when importing plugins
-internet.py: Fixed error when logs/twitter.log does not exist
-mobs.py: Disabled.
-modutil.py: Removing /ipspec for now, moved /sendhb to serverutil.py, and some wording problems.
-playerutil.py: /tp now belongs to player category in /cmdlist
-serverutil.py: /sendhb now belongs here
-worldutil.py: /backup now copies world.meta as well (unifying backup code in progress)
-protocol.py: loops and timers are now also a protocol object
-server.py: Now it is possible to trigger heartbeat sending, removing IPSpec reference
-world.py: Removed mobs.py reference

I have been working on the brand new ranking system, stay tuned!
  • Loading branch information
tyteen4a03 committed Mar 22, 2011
1 parent d9ed95d commit 678d7a3
Show file tree
Hide file tree
Showing 22 changed files with 483 additions and 530 deletions.
6 changes: 3 additions & 3 deletions archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ def rip(key, username, password):
def main():
config = ConfigParser()
try:
config.read(os.path.join(os.path.dirname(__file__), "client.conf"))
config.read(os.path.join(os.path.dirname(__file__), "client.ini"))
except:
logger.error("You need to rename client.example.conf to client.conf")
exit(1);
logger.error("You need to rename client.dist.ini to client.ini")
exit(1)
rip(sys.argv[1], config.get("client", "username"), config.get("client", "password"))

# this only runs if the module was *not* imported
Expand Down
31 changes: 20 additions & 11 deletions blockbox/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# blockBox is licensed under the Creative Commons by-nc-sa 3.0 UnPorted License.
# To view more details, please see the "LICENSING" file in the "docs" folder of the blockBox Package.

import datetime, logging, sys, threading, time, traceback
import datetime, gc, logging, sys, threading, time, traceback

from lib.twisted.internet import reactor

Expand Down Expand Up @@ -118,23 +118,31 @@ def run(self):
print ("Please specify a username.")
else:
try:
print Rank(message, 'console', True, self.server)
print Rank(self, message, 'console', True, self.server)
except:
print ("You must specify a rank and username.")
elif message[0] == "derank":
if len(message) == 1:
print ("Please specify a username.")
else:
try:
print DeRank(message, 'console', True, self.server)
print DeRank(self, message, 'console', True, self.server)
except:
print ("You must specify a rank and username.")
elif message[0] == "spec":
if len(message) == 1:
print ("Please specify a username.")
else:
try:
print Spec(message[1], 'console', True, self.server)
print Spec(self, message[1], 'console', True, self.server)
except:
print ("Please specify a username.")
elif message[0] == "spec":
if len(message) == 1:
print ("Please specify a username.")
else:
try:
print DeSpec(self, message[1], 'console', True, self.server)
except:
print ("Please specify a username.")
elif message[0] == ("boot"):
Expand Down Expand Up @@ -201,7 +209,7 @@ def run(self):
print ("StaffChat: #message")
print ("Commands: /cmdlist")
elif message[0] == ("cmdlist"):
print ("about boot ban cmdlist cpr derank irc_cpr help kick me new pll plr plu rank say shutdown spec srb srs u")
print ("about boot ban cmdlist cpr derank despec irc_cpr help kick me new pll plr plu rank say shutdown spec srb srs u")
elif message[0] == ("about"):
print ("About The Server")
print ("Powered by blockBox %s - http://blockbox.hk-diy.net/"% VERSION )
Expand All @@ -217,7 +225,8 @@ def run(self):
self.server.queue.put((self, TASK_SERVERMESSAGE, ("[MSG] "+(" ".join(message[1:])))))
elif message[0] == ("gc"):
#ManualGarbageMe
self.server.cleanGarbage()
count = gc.collect()
self.logger.info("%i garbage objects collected, %i could not be collected." % (count, len(gc.garbage)))
elif message[0] == ("u"):
if len(message) == 1:
print ("Please type a message.")
Expand All @@ -230,7 +239,7 @@ def run(self):
try:
self.server.unloadPlugin(message[1])
self.server.loadPlugin(message[1])
except IOError:
except ImportError:
print ("No such plugin '%s'." % message[1])
else:
print ("Plugin '%s' reloaded." % message[1])
Expand All @@ -240,7 +249,7 @@ def run(self):
else:
try:
self.server.unloadPlugin(message[1])
except IOError:
except KeyError:
print ("No such plugin '%s'." % message[1])
else:
print ("Plugin '%s' unloaded." % message[1])
Expand All @@ -250,7 +259,7 @@ def run(self):
else:
try:
self.server.loadPlugin(message[1])
except IOError:
except ImportError:
print ("No such plugin '%s'." % message[1])
else:
print ("Plugin '%s' loaded." % message[1])
Expand Down Expand Up @@ -298,8 +307,8 @@ def run(self):
print ("Please include a message to send.")
else:
try:
world, out = message[1:len(message)-1].split(" ")
text = COLOUR_YELLOW+"!"+COLOUR_DARKGREEN+"Console:"+COLOUR_WHITE+" "+out
world, out = message[1:len(message)-1].split(" ")
text = COLOUR_YELLOW+"!"+COLOUR_DARKGREEN+"Console:"+COLOUR_WHITE+" "+out
except ValueError:
print ("Please include a message to send.")
else:
Expand Down
65 changes: 63 additions & 2 deletions blockbox/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
TYPE_PLAYERLEAVE = 12
TYPE_MESSAGE = 13
TYPE_ERROR = 14
TYPE_SMP = 255

TYPE_FORMATS = {
TYPE_INITIAL: Format("bssb"),
Expand All @@ -46,6 +47,7 @@
TYPE_PLAYERLEAVE: Format("b"),
TYPE_MESSAGE: Format("bs"),
TYPE_ERROR: Format("s"),
TYPE_SMP: Format(""),
}

TASK_BLOCKSET = 1
Expand Down Expand Up @@ -372,7 +374,61 @@
BLOCK_OBSIDIAN = 49
BLOCK_OPSIDIAN = 49

VIPS = set(["notch", "ez", "dock", "pixeleater", "andrewph", "ikjames", "goober", "gothfox", "destroyerx1", "willempiee", "dwarfy", "erronjason", "adam01", "aera", "andrewgodwin", "revenant", "gdude2002", "varriount", "notmeh", "bidoof_king", "rils", "fragmer", "tktech", "pyropyro", "mmavipc", "tyteen4a03", "uberfox"])
BlockList = []
while len(BlockList) != 50:
BlockList.append('')
BlockList[0]="air"
BlockList[1]="rock"
BlockList[2]="grass"
BlockList[3]="dirt"
BlockList[4]="stone"
BlockList[5]="wood"
BlockList[6]="plant"
BlockList[7]="adminblock"
BlockList[8]="water"
BlockList[9]="still_water"
BlockList[10]="lava"
BlockList[11]="still_lava"
BlockList[12]="sand"
BlockList[13]="gravel"
BlockList[14]="goldore"
BlockList[15]="ironore"
BlockList[16]="coal"
BlockList[17]="log"
BlockList[18]="leaves"
BlockList[19]="sponge"
BlockList[20]="glass"
BlockList[21]="red"
BlockList[22]="orange"
BlockList[23]="yellow"
BlockList[24]="lime"
BlockList[25]="green"
BlockList[26]="turquoise"
BlockList[27]="cyan"
BlockList[28]="blue"
BlockList[29]="indigo"
BlockList[30]="violet"
BlockList[31]="purple"
BlockList[32]="magenta"
BlockList[33]="pink"
BlockList[34]="black"
BlockList[35]="grey"
BlockList[36]="white"
BlockList[37]="yellow_flower"
BlockList[38]="red_flower"
BlockList[39]="brown_mushroom"
BlockList[40]="red_mushroom"
BlockList[41]="gold"
BlockList[42]="iron"
BlockList[43]="step"
BlockList[44]="doublestep"
BlockList[45]="brick"
BlockList[46]="tnt"
BlockList[47]="bookcase"
BlockList[48]="moss"
BlockList[49]="obsidian"

VIPS = set(["notch", "ez", "dock", "pixeleater", "andrewph", "ikjames", "goober", "gothfox", "destroyerx1", "willempiee", "dwarfy", "erronjason", "adam01", "aera", "andrewgodwin", "revenant", "gdude2002", "varriount", "notmeh", "bidoof_king", "rils", "fragmer", "tktech", "pyropyro", "fizyplankton", "tyteen4a03", "uberfox"])

class ServerFull(Exception):
pass
Expand All @@ -381,15 +437,20 @@ class TemplateDoesNotExist(Exception):
pass

class NotConfigured(Exception):
"""Raised when configuration files are missing."""
def __init__(self):
self.msg = "blockBox is not configured. Read the installation guide if you wish to proceed."

def __str__(self):
return self.msg

class StoringMethodNotSupported(Exception):

def __init__(self):
self.msg = "blockBox currently does not support the storing method supplied. Please refer to the installation guide about storing methods blockBox supports."

def __str__(self):
return self.msg
return self.msg

class WorldFileDoesNotExist(Exception):
pass
4 changes: 2 additions & 2 deletions blockbox/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def info_list(func):
func.info_list = True
return func

def only_username_command(func):
"Decorator for commands that accept a single username parameter, and need a client"
def username_command(func):
"Decorator for commands that accept a single username parameter, and need a Client"
def inner(self, parts, fromloc, overriderank):
if len(parts) == 1:
self.client.sendServerMessage("Please specify a username.")
Expand Down
8 changes: 4 additions & 4 deletions blockbox/irc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,17 @@ def AdminCommand(self, command):
if not command > 2:
self.msg(user, "You must provide a username.")
else:
self.msg(user,Rank(command[1:] + [user], False, True, self.factory))
self.msg(user, Rank(self, command[1:] + [user], False, True, self.factory))
elif command[1] == ("derank"):
if not command > 2:
self.msg(user, "You must provide a username.")
else:
self.msg(user,DeRank(command[1:] + [user], False, True, self.factory))
self.msg(user, DeRank(self, command[1:] + [user], False, True, self.factory))
elif command[1] == ("spec"):
if not command > 2:
self.msg(user, "You must provide a username.")
else:
self.msg(user,Spec(command[1], False, True, self.factory))
self.msg(user, Spec(self, command[1], False, True, self.factory))
elif command[1] == ("boot"):
world = str(command[2]).lower()
self.factory.loadWorld("worlds/"+world, world)
Expand Down Expand Up @@ -202,7 +202,7 @@ def privmsg(self, user, channel, msg):
elif msg_command[1] == ("credits"):
self.msg(self.factory.irc_channel,"Please see your PM for the Credits.")
self.msg(user,"The Credits")
list = Credits(self, self.factory)
list = Credits()
for each in list:
self.msg(user,"".join(each))
elif msg_command[1] == ("help"):
Expand Down
5 changes: 3 additions & 2 deletions blockbox/plugins/blb.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def do_step():
reactor.callLater(0.01, do_step) # This is how long (in seconds) it waits to run another 10 blocks
except StopIteration:
if fromloc == 'user':
self.client.finalizeMassCMD('bwb', self.client.count)
self.client.finalizeMassCMD('bwb', self.client.total)
pass
do_step()

Expand Down Expand Up @@ -626,7 +626,8 @@ def do_step():
reactor.callLater(0.01, do_step) #This is how long(in seconds) it waits to run another 10 blocks
except StopIteration:
if fromloc == 'user':
self.client.finalizeMassCMD('bfb', count)
self.client.finalizeMassCMD('bfb', self.client.total)
self.client.total = 0
pass
do_step()

Expand Down
80 changes: 14 additions & 66 deletions blockbox/plugins/blockinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,7 @@
from blockbox.plugins import ProtocolPlugin

class BlockInfoPlugin(ProtocolPlugin):
"Commands which tells players more about that block."
BlockList = []
while len(BlockList) != 50:
BlockList.append('')
BlockList[0]="air"
BlockList[1]="rock"
BlockList[2]="grass"
BlockList[3]="dirt"
BlockList[4]="stone"
BlockList[5]="wood"
BlockList[6]="plant"
BlockList[7]="adminblock"
BlockList[8]="water"
BlockList[9]="still_water"
BlockList[10]="lava"
BlockList[11]="still_lava"
BlockList[12]="sand"
BlockList[13]="gravel"
BlockList[14]="goldore"
BlockList[15]="ironore"
BlockList[16]="coal"
BlockList[17]="log"
BlockList[18]="leaves"
BlockList[19]="sponge"
BlockList[20]="glass"
BlockList[21]="red"
BlockList[22]="orange"
BlockList[23]="yellow"
BlockList[24]="lime"
BlockList[25]="green"
BlockList[26]="turquoise"
BlockList[27]="cyan"
BlockList[28]="blue"
BlockList[29]="indigo"
BlockList[30]="violet"
BlockList[31]="purple"
BlockList[32]="magenta"
BlockList[33]="pink"
BlockList[34]="black"
BlockList[35]="grey"
BlockList[36]="white"
BlockList[37]="yellow_flower"
BlockList[38]="red_flower"
BlockList[39]="brown_mushroom"
BlockList[40]="red_mushroom"
BlockList[41]="gold"
BlockList[42]="iron"
BlockList[43]="step"
BlockList[44]="doublestep"
BlockList[45]="brick"
BlockList[46]="tnt"
BlockList[47]="bookcase"
BlockList[48]="moss"
BlockList[49]="obsidian"
"Commands which tells players more about that block."

hooks = {
"preblockchange": "blockChanged",
Expand All @@ -72,13 +19,13 @@ class BlockInfoPlugin(ProtocolPlugin):
"bget": "commandInfo",
"rget": "commandInfo",
"pget": "commandInfo",
"binfoend": "commandInfoEnd",
"infoend": "commandInfoEnd",
"blockindex": "commandBlockindex",
"bindex": "commandBlockindex",
}
}

def gotClient(self):
self.binfo = 0
self.binfo = False

def blockChanged(self, x, y, z, block, selected_block, fromloc):
if self.binfo == 1:
check_offset = self.client.world.blockstore.get_offset(x, y, z)
Expand All @@ -90,18 +37,19 @@ def blockChanged(self, x, y, z, block, selected_block, fromloc):
else:
self.client.sendServerMessage("Block Info: %s (%s)" % (self.BlockList[block2], block2))
self.client.sendServerMessage("x: %s y: %s z: %s" % (x, y, z))
return block2
return block2

@build_list
def commandInfo(self,parts,fromloc,overriderank):
self.binfo = 1
def commandInfo(self, parts, fromloc, overriderank):
"/info - Guest\nAliases: bget, binfo, pget, rget\nClick on a block, returns block info."
if self.binfo:
self.binfo = False
self.client.sendServerMessage("You are no longer getting information about blocks.")
else:
self.binfo = True
self.client.sendServerMessage("You are now getting info about blocks.")
self.client.sendServerMessage("Use '/infoend' to stop.")

@build_list
def commandInfoEnd(self,parts,fromloc,overriderank):
self.binfo = 0
self.client.sendServerMessage("You are no longer getting info about blocks.")

@build_list
def commandBlockindex(self, parts, fromloc, overriderank):
"/blockindex blockname - Guest\nAliases: bindex\nGives you the index of the block."
Expand Down
Loading

0 comments on commit 678d7a3

Please sign in to comment.