コード例 #1
0
 public static void Info(string msg)
 {
     if (m_Logger != null)
     {
         m_Logger.Info(msg);
     }
 }
コード例 #2
0
 public static void Info(string msg)
 {
     if (m_Logger != null)
     {
         m_Logger.Info(msg);
     }
     TryToSendLogToGui("[INFO] " + msg);
 }
コード例 #3
0
        public void Start()
        {
            Stop();

            m_Logger.Info("Clean up old cache...");
            Thread.Sleep(500);

            try
            {
                var dbhelper = m_Node.GetDataHelper();
                using (var cnn = dbhelper.OpenDatabase(m_MainCache))
                {
                    using (var cmd = cnn.CreateCommand())
                    {
                        dbhelper.AddParam(cmd, "@server_code", m_Node.GetName());
                        dbhelper.AddParam(cmd, "@table_code", TableCode);

                        cmd.CommandText = " delete from tbl_round_state "
                                          + " where server_code = @server_code ; ";
                        cmd.CommandText = cmd.CommandText + " delete from tbl_round_state "
                                          + " where table_code = @table_code ; ";

                        cmd.ExecuteNonQuery();
                    }
                }

                Thread.Sleep(500);
                m_Logger.Info("Done");
            }
            catch (Exception ex)
            {
                m_Logger.Error("Failed to clean up old cache: ");
                m_Logger.Error(ex.ToString());
            }


            m_RoundIndex = 0;
            //m_GameCode = Guid.NewGuid().ToString();
            m_ShoeCode = DateTime.Now.ToString("yyyyMMddHHmmss");
            m_History.Clear();
            m_GameReadyCountdown = GET_READY_COUNTDOWN;
            m_GameState          = GAME_STATUS.GetGameReady;
            m_WaitingForDealing  = false;
            m_IsRunningGameLoop  = false;
            m_Timer = new Timer(Tick, m_Rng, 500, 1000 * 1);
        }
コード例 #4
0
        private async void Deliver()
        {
            Dictionary <string, List <dynamic> > betResults = new Dictionary <string, List <dynamic> >();
            var dbhelper = m_Node.GetDataHelper();

            using (var cnn = dbhelper.OpenDatabase(m_MainCache))
            {
                using (var cmd = cnn.CreateCommand())
                {
                    dbhelper.AddParam(cmd, "@front_end", m_ServerName);

                    cmd.CommandText = " update tbl_bet_record "
                                      + " set bet_state = 2 " // that means we are going to send them
                                      + " where front_end = @front_end and bet_state = 1 ";

                    cmd.ExecuteNonQuery();
                }

                using (var cmd = cnn.CreateCommand())
                {
                    dbhelper.AddParam(cmd, "@front_end", m_ServerName);

                    // select records which are ready to be sent
                    cmd.CommandText = " select * from tbl_bet_record "
                                      + " where front_end = @front_end and bet_state = 2 ";

                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var item = new
                            {
                                client    = reader["client_id"].ToString(),
                                server    = reader["server_code"].ToString(),
                                table     = reader["table_code"].ToString(),
                                shoe      = reader["shoe_code"].ToString(),
                                round     = Convert.ToInt32(reader["round_number"].ToString()),
                                pool      = Convert.ToInt32(reader["bet_pool"].ToString()),
                                bet_type  = Convert.ToInt32(reader["bet_type"].ToString()),
                                bet_input = reader["game_input"].ToString(),
                                bet_id    = reader["bet_uuid"].ToString(),
                                bet       = Convert.ToDecimal(reader["bet_amount"].ToString()),
                                payout    = Convert.ToDecimal(reader["pay_amount"].ToString()),
                                result    = reader["game_result"].ToString()
                            };

                            if (betResults.ContainsKey(item.client))
                            {
                                var list = betResults[item.client];
                                list.Add(item);
                            }
                            else
                            {
                                var list = new List <dynamic>();
                                list.Add(item);
                                betResults.Add(item.client, list);
                            }
                        }
                    }
                }

                using (var cmd = cnn.CreateCommand())
                {
                    dbhelper.AddParam(cmd, "@front_end", m_ServerName);

                    // remove them
                    cmd.CommandText = " delete from tbl_bet_record "
                                      + " where front_end = @front_end and bet_state = 2 ";

                    cmd.ExecuteNonQuery();
                }
            }

            foreach (var item in betResults)
            {
                try
                {
                    var list      = item.Value;
                    var clientMsg = new
                    {
                        msg     = "bet_result",
                        results = list
                    };
                    ClientInfo client = null;
                    if (m_Clients.TryGetValue(item.Key, out client))
                    {
                        await client.Session.Send(m_Node.GetJsonHelper().ToJsonString(clientMsg));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("FES Send-Bet-Result Error - " + ex.ToString());
                }
            }

            if (betResults.Count > 0)
            {
                m_Logger.Info("Sent bet results to clients - " + betResults.Count);
            }
        }
