Exemple #1
0
    def __init__(self, mod_index_file, progressbar):
        self.mod_count = unitsync.GetPrimaryModCount()
        self.mod_index_file = mod_index_file

        self.progressbar = progressbar

        self.mod_index = ConfigParser.ConfigParser()
        self.mod_index.optionxform = lambda x: x
        self.mod_index.read(self.mod_index_file)
Exemple #2
0
 def mod_sides(self, mod_archive):
     unitsync.Init(True, 1)
     unitsync.GetPrimaryModCount()
     unitsync.AddAllArchives(mod_archive)
     sides_count = unitsync.GetSideCount()
     mod_sides = []
     if sides_count == 0:
         mod_sides = [
             'ARM', 'CORE'
         ]  # Hack -> Workaround for when Mod Author's forget to define sides
     else:
         for i in range(0, sides_count):
             mod_sides.append(unitsync.GetSideName(i))
     return mod_sides
Exemple #3
0
def update_index(self):
    filename = self.mod_index
    mod_index = ConfigParser.ConfigParser()
    mod_index.optionxform = lambda x: x
    mod_index.read(filename)

    mod_count = unitsync.GetPrimaryModCount()
    checksums = []

    # Add Mods to Archive
    if mod_count != 0:
        # Add Mods
        for i in range(0, mod_count):
            # TODO Add GUI Progress Bar
            #  Just Added console output, so users aware app is still working away
            print('mod Count = ', i)
            checksums.append(str(unitsync.GetPrimaryModChecksum(i)))
            if mod_index.has_section(checksums[i]) == False:
                mod_index.add_section(checksums[i])
                mod_archive = unitsync.GetPrimaryModArchive(i)
                mod_index.set(checksums[i], 'MOD_NAME',
                              unitsync.GetPrimaryModName(i))
                mod_index.set(checksums[i], 'MOD_ARCHIVE', mod_archive)
                sides = mod_sides(self, mod_archive)
                mod_index.set(checksums[i], 'SIDE_COUNT', len(sides))
                for p in range(0, len(sides)):
                    mod_index.set(checksums[i], 'SIDE_' + str(p + 1), sides[p])

        # Remove mods
        index_checksums = mod_index.sections()
        for o in range(0, len(index_checksums)):
            test = False
            for p in range(0, len(checksums)):
                if index_checksums[o] == checksums[p]:
                    test = True
                    break
            if test == False:
                mod_index.remove_section(index_checksums[o])

        mod_index.write(open(filename, "w+"))
    else:
        create_index(self)
Exemple #4
0
    def joinBattle(self, index):
        battle = self.battleList[index]

        #make sure we are in the right directory! =======
        config = wx.Config().Get()
        cwd = os.getcwd()

        if os.path.exists(config.Read("/Spring/DataDirectory")):
            map_path = os.path.join(config.Read("/Spring/DataDirectory"),
                                    'maps/')

        # HACK need to fix this
        os.chdir(config.Read("/Spring/DataDirectory"))
        #================================================

        if battle == None:
            misc.CreateMessageBox(self.parent_window, MSGBOX_ERROR, str(index))

        password = ""
        mod_passed = False
        map_passed = False

        #Check for password
        if battle.passworded == True:
            #ask for the password using a dialog
            getpass = wx.TextEntryDialog(
                self.parent_window,
                "Password needed to join \"" + battle.name + "\":",
                "Enter password", "", wx.OK | wx.CANCEL)
            choice = getpass.ShowModal()

            if choice == wx.ID_OK:

                if getpass.GetValue() != "":

                    password = getpass.GetValue()
                    #config.Write("/Player/Name", self.client_username)

                    getpass.Close(True)

                else:
                    misc.CreateMessageBox(self.parent_window, MSGBOX_ERROR,
                                          "Password entered is invalid.")
                    getpass.Close(True)
                    return None

            else:
                getpass.Close(True)
                return False

        #Check for mod availability
        mod = str(battle.modName)
        unitsync.Init(False, 0)
        unitsync.InitArchiveScanner()

        count = unitsync.GetPrimaryModCount()
        modList = []
        fileList = []

        selection = False

        for i in range(0, count):
            modname = unitsync.GetPrimaryModName(i)
            if modname == mod:
                mod_passed = True

        if mod_passed == False:
            misc.CreateMessageBox(
                self.parent_window, MSGBOX_ERROR,
                "You do not have the correct mod to join this battle.\nMod \'"
                + mod + "\' not found.")

            unitsync.UnInit()
            os.chdir(cwd)
            return False

        #Check for map availability
        map = str(battle.mapName)

        count = unitsync.GetMapCount()
        mapList = []

        for i in range(0, count):
            mapname = unitsync.GetMapName(i)
            if mapname == map:
                map_passed = True

        if map_passed == False:
            misc.CreateMessageBox(
                self.parent_window, MSGBOX_ERROR,
                "You do not have the correct map to join this battle.\nMap \'"
                + mod + "\' not found.")

            unitsync.UnInit()
            os.chdir(cwd)
            return False

        #uninit unitsync and change to the old cwd
        unitsync.UnInit()
        os.chdir(cwd)

        if password != "":
            self.parent_window.client.send("JOINBATTLE " +
                                           str(battle.server_id) + " " +
                                           password)
        else:
            self.parent_window.client.send("JOINBATTLE " +
                                           str(battle.server_id))

        return True
Exemple #5
0
 def get_mod_count(self):
     self.mod_count = unitsync.GetPrimaryModCount()
     return self.mod_count