Example #1
0
 def reset_settings(self, old_obj):
     for option in Option.objects.filter(server=self):
         option.delete()
     for tune in Tune.objects.filter(server=self):
         tune.delete()
     for vote in Vote.objects.filter(server=self):
         vote.delete()
     for rcon_command in RconCommand.objects.filter(server=self):
         rcon_command.delete()
     for available_rcon_command in AvailableRconCommand.objects.filter(server=self):
         available_rcon_command.delete()
     config_path = os.path.join(MEDIA_ROOT, 'mods', self.mod.title, 'config.cfg')
     config = TwConfig(config_path)
     config.read()
     for key, value in config.options.iteritems():
         widget = 1  # text
         for widget_type in Option.WIDGET_CHOICES:
             if widget_type[1] == value[1]:
                 widget = widget_type[0]
         data = Option(server=self, command=key, value=value[0], widget=widget)
         data.save()
     for tune in config.tunes:
         data = Tune(server=self, command=tune['command'], value=tune['value'])
         data.save()
     for vote in config.votes:
         data = Vote(server=self, command=vote['command'], title=vote['title'])
         data.save()
     for rcon_command in config.available_rcon_commands:
         data = AvailableRconCommand(server=self, command=rcon_command)
         data.save()
     # copy maps if there are already some
     if old_obj:
         server_maps_path = os.path.join(MEDIA_ROOT, 'mods', old_obj.mod.title, 'servers', old_obj.owner.username, '{0}'.format(old_obj.id), old_obj.random_key, 'maps')
         if os.path.exists(server_maps_path):
             maps = [_file for _file in os.listdir(server_maps_path) if os.path.splitext(_file)[1].lower() == '.map']
             for _map in maps:
                 new_server_maps_path = os.path.join(MEDIA_ROOT, 'mods', self.mod.title, 'servers', self.owner.username, '{0}'.format(self.id), self.random_key, 'maps')
                 if not os.path.exists(new_server_maps_path):
                     os.makedirs(new_server_maps_path)
                 copyfile(os.path.join(server_maps_path, _map), os.path.join(new_server_maps_path, _map))
             rmtree(os.path.join(MEDIA_ROOT, 'mods', old_obj.mod.title, 'servers', old_obj.owner.username))
     # copy default mod maps
     maps_path = os.path.join(MEDIA_ROOT, 'mods', self.mod.title, 'data', 'maps')
     if os.path.exists(maps_path):
         maps = [_file for _file in os.listdir(maps_path) if os.path.splitext(_file)[1].lower() == '.map']
         for _map in maps:
             map_obj = Map.objects.filter(server=self, name=os.path.splitext(_map)[0])
             if not map_obj:
                 map_obj = Map(server=self, name=os.path.splitext(_map)[0])
                 map_obj.save()
                 server_maps_path = os.path.join(MEDIA_ROOT, 'mods', self.mod.title, 'servers', self.owner.username, '{0}'.format(self.id), self.random_key, 'maps')
                 if not os.path.exists(server_maps_path):
                     os.makedirs(server_maps_path)
                 copyfile(os.path.join(maps_path, _map), os.path.join(server_maps_path, _map))
