def requestAuth(self, params): rules = { 'link': {'not_null': 1, 'min_length': 3}, 'fullname': {'not_null': 1, 'min_length': 3}, 'email': {'not_null': 1}, 'rules': {'not_null': 1} } status = self.checkParams(params, rules) if status['status']: data = { 'twitter_name': self.cur_player['login_name'], 'game_id': self.cur_player['login_id'], 'link': params['link'].strip(), 'fullname': params['fullname'].strip(), 'email': params['email'].strip(), 'time': time.time(), 'additional': formatTextareaInput(params['additional']) } self.model.misc.addAuthRequest(data) self.sbuilder.httpRedirect('/thx?n=ugc_request') else: params.update({'errors': status['errors']})
def addNews(self, params): guild = self.model.guilds.getPlayersGuild(self.cur_player['login_id']) if guild and guild['creator'] == self.cur_player['login_id']: rules = { 'text': {'min_length':3} } status = self.checkParams(params, rules) if status['status']: news_body = { 'header': params['header'].strip(), 'text': formatTextareaInput(params['text']), 'link': params['link'].strip(), 'create_date': time(), 'UID': int(time()), 'author': self.cur_player['login_id'], 'author_name': self.cur_player['login_name'] } self.model.guilds.addNewsToBase(guild['_id'], news_body) return self.sbuilder.redirect('/guilds/story?id='+str(news_body['UID'])) else: return self.sbuilder.redirect('/guilds/addnews?error=true')
def createGuild(self, params): rules = { 'name': {'min_length':3, 'max_length': 21, 'match': self.RE_CHECK_NAME}, 'image_file': {'exist':1} } status = self.checkParams(params, rules) if self.cur_player['login_guild'] != '': return self.sbuilder.redirect('/guilds/'+self.cur_player['login_guild']) if status['status']: is_open_guild = 'closed' in params params['name'] = params['name'].strip() new_guild = self.model.guild({ 'name': params['name'], 'description': formatTextareaInput(params['desc']), 'creator': self.cur_player['login_id'], 'open': not is_open_guild, 'site_link': params['site_link'], 'people_count': 1, 'guild_points': 0, 'people': [self.cur_player['login_id']], 'search_name': params['name'].upper(), 'link_name': re.sub(' ','_', params['name']), 'faction': self.cur_player['login_faction'] }) exist = self.model.guilds.isGuildExist(params['name'].upper()) if exist: return self.sbuilder.redirect('/guilds/add?error=1&name='+params['name']+'&desc='+params['desc']) if 'image_file' in params: avatar = self.uploadImage(new_guild.data, params['image_file']) else: avatar = 'not_uploaded' if 'not_uploaded' in avatar: new_guild.data['img'] = '' elif not 'error' in avatar: new_guild.data['img'] = avatar['link'] else: return {'error':avatar['error']} result = self.model.guilds.addGuild(new_guild.data.copy()) del new_guild if result: return self.sbuilder.redirect('/guilds/'+params['name']) else: return self.sbuilder.redirect('/guilds/add?error=1&name='+params['name']+'&desc='+params['desc']) else: params.update({'operation_result': 'error', 'errors': status['errors']})
def editSpell(self, params): spell = self.getSpell(params, logged_check=True, self_item_check=True) rules = { 'desc': {'min_length':5, 'max_length': 140}, 'cost': {'gt': 0, 'lt': 1000000, 'not_null': 1} } if spell['keyword'] != params['keyword']: rules.update({'keyword': {'gte': 3, 'lte': 20, 'match': self.RE_CHECK_NAME, 'not_dublicate': {'col_spells_crafted_patterns': 'keyword'}}}) if spell['name'] != params['name']: rules.update({'name': {'min_length':3, 'max_length': 40, 'match': self.RE_CHECK_NAME, 'not_dublicate': {'col_spells_crafted_patterns': 'name'}}}) status = self.checkParams(params, rules) if status['status']: cost = int(params['cost']) if cost < 0: cost = 1 new_spell = { 'desc': formatTextareaInput(params['desc']), 'name': params['name'], 'keyword': params['keyword'], 'cost': cost } if params['img'].strip(): new_spell.update({"img": params["img"]}) new_spell.update(self.model.misc.getImageInfo(params)) old_data = {} for key in ['name', 'desc', 'cost', 'keyword', 'img']: if key in new_spell and spell[key] != new_spell[key]: old_data.update({key: spell[key]}) for key in ['link', 'name', 'email', 'twitter']: if key in new_spell['img_info'] and new_spell['img_info'][key] and key in spell['img_info']: old_data.update({'Artwork: '+key: spell['img_info'][key]}) no_need_approve = 'login_admin' in self.cur_player and self.cur_player['login_admin'] or 'login_moderator' in self.cur_player and self.cur_player['login_moderator'] if not no_need_approve: no_need_approve = 'cost' in old_data and len(old_data) == 1 or not old_data else: self.model.misc.writeToLog(self.cur_player['login_id'], { 'action': 'spell edit', 'spell_id': spell['_id'] }) new_spell.update({'old_data': old_data}) self.model.spells.updateSpellData(spell['_id'], new_spell, no_need_approve) self.sbuilder.httpRedirect('/u/spell?id='+params['id']+'&edit=ok') self.sbuilder.httpRedirect('/u/edit_spell?id='+params['id']+'&edit=fail')
def createArtwork(self, params): if self.balance.MIN_LEVEL_TO_CREATE > self.cur_player['login_lvl']: return self.sbuilder.throwWebError(6001) rules = { 'name': {'min_length':3, 'max_length': 40, 'match': self.RE_CHECK_NAME, 'not_dublicate': {'col_artworks': 'name'}}, 'desc': {'min_length':4, 'max_length': 1000}, 'img': {'not_null': 1}, 'race': {'not_null':1}, 'class': {'gte':1, 'lte': 3, 'not_null':1}, 'cost': {'int': 1, 'gt': 0, 'lt': 1000000, 'not_null': 1} } status = self.checkParams(params, rules) if status['status']: buff = params['race'].split(':') if len(buff) == 2: faction_id = int(buff[0]) race_id = int(buff[1]) else: return False cost = int(params['cost']) if cost < 0: cost = 1 artwork = self.model.artwork({ "cost": cost, "img": params["img"], "faction": faction_id, "author": self.cur_player['login_id'], "race": race_id, "desc": formatTextareaInput(params['desc']), "class": int(params['class']), "name": params['name'].strip().title() }) artwork.data.update(self.model.misc.getImageInfo(params)) self.model.misc.addArtwork(artwork.data) self.sbuilder.httpRedirect(self.core.loaded_data['site_address']+'/u/creation_center?creation=ok&type=artwork') else: params.update({'errors': status['errors']})
def requestAuth(self, params): rules = { 'link': { 'not_null': 1, 'min_length': 3 }, 'fullname': { 'not_null': 1, 'min_length': 3 }, 'email': { 'not_null': 1 }, 'rules': { 'not_null': 1 } } status = self.checkParams(params, rules) if status['status']: data = { 'twitter_name': self.cur_player['login_name'], 'game_id': self.cur_player['login_id'], 'link': params['link'].strip(), 'fullname': params['fullname'].strip(), 'email': params['email'].strip(), 'time': time.time(), 'additional': formatTextareaInput(params['additional']) } self.model.misc.addAuthRequest(data) self.sbuilder.httpRedirect('/thx?n=ugc_request') else: params.update({'errors': status['errors']})
def changeSettings(self, param): guild = self.model.guilds.getGuildByName(self.cur_player['login_guild']) rules = { 'description': {}, 'site_link': {} } status = self.checkParams(param, rules) updated_fields = {} if 'image_file' in param: new_avatar = self.uploadImage(guild, param['image_file']) if 'error' in new_avatar: status = self.thrownCheckError('image', 'oops') if not 'error' in new_avatar and not 'not_uploaded' in new_avatar: updated_fields.update({'img':new_avatar['link']}) if status['status']: param['site_link'] = re.sub('.*\:\/\/','',param['site_link']) param['description'] = formatTextareaInput(param['description']) type_of_membership = not 'closed' in param updated_fields.update({ 'open': type_of_membership, 'description': param['description'], 'site_link' : param['site_link'] }) self.model.guilds.changeSettings(guild['_id'], updated_fields) self.httpRedirect(param, '?success=ok')
def editArtwork(self, params): artwork = self.getArtwork(params, logged_check=True, self_item_check=True) rules = { 'desc': { 'min_length': 4, 'max_length': 1000 }, 'race': { 'not_null': 1 }, 'class': { 'gte': 1, 'lte': 3, 'not_null': 1 }, 'cost': { 'int': 1, 'gt': 0, 'lt': 1000000, 'not_null': 1 } } if artwork['name'] != params['name']: rules.update({ 'name': { 'min_length': 3, 'max_length': 40, 'match': self.RE_CHECK_NAME, 'not_dublicate': { 'col_artworks': 'name' } } }) status = self.checkParams(params, rules) if status['status']: buff = params['race'].split(':') if len(buff) == 2: faction_id = int(buff[0]) race_id = int(buff[1]) else: return False cost = int(params['cost']) if cost < 0: cost = 1 new_artwork_data = { "cost": cost, "faction": faction_id, "race": race_id, "desc": formatTextareaInput(params['desc']), "class": int(params['class']), "name": params['name'].strip() } if params['img'].strip(): new_artwork_data.update({"img": params["img"]}) new_artwork_data.update(self.model.misc.getImageInfo(params)) old_data = {} for key in [ 'name', 'desc', 'cost', 'race', 'class', 'faction', 'img' ]: if key in new_artwork_data and new_artwork_data[ key] != artwork[key]: old_data.update({key: artwork[key]}) for key in ['link', 'name', 'email', 'twitter']: if key in new_artwork_data['img_info'] and new_artwork_data[ 'img_info'][key] and key in artwork['img_info']: old_data.update( {'Artwork: ' + key: artwork['img_info'][key]}) no_need_approve = 'login_admin' in self.cur_player and self.cur_player[ 'login_admin'] or 'login_moderator' in self.cur_player and self.cur_player[ 'login_moderator'] if not no_need_approve: no_need_approve = 'cost' in old_data and len( old_data) == 1 or not old_data else: self.model.misc.writeToLog(self.cur_player['login_id'], { 'action': 'artwork edit', 'artwork_id': artwork['_id'] }) new_artwork_data.update({'old_data': old_data}) self.model.misc.updateArtworkData(artwork['_id'], new_artwork_data, no_need_approve) self.sbuilder.httpRedirect('/u/artwork?id=' + params['id'] + '&edit=ok') self.sbuilder.httpRedirect('/u/edit_artwork?id=' + params['id'] + '&edit=fail')
def createArtwork(self, params): if self.balance.MIN_LEVEL_TO_CREATE > self.cur_player['login_lvl']: return self.sbuilder.throwWebError(6001) rules = { 'name': { 'min_length': 3, 'max_length': 40, 'match': self.RE_CHECK_NAME, 'not_dublicate': { 'col_artworks': 'name' } }, 'desc': { 'min_length': 4, 'max_length': 1000 }, 'img': { 'not_null': 1 }, 'race': { 'not_null': 1 }, 'class': { 'gte': 1, 'lte': 3, 'not_null': 1 }, 'cost': { 'int': 1, 'gt': 0, 'lt': 1000000, 'not_null': 1 } } status = self.checkParams(params, rules) if status['status']: buff = params['race'].split(':') if len(buff) == 2: faction_id = int(buff[0]) race_id = int(buff[1]) else: return False cost = int(params['cost']) if cost < 0: cost = 1 artwork = self.model.artwork({ "cost": cost, "img": params["img"], "faction": faction_id, "author": self.cur_player['login_id'], "race": race_id, "desc": formatTextareaInput(params['desc']), "class": int(params['class']), "name": params['name'].strip().title() }) artwork.data.update(self.model.misc.getImageInfo(params)) self.model.misc.addArtwork(artwork.data) self.sbuilder.httpRedirect( self.core.loaded_data['site_address'] + '/u/creation_center?creation=ok&type=artwork') else: params.update({'errors': status['errors']})
def editArtwork(self, params): artwork = self.getArtwork(params, logged_check=True, self_item_check=True) rules = { 'desc': {'min_length':4, 'max_length': 1000}, 'race': {'not_null': 1}, 'class': {'gte':1, 'lte': 3, 'not_null':1}, 'cost': {'int': 1, 'gt': 0, 'lt': 1000000, 'not_null': 1} } if artwork['name'] != params['name']: rules.update({'name': {'min_length':3, 'max_length': 40, 'match': self.RE_CHECK_NAME, 'not_dublicate': {'col_artworks': 'name'}}}) status = self.checkParams(params, rules) if status['status']: buff = params['race'].split(':') if len(buff) == 2: faction_id = int(buff[0]) race_id = int(buff[1]) else: return False cost = int(params['cost']) if cost < 0: cost = 1 new_artwork_data = { "cost": cost, "faction": faction_id, "race": race_id, "desc": formatTextareaInput(params['desc']), "class": int(params['class']), "name": params['name'].strip() } if params['img'].strip(): new_artwork_data.update({"img": params["img"]}) new_artwork_data.update(self.model.misc.getImageInfo(params)) old_data = {} for key in ['name', 'desc', 'cost', 'race', 'class', 'faction', 'img']: if key in new_artwork_data and new_artwork_data[key] != artwork[key]: old_data.update({key: artwork[key]}) for key in ['link', 'name', 'email', 'twitter']: if key in new_artwork_data['img_info'] and new_artwork_data['img_info'][key] and key in artwork['img_info']: old_data.update({'Artwork: '+key: artwork['img_info'][key]}) no_need_approve = 'login_admin' in self.cur_player and self.cur_player['login_admin'] or 'login_moderator' in self.cur_player and self.cur_player['login_moderator'] if not no_need_approve: no_need_approve = 'cost' in old_data and len(old_data) == 1 or not old_data else: self.model.misc.writeToLog(self.cur_player['login_id'], { 'action': 'artwork edit', 'artwork_id': artwork['_id'] }) new_artwork_data.update({'old_data': old_data}) self.model.misc.updateArtworkData(artwork['_id'], new_artwork_data, no_need_approve) self.sbuilder.httpRedirect('/u/artwork?id='+params['id']+'&edit=ok') self.sbuilder.httpRedirect('/u/edit_artwork?id='+params['id']+'&edit=fail')
def addNewEvent(self, params): def getHashtag(value): hashtag = value.strip() if hashtag: if hashtag[0] == '#': hashtag = hashtag[1:] return hashtag else: return False rules = { 'desc': {}, 'start_date': {}, 'event_type': { 'in': ['war', 'raid', 'attack'] } } status = self.checkParams(params, rules) if status['status']: try: start_time_wutc = time.mktime( datetime.strptime(params['start_date'], "%d.%m.%Y %H:%M").timetuple()) except Exception: start_time_wutc = 0 start_time = start_time_wutc + self.core.server_utc_offset - self.cur_player[ 'login_utc_offset'] if start_time < time.time(): start_time = time.time() + 3600 event = self.model.event({ 'type': params['event_type'], 'author': self.cur_player['login_id'], 'guild_run': 'guild_run' in params, 'desc': formatTextareaInput(params['desc']), 'start_date': start_time, 'create_date': time.time(), 'status': 'active', 'faction': self.cur_player['login_faction'], 'people': [self.cur_player['login_id']] }) if 'hashtag' in params: event.data.update( {'promoted_hashtag': getHashtag(params['hashtag'])}) add_guild_data = False if params['event_type'] == 'raid': target = self.model.events.getRaidDungeonById( int(params['where'])) event.data.update({ 'target': int(params['where']), 'target_name': target['name'], 'lvl_min': target['lvl_min'], 'lvl_max': target['lvl_max'], 'position': target['position'] }) finish_time = self.balance.LENGTH_OF_RAID if 'guild_run' in params: add_guild_data = True elif params['event_type'] == 'war': target = self.model.guilds.getGuildByName( params['vs_guild'], type_of_name='search_name') if target: raw_coords = sample(self.sbuilder.balance.GVG_POINTS, 1)[0] event.data.update({ 'target': target['_id'], 'target_name': target['name'], 'position': { 'x': raw_coords[0], 'y': raw_coords[1] } }) else: self.httpRedirect(params, '?fail=1&n=no_guild') add_guild_data = True finish_time = self.balance.LENGTH_OF_WAR else: finish_time = 0 if add_guild_data: self_guild = self.model.guilds.getPlayersGuild( self.cur_player['login_id']) if self_guild: if event.data[ 'type'] == 'war' and not self.canCreateGvGEvent( self_guild, self.cur_player['login_id']): self.httpRedirect(params, '?fail=1&n=cant_create') event.data.update({ 'guild_side': self_guild['_id'], 'guild_side_name': self_guild['name'] }) if event.data['type'] == 'war' and event.data[ 'target'] == self_guild['_id']: self.httpRedirect(params, '?fail=1&n=your_guild') else: self.httpRedirect(params, '?fail=1&n=no_guild') event.data['finish_date'] = start_time + finish_time is_available = self.isAvailableToJoinEvent(start_time) if params['event_type'] == 'war' and is_available['result']: reach_max = self.model.events.getPlayerCreatedGuildEventsCount( self.cur_player['login_id'] ) >= self.sbuilder.balance.MAX_GVG_CREATED if reach_max: is_available = { 'result': False, 'error': 'cant_create_more_gvg' } if is_available['result']: self.model.events.addNewEvent(event.data) self.updatePlayerDirection(self, self.cur_player['login_id'], event.data) event_id = self.model.events.getEventID( self.cur_player['login_id'], event.data['create_date']) params['__page__'] = '/events/' + str(event_id) self.httpRedirect(params, '?success=0') else: self.httpRedirect(params, '?fail=1&n=' + is_available['error'])
def createSpellPattern(self, params): def getSpellActionsFormatted(params): spell_actions = [] for param_number in [1,2,3]: param = 'action'+str(param_number) if param in params and params[param] != '': try: param_id = int(params[param]) value = int(params['action1_value'][param_number-1]) except Exception: param_id = False if param_id: spell_actions.append({ 'UID': param_id, 'value': value }) _ids = [] for action in spell_actions: _ids.append(action['UID']) active_actions = self.model.spells.getSpellActionsByID(_ids) result = [] for action in spell_actions: for active in active_actions: if int(action['UID']) == active['UID']: result.append({ 'UID': int(action['UID']), 'value': action['value'], 'effect': active['effect'], 'power': active['power'], 'type': active['type'], 'name': active['name'], 'img': active['img'], 'effect_desc': active['effect_desc'], '_misc': { 'restriction': active['restriction_by_lvl'], 'cost': active['cost_by_effect'] } }) return result def isEnoughResources(params, cost): return self.cur_player['login_resources']['prg'] >= cost if self.balance.MIN_LEVEL_TO_CREATE > self.cur_player['login_lvl']: return self.sbuilder.throwWebError(6001) rules = { 'name': {'min_length':3, 'max_length': 40, 'match': self.RE_CHECK_NAME, 'not_dublicate': {'col_spells_crafted_patterns': 'name'}}, 'desc': {'min_length':5, 'max_length': 140}, 'img': {}, 'cost': {'gt': 0, 'lt': 1000000, 'not_null': 1}, 'lvl': {'gt': 0, 'lte': int(self.cur_player['login_lvl'])}, 'action1': {}, 'keyword': {'gte': 3, 'lte': 20, 'match': self.RE_CHECK_NAME, 'not_dublicate': {'col_spells_crafted_patterns': 'keyword'}}, 'action1_value': {'not_null': 1} } status = self.checkParams(params, rules) if status['status']: cost = int(params['cost']) if cost < 0: cost = 1 spell_pattern = self.model.craftedSpellPattern({ 'img': params['img'], 'lvl_min': int(params['lvl']), 'lvl_max': self.balance.max_lvl, 'desc': formatTextareaInput(params['desc']), 'name': params['name'].strip().title(), 'author': self.cur_player['login_id'], 'keyword': params['keyword'], 'cost': cost }) spell_pattern.data.update(self.model.misc.getImageInfo(params)) # Проверяем эффекты spell_actions = getSpellActionsFormatted(params) cost_parch = len(spell_actions) if not isEnoughResources(params, cost_parch): self.thrownCheckError('Not enough parchment', 'There are no parchment to craft spell') if spell_actions: total_cost = 0 for spell_action in spell_actions: if spell_action['_misc']['restriction']*self.cur_player['login_lvl'] < spell_action['value']: self.thrownCheckError('Spell effect error', 'Restriction error') total_cost += (spell_action['_misc']['cost']*spell_action['value']) del spell_action['_misc'] spell_pattern.data.update({ 'mana_cost': total_cost, 'spell_actions': spell_actions }) if not spell_actions or total_cost == 0: self.thrownCheckError('No effects', 'There are no effects') self.model.spells.createSpellPattern(self.cur_player['login_id'], spell_pattern.data, cost_parch) params.update({'operation': 'add_spell', 'operation_result': 'ok'}) self.sbuilder.httpRedirect(self.core.loaded_data['site_address']+'/u/creation_center?creation=ok&type=spell') else: params.update({'operation': 'add_spell', 'operation_result': 'error', 'errors': status['errors']})
def addNewEvent(self, params): def getHashtag(value): hashtag = value.strip() if hashtag: if hashtag[0] == '#': hashtag = hashtag[1:] return hashtag else: return False rules = { 'desc': {}, 'start_date': {}, 'event_type': {'in': ['war', 'raid', 'attack']} } status = self.checkParams(params, rules) if status['status']: try: start_time_wutc = time.mktime(datetime.strptime(params['start_date'], "%d.%m.%Y %H:%M").timetuple()) except Exception: start_time_wutc = 0 start_time = start_time_wutc + self.core.server_utc_offset - self.cur_player['login_utc_offset'] if start_time < time.time(): start_time = time.time() + 3600 event = self.model.event({ 'type': params['event_type'], 'author': self.cur_player['login_id'], 'guild_run': 'guild_run' in params, 'desc': formatTextareaInput(params['desc']), 'start_date': start_time, 'create_date': time.time(), 'status': 'active', 'faction': self.cur_player['login_faction'], 'people': [self.cur_player['login_id']] }) if 'hashtag' in params: event.data.update({'promoted_hashtag': getHashtag(params['hashtag'])}) add_guild_data = False if params['event_type'] == 'raid': target = self.model.events.getRaidDungeonById(int(params['where'])) event.data.update({ 'target': int(params['where']), 'target_name': target['name'], 'lvl_min': target['lvl_min'], 'lvl_max': target['lvl_max'], 'position': target['position'] }) finish_time = self.balance.LENGTH_OF_RAID if 'guild_run' in params: add_guild_data = True elif params['event_type'] == 'war': target = self.model.guilds.getGuildByName(params['vs_guild'], type_of_name='search_name') if target: raw_coords = sample(self.sbuilder.balance.GVG_POINTS, 1)[0] event.data.update({ 'target': target['_id'], 'target_name': target['name'], 'position': {'x': raw_coords[0], 'y': raw_coords[1]} }) else: self.httpRedirect(params, '?fail=1&n=no_guild') add_guild_data = True finish_time = self.balance.LENGTH_OF_WAR else: finish_time = 0 if add_guild_data: self_guild = self.model.guilds.getPlayersGuild(self.cur_player['login_id']) if self_guild: if event.data['type'] == 'war' and not self.canCreateGvGEvent(self_guild, self.cur_player['login_id']): self.httpRedirect(params, '?fail=1&n=cant_create') event.data.update({ 'guild_side': self_guild['_id'], 'guild_side_name': self_guild['name'] }) if event.data['type'] == 'war' and event.data['target'] == self_guild['_id']: self.httpRedirect(params, '?fail=1&n=your_guild') else: self.httpRedirect(params, '?fail=1&n=no_guild') event.data['finish_date'] = start_time + finish_time is_available = self.isAvailableToJoinEvent(start_time) if params['event_type'] == 'war' and is_available['result']: reach_max = self.model.events.getPlayerCreatedGuildEventsCount(self.cur_player['login_id']) >= self.sbuilder.balance.MAX_GVG_CREATED if reach_max: is_available = { 'result': False, 'error': 'cant_create_more_gvg' } if is_available['result']: self.model.events.addNewEvent(event.data) self.updatePlayerDirection(self, self.cur_player['login_id'], event.data) event_id = self.model.events.getEventID(self.cur_player['login_id'], event.data['create_date']) params['__page__'] = '/events/'+str(event_id) self.httpRedirect(params, '?success=0') else: self.httpRedirect(params, '?fail=1&n='+is_available['error'])
def addNewItem(self, params): def isEnoughResources(params): is_enough = self.cur_player['login_resources']['ore'] >= self.balance.ORE_COST_PER_ITEM if 'rune' in params: is_enough = is_enough and self.cur_player['login_resources']['eore'] >= int(params['rune']) return is_enough if self.balance.MIN_LEVEL_TO_CREATE > self.cur_player['login_lvl']: return self.sbuilder.throwWebError(6001) try: min_cost = self.balance.getItemMinCost({'lvl': int(params['level'])}) except Exception: min_cost = self.balance.getItemMinCost({'lvl': self.cur_player['login_lvl']}) rules = { 'name': {'min_length':3, 'max_length': 40, 'match': self.RE_CHECK_NAME, 'not_dublicate': {'col_crafted': 'name'}}, 'desc': {'min_length':4, 'max_length': 1000}, 'img': {'not_null': 1}, 'level': {'gt': 0, 'not_null':1, 'int': 1}, 'item_type': {'not_null':1}, 'cost': {'int': 1, 'gt': min_cost-1, 'lt': 1000000 ,'not_null': 1} } status = self.checkParams(params, rules) if status['status']: if isEnoughResources(params): crafted_item = self.model.crafted_item() original_file = self.sbuilder.core_settings.APP_DIR+self.sbuilder.core_settings.TEMPLATES_FOLDER+params['img'] if os.path.exists(original_file): dest_file_name = original_file.split("/")[-1] dest_file = self.sbuilder.core_settings.APP_DIR+self.sbuilder.core_settings.TEMPLATES_FOLDER+self.sbuilder.core_settings.IMAGE_BUFFER_FOLDER+dest_file_name shutil.copyfile(original_file,dest_file) os.unlink(original_file) params['img'] = self.sbuilder.core_settings.RESIZED_IMG_PATH+'items/'+dest_file_name else: params['img'] = "" cost = int(params['cost']) if cost < min_cost-1: cost = min_cost crafted_item.data.update({ 'name': params['name'].strip().title(), 'desc': formatTextareaInput(params['desc']), 'author': self.cur_player['login_id'], 'img': params['img'], 'cost': cost, 'lvl_min': int(params['level']), 'lvl_max': self.balance.max_lvl, }) crafted_item.data.update(self.model.misc.getImageInfo(params)) item_type_data = params['item_type'].split(':') if len(item_type_data) > 1: crafted_item.data['type'] = int(item_type_data[0]) crafted_item.data['view'] = item_type_data[1] else: crafted_item.data['type'] = int(params['item_type']) crafted_item.data['view'] = self.balance.item_types[int(params['item_type'])] bonus = {} total_max_bonus = int(self.cur_player['login_lvl'])*2+10 total_value = 0 for key in ['str', 'dex', 'int', 'luck', 'DEF', 'DMG', 'HP', 'MP']: try: value = int(params[key]) except Exception: value = 0 if value != 0: total_value += value bonus.update({key: value}) if total_value <= total_max_bonus: crafted_item.data.update({'bonus': bonus}) if 'rune' in params: eore_added = int(params['rune']) else: eore_added = False self.model.items.addCraftedItem(self.cur_player['login_id'], crafted_item.data, eore_added) params.update({'operation': 'add_item', 'operation_result': 'ok'}) self.sbuilder.httpRedirect(self.core.loaded_data['site_address']+'/u/creation_center?creation=ok&type=item') else: params.update({'operation': 'add_item', 'operation_result': 'error', 'errors': status['errors']}) else: params.update({'operation': 'add_item', 'operation_result': 'error', 'errors': status['errors']}) else: params.update({'operation': 'add_item', 'operation_result': 'error', 'errors': status['errors']})
def editItem(self, params): item = self.getItem(params, logged_check=True, self_item_check=True) min_cost = self.balance.getItemMinCost({'lvl': item['lvl_min']}) rules = { 'desc': {'min_length':4, 'max_length': 1000}, 'item_type': {'not_null':1}, 'cost': {'int': 1, 'gt': min_cost-1, 'lt': 1000000 ,'not_null': 1} } if item['name'] != params['name']: rules.update({'name': {'min_length':3, 'max_length': 40, 'match': self.RE_CHECK_NAME, 'not_dublicate': {'col_crafted': 'name'}}}) status = self.checkParams(params, rules) if status['status']: new_item_data = {} item_type_data = params['item_type'].split(':') if len(item_type_data) > 1: new_item_data['type'] = int(item_type_data[0]) new_item_data['view'] = item_type_data[1] else: new_item_data['type'] = int(params['item_type']) new_item_data['view'] = self.balance.item_types[int(params['item_type'])] cost = int(params['cost']) if cost < min_cost-1: cost = min_cost try: original_file = self.sbuilder.core_settings.APP_DIR+self.sbuilder.core_settings.TEMPLATES_FOLDER+params['img'] if os.path.exists(original_file): dest_file_name = original_file.split("/")[-1] dest_file = self.sbuilder.core_settings.APP_DIR+self.sbuilder.core_settings.TEMPLATES_FOLDER+self.sbuilder.core_settings.IMAGE_BUFFER_FOLDER+dest_file_name shutil.copyfile(original_file,dest_file) os.unlink(original_file) new_item_data.update({'img':self.sbuilder.core_settings.RESIZED_IMG_PATH+'items/'+dest_file_name}) except Exception: pass new_item_data.update({ 'name': params['name'].strip(), 'desc': formatTextareaInput(params['desc']), 'cost': cost }) new_item_data.update(self.model.misc.getImageInfo(params)) old_data = {} for key in ['name', 'desc', 'cost', 'type', 'img']: if key in new_item_data and new_item_data[key] != item[key]: old_data.update({key: item[key]}) for key in ['link', 'name', 'email', 'twitter']: if key in new_item_data['img_info'] and new_item_data['img_info'][key] and key in item['img_info']: old_data.update({'Artwork: '+key: item['img_info'][key]}) no_need_approve = 'login_admin' in self.cur_player and self.cur_player['login_admin'] or 'login_moderator' in self.cur_player and self.cur_player['login_moderator'] if not no_need_approve: no_need_approve = 'cost' in old_data and len(old_data) == 1 or not old_data else: self.model.misc.writeToLog(self.cur_player['login_id'], { 'action': 'item edit', 'item_id': item['_id'] }) new_item_data.update({'old_data': old_data}) self.model.items.updateItemData(item['_id'], new_item_data, no_need_approve) self.sbuilder.httpRedirect('/u/item?id='+params['id']+'&edit=ok') self.sbuilder.httpRedirect('/u/edit_item?id='+params['id']+'&edit=fail')