コード例 #5
0
        public async Task <dynamic> AcceptBet(dynamic betreq)
        {
            string replyMsgType   = "bet_reply";
            int    replyErrorCode = -1;
            string replyErroMsg   = "input invalid";

            if (betreq.bet_pool < 1)
            {
                return(new
                {
                    msg = replyMsgType,

                    error_code = replyErrorCode,
                    error_msg = replyErroMsg
                });
            }

            string  betGuid       = "";
            decimal playerBalance = -1;

            var dbhelper = m_Node.GetDataHelper();

            using (var cnn = dbhelper.OpenDatabase(m_MainCache))
            {
                using (var cmd = cnn.CreateCommand())
                {
                    dbhelper.AddParam(cmd, "@server_code", betreq.server_code);
                    dbhelper.AddParam(cmd, "@table_code", betreq.table_code);
                    dbhelper.AddParam(cmd, "@shoe_code", betreq.shoe_code);
                    dbhelper.AddParam(cmd, "@round_number", betreq.round_number);

                    cmd.CommandText = " select * from tbl_round_state "
                                      + " where round_state = 4 and bet_time_countdown > 0 "
                                      + " and server_code = @server_code and table_code = @table_code "
                                      + " and shoe_code = @shoe_code and round_number = @round_number ";
                    using (var reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            replyErrorCode = 2;
                            replyErroMsg   = "timing is fine";
                        }
                        else
                        {
                            replyErrorCode = -2;
                            replyErroMsg   = "out of betting time";
                        }
                    }
                }

                if (replyErrorCode >= 0)
                {
                    m_Logger.Info("Saving bet record to database...");

                    string betTime = "";
                    string retStr  = await RemoteCaller.RandomCall(m_Node.GetRemoteServices(),
                                                                   "bet-data", "save-record", m_Node.GetJsonHelper().ToJsonString(betreq));

                    if (retStr.Contains("{") && retStr.Contains("-"))
                    {
                        dynamic ret = m_Node.GetJsonHelper().ToJsonObject(retStr);
                        betGuid = ret.bet_uuid;
                        betTime = ret.bet_time;
                        m_Logger.Info("Update database successfully");
                    }
                    else
                    {
                        m_Logger.Error("Failed to save bet data in database");
                    }

                    if (betGuid.Length > 0 && betTime.Length > 0)
                    {
                        // call single wallet

                        m_Logger.Info("Call single wallet...");

                        var swReq = new
                        {
                            bet_uuid      = betGuid,
                            table_code    = betreq.table_code,
                            shoe_code     = betreq.shoe_code,
                            round_number  = betreq.round_number,
                            bet_pool      = betreq.bet_pool,
                            merchant_code = betreq.merchant_code,
                            player_id     = betreq.player_id,
                            bet_amount    = betreq.bet_amount,
                            bet_time      = betTime
                        };

                        string swReplyStr = await RemoteCaller.RandomCall(m_Node.GetRemoteServices(),
                                                                          "single-wallet", "debit-for-placing-bet", m_Node.GetJsonHelper().ToJsonString(swReq));

                        if (String.IsNullOrEmpty(swReplyStr))
                        {
                            replyErrorCode = -5;
                            replyErroMsg   = "failed to call single-wallet service";
                        }
                        else
                        {
                            dynamic ret = m_Node.GetJsonHelper().ToJsonObject(swReplyStr);

                            if (ret.error_code == 0)
                            {
                                playerBalance = ret.player_balance;
                            }
                            else
                            {
                                replyErrorCode = -5;
                                replyErroMsg   = "failed to debit from merchant";
                            }
                        }
                    }
                    else
                    {
                        replyErrorCode = -4;
                        replyErroMsg   = "failed to add it to db";
                    }

                    if (replyErrorCode >= 0 && playerBalance >= 0)
                    {
                        using (var cmd = cnn.CreateCommand())
                        {
                            dbhelper.AddParam(cmd, "@bet_uuid", betGuid);

                            dbhelper.AddParam(cmd, "@merchant_code", betreq.merchant_code);
                            dbhelper.AddParam(cmd, "@player_id", betreq.player_id);

                            dbhelper.AddParam(cmd, "@server_code", betreq.server_code);
                            dbhelper.AddParam(cmd, "@table_code", betreq.table_code);
                            dbhelper.AddParam(cmd, "@shoe_code", betreq.shoe_code);
                            dbhelper.AddParam(cmd, "@round_number", betreq.round_number);
                            dbhelper.AddParam(cmd, "@client_id", betreq.client_id);
                            dbhelper.AddParam(cmd, "@front_end", betreq.front_end);
                            dbhelper.AddParam(cmd, "@bet_pool", betreq.bet_pool);
                            dbhelper.AddParam(cmd, "@bet_amount", betreq.bet_amount);

                            cmd.CommandText = " insert into tbl_bet_record "
                                              + " ( bet_uuid, merchant_code, player_id, server_code, table_code, shoe_code, round_number, client_id, front_end, bet_pool, bet_amount, bet_time ) values "
                                              + " ( @bet_uuid, @merchant_code, @player_id, @server_code , @table_code , @shoe_code , @round_number , @client_id , @front_end , @bet_pool, @bet_amount , CURRENT_TIMESTAMP ) "
                            ;

                            int rows = cmd.ExecuteNonQuery();
                            if (rows > 0)
                            {
                                replyErrorCode = 3;
                                replyErroMsg   = "added to cache";
                            }
                            else
                            {
                                replyErrorCode = -3;
                                replyErroMsg   = "failed to add it to cache";
                            }
                        }
                    }
                }

                if (replyErrorCode >= 0)
                {
                    return(new
                    {
                        msg = replyMsgType,
                        player_balance = playerBalance,
                        error_code = 0,
                        error_msg = "ok"
                    });
                }
                else
                {
                    return new
                           {
                               msg            = replyMsgType,
                               player_balance = playerBalance,
                               error_code     = replyErrorCode,
                               error_msg      = replyErroMsg
                           }
                };
            }
        }
    }
