Пример #1
0
        public void NapackUploadOperationSuccess()
        {
            RegisterOperation registerOperation = new RegisterOperation()
            {
                Operation          = "Register",
                UserEmail          = "*****@*****.**",
                NapackSettingsFile = NapackOperationTests.SettingsFileLocation,
                SaveAsDefault      = true
            };

            registerOperation.PerformOperation();
            operationLogs.Clear();

            UploadOperation uploadOperation = new UploadOperation()
            {
                Operation = "Upload",
                ForceMajorUpversioning = false,
                ForceMinorUpversioning = false,
                PackageFile            = NapackOperationTests.PackageJsonFileLocation,
                NapackSettingsFile     = NapackOperationTests.SettingsFileLocation + NapackOperationTests.ModifierSuffix
            };

            uploadOperation.PerformOperation();
            Assert.IsTrue(operationLogs.Any(log => log.Contains("Created package PointInSphere")));
        }
Пример #2
0
        private void DoScan(Assembly assembly, Func <Type, bool> filter, RegisterOperation register, Action <ApiOperationDescriptor> configure = null)
        {
            var source = $"Scan {assembly.FullName}";

            foreach (var type in assembly.GetExportedTypes())
            {
                // We only care about actual classes, and those that are NOT abstract.
                if (type.IsAbstract)
                {
                    continue;
                }

                // The filter passed in to an assembly scan can _remove_ any types that should
                // NOT be included
                if (filter?.Invoke(type) == false)
                {
                    continue;
                }

                // By default types are NOT included. It's only if a convention is positive
                // that a type will be included (note that only ONE convention needs to include the
                // message).
                foreach (var globalFilters in this._conventions)
                {
                    if (globalFilters.IsSupported(type))
                    {
                        register(type, source, configure);

                        break;
                    }
                }
            }
        }
Пример #3
0
    void Update()
    {
        // If user presses Space, then perform the login operation.
        if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("Starting login process...");

            LoginOperation.Create(LoginCriteria.Create("greg7", "asdf2")).ExecuteAsync(Callback);

            // Alternatively, executes the operation synchronously.
            //  This WILL block until the web operation is completed (sometimes it takes as long as ~250 frames), so asynchronous is preferred to prevent gameplay hiccups.
            //LoginOperationResult result = operation.Execute();

            Debug.Log("Finished login operation!");
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            RegisterOperationCriteria criteria = RegisterOperationCriteria.Builder.Create()
                                                 .Username("greg900563")
                                                 .Password("")
                                                 .Email("*****@*****.**")
                                                 .DateOfBirth(new DateTime(1989, 11, 25))
                                                 .Gender(RegistrationCriteriaGender.Male)
                                                 .ZipCode("52333").Build();

            RegisterOperation registerOperation = RegisterOperation.Create(criteria);
            registerOperation.ExecuteAsync(RegisterCallback);
        }
    }
Пример #4
0
        public static string ParseLine(string line)
        {
            StringSplitOptions opt = new StringSplitOptions();
            RegisterOperation  ro  = RegisterOperation.inc;

            if (line.Contains("dec"))
            {
                ro = RegisterOperation.dec;
            }

            // parse the line for the actions to take
            string[] args = { "inc", "dec", "if" };
            string[] res  = line.Split(args, opt);
            for (int i = 0; i < res.Length; i++)
            {
                res[i] = res[i].Trim();
            }

            // add new "register"
            if (!registers.ContainsKey(res[0]))
            {
                registers.Add(res[0], 0);
            }

            Array.ForEach <string>(res, x => Console.WriteLine(x));
            return("yers");
        }
        public async Task <IOperationToken> RegisterAsync(string instanceName, string serviceType, string domain, string host, ushort port, byte[] txtRecord, uint interfaceIndex = 0, object context = null)
        {
            await CheckConnectionAsync();

            var op = new RegisterOperation(instanceName, serviceType, domain, host, port, txtRecord, interfaceIndex, context);

            op.RegistrationEvent += (s, e) => RegistrationEvent?.Invoke(s, e);

            await _connection.AddAndExecuteSubordinate(op);

            return(op.Token);
        }
Пример #6
0
        public void NapackRegistrationOperationRegistersNewUser()
        {
            RegisterOperation registerOperation = new RegisterOperation()
            {
                Operation          = "Register",
                UserEmail          = "*****@*****.**",
                NapackSettingsFile = NapackOperationTests.SettingsFileLocation
            };

            operationLogs.Clear();
            registerOperation.PerformOperation();
            Assert.IsTrue(operationLogs.Any(line => line.Contains("[email protected] successfully registered")));
        }