Example #2
0
File: admin.py Project: kolko/upTee
 def save_model(self, request, obj, form, change):
     obj.save()
     if not obj.is_active:
         obj.set_offline()
     if not change:
         mod_path = os.path.join(MEDIA_ROOT, "mods", obj.mod.title)
         config_path = os.path.join(mod_path, "config.cfg")
         config = TwCongig(config_path)
         config.read()
         for key, value in config.options.iteritems():
             widget = 1  # text
             for widget_type in Option.WIDGET_CHOICES:
                 if widget_type[1] == value[1]:
                     widget = widget_type[0]
             data = Option(server=obj, command=key, value=value[0], widget=widget)
             data.save()
         for tune in config.tunes:
             data = Tune(server=obj, command=tune["command"], value=tune["value"])
             data.save()
         for vote in config.votes:
             data = Vote(server=obj, command=vote["command"], title=vote["title"])
             data.save()
     maps_path = os.path.join(MEDIA_ROOT, "mods", obj.mod.title, "data", "maps")
     if os.path.exists(maps_path):
         maps = [_file for _file in os.listdir(maps_path) if os.path.splitext(_file)[1].lower() == ".map"]
         for _map in maps:
             map_obj = Map.objects.filter(server=obj, name=os.path.splitext(_map)[0])
             if not map_obj:
                 map_obj = Map(server=obj, name=os.path.splitext(_map)[0])
                 map_obj.save()
             server_maps_path = os.path.join(
                 MEDIA_ROOT, "mods", obj.mod.title, "servers", obj.owner.username, "{0}".format(obj.id), "maps"
             )
             if not os.path.exists(server_maps_path):
                 os.makedirs(server_maps_path)
             copyfile(os.path.join(maps_path, _map), os.path.join(server_maps_path, _map))
Example #3
0
 def reset_settings(self, old_obj):
     for option in Option.objects.filter(server=self):
         option.delete()
     for tune in Tune.objects.filter(server=self):
         tune.delete()
     for vote in Vote.objects.filter(server=self):
         vote.delete()
     for rcon_command in RconCommand.objects.filter(server=self):
         rcon_command.delete()
     for available_rcon_command in AvailableRconCommand.objects.filter(
             server=self):
         available_rcon_command.delete()
     config_path = os.path.join(MEDIA_ROOT, 'mods', self.mod.title,
                                'config.cfg')
     config = TwConfig(config_path)
     config.read()
     for key, value in config.options.iteritems():
         widget = 1  # text
         for widget_type in Option.WIDGET_CHOICES:
             if widget_type[1] == value[1]:
                 widget = widget_type[0]
         data = Option(server=self,
                       command=key,
                       value=value[0],
                       widget=widget)
         data.save()
     for tune in config.tunes:
         data = Tune(server=self,
                     command=tune['command'],
                     value=tune['value'])
         data.save()
     for vote in config.votes:
         data = Vote(server=self,
                     command=vote['command'],
                     title=vote['title'])
         data.save()
     for rcon_command in config.available_rcon_commands:
         data = AvailableRconCommand(server=self, command=rcon_command)
         data.save()
     # copy maps if there are already some
     if old_obj:
         server_maps_path = os.path.join(MEDIA_ROOT, 'mods',
                                         old_obj.mod.title, 'servers',
                                         old_obj.owner.username,
                                         '{0}'.format(old_obj.id),
                                         old_obj.random_key, 'maps')
         if os.path.exists(server_maps_path):
             maps = [
                 _file for _file in os.listdir(server_maps_path)
                 if os.path.splitext(_file)[1].lower() == '.map'
             ]
             for _map in maps:
                 new_server_maps_path = os.path.join(
                     MEDIA_ROOT, 'mods', self.mod.title, 'servers',
                     self.owner.username, '{0}'.format(self.id),
                     self.random_key, 'maps')
                 if not os.path.exists(new_server_maps_path):
                     os.makedirs(new_server_maps_path)
                 copyfile(os.path.join(server_maps_path, _map),
                          os.path.join(new_server_maps_path, _map))
             rmtree(
                 os.path.join(MEDIA_ROOT, 'mods', old_obj.mod.title,
                              'servers', old_obj.owner.username))
     # copy default mod maps
     maps_path = os.path.join(MEDIA_ROOT, 'mods', self.mod.title, 'data',
                              'maps')
     if os.path.exists(maps_path):
         maps = [
             _file for _file in os.listdir(maps_path)
             if os.path.splitext(_file)[1].lower() == '.map'
         ]
         for _map in maps:
             map_obj = Map.objects.filter(server=self,
                                          name=os.path.splitext(_map)[0])
             if not map_obj:
                 map_obj = Map(server=self, name=os.path.splitext(_map)[0])
                 map_obj.save()
                 server_maps_path = os.path.join(MEDIA_ROOT, 'mods',
                                                 self.mod.title, 'servers',
                                                 self.owner.username,
                                                 '{0}'.format(self.id),
                                                 self.random_key, 'maps')
                 if not os.path.exists(server_maps_path):
                     os.makedirs(server_maps_path)
                 copyfile(os.path.join(maps_path, _map),
                          os.path.join(server_maps_path, _map))
