Esempio n. 1
0
 def commandCreate(self, parts, byuser, overriderank):
     "/create worldname width height length - Admin\nCreates a new world with specified dimensions."
     if len(parts) == 1:
         self.client.sendServerMessage("Please specify a world name.")
     elif self.client.factory.world_exists(parts[1]):
         self.client.sendServerMessage("Worldname in use")
     elif len(parts) < 5:
         self.client.sendServerMessage("Please specify dimensions. (width, length, height)")
     elif int(parts[2]) < 16 or int(parts[3]) < 16 or int(parts[4]) < 16:
         self.client.sendServerMessage("No dimension may be smaller than 16.")
     elif int(parts[2]) > 1024 or int(parts[3]) > 1024 or int(parts[4]) > 1024:
         self.client.sendServerMessage("No dimension may be greater than 1024.")
     elif (int(parts[2]) % 16) > 0 or (int(parts[3]) % 16) > 0 or (int(parts[4]) % 16) > 0:
         self.client.sendServerMessage("All dimensions must be divisible by 16.")
     else:
         world_id = parts[1].lower()
         sx, sy, sz = int(parts[2]), int(parts[3]), int(parts[4])
         grass_to = (sy // 2)
         world = World.create(
             "worlds/%s" % world_id,
             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
             )
         self.client.factory.loadWorld("worlds/%s" % world_id, world_id)
         self.client.factory.worlds[world_id].all_write = False
         self.client.sendServerMessage("World '%s' made and booted." % world_id)
Esempio n. 2
0
 def __init__(self):
     self.ServerVars = dict()
     self.specs = ConfigParser()
     self.last_heartbeat = time.time()
     self.lastseen = ConfigParser()
     self.config = ConfigParser()
     self.options_config = ConfigParser()
     self.ploptions_config = ConfigParser()
     self.wordfilter = ConfigParser()
     self.save_count = 1
     try:
         self.config.read("config/main.conf")
     except:
         logging.log(logging.ERROR, "Something is messed up with your main.conf file. (Did you edit it in Notepad?)")
         sys.exit(1)
     try:
         self.options_config.read("config/options.conf")
     except:
         logging.log(logging.ERROR, "Something is messed up with your options.conf file. (Did you edit it in Notepad?)")
         sys.exit(1)
     try:
         self.ploptions_config.read("config/ploptions.conf")
     except:
         logging.log(logging.ERROR, "Something is messed up with your ploptions.conf file. (Did you edit it in Notepad?)")
         sys.exit(1)
     self.use_irc = False
     if  (os.path.exists("config/irc.conf")):
         self.use_irc = True
         self.irc_config = ConfigParser()
         try:
             self.irc_config.read("config/irc.conf")
         except:
             logging.log(logging.ERROR, "Something is messed up with your irc.conf file. (Did you edit it in Notepad?)")
             sys.exit(1)
     self.saving = False
     try:
         self.max_clients = self.config.getint("main", "max_clients")
         self.server_message = self.config.get("main", "description")
         self.public = self.config.getboolean("main", "public")
         self.controller_port = self.config.get("network", "controller_port")
         self.controller_password = self.config.get("network", "controller_password")
         self.server_name = self.config.get("main", "name")
         if self.server_name == "iCraft Server":
             logging.log(logging.ERROR, "You forgot to give your server a name.")
         self.owner = self.config.get("main", "owner").lower()
         if self.owner == "yournamehere":
             logging.log(logging.ERROR, "You forgot to make yourself the server owner.")
     except:
         logging.log(logging.ERROR, "You don't have a main.conf file! You need to rename main.example.conf to main.conf")
         sys.exit(1)
     try:
         self.duplicate_logins = self.options_config.getboolean("options", "duplicate_logins")
         self.info_url = self.options_config.get("options", "info_url")
         self.away_kick = self.options_config.getboolean("options", "away_kick")
         self.away_time = self.options_config.getint("options", "away_time")
         self.colors = self.options_config.getboolean("options", "colors")
         self.physics_limit = self.options_config.getint("worlds", "physics_limit")
         self.default_name = self.options_config.get("worlds", "default_name")
         self.default_backup = self.options_config.get("worlds", "default_backup")
         self.asd_delay = self.options_config.getint("worlds", "asd_delay")
         self.gchat = self.options_config.getboolean("worlds", "gchat")
     except:
         logging.log(logging.ERROR, "You don't have a options.conf file! You need to rename options.example.conf to options.conf")
         sys.exit(1)
     try:
         self.grief_blocks = self.ploptions_config.getint("antigrief", "blocks")
         self.grief_time = self.ploptions_config.getint("antigrief", "time")
         self.backup_freq = self.ploptions_config.getint("backups", "backup_freq")
         self.backup_default = self.ploptions_config.getboolean("backups", "backup_default")
         self.backup_max = self.ploptions_config.getint("backups", "backup_max")
         self.backup_auto = self.ploptions_config.getboolean("backups", "backup_auto")
         self.enable_archives = self.ploptions_config.getboolean("archiver", "enable_archiver")
         self.currency = self.ploptions_config.get("bank", "currency")
         self.build_director = self.ploptions_config.get("build", "director")
         self.build_admin = self.ploptions_config.get("build", "admin")
         self.build_mod = self.ploptions_config.get("build", "mod")
         self.build_op = self.ploptions_config.get("build", "op")
         self.build_other = self.ploptions_config.get("build", "other")
         if self.backup_auto:
             reactor.callLater(float(self.backup_freq * 60),self.AutoBackup)
     except:
         logging.log(logging.ERROR, "You don't have a ploptions.conf file! You need to rename ploptions.example.conf to ploptions.conf")
         sys.exit(1)
     #if not os.path.exists("config/greeting.txt"):
     #    logging.log(logging.ERROR, "You don't have a greeting.txt file! You need to rename greeting.example.txt to greeting.txt (If this error persists, you may have used Notepad.)")
     #    sys.exit(1)
     #if not os.path.exists("config/rules.txt"):
     #    logging.log(logging.ERROR, "You don't have a rules.txt file! You need to rename rules.example.txt to rules.txt (If this error persists, you may have used Notepad.)")
     #    sys.exit(1)
     if self.use_irc:
         self.irc_nick = self.irc_config.get("irc", "nick")
         self.irc_pass = self.irc_config.get("irc", "password")
         self.irc_channel = self.irc_config.get("irc", "channel")
         self.irc_cmdlogs = self.irc_config.getboolean("irc", "cmdlogs")
         self.ircbot = self.irc_config.getboolean("irc", "ircbot")
         self.staffchat = self.irc_config.getboolean("irc", "staffchat")
         self.irc_relay = ChatBotFactory(self)
         if self.ircbot and not (self.irc_channel == "#icraft" or self.irc_channel == "#channel") and not self.irc_nick == "botname":
             reactor.connectTCP(self.irc_config.get("irc", "server"), self.irc_config.getint("irc", "port"), self.irc_relay)
         else:
             logging.log(logging.ERROR, "IRC Bot failed to connect, you could modify, rename or remove irc.conf")
             logging.log(logging.ERROR, "You need to change your 'botname' and 'channel' fields to fix this error or turn the bot off by disabling 'ircbot'")
     else:
         self.irc_relay = None
     self.default_loaded = False
     # Word Filter
     try:
         self.wordfilter.read("config/wordfilter.conf")
     except:
         logging.log(logging.ERROR, "Something is messed up with your wordfilter.conf file. (Did you edit it in Notepad?)")
         sys.exit(1)
     self.filter = []
     try:
         number = int(self.wordfilter.get("filter","count"))
     except:
         logging.log(logging.ERROR, "You need to rename wordfilter.example.conf to wordfilter.conf")
         sys.exit(1);
     for x in range(number):
         self.filter = self.filter + [[self.wordfilter.get("filter","s"+str(x)),self.wordfilter.get("filter","r"+str(x))]]
     # Salt, for the heartbeat server/verify-names
     self.salt = hashlib.md5(hashlib.md5(str(random.getrandbits(128))).digest()).hexdigest()[-32:].strip("0")
     # Load up the plugins specified
     self.plugins_config = ConfigParser()
     try:
         self.plugins_config.read("config/plugins.conf")
     except:
         logging.log(logging.ERROR, "Something is messed up with your irc.conf file. (Did you edit it in Notepad?)")
         sys.exit(1)
     try:
         plugins = self.plugins_config.options("plugins")
     except:
         print ("NOTICE: You need to rename plugins.example.conf to plugins.conf")
         sys.exit(1);
     logging.log(logging.INFO, "Loading plugins...")
     load_plugins(plugins)
     # Open the chat log, ready for appending
     self.chatlog = open("logs/server.log", "a")
     self.chatlog = open("logs/chat.log", "a")
     # Create a default world, if there isn't one.
     if not os.path.isdir("worlds/%s" % self.default_name):
         logging.log(logging.INFO, "Generating %s world..." % self.default_name)
         sx, sy, sz = 64, 64, 64
         grass_to = (sy // 2)
         world = World.create(
             "worlds/%s" % self.default_name,
             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
         )
         logging.log(logging.INFO, "Generated.")
     # Initialise internal datastructures
     self.worlds = {}
     self.directors = set()
     self.admins = set()
     self.mods = set()
     self.globalbuilders = set()
     self.members = set()
     self.spectators = set()
     self.silenced = set()
     self.banned = {}
     self.ipbanned = {}
     self.lastseen = {}
     # Load up the contents of those.
     self.loadMeta()
     # Set up a few more things.
     self.queue = Queue()
     self.clients = {}
     self.usernames = {}
     self.console = StdinPlugin(self)
     self.console.start()
     self.heartbeat = Heartbeat(self)
     # Boot worlds that got loaded
     for world in self.worlds:
         self.loadWorld("worlds/%s" % world, world)
     # Set up tasks to run during execution
     reactor.callLater(0.1, self.sendMessages)
     reactor.callLater(1, self.printInfo)
     # Initial startup is instant, but it updates every 10 minutes.
     self.world_save_stack = []
     reactor.callLater(60, self.saveWorlds)
     if self.enable_archives:
         self.loadPlugin('archives')
         reactor.callLater(1, self.loadArchives)
     gc.disable()
     self.cleanGarbage()