コード例 #1
0
        private void Tick(object param)
        {
            if (!m_IsWorking)
            {
                return;
            }

            if (m_IsRunning)
            {
                return;
            }
            m_IsRunning = true;
            try
            {
                //Console.WriteLine("Check and send table info...");
                //m_Logger.Info("Check and send table info...");
                Deliver();
            }
            catch (Exception ex)
            {
                m_Logger.Error(ex.ToString());
                m_Logger.Error(ex.StackTrace);
            }
            finally
            {
                m_IsRunning = false;
            }
        }
コード例 #2
0
 private void Tick(object param)
 {
     if (!m_IsWorking)
     {
         return;
     }
     if (m_IsRunning)
     {
         return;
     }
     m_IsRunning = true;
     try
     {
         UpdateLocalCacheFromDb();
     }
     catch (Exception ex)
     {
         m_Logger.Error(ex.ToString());
         m_Logger.Error(ex.StackTrace);
     }
     finally
     {
         m_IsRunning = false;
     }
 }
コード例 #3
0
        public async Task <object> Call(string actionName, object param, bool publicOnly, bool includingLocal, object defaultResult)
        {
            object result = null;

            try
            {
                MethodInfo method = null;
                if (!m_PublicActions.TryGetValue(actionName, out method))
                {
                    method = null;
                    if (!publicOnly)
                    {
                        if (!m_InternalActions.TryGetValue(actionName, out method))
                        {
                            method = null;
                            if (includingLocal)
                            {
                                if (!m_LocalActions.TryGetValue(actionName, out method))
                                {
                                    method = null;
                                }
                            }
                        }
                    }
                }
                if (method != null)
                {
                    result = method.Invoke(ServiceObject, new object[] { param });
                }
                else
                {
                    if (!includingLocal && m_DefaultAction != null)
                    {
                        result = m_DefaultAction.Invoke(ServiceObject, new object[] { param });
                    }
                    else if (defaultResult != null)
                    {
                        result = defaultResult;
                    }
                }

                result = await ReturnAsyncResult(result);
            }
            catch (Exception ex)
            {
                m_Logger.Error("Failed to call service action - " + ServiceName + "." + actionName + " , error: " + ex.Message);
                m_Logger.Error(ex.StackTrace);
            }
            return(result);
        }
コード例 #4
0
 public static void Error(string msg)
 {
     if (m_Logger != null)
     {
         m_Logger.Error(msg);
     }
 }
コード例 #5
0
 public static void Error(string msg)
 {
     if (m_Logger != null)
     {
         m_Logger.Error(msg);
     }
     TryToSendLogToGui("[ERROR] " + msg);
 }
コード例 #6
0
 private void Tick(object param)
 {
     if (m_IsRunning)
     {
         return;
     }
     m_IsRunning = true;
     try
     {
         Deliver();
     }
     catch (Exception ex)
     {
         m_Logger.Error(ex.ToString());
         m_Logger.Error(ex.StackTrace);
     }
     finally
     {
         m_IsRunning = false;
     }
 }
コード例 #7
0
        async Task <string> CallMerchantApi(string serviceName, string actionName, string jsonParam)
        {
            //System.Diagnostics.Debugger.Break();
            var svcs = m_Node.GetLocalServices();

            if (svcs.InternalServices.ContainsKey(serviceName))
            {
                var    svc = svcs.InternalServices[serviceName];
                object ret = await svc.LocalCall(actionName, jsonParam);

                if (ret != null)
                {
                    return(ret.ToString());
                }
            }
            else
            {
                m_Logger.Error("Merchant API service not found: " + serviceName + "|" + actionName);
            }
            return(null);
        }
コード例 #8
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);
        }
コード例 #9
0
        public virtual string Validate(string clientIp, string requestPath)
        {
            if (clientIp == null || requestPath == null)
            {
                return("");
            }

            string reqPath = requestPath.Trim();

            if (reqPath.Length <= 0)
            {
                return("");
            }

            bool isRemoteValidationOK = true;

            if (m_ValidationURL != null && m_ValidationURL.Length > 0)
            {
                isRemoteValidationOK = false;

                try
                {
                    HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(m_ValidationURL);
                    httpWebRequest.ContentType = "text/plain";
                    httpWebRequest.Method      = "POST";

                    using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
                    {
                        streamWriter.Write(clientIp.Trim() + (reqPath[0] == '/' ? "" : "/") + reqPath);
                        streamWriter.Flush();
                        streamWriter.Close();
                    }

                    HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();
                    using (StreamReader sr = new StreamReader(response.GetResponseStream()))
                    {
                        string responseResult = sr.ReadToEnd();
                        if (responseResult != null && responseResult.Trim().ToLower() == "ok")
                        {
                            isRemoteValidationOK = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    m_Logger.Error("Failed to send request to validate client: " + ex.Message);
                }
            }

            if (isRemoteValidationOK == false)
            {
                return("");
            }

            List <string> paramList = new List <string>();

            string[] parts = reqPath.Split('/');
            foreach (var part in parts)
            {
                if (part.Trim().Length > 0)
                {
                    paramList.Add(part.Trim());
                }
            }
            if (paramList.Count <= 0)
            {
                return("");
            }

            string sourceName = paramList.First();

            return(sourceName);
        }
コード例 #10
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
                           }
                };
            }
        }
    }