using Sog; namespace Account { public class AccountTableOp : BaseReloadableService { private AccountTable m_table; public override int GetServiceType() { return AccountServiceType.AccountTableOp; } //销毁的时候置空 public override void Dispose() { m_table = null; } public AccountTableOp(AccountTable accountTable) { m_table = accountTable; } public AccountInfoOnAccountServer GetAccountInfo(int accountType, string accountID) { string accountKey = AccountUtils.CalcAccountKey(accountType, accountID); //是否存在 if(m_table.m_accountTable.ContainsKey(accountKey)) { return m_table.m_accountTable[accountKey]; } return null; } public int AddAccountInfo(AccountInfoOnAccountServer accountInfo) { string accountKey = AccountUtils.CalcAccountKey(accountInfo.AccountType, accountInfo.AccountID); //是否存在 if (m_table.m_accountTable.ContainsKey(accountKey)) { TraceLog.Error("AccountTableOp.AddAccountInfo type {0} accountId {1} already exist" , accountInfo.AccountType, accountInfo.AccountID); return -1; } m_table.m_accountTable.Add(accountKey, accountInfo); return 0; } public AccountInfoOnAccountServer CreateAccountInfo(int accountType, string accountID) { string accountKey = AccountUtils.CalcAccountKey(accountType, accountID); //是否存在 if (m_table.m_accountTable.ContainsKey(accountKey)) { return m_table.m_accountTable[accountKey]; } AccountInfoOnAccountServer accountInfo = new AccountInfoOnAccountServer(); accountInfo.runtimeId = AccountServerUtils.GetAccountServerData().m_uniqueIdMgr.GenUniqueId(); accountInfo.LastReqAuthTime = AccountServerUtils.GetTimeSecond(); accountInfo.AccountType = accountType; accountInfo.AccountID = accountID; m_table.m_accountTable.Add(accountKey, accountInfo); TraceLog.Trace("AccountTableOp.CreateAccountInfo create it accType {0} accountId {1} runtimeId {2}", accountType, accountID, accountInfo.runtimeId); return accountInfo; } public void RemoveAccountInfo(int accountType, string accountID) { string accountKey = AccountUtils.CalcAccountKey(accountType, accountID); //是否存在 if (m_table.m_accountTable.ContainsKey(accountKey)) { m_table.m_accountTable.Remove(accountKey); } } //不存在,需要查询 public bool NeedQueryHttpUserInfo(AccountInfoOnAccountServer accountInfo) { //是否存在 if (accountInfo == null) { return true; } //游客也需要验证一下, /* * if(accountInfo.AccountType == 0) { return false; } */ // 不刷新token, userInfo也不会同步更新 if (AccountServerUtils.GetServerConfig().accountTokenUpdateTime <= 0) { return false; } //重新刷新一次icon,name等信息 //这个逻辑算是容错逻辑 if (AppTime.GetNowSysSecond() > accountInfo.LastQueryHttpUserInfoTime + AccountServerUtils.GetServerConfig().accountTokenUpdateTime) { return true; } return false; } public bool NeedQueryHttpSnsFriend(AccountInfoOnAccountServer accountInfo) { /*游客模式也查询一下 if(accountInfo.AccountType == 0) { return false; } */ //5分钟可以重新刷新一次sns的好友列表 //这个逻辑算是容错逻辑 if (AppTime.GetNowSysMs() > accountInfo.LastQueryHttpSnsFriendTime + 300 * 1000) { return true; } return false; } } }