def setUp(self): char_initialize(1, 1, 1, 'a') self.char_id = 1 self.session = crypto.encrypt('1:1:{0}'.format(self.char_id)) char_initialize(2, 1, 2, 'b') self.char_two_id = 2 self.char_two_session = crypto.encrypt('1:1:{0}'.format(self.char_two_id))
def setUp(self): char_initialize(1, 1, 1, 'a') self.char_id = 1 self.session = crypto.encrypt('1:1:{0}'.format(self.char_id)) char_initialize(2, 1, 2, 'b') self.char_two_id = 2 self.char_two_session = crypto.encrypt('1:1:{0}'.format( self.char_two_id))
def setUp(self): char = char_initialize(1, 1, 1, "a") self.char_id = 1 self.session = crypto.encrypt("1:1:{0}".format(self.char_id)) id_range = save_hero(self.char_id, 1).id_range self.hero_id = id_range[0]
def setUp(self): char = char_initialize(1, 1, 1, 'a') self.char_id = 1 self.session = crypto.encrypt('1:1:{0}'.format(self.char_id)) id_range = save_hero(self.char_id, 1).id_range self.hero_id = id_range[0]
def login(request): req = request._proto try: account_data = make_account_dict_from_message(req.login) except Exception as e: raise SanguoException(errormsg.BAD_MESSAGE, 0, 'Login', e.args[0]) account_data['server_id'] = server.id try: res = api_account_login(data=account_data) except APIFailure: raise SanguoException(errormsg.SERVER_FAULT, 0, 'Login', 'APIFailure. api_account_login') if res['ret'] != 0: raise SanguoException( res['ret'], 0, 'Login', 'login, api_account_login, ret = {0}'.format(res['ret'])) account_id = res['data']['account_id'] char_id = res['data']['char_id'] new_token = res['data']['new_token'] request._account_id = account_id request._server_id = server.id login_signal.send( sender=None, char_id=char_id, real_login=True, ) if char_id: request._char_id = char_id else: request._char_id = None session = GameSession(request._account_id, request._server_id, request._char_id) if char_id: Player(char_id).set_login_id(session.login_id) request._game_session = session session = crypto.encrypt(session_dumps(session)) response = StartGameResponse() response.ret = 0 response.login.MergeFrom(make_login_response_msg(req.login, new_token)) response.need_create_new_char = char_id == 0 sync = SyncResponse() sync.ret = 0 sync.utc_timestamp = arrow.utcnow().timestamp return [pack_msg(response, session), pack_msg(sync)]
def update(self, instance, validated_data): ''' ''' if 'password' in validated_data: # instance.password =crypto.encrypt(validated_data.get('password', instance.password).encode()) instance.password =crypto.encrypt(validated_data.get('password').encode()) instance.save() return instance
def setUp(self): char_initialize(1, 1, 1, 'a') self.char_id = 1 self.session = crypto.encrypt('1:1:{0}'.format(self.char_id)) item = Item(self.char_id) eid = item.equip_add(1) self.equip_id = eid gems = [(1, 10), (2, 1)] item.gem_add(gems)
def create_character(request): req = request._proto data = { 'account_id': request._account_id, 'server_id': server.id, 'name': req.name } res = api_character_create(data) if res['ret'] != 0: raise SanguoException( res['ret'], 0, 'Character Create', 'api_character_create, ret = {0}'.format(res['ret']) ) char_id = res['data']['char_id'] try: char_initialize(request._account_id, server.id, char_id, req.name) except Exception as e: data = { 'char_id': char_id, } api_character_failure(data) raise e login_signal.send( sender=None, char_id=char_id, real_login=True, ) request._char_id = char_id game_session = request._game_session game_session.char_id = char_id new_session = crypto.encrypt(session_dumps(game_session)) Player(char_id).set_login_id(game_session.login_id) response = CreateCharacterResponse() response.ret = 0 return pack_msg(response, new_session)
def create_character(request): req = request._proto data = { 'account_id': request._account_id, 'server_id': server.id, 'name': req.name } try: res = api_character_create(data) except APIFailure: raise SanguoException( errormsg.SERVER_FAULT, 0, 'Character Create', 'APIFailure, api_character_create' ) if res['ret'] != 0: raise SanguoException( res['ret'], 0, 'Character Create', 'api_character_create, ret = {0}'.format(res['ret']) ) char_id = res['data']['char_id'] login_signal.send( sender=None, char_id=char_id ) request._char_id = char_id game_session = request._game_session game_session.char_id = char_id new_session = crypto.encrypt(session_dumps(game_session)) Player(char_id).set_login_id(game_session.login_id) response = CreateCharacterResponse() response.ret = 0 return pack_msg(response, new_session)
def resume(request): sync = SyncResponse() sync.ret = 0 sync.utc_timestamp = arrow.utcnow().timestamp login_signal.send( sender=None, char_id=request._char_id, ) new_session = GameSession(request._account_id, request._server_id, request._char_id) encrypted_session = crypto.encrypt(session_dumps(new_session)) Player(request._char_id).set_login_id(new_session.login_id) response = ResumeResponse() response.ret = 0 return [pack_msg(response, encrypted_session), pack_msg(sync)]
def create_character(request): req = request._proto data = { 'account_id': request._account_id, 'server_id': server.id, 'name': req.name } res = api_character_create(data) if res['ret'] != 0: raise SanguoException( res['ret'], 0, 'Character Create', 'api_character_create, ret = {0}'.format(res['ret'])) char_id = res['data']['char_id'] try: char_initialize(request._account_id, server.id, char_id, req.name) except Exception as e: data = { 'char_id': char_id, } api_character_failure(data) raise e login_signal.send( sender=None, char_id=char_id, real_login=True, ) request._char_id = char_id game_session = request._game_session game_session.char_id = char_id new_session = crypto.encrypt(session_dumps(game_session)) Player(char_id).set_login_id(game_session.login_id) response = CreateCharacterResponse() response.ret = 0 return pack_msg(response, new_session)
def resume(request): req = request._proto sync = SyncResponse() sync.ret = 0 sync.utc_timestamp = timezone.utc_timestamp() login_signal.send( sender=None, account_id=request._account_id, server_id=request._server_id, char_id=request._char_id, ) new_session = '%d:%d:%d' % (request._account_id, req.server_id, request._char_id) new_session = crypto.encrypt(new_session) response = ResumeResponse() response.ret = 0 return [pack_msg(response, new_session), pack_msg(sync)]
def validate(self, data): """ To validated email and password. """ pattern = "^(?!\.)[^. \n]+$" valid_password = re.findall(pattern, data['password']) """ If Valid Passwod is Empty.! when password contain space or any spacial charactre in first. """ if not valid_password: raise serializers.ValidationError('Invalid Password') try: user = User.objects.get( email = data["email"], password = crypto.encrypt(data["password"].encode()) ) except: raise serializers.ValidationError('Invalid Credential') return data
def before_request(): request.is_admin = False auth = request.cookies.get('auth') # print(auth) if auth is not None: plain = decrypt(auth).decode() print(plain) if plain == 0: raise AuthExcp(500, "invalid auth") try: j = json.loads(plain) except Exception as e: print(e) raise AuthExcp(500, "invalid json") request.is_admin = j["admin"] if not j["admin"]: raise AuthExcp(500, "Are you the manager?") else: j = {"uid": 100, "admin": False} resp = redirect('/') resp.set_cookie("auth", encrypt(json.dumps(j))) return resp
def setUp(self): char_initialize(1, 1, 1, 'a') self.char_id = 1 self.session = crypto.encrypt('1:1:{0}'.format(self.char_id)) self.item = Item(self.char_id) self.equip_id = self.item.equip_add(1)
def setUp(self): char_initialize(1, 1, 1, 'a') self.session = crypto.encrypt('1:1:{0}'.format(1))
def login(request): req = request._proto data = {} data['server_id'] = req.server_id if req.regular.email: data['method'] = 'regular' data['name'] = req.regular.email data['password'] = req.regular.password else: data['method'] = 'anonymous' data['token'] = req.anonymous.device_token try: res = api_account_login(data) except APIFailure: raise SanguoException(errormsg.SERVER_FAULT, 0, 'Login', 'APIFailure. api_account_login') if res['ret'] != 0: raise SanguoException( res['ret'], 0, 'Login', 'login, api_account_login, ret = {0}'.format(res['ret'])) account_id = res['data']['account_id'] char_id = res['data']['char_id'] new_token = res['data']['new_token'] request._account_id = account_id request._server_id = req.server_id login_signal.send(sender=None, account_id=request._account_id, server_id=request._server_id, char_id=char_id) if char_id: request._char_id = char_id session_str = '{0}:{1}:{2}'.format(request._account_id, request._server_id, request._char_id) else: request._char_id = None session_str = '{0}:{1}'.format(request._account_id, request._server_id) session = crypto.encrypt(session_str) response = StartGameResponse() response.ret = 0 if req.regular.email: response.regular.MergeFrom(req.regular) else: response.anonymous.device_token = str(new_token) response.need_create_new_char = char_id == 0 sync = SyncResponse() sync.ret = 0 sync.utc_timestamp = timezone.utc_timestamp() return [pack_msg(response, session), pack_msg(sync)]
def setUp(self): char_initialize(1, 1, 1, 'a') self.char_id = 1 self.session = crypto.encrypt('1:1:{0}'.format(self.char_id)) self.panel = HeroPanel(self.char_id)
def setUp(self): char_initialize(1, 1, 1, 'a') self.session = crypto.encrypt('1:1:{0}'.format(1)) char = char_initialize(2, 1, 2, 'b') self.other_char_id = 2
def validate(self, data): # print(crypto.encrypt(b'rajuna')) extra = {'password':crypto.encrypt(generate_pass.generatePass().encode())} data.update(extra) return data
def login(request): req = request._proto try: account_data = make_account_dict_from_message(req.login) except Exception as e: raise SanguoException( errormsg.BAD_MESSAGE, 0, 'Login', e.args[0] ) account_data['server_id'] = server.id try: res = api_account_login(data=account_data) except APIFailure: raise SanguoException( errormsg.SERVER_FAULT, 0, 'Login', 'APIFailure. api_account_login' ) if res['ret'] != 0: raise SanguoException( res['ret'], 0, 'Login', 'login, api_account_login, ret = {0}'.format(res['ret']) ) account_id = res['data']['account_id'] char_id = res['data']['char_id'] new_token = res['data']['new_token'] request._account_id = account_id request._server_id = server.id login_signal.send( sender=None, char_id=char_id ) if char_id: request._char_id = char_id else: request._char_id = None session = GameSession(request._account_id, request._server_id, request._char_id) if char_id: Player(char_id).set_login_id(session.login_id) request._game_session = session session = crypto.encrypt(session_dumps(session)) response = StartGameResponse() response.ret = 0 response.login.MergeFrom(make_login_response_msg(req.login, new_token)) response.need_create_new_char = char_id == 0 sync = SyncResponse() sync.ret = 0 sync.utc_timestamp = arrow.utcnow().timestamp return [pack_msg(response, session), pack_msg(sync)]
def setUp(self): char_initialize(1, 1, 1, "a") self.char_id = 1 self.session = crypto.encrypt("1:1:{0}".format(self.char_id)) self.panel = HeroPanel(self.char_id)
def login(request): req = request._proto data = {} data['server_id'] = req.server_id if req.regular.email: data['method'] = 'regular' data['name'] = req.regular.email data['password'] = req.regular.password else: data['method'] = 'anonymous' data['token'] = req.anonymous.device_token try: res = api_account_login(data) except APIFailure: raise SanguoException( errormsg.SERVER_FAULT, 0, 'Login', 'APIFailure. api_account_login' ) if res['ret'] != 0: raise SanguoException( res['ret'], 0, 'Login', 'login, api_account_login, ret = {0}'.format(res['ret']) ) account_id = res['data']['account_id'] char_id = res['data']['char_id'] new_token = res['data']['new_token'] request._account_id = account_id request._server_id = req.server_id login_signal.send( sender=None, account_id=request._account_id, server_id=request._server_id, char_id=char_id ) if char_id: request._char_id = char_id session_str = '{0}:{1}:{2}'.format( request._account_id, request._server_id, request._char_id ) else: request._char_id = None session_str = '{0}:{1}'.format(request._account_id, request._server_id) session = crypto.encrypt(session_str) response = StartGameResponse() response.ret = 0 if req.regular.email: response.regular.MergeFrom(req.regular) else: response.anonymous.device_token = str(new_token) response.need_create_new_char = char_id == 0 sync = SyncResponse() sync.ret = 0 sync.utc_timestamp = timezone.utc_timestamp() return [pack_msg(response, session), pack_msg(sync)]