Example #4
0
 def save_config(self, download=False):
     path = os.path.join(MEDIA_ROOT, 'mods', self.mod.title)
     config = TwConfig(
         os.path.join(path, 'servers', self.owner.username,
                      '{0}'.format(self.id), self.random_key,
                      'generated.cfg'))
     for option in self.config_options.all():
         if option.widget == Option.WIDGET_SELECT:
             value = option.value.split(',', 1)[0]
             widget = 'select:{0}'.format(option.value.split(',', 1)[1])
             config.add_option(option.command, value, widget)
         else:
             if download and option.widget == Option.WIDGET_PASSWORD:
                 config.add_option(option.command, '',
                                   option.get_widget_display())
             else:
                 config.add_option(option.command, option.value,
                                   option.get_widget_display())
     if download:
         config.add_option('sv_port', '8303')
     else:
         config.add_option('sv_port', self.port.port)
         config.add_option('ec_port', self.port.port)
         config.add_option('ec_password', 'uptee')
     for tune in self.config_tunes.all():
         config.add_tune(tune.command, tune.value)
     for vote in self.config_votes.all():
         config.add_vote(vote.command, vote.title)
     for rcon_command in self.config_rconcommands.all():
         config.add_rcon_command(rcon_command.command, rcon_command.value)
     config.write()
Example #5
0
 def set_online(self):
     ports = Port.objects.filter(server=self)
     if ports:
         for port in ports:
             server = port.server
             server.set_offline()
     self.port = Port.get_free_port()
     self.port.is_active = True
     self.port.save()
     path = os.path.join(MEDIA_ROOT, 'mods', self.mod.title)
     config = TwConfig(os.path.join(path, 'generated.cfg'))
     for option in self.config_options.all():
         config.add_option(option.command, option.value, option.get_widget_display())
     config.add_option('sv_port', self.port.port)
     for tune in self.config_tunes.all():
         config.add_tune(tune.command, tune.value)
     for vote in self.config_votes.all():
         config.add_vote(vote.command, vote.title)
     config.write()
     with open(os.path.join(path, 'storage.cfg'), 'w') as storage:
         storage.write('add_path servers/{0}/{1}\nadd_path $CURRENTDIR\n'.format(self.owner.username, self.id))
     run_server.delay(path, self)
Example #6
0
 def save_config(self, download=False):
     path = os.path.join(MEDIA_ROOT, 'mods', self.mod.title)
     config = TwConfig(os.path.join(path, 'servers', self.owner.username, '{0}'.format(self.id), self.random_key, 'generated.cfg'))
     for option in self.config_options.all():
         if option.widget == Option.WIDGET_SELECT:
             value = option.value.split(',', 1)[0]
             widget = 'select:{0}'.format(option.value.split(',', 1)[1])
             config.add_option(option.command, value, widget)
         else:
             if download and option.widget == Option.WIDGET_PASSWORD:
                 config.add_option(option.command, '', option.get_widget_display())
             else:
                 config.add_option(option.command, option.value, option.get_widget_display())
     if download:
         config.add_option('sv_port', '8303')
     else:
         config.add_option('sv_port', self.port.port)
         config.add_option('ec_port', self.port.port)
         config.add_option('ec_password', 'uptee')
     for tune in self.config_tunes.all():
         config.add_tune(tune.command, tune.value)
     for vote in self.config_votes.all():
         config.add_vote(vote.command, vote.title)
     for rcon_command in self.config_rconcommands.all():
         config.add_rcon_command(rcon_command.command, rcon_command.value)
     config.write()