public static uint GenerateCRC(byte[] buffer, long amount, byte[] key)
        {
            using (ILogMethod method = Log.LogMethod(DYN_MODULE_NAME, "GenerateCRC"))
            {
                uint crc = 0;

                try
                {
                    byte[] tk = new byte[TK_DATA_LENGTH];

                    // Key
                    if (key != null && key.Length == TK_KEY_LENGTH)
                    {
                        tk.CopyToBuffer(key, 0, TK_KEY_LENGTH);
                    }

                    // Amount
                    byte[] amountInBytes = FFDataTypeHelper.GetInt32Bytes((int)amount, FFEndianType.BigEndian);
                    tk.CopyToBuffer(amountInBytes, TK_KEY_LENGTH, TK_AMOUNT_LENGTH);

                    // barcode
                    if (buffer != null && buffer.Length == TK_NUMBER_LENGTH)
                    {
                        tk.CopyToBuffer(buffer, TK_KEY_LENGTH + TK_AMOUNT_LENGTH, TK_NUMBER_LENGTH);
                    }

                    // crc
                    crc = CreateCRC(tk, (uint)tk.Length, 0) % 1000;
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }

                return(crc);
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.Title = "ExCommsServer Testing";
            Console.SetWindowSize(80, 58);

            BMCRegistryHelper.ActiveInstallationType = BMCCategorizedInstallationTypes.Exchange;
            Log.AddAppFileLoggingSystem();
            Log.GlobalWriteToExternalLog += Log_GlobalWriteToExternalLog;

            TestPIDData();
            //MonMsg_H2G monH2G = new MonMsg_H2G();
            //MonTgt_H2G_AckNack nack = new MonTgt_H2G_AckNack();
            //nack.Nack = true;
            //monH2G.AddTarget(nack);
            //var msg2 = MonitorEntityFactory.CreateEntity(monH2G);
            //var ffBuffer = FreeformEntityFactory.CreateBuffer(msg2);

            var configStore = ExMonitorServerConfigStoreFactory.Store;
            var cat         = ErrorEventCategoryFactory.Categories;

            string       barcode = "889900027000052237";
            TicketIDInfo idInfo  = new TicketIDInfo(barcode);
            int          seqno   = idInfo.SequenceNumber;
            //byte[] packed = FreeformHelper.GetBCDToBytes(sUnpacked, sUnpacked.Length / 2);
            //string sUnpacked2 = packed.GetBCDValueString(0, 0, 9);



            //EncryptSecurity();

            //var dr = ExCommsDataContext.Current.GetMeterDeltaForPlayerSession(27, "1000012345", "IR");
            //ExecutionStepsTest();
            //return;

            //ExCommsHostingModuleTypeHelper.Current.SetAll();
            //_server = new ExCommsServerImpl(ExecutorServiceFactory.CreateExecutorService());
            //_server.Start();
            IExecutorService exec = ExecutorServiceFactory.CreateExecutorService();
            //ExecutionStepFactory.Initialize(exec, false, ExecutionStepDeviceTypes.GMU);
            //FFMsgHandlerFactory.Initialize(exec, FFTgtHandlerDeviceTypes.GMU, () =>
            //{
            //    return new FFMsgTransmitter();
            //});
            MonTgt_G2H_GIM_GameIDInfo  target = new MonTgt_G2H_GIM_GameIDInfo();
            MonTgt_G2H_GVA_TED_Request r      = new MonTgt_G2H_GVA_TED_Request();

            //TestGIM();

            //Console.ForegroundColor = ConsoleColor.Cyan;
            //GenerateKeys(SECURITY_KEY_INDEX.TICKET_KEY, IPADDR);
            //GenerateKeys(SECURITY_KEY_INDEX.EFT_KEY, IPADDR);
            //Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Start ExComms Server?");
            Console.ResetColor();
            string anser = "y";// Console.ReadLine();

            if (anser == "y")
            {
                var activators =
                    MEFHelper.GetExportedValues <IExCommsServerHostFactoryActivator>();

                ExCommsServerHostFactoryActivatorFactory factory = new ExCommsServerHostFactoryActivatorFactory(exec,
                                                                                                                ExCommsHostingModuleType.CommunicationServer |
                                                                                                                ExCommsHostingModuleType.MonitorServer4CommsServer |
                                                                                                                ExCommsHostingModuleType.MonitorServer4MonProcessor
                                                                                                                ,
                                                                                                                activators);
                factory.Start();
            }

            long ticks = DateTime.Now.Ticks;

            byte[] lohi = FFDataTypeHelper.GetInt64Bytes(ticks, FFEndianType.LittleEndian);
            //TestGIM();

            while (true)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Press any key to continue...");
                Console.ResetColor();
                string s = Console.ReadLine();
                if (s == "q")
                {
                    return;
                }

                //TestEncryptedTicketMessage();
                //InitKeyExchangeStart();
                //if (s == "k1") InitKeyExchangeStartG2H();
                //if (s == "k2") InitKeyExchangeEnd();
                //if (s == "t") GenerateKeys(SECURITY_KEY_INDEX.TICKET_KEY);
                //if (s == "e") GenerateKeys(SECURITY_KEY_INDEX.EFT_KEY);
                if (s == "g")
                {
                    ExecutionStepsTest();
                }
                if (s == "ss")
                {
                    EncryptSecurity();
                }
                if (s == "pci")
                {
                    TestPlayerCardIn();
                }
                if (s == "pco")
                {
                    TestPlayerCardOut();
                }
                if (s == "bal")
                {
                    TestECashBalanceRequest();
                }
            }
            //TestKeyExchangePartialKey();
            return;

            //short sval = 9999;
            //short ss1 = sval;
            //List<byte> ll = new List<byte>();
            //while (true)
            //{
            //    byte b1 = (byte)(ss1 % 10);
            //    ll.Add(b1);
            //    ss1 /= 10;
            //}

            byte[] b1234 = new byte[] { 0x12, 0x34, 0x56, 0x78 };
            ulong  u     = b1234.GetBytesToBCDUInt64(0, 4);
            int    v     = 99999;
            byte   b1    = (byte)(v & 0x0F);
            byte   b2    = (byte)((v >> 4) & 0x0F);

            byte[] buf = "1000500026".GetBCDToBytes(5);
            byte[] iv  = FFDataTypeHelper.GetInt32Bytes(99999, FFEndianType.LittleEndian);
            byte[] sb1 = FFDataTypeHelper.GetInt16Bytes(9999, FFEndianType.LittleEndian);
            byte[] sb2 = FFDataTypeHelper.GetInt16Bytes(9999, FFEndianType.BigEndian);
            short  s1  = FFDataTypeHelper.GetInt16(sb1, FFEndianType.LittleEndian);
            short  s2  = FFDataTypeHelper.GetInt16(sb2, FFEndianType.BigEndian);

            string cc = "1A345";

            byte[] b = cc.GetHexBytesValue(2);
            //FF_AppId_SessionIds sval = FFEnumParserFactory.GetAppId<FF_GmuId_SessionIds, FF_AppId_SessionIds>(FF_GmuId_SessionIds.ECash);
            //FF_GmuId_SessionIds ss2 = FFEnumParserFactory.GetGmuId<FF_AppId_SessionIds, FF_GmuId_SessionIds>(FF_AppId_SessionIds.GIM);

            //byte b = 23;
            //FF_AppId_SessionIds ss3 = b.GetAppId<FF_GmuId_SessionIds, FF_AppId_SessionIds>();
        }