Пример #7
0
        public void Benchmark()
        {
            IScriptContext context = new ScriptContext();

            //Example 0: Machine

            ExecutableMachine machine = ExecutableMachine.Create();

            int iterations = 2;// 10000000;

            //loops = 10000000
            ValueOperation op0 = machine.CreateOperation <ValueOperation>();

            op0.Value = iterations;
            SetValueOperation op1 = machine.CreateOperation <SetValueOperation>();

            op1.Id = "loops";

            // counter = 0
            ValueOperation op2 = machine.CreateOperation <ValueOperation>();

            op2.Value = 0;
            SetValueOperation op3 = machine.CreateOperation <SetValueOperation>();

            op3.Id = "counter";

            //while (loops > 0)
            RegisterOperation op4 = machine.CreateOperation <RegisterOperation>();

            op4.Destination = MachineRegisters.BX;
            op4.Value       = 0;
            GetValueOperation op5 = machine.CreateOperation <GetValueOperation>();

            op5.Id = "loops";
            CmpOperation   op6 = machine.CreateOperation <CmpOperation>();
            JmpIfOperation op7 = machine.CreateOperation <JmpIfOperation>();

            op7.Offset = 8;
            //loops = loops -1;
            GetValueOperation op8 = machine.CreateOperation <GetValueOperation>();

            op8.Id = "loops";
            DecOperation      op9  = machine.CreateOperation <DecOperation>();
            SetValueOperation op10 = machine.CreateOperation <SetValueOperation>();

            op10.Id = "loops";

            //counter = counter + 1;
            GetValueOperation op11 = machine.CreateOperation <GetValueOperation>();

            op11.Id = "counter";
            IncOperation      op12 = machine.CreateOperation <IncOperation>();
            SetValueOperation op13 = machine.CreateOperation <SetValueOperation>();

            op13.Id = "counter";

            JmpOperation op14 = machine.CreateOperation <JmpOperation>();

            op14.Offset = -10;

            machine.CreateOperation <RetOperation>();
            machine.Execute(context);

            object rez = context.GetItem("counter", true);

            Assert.Equal(iterations, rez);
        }
