public async Task <string> Load(IServerNode node) { //System.Diagnostics.Debugger.Break(); await Task.Delay(50); node.GetLogger().Info(this.GetType().Name + " service started"); await Task.Delay(50); return(""); }
public async Task <string> Load(IServerNode node) { //System.Diagnostics.Debugger.Break(); m_LocalNode = node; await Task.Delay(50); node.GetLogger().Info(this.GetType().Name + " service loaded - default merchant api service"); return(""); }
public BaccaratGame(IServerNode node) { m_Node = node; m_Logger = m_Node.GetLogger(); m_GameState = GAME_STATUS.Unknown; m_WaitingForDealing = false; m_IsRunningGameLoop = false; PlayerPoints = -1; BankerPoints = -1; m_ShoeCode = ""; m_RoundIndex = 0; }
public async Task <string> Load(IServerNode node) { //System.Diagnostics.Debugger.Break(); if (m_Updater == null) { m_Updater = new BetResultUpdater(node); } await Task.Delay(50); node.GetLogger().Info(this.GetType().Name + " service started"); return(""); }
public ClientHolder(IServerNode node) { m_Node = node; m_Logger = m_Node.GetLogger(); m_ServerName = m_Node.GetName(); if (m_Clients != null) { m_Clients.Clear(); } else { m_Clients = new Dictionary <string, ClientInfo>(); } }
public async Task <string> Unload(IServerNode node) { //System.Diagnostics.Debugger.Break(); await Task.Delay(100); if (m_LocalCacheUpdater != null) { m_LocalCacheUpdater.Stop(); m_LocalCacheUpdater = null; } await Task.Delay(100); node.GetLogger().Info(this.GetType().Name + " service stopped"); return(""); }
public async Task <string> Load(IServerNode node) { //System.Diagnostics.Debugger.Break(); if (m_LocalCacheUpdater == null) { m_LocalCacheUpdater = new MerchantDataCache(node); } await Task.Delay(50); if (m_LocalCacheUpdater != null) { await m_LocalCacheUpdater.Start(); } await Task.Delay(50); node.GetLogger().Info(this.GetType().Name + " service started"); return(""); }
public async Task <string> Load(IServerNode node) { //System.Diagnostics.Debugger.Break(); m_LocalNode = node; if (m_Cleaner == null) { m_Cleaner = new TransactionCleaner(node); } await Task.Delay(50); if (m_Cleaner != null) { await m_Cleaner.Start(); } await Task.Delay(50); node.GetLogger().Info(this.GetType().Name + " service started"); return(""); }
public BetResultUpdater(IServerNode node) { m_Node = node; m_Logger = m_Node.GetLogger(); }
public async Task <string> PlayerLogin(string jsonRequest) { if (m_LocalNode == null) { return(m_LocalNode.GetJsonHelper().ToJsonString(new { error_code = -1, error_message = "Service is not available" })); } m_LocalNode.GetLogger().Info("call merchant api: player-login"); dynamic req = m_LocalNode.GetJsonHelper().ToJsonObject(jsonRequest); string merchantUrl = req.merchant_url.ToString(); m_LocalNode.GetLogger().Info("Player login - [" + req.merchant_code.ToString() + "] " + req.player_id.ToString()); m_LocalNode.GetLogger().Info("Merchant URL - " + merchantUrl); dynamic ret = null; var apiReq = new { req.merchant_code, req.currency_code, req.player_id, req.login_token }; try { var rawret = await RemoteCaller.Request <Tuple <int, string> >(merchantUrl + "/player/validate-login", apiReq, null, 10 * 1000); m_LocalNode.GetLogger().Info("3-Way Login Reply Code: " + rawret.Item1); ret = m_LocalNode.GetJsonHelper().ToJsonObject(rawret.Item2); } catch (Exception ex) { ret = null; m_LocalNode.GetLogger().Error("Three-Way Login Error - Failed to call merchant API: " + ex.Message); } if (ret == null) { return(null); } if (ret.error_code != 0) { m_LocalNode.GetLogger().Error("Three-Way Login Error: " + (ret == null ? "Failed to call merchant API" : ret.error_message)); return(m_LocalNode.GetJsonHelper().ToJsonString(new { error_code = -1, error_message = "Three-Way Login Error" })); } return(m_LocalNode.GetJsonHelper().ToJsonString(ret)); }
//private Dictionary<string, List<long>> m_BetRecordLists = new Dictionary<string, List<long>>(); public BetCollector(IServerNode node) { m_Node = node; m_Logger = m_Node.GetLogger(); }
public void OnConnect(IWebSession session) { //Console.WriteLine(m_LocalNode.GetName() + " - OnConnect: " + session.GetRemoteAddress()); //System.Diagnostics.Debugger.Break(); m_LocalNode.GetLogger().Info("OnClientConnect: " + session.GetRequestPath()); var count = 0; var playerId = ""; var merchantCode = ""; var sessionId = ""; var parts = session.GetRequestPath().Split('/'); foreach (var part in parts) { if (part.Length <= 0) { continue; } count++; if (count == 1) { merchantCode = part; } if (count == 2) { playerId = part; } if (count == 3) { sessionId = part; } if (count > 3) { break; } } var okay = false; if (!String.IsNullOrEmpty(merchantCode) && !String.IsNullOrEmpty(playerId) && !String.IsNullOrEmpty(sessionId)) { var dbhelper = m_LocalNode.GetDataHelper(); using (var cnn = dbhelper.OpenDatabase(m_MainCache)) { using (var cmd = cnn.CreateCommand()) { dbhelper.AddParam(cmd, "@session_id", sessionId); dbhelper.AddParam(cmd, "@merchant_code", merchantCode); dbhelper.AddParam(cmd, "@player_id", playerId); cmd.CommandText = " select * from tbl_player_session " + " where merchant_code = @merchant_code " + " and player_id = @player_id " + " and session_id = @session_id " ; using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { okay = true; } } } } } if (okay) { m_LocalNode.GetLogger().Info("Client session is ok: " + sessionId); } else { m_LocalNode.GetLogger().Info("Invalid session: " + sessionId); } if (okay && m_Deliverer != null) { m_Deliverer.AddClient(session.GetRemoteAddress(), session); } else { session.CloseConnection(); } }
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 + ")"); } }
public async Task <string> Load(IServerNode node) { //System.Diagnostics.Debugger.Break(); node.GetLogger().Info(this.GetType().Name + " is loading settings from config..."); TableGroupSetting tableSettings = null; try { ConfigurationManager.RefreshSection("appSettings"); await Task.Delay(100); var keys = ConfigurationManager.AppSettings.Keys; foreach (var key in keys) { if (key.ToString() == "GameTableSetting") { string settings = ConfigurationManager.AppSettings["GameTableSetting"].ToString(); tableSettings = node.GetJsonHelper().ToJsonObject <TableGroupSetting>(settings); continue; } } } catch (Exception ex) { node.GetLogger().Error("Failed to load settings from config for GameServerService: "); node.GetLogger().Error(ex.ToString()); } //if (m_Game != null) await m_Game.Open(); if (tableSettings != null) { lock (m_GameTables) { foreach (var setting in tableSettings.Tables) { if (m_GameTables.ContainsKey(setting.TableCode)) { continue; } TurnBasedGameTable gameTable = null; if (tableSettings.GameType == GameLogicBigTwo.GAME_TYPE) { gameTable = new TurnBasedGameTable(node, new GameLogicBigTwo()); } if (gameTable != null) { gameTable.TableCode = setting.TableCode; gameTable.TableType = tableSettings.TableType; gameTable.TableName = setting.TableName; gameTable.TestMerchant = tableSettings.TestMerchant; gameTable.TimeToBet = tableSettings.BettingTime; m_GameTables.Add(gameTable.TableCode, gameTable); } } } } else { node.GetLogger().Info("Failed to load game tables from app setting"); } var tables = GetGameTables(); if (tables.Count <= 0) { node.GetLogger().Info("No game table created from app setting"); } else { node.GetLogger().Info(tables.Count + " game table(s) created from app setting"); foreach (var gameTable in tables) { node.GetLogger().Info("--------------------------------------"); node.GetLogger().Info("Table Code: " + gameTable.TableCode); node.GetLogger().Info("Betting Time: " + gameTable.TimeToBet); node.GetLogger().Info("Test Merchant Code: " + gameTable.TestMerchant); await gameTable.Open(); } node.GetLogger().Info("--------------------------------------"); } await Task.Delay(100); node.GetLogger().Info(this.GetType().Name + " started"); return(""); }
//private Dictionary<string, List<long>> m_BetRecordLists = new Dictionary<string, List<long>>(); public BetWinlossChecker(IServerNode node) { m_Node = node; m_Logger = m_Node.GetLogger(); }