コード例 #6
0
        private async Task TryToCancelDebits()
        {
            //System.Diagnostics.Debugger.Break();

            //m_Logger.Info("TryToCancelDebits - START -");

            var totalCount = 0;

            Dictionary <string, List <dynamic> > debitItems = new Dictionary <string, List <dynamic> >();
            Dictionary <string, dynamic>         merchants  = new Dictionary <string, dynamic>();
            var dbhelper = m_Node.GetDataHelper();

            using (var cnn = dbhelper.OpenDatabase(m_CommonMerchantDb))
            {
                using (var cmd = cnn.CreateCommand())
                {
                    // select records which need to cancel
                    cmd.CommandText = " select debit_uuid, bet_uuid, player_id, client_id, session_id, "
                                      + " merchant_code, currency_code, debit_amount from tbl_trans_debit "
                                      + " where is_cancelled = 0 and network_error <> 0 ";

                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string  debitUuid    = reader["debit_uuid"].ToString();
                            string  betUuid      = reader["bet_uuid"].ToString();
                            string  playerId     = reader["player_id"].ToString();
                            string  clientId     = reader["client_id"].ToString();
                            string  sessionId    = reader["session_id"].ToString();
                            string  merchantCode = reader["merchant_code"].ToString();
                            string  currencyCode = reader["currency_code"].ToString();
                            decimal debitAmount  = Convert.ToDecimal(reader["debit_amount"].ToString());

                            var reqIp = clientId;
                            if (reqIp.Contains(":"))
                            {
                                reqIp = reqIp.Split(':')[0];
                            }

                            var item = new
                            {
                                debit_uuid    = debitUuid,
                                trans_uuid    = debitUuid + "-cancel",
                                bet_uuid      = betUuid,
                                merchant_code = merchantCode,
                                currency_code = currencyCode,
                                player_id     = playerId,
                                player_ip     = reqIp,
                                session_id    = sessionId,
                                amount        = debitAmount
                            };

                            string merchantKey = item.merchant_code + item.currency_code;

                            if (debitItems.ContainsKey(merchantKey))
                            {
                                var list = debitItems[merchantKey];
                                list.Add(item);
                            }
                            else
                            {
                                var list = new List <dynamic>();
                                list.Add(item);
                                debitItems.Add(merchantKey, list);
                            }
                        }
                    }
                }

                foreach (var item in debitItems)
                {
                    if (!merchants.ContainsKey(item.Key))
                    {
                        string merchantInfo = await RemoteCaller.RandomCall(m_Node.GetRemoteServices(),
                                                                            "merchant-data", "get-merchant-info", item.Key);

                        if (String.IsNullOrEmpty(merchantInfo) || !merchantInfo.Contains('{') || !merchantInfo.Contains(':'))
                        {
                            continue;
                        }

                        dynamic merchant = m_Node.GetJsonHelper().ToJsonObject(merchantInfo);
                        if (merchant != null)
                        {
                            merchants.Add(item.Key, merchant);
                        }
                    }

                    if (!merchants.ContainsKey(item.Key))
                    {
                        continue;
                    }

                    string apiUrl = merchants[item.Key].url.ToString();
                    string apiSvc = merchants[item.Key].service.ToString();

                    var list = item.Value;

                    foreach (var debit in list)
                    {
                        var apiReq = new
                        {
                            merchant_url = apiUrl,
                            debit.trans_uuid,
                            debit.debit_uuid,
                            debit.bet_uuid,
                            debit.merchant_code,
                            debit.currency_code,
                            debit.player_id,
                            debit.player_ip,
                            debit.session_id,
                            debit.amount
                        };

                        dynamic ret = null;
                        try
                        {
                            string retJson = await CallMerchantApi(apiSvc, "cancel-debit", m_Node.GetJsonHelper().ToJsonString(apiReq));

                            ret = string.IsNullOrEmpty(retJson) ? null : m_Node.GetJsonHelper().ToJsonObject(retJson);
                        }
                        catch (Exception ex)
                        {
                            ret = null;
                            m_Node.GetLogger().Error("Failed to call cancel debit: " + ex.Message);
                        }

                        try
                        {
                            if (ret != null)
                            {
                                int respCode = ret.error_code;

                                var sql = " update tbl_trans_debit "
                                          + " set network_error = 0 , response_error = " + respCode;
                                if (respCode == 0)
                                {
                                    sql += " , is_cancelled = 1 ";
                                }
                                sql += " , update_time = NOW() ";
                                sql += " where debit_uuid = @debit_uuid ";

                                var okay  = false;
                                var trans = cnn.BeginTransaction();

                                using (var cmd = cnn.CreateCommand())
                                {
                                    cmd.Transaction = trans;

                                    dbhelper.AddParam(cmd, "@debit_uuid", debit.debit_uuid);
                                    cmd.CommandText = sql;

                                    okay = cmd.ExecuteNonQuery() > 0;
                                }

                                if (okay)
                                {
                                    sql  = " update tbl_bet_record set cancel_state = 1 ";
                                    sql += " , update_time = CURRENT_TIMESTAMP ";
                                    if (respCode == 0)
                                    {
                                        sql += " , cancel_time = CURRENT_TIMESTAMP ";
                                    }
                                    sql += " where bet_uuid = @bet_uuid ";

                                    using (var cmd = cnn.CreateCommand())
                                    {
                                        cmd.Transaction = trans;

                                        dbhelper.AddParam(cmd, "@bet_uuid", debit.bet_uuid);

                                        cmd.CommandText = sql;

                                        okay = okay && cmd.ExecuteNonQuery() > 0;
                                    }
                                }

                                if (okay)
                                {
                                    trans.Commit();
                                }
                                else
                                {
                                    trans.Rollback();
                                }
                            }

                            totalCount++;
                        }
                        catch (Exception ex)
                        {
                            ret = null;
                            m_Node.GetLogger().Error("Failed to call cancel debit: " + ex.Message);
                        }
                    } // end of debits of same merchant
                }     // end of all debits
            }         // end of using db cnn

            if (totalCount > 0)
            {
                m_Logger.Info("TryToCancelDebits - DONE (" + totalCount + ")");
            }
        }