Пример #8
0
        public bool HandleMessage(IMessage message, IServerPeer peer)
        {
            var serverPeer = peer as PhotonServerPeer;
            var operation  = new RegisterOperation(serverPeer.protocol, message);

            if (!operation.IsValid)
            {
                peer.SendMessage(new Response(Code, SubCode, new Dictionary <byte, object>()
                {
                    { (byte)MessageParameterCode.SubCodeParameterCode, SubCode },
                    { (byte)MessageParameterCode.PeerIdParameterCode, message.Parameters[(byte)MessageParameterCode.PeerIdParameterCode] },
                }, operation.GetErrorMessage(), (int)ReturnCode.OperationInvalid));

                return(true);
            }

            if (operation.Login.Length < 6 || operation.Password.Length < 6)
            {
                peer.SendMessage(new Response(Code, SubCode, new Dictionary <byte, object>()
                {
                    { (byte)MessageParameterCode.SubCodeParameterCode, SubCode },
                    { (byte)MessageParameterCode.PeerIdParameterCode, message.Parameters[(byte)MessageParameterCode.PeerIdParameterCode] },
                }, "Login and password can't be less than 6 symbols.", (int)ReturnCode.OperationInvalid));

                return(true);
            }
            else if (operation.Login.Length > 16 || operation.Password.Length > 16)
            {
                peer.SendMessage(new Response(Code, SubCode, new Dictionary <byte, object>()
                {
                    { (byte)MessageParameterCode.SubCodeParameterCode, SubCode },
                    { (byte)MessageParameterCode.PeerIdParameterCode, message.Parameters[(byte)MessageParameterCode.PeerIdParameterCode] },
                }, "Login and password can't be more than 16 symbols.", (int)ReturnCode.OperationInvalid));

                return(true);
            }

            var checkMail = new EmailAddressAttribute();

            if (!checkMail.IsValid(operation.Email))
            {
                peer.SendMessage(new Response(Code, SubCode, new Dictionary <byte, object>()
                {
                    { (byte)MessageParameterCode.SubCodeParameterCode, SubCode },
                    { (byte)MessageParameterCode.PeerIdParameterCode, message.Parameters[(byte)MessageParameterCode.PeerIdParameterCode] },
                }, "Email address incorrect.", (int)ReturnCode.OperationInvalid));

                return(true);
            }

            var characterData = MessageSerializerService.DeserializeObjectOfType <RegisterCharacterData>(
                operation.CharacterRegisterData);

            characterData.CharacterType = 1;             // delete this if we add more types

            if (characterData.CharacterName.Length < 6)
            {
                peer.SendMessage(new Response(Code, SubCode, new Dictionary <byte, object>()
                {
                    { (byte)MessageParameterCode.SubCodeParameterCode, SubCode },
                    { (byte)MessageParameterCode.PeerIdParameterCode, message.Parameters[(byte)MessageParameterCode.PeerIdParameterCode] },
                }, "Name of your character can't be less than 6 symbols.", (int)ReturnCode.OperationInvalid));

                return(true);
            }
            else if (characterData.CharacterName.Length > 16)
            {
                peer.SendMessage(new Response(Code, SubCode, new Dictionary <byte, object>()
                {
                    { (byte)MessageParameterCode.SubCodeParameterCode, SubCode },
                    { (byte)MessageParameterCode.PeerIdParameterCode, message.Parameters[(byte)MessageParameterCode.PeerIdParameterCode] },
                }, "Name of your can't be more than 16 symbols.", (int)ReturnCode.OperationInvalid));

                return(true);
            }
            else if (characterData.Sex != "Male" && characterData.Sex != "Female")
            {
                return(true);
            }
            else if (characterData.CharacterType != 1)             // add more types
            {
                return(true);
            }
            else if (characterData.Class != "Warrior" && characterData.Class != "Rogue" && characterData.Class != "Mage")
            {
                return(true);
            }
            else if (characterData.SubClass != "Warlock" && characterData.SubClass != "Cleric")
            {
                return(true);
            }

            try
            {
                using (var session = NHibernateHelper.OpenSession())
                {
                    using (var transaction = session.BeginTransaction())
                    {
                        var accounts        = session.QueryOver <AccountModel>().Where(a => a.Login == operation.Login).List();
                        var accountsByEmail = session.QueryOver <AccountModel>().Where(a => a.Email == operation.Email).List();
                        var characters      = session.QueryOver <CharacterModel>().Where(c => c.Name == characterData.CharacterName).List();

                        if (accounts.Count > 0)
                        {
                            transaction.Commit();

                            peer.SendMessage(new Response(Code, SubCode, new Dictionary <byte, object>()
                            {
                                { (byte)MessageParameterCode.SubCodeParameterCode, SubCode },
                                { (byte)MessageParameterCode.PeerIdParameterCode, message.Parameters[(byte)MessageParameterCode.PeerIdParameterCode] },
                            }, "Login already taken.", (int)ReturnCode.AlreadyExist));

                            return(true);
                        }
                        else if (accountsByEmail.Count > 0)
                        {
                            transaction.Commit();

                            peer.SendMessage(new Response(Code, SubCode, new Dictionary <byte, object>()
                            {
                                { (byte)MessageParameterCode.SubCodeParameterCode, SubCode },
                                { (byte)MessageParameterCode.PeerIdParameterCode, message.Parameters[(byte)MessageParameterCode.PeerIdParameterCode] },
                            }, "Email already taken.", (int)ReturnCode.AlreadyExist));

                            return(true);
                        }
                        else if (characters.Count > 0)
                        {
                            transaction.Commit();

                            peer.SendMessage(new Response(Code, SubCode, new Dictionary <byte, object>()
                            {
                                { (byte)MessageParameterCode.SubCodeParameterCode, SubCode },
                                { (byte)MessageParameterCode.PeerIdParameterCode, message.Parameters[(byte)MessageParameterCode.PeerIdParameterCode] },
                            }, "Name already taken.", (int)ReturnCode.AlreadyExist));

                            return(true);
                        }

                        string salt = Guid.NewGuid().ToString().Replace("-", "");

                        AccountModel newAccount = new AccountModel()
                        {
                            Login    = operation.Login,
                            Password = BitConverter.ToString(SHA512.Create().ComputeHash(
                                                                 Encoding.UTF8.GetBytes(salt + operation.Password))).Replace("-", ""),
                            Salt  = salt,
                            Email = operation.Email,

                            AdminLevel = 0,
                            BanLevel   = 0,

                            Created = DateTime.Now,
                            Updated = DateTime.Now
                        };

                        session.Save(newAccount);
                        transaction.Commit();

                        Log.DebugFormat("Create new Account. Login - {0}.", operation.Login);
                    }

                    using (var transaction = session.BeginTransaction())
                    {
                        var accounts = session.QueryOver <AccountModel>().Where(a => a.Login == operation.Login).SingleOrDefault();

                        CharacterModel newCharacter = new CharacterModel()
                        {
                            AccountId = accounts,

                            Name          = characterData.CharacterName,
                            Sex           = characterData.Sex,
                            CharacterType = characterData.CharacterType,
                            Class         = characterData.Class,
                            SubClass      = characterData.SubClass,

                            Level     = 1,
                            Exp       = 0,
                            Strength  = 1,
                            Intellect = 1,

                            RangLevel = 0,

                            Gold       = 10000,
                            Donate     = 0,
                            SkillPoint = 1000,
                            StatPoint  = 0,

                            InventorySize = 32,

                            GuildId = 0,

                            Created = DateTime.Now,
                            Updated = DateTime.Now
                        };

                        session.Save(newCharacter);
                        transaction.Commit();

                        Log.DebugFormat("Create new Character. Name - {0}.", characterData.CharacterName);
                    }

                    peer.SendMessage(new Response(Code, SubCode, new Dictionary <byte, object>()
                    {
                        { (byte)MessageParameterCode.SubCodeParameterCode, SubCode },
                        { (byte)MessageParameterCode.PeerIdParameterCode, message.Parameters[(byte)MessageParameterCode.PeerIdParameterCode] },
                    }, "Register success.", (int)ReturnCode.OK));
                }

                return(true);
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Error register handler: {0}", ex);

                peer.SendMessage(new Response(Code, SubCode, new Dictionary <byte, object>()
                {
                    { (byte)MessageParameterCode.SubCodeParameterCode, SubCode },
                    { (byte)MessageParameterCode.PeerIdParameterCode, message.Parameters[(byte)MessageParameterCode.PeerIdParameterCode] },
                }, ex.ToString(), (int)ReturnCode.OperationDenied));

                return(true);
            }
        }