示例#1
0
        private void GetRound(AsyncTcpServer asyncTcpServer, byte[] array)
        {
            try
            {
                string sendMessage = string.Empty;
                byte[] data        = null;

                string msg = CryptoVending.Decrypt(array);
                context.Post(new SendOrPostCallback(MessageCallBack), (object)(msg + "\n"));
                //AppendLog(msg + "\n");

                Logbook.FileAppend("AccountID: " + AccountID.ToString() + " " + msg, EventType.Info);

                string[] message = msg.Split(';');



                VendingCommands vendingCommands = (VendingCommands)Convert.ToInt16(message[0]);
                switch (vendingCommands)
                {
                case VendingCommands.GetBalance:

                    R_Keeper_CodeCard    = HexToDec(HexToDescSort(message[2]));
                    R_Keeper_BalanceCard = getBalance(SocketHelper.R_Keeper_CodeCard);
                    R_Keeper_BonusCard   = RKeeper.RKeeper.AccountInfo.Bonus == 1;

                    msg = string.Format("Code Card {0} -> Balance {1} Bonus Enable {2} ", R_Keeper_CodeCard, R_Keeper_BalanceCard, R_Keeper_BonusCard);
                    context.Post(new SendOrPostCallback(MessageCallBack), (object)(msg + "\n"));

                    sendMessage = string.Format("5;0;{0};", R_Keeper_BalanceCard);

                    Logbook.FileAppend("AccountID: " + AccountID.ToString() + " " + sendMessage, EventType.Info);

                    data = GetMessageToByte(sendMessage);

                    if (asyncTcpServer.GetCouuntClient() > 0)
                    {
                        asyncTcpServer.SendMessage(asyncTcpServer.GetTcpClient(0), data);
                    }

                    break;

                case VendingCommands.BeginTran:
                    ID          = random.Next(1, 1000);
                    sendMessage = string.Format("1;0;{0}", ID);

                    Logbook.FileAppend("AccountID: " + AccountID.ToString() + " " + sendMessage, EventType.Info);

                    data = GetMessageToByte(sendMessage);
                    asyncTcpServer.SendMessage(asyncTcpServer.GetTcpClient(0), data);
                    break;

                case VendingCommands.BuyWares:
                    WaresPrice  = Convert.ToInt32(message[4]);
                    sendMessage = "2;0;";

                    Logbook.FileAppend("AccountID: " + AccountID.ToString() + " " + sendMessage, EventType.Info);

                    data = GetMessageToByte(sendMessage);
                    asyncTcpServer.SendMessage(asyncTcpServer.GetTcpClient(0), data);
                    break;

                case VendingCommands.SuccsesBuy:
                    if (AccountID > 0)
                    {
                        Logbook.FileAppend(string.Format("AccountID: {0} R_Keeper_CodeCard: {1} R_Keeper_BalanceCard: {2} WaresPrice: {3} WaresName: {4} ", AccountID, R_Keeper_CodeCard, R_Keeper_BalanceCard, WaresPrice, WaresName), EventType.Info);

                        if (IsSaveDB)
                        {
                            PutWaresSale(R_Keeper_CodeCard, R_Keeper_BalanceCard, WaresPrice, WaresName);
                        }

                        if (RKeeperWaresSale(AccountID, WaresPrice))
                        {
                            msg = string.Format("Code Card {0} -> Append Wares Sale {1} ", R_Keeper_CodeCard, WaresPrice);
                            context.Post(new SendOrPostCallback(MessageCallBack), (object)(msg + "\n"));

                            Logbook.FileAppend(string.Format("Success AccountID: {0} R_Keeper_CodeCard: {1} R_Keeper_BalanceCard: {2} WaresPrice: {3} WaresName: {4} ", AccountID, R_Keeper_CodeCard, R_Keeper_BalanceCard, WaresPrice, WaresName), EventType.Info);
                            if (R_Keeper_BonusCard)
                            {
                                AppendBonus = 0;
                                if (RKeeperAppnedBonus(AccountID, WaresPrice, R_Keeper_BonusTotal, ref AppendBonus))
                                {
                                    msg = string.Format("Code Card {0} -> Append Bonus {1} ", R_Keeper_CodeCard, AppendBonus);
                                    context.Post(new SendOrPostCallback(MessageCallBack), (object)(msg + "\n"));
                                    Logbook.FileAppend(string.Format("Success AccountID: {0} R_Keeper_CodeCard: {1} R_Keeper_BalanceCard: {2} Bonus: {3} ", AccountID, R_Keeper_CodeCard, R_Keeper_BalanceCard, AppendBonus), EventType.Info);
                                }
                                else
                                {
                                    Logbook.FileAppend(string.Format("Unsuccess AccountID: {0} R_Keeper_CodeCard: {1} R_Keeper_BalanceCard: {2} Bonus: {3} ", AccountID, R_Keeper_CodeCard, R_Keeper_BalanceCard, AppendBonus), EventType.Info);
                                }
                            }
                        }
                        else
                        {
                            Logbook.FileAppend(string.Format("UnSuccessfull AccountID: {0} R_Keeper_CodeCard: {1} R_Keeper_BalanceCard: {2} WaresPrice: {3} WaresName: {4} ", AccountID, R_Keeper_CodeCard, R_Keeper_BalanceCard, WaresPrice, WaresName), EventType.Info);
                        }
                    }

                    sendMessage = "3;0;";

                    Logbook.FileAppend("AccountID: " + AccountID.ToString() + " " + sendMessage, EventType.Info);

                    data = GetMessageToByte(sendMessage);
                    asyncTcpServer.SendMessage(asyncTcpServer.GetTcpClient(0), data);
                    AccountID = 0;

                    break;

                case VendingCommands.CancelBuy:
                    sendMessage = string.Format("4;{0}", ID);

                    Logbook.FileAppend(sendMessage, EventType.Info);

                    data = GetMessageToByte(sendMessage);
                    asyncTcpServer.SendMessage(asyncTcpServer.GetTcpClient(0), data);
                    break;

                default:
                    //asyncTcpServer.SendMessage(asyncTcpServer.GetTcpClient(0), message[0] + ";3");
                    break;
                }
            }
            catch (Exception e)
            {
                context.Post(new SendOrPostCallback(MessageCallBack), (object)(e.Message + "\n"));
                // MessageBox.Show(e.Message);
            }
        }