コード例 #7
0
        public List <dynamic> CheckBetWinlossByGameResult(string gameServer)
        {
            //System.Diagnostics.Debugger.Break();

            m_Logger.Info("CheckBetWinlossByGameResult - " + gameServer);

            List <dynamic> bets = new List <dynamic>();

            Dictionary <string, decimal> payouts   = new Dictionary <string, decimal>();
            Dictionary <string, int>     results   = new Dictionary <string, int>();
            Dictionary <string, string>  merchants = new Dictionary <string, string>();
            Dictionary <string, string>  players   = new Dictionary <string, string>();
            Dictionary <string, int>     pools     = new Dictionary <string, int>();
            var dbhelper = m_Node.GetDataHelper();

            using (var cnn = dbhelper.OpenDatabase(m_MainCache))
            {
                using (var cmd = cnn.CreateCommand())
                {
                    dbhelper.AddParam(cmd, "@server_code", gameServer);

                    cmd.CommandText = " select a.game_result, b.bet_uuid, b.merchant_code, b.player_id, b.bet_pool, b.bet_amount from tbl_round_state a, tbl_bet_record b "
                                      + " where a.round_state = 9 and b.bet_state = 0 "
                                      + " and a.server_code = @server_code "
                                      + " and a.server_code = b.server_code "
                                      + " and a.table_code = b.table_code "
                                      + " and a.shoe_code = b.shoe_code "
                                      + " and a.round_number = b.round_number "
                    ;
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            string  result   = reader["game_result"].ToString();
                            string  betGuid  = reader["bet_uuid"].ToString();
                            string  merchant = reader["merchant_code"].ToString();
                            string  player   = reader["player_id"].ToString();
                            int     pool     = Convert.ToInt32(reader["bet_pool"].ToString());
                            decimal amount   = Convert.ToDecimal(reader["bet_amount"].ToString());

                            if (payouts.ContainsKey(betGuid))
                            {
                                continue;
                            }

                            merchants.Add(betGuid, merchant);
                            players.Add(betGuid, player);
                            pools.Add(betGuid, pool);

                            if (result[0] == '1' && pool == 1)
                            {
                                payouts.Add(betGuid, amount * m_PayRates["B"]);
                            }
                            else if (result[0] == '2' && pool == 2)
                            {
                                payouts.Add(betGuid, amount * m_PayRates["P"]);
                            }
                            else if (result[0] == '3' && pool == 3)
                            {
                                payouts.Add(betGuid, amount * m_PayRates["T"]);
                            }
                            else if (result[0] == '3' && (pool == 1 || pool == 2))
                            {
                                payouts.Add(betGuid, amount);                                                    // zero winloss
                            }
                            else
                            {
                                payouts.Add(betGuid, 0);  // lose
                            }
                            results.Add(betGuid, Convert.ToInt32(result));
                        }
                    }
                }

                if (payouts.Count <= 0)
                {
                    return(bets);
                }

                foreach (var item in payouts)
                {
                    dynamic bet = new
                    {
                        bet_uuid      = item.Key,
                        pay_amount    = item.Value,
                        game_result   = results[item.Key],
                        bet_pool      = pools[item.Key],
                        merchant_code = merchants[item.Key],
                        player_id     = players[item.Key]
                    };

                    bets.Add(bet);
                }

                return(bets);
            }
        }