/// <summary> /// 将日期时间字符串转为整数表示 /// </summary> /// <param name="str"></param> /// <returns></returns> public static long ConvertToTicks(string str, long defVal) { if ("*" == str) { return(defVal); } str = str.Replace('$', ':'); try { DateTime dt; if (!DateTime.TryParse(str, out dt)) { return(0L); } return(dt.Ticks / 10000); } catch (Exception e) { DebugMod.LogException(e); } return(0L); }
public static void ThreadProc(object param) { try { DebugMod.Log("Logic Thread Start."); GameMain frame = param as GameMain; long prevTick = DateTime.Now.Ticks; if (null != param) { while (!m_AppExit) { long nowTick = DateTime.Now.Ticks; long elapseTick = nowTick - prevTick; if (elapseTick > 333333) //33ms { prevTick = nowTick; frame.OnThreadUpdate(); } } } DebugMod.Log("Logic Thread Exit."); } catch (Exception ex) { DebugMod.LogException(ex); } }
/// <summary> /// 输入明文和密钥,输出密文 /// </summary> /// <param name="plainText"></param> /// <param name="key"></param> /// <returns></returns> public static string Encrypt(string plainText, string passwd, string saltValue) { if (string.IsNullOrEmpty(plainText)) { return(null); } byte[] bytesData = null; try { bytesData = new UTF8Encoding().GetBytes(plainText); } catch (Exception e) { DebugMod.LogException(e); return(null); } byte[] bytesResult = null; try { bytesResult = AesHelper.AesEncryptBytes(bytesData, passwd, saltValue); } catch (Exception e) { DebugMod.LogException(e); return(null); } return(ByteHelper.Bytes2HexString(bytesResult)); }
private void DequueLogicAction() { try { LogicAction action = null; do { action = null; lock (m_QueueLogicAction) { if (0 < m_QueueLogicAction.Count) { action = m_QueueLogicAction.Dequeue();//移除并返回栈顶数据 } } if (null != action) { action.ProcessAction(); } } while (action != null); } catch (Exception ex) { DebugMod.LogException(ex); } }
public static void LogException(Exception e, string extMsg, bool showMsgBox) { try { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendFormat("应用程序出现了异常:\r\n{0}\r\n", e.Message); stringBuilder.AppendFormat("\r\n 额外信息: {0}", extMsg); if (null != e) { if (e.InnerException != null) { stringBuilder.AppendFormat("\r\n {0}", e.InnerException.Message); } stringBuilder.AppendFormat("\r\n {0}", e.StackTrace); } //记录异常日志文件 //LogManager.WriteException(stringBuilder.ToString()); if (showMsgBox) { //弹出异常日志窗口 System.Console.WriteLine(stringBuilder.ToString()); } } catch (Exception ex) { DebugMod.LogException(ex); } }
public void OnThreadUpdate() { try { DequueLogicAction(); m_FrmworkThreader.Update(); } catch (Exception ex) { DebugMod.LogException(ex); } }
public int PutData(byte[] byteData, int offset, int len) { if (len <= 0 || len > _maxLen) { //PRINT("CCircularBuffer::PutData len is <=0\n"); return(0); } while (IsOverFlowCondition(len)) { BufferResize(); } m_nValidCount += len; try { if (IsIndexOverFlow(len)) { int FirstCopyLen = m_iBufSize - m_iTailPos; int SecondCopyLen = len - FirstCopyLen; Tools.Assert.Check(FirstCopyLen > 0); Array.Copy(byteData, offset, m_Buffer, m_iTailPos, FirstCopyLen); if (SecondCopyLen > 0) { Array.Copy(byteData, offset + FirstCopyLen, m_Buffer, 0, SecondCopyLen); m_iTailPos = SecondCopyLen; } else { m_iTailPos = 0; } } else { Array.Copy(byteData, offset, m_Buffer, m_iTailPos, len); m_iTailPos += len; } } catch (Exception e) { DebugMod.LogException(e, "CircleBuffer.PutData", false); } return(len); }
/// <summary> /// 判断如果不是 "*", 则转为指定的值, 否则默认值 /// </summary> /// <param name="str"></param> /// <returns></returns> public static Int32 ConvertToInt32(string str, Int32 defVal) { try { if ("*" != str) { return(Convert.ToInt32(str)); } return(defVal); } catch (Exception e) { DebugMod.LogException(e); } return(defVal); }
public void Init() { try { //创建逻辑线程 DebugMod.Log("GameMain Init"); OutLog.Instance.InitLog(); //Thread t = new Thread(new ParameterizedThreadStart(ThreadProc)); //t.Start(this); //Thread.Sleep(0); LogicActionFactory.Instance.ActionAssembly = System.Reflection.Assembly.GetCallingAssembly(); BattleManager.Instance.Init(); } catch (Exception ex) { DebugMod.LogException(ex); } }
/// <summary> /// 格式化堆栈信息 /// </summary> /// <param name="msg"></param> /// <returns></returns> public static void LogFormatStack(System.Diagnostics.StackTrace stackTrace, string extMsg) { try { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendFormat("应用程序出现了对象锁定超时错误:\r\n"); stringBuilder.AppendFormat("\r\n 额外信息: {0}", extMsg); stringBuilder.AppendFormat("\r\n {0}", stackTrace.ToString()); //记录异常日志文件 //LogManager.WriteException(stringBuilder.ToString()); } catch (Exception e) { DebugMod.LogException(e); } }
/// <summary> /// 将日期时间字符串转为整数表示 /// </summary> /// <param name="str"></param> /// <returns></returns> public static long ConvertToTicks(string str) { try { DateTime dt; if (!DateTime.TryParse(str, out dt)) { return(0L); } return(dt.Ticks / 10000); } catch (Exception e) { DebugMod.LogException(e); } return(0L); }
public void Init() { GlobalObject = gameObject; try { //创建逻辑线程 DebugMod.Log("GameMain Init"); LuaScriptMgr.Instance.Init(); LuaScriptMgr.Instance.InitStart(); //Thread t = new Thread(new ParameterizedThreadStart(ThreadProc)); //t.Start(this); //Thread.Sleep(0); NetActionFactory.Instance.ActionAssembly = System.Reflection.Assembly.GetCallingAssembly(); } catch (Exception ex) { DebugMod.LogException(ex); } }
/// <summary> /// 输入密文和密钥,输出明文 /// </summary> /// <param name="plainText"></param> /// <param name="key"></param> /// <returns></returns> public static string Decrypt(string encryptText, string passwd, string saltValue) { if (string.IsNullOrEmpty(encryptText)) { return(null); } byte[] bytesData = ByteHelper.HexString2Bytes(encryptText); if (null == bytesData) { return(null); } byte[] bytesResult = null; try { bytesResult = AesHelper.AesDecryptBytes(bytesData, passwd, saltValue); } catch (Exception e) { DebugMod.LogException(e); return(null); } string strResult = null; try { strResult = new UTF8Encoding().GetString(bytesResult, 0, bytesResult.Length); } //解析错误 catch (Exception e) { DebugMod.LogException(e); return(null); } return(strResult); }
/// <summary> /// AES解密字节流 /// </summary> /// <param name="encryptData">密文字节流</param> /// <param name="passwd">密码</param> /// <param name="saltValue">盐值</param> /// <returns>解密后的明文字节流</returns> public static byte[] AesDecryptBytes(byte[] encryptData, string passwd, string saltValue) { // 盐值(与加密时设置的值必须一致) // 密码值(与加密时设置的值必须一致) byte[] saltBytes = Encoding.UTF8.GetBytes(saltValue); AesManaged aes = new AesManaged(); Rfc2898DeriveBytes rfc = new Rfc2898DeriveBytes(passwd, saltBytes); aes.BlockSize = aes.LegalBlockSizes[0].MaxSize; aes.KeySize = aes.LegalKeySizes[0].MaxSize; aes.Key = rfc.GetBytes(aes.KeySize / 8); aes.IV = rfc.GetBytes(aes.BlockSize / 8); // 用当前的 Key 属性和初始化向量 IV 创建对称解密器对象 ICryptoTransform decryptTransform = aes.CreateDecryptor(); // 解密后的输出流 MemoryStream decryptStream = new MemoryStream(); // 将解密后的目标流(decryptStream)与解密转换(decryptTransform)相连接 CryptoStream decryptor = new CryptoStream(decryptStream, decryptTransform, CryptoStreamMode.Write); try { // 将一个字节序列写入当前 CryptoStream (完成解密的过程) decryptor.Write(encryptData, 0, encryptData.Length); decryptor.Close(); } catch (Exception e) { DebugMod.LogException(e); return(null); //解密失败 } // 将解密后所得到的流转换为字符串 return(decryptStream.ToArray()); }
public bool CallLogicAction(ActionDefine actionType, ActionParam param) { try { LogicAction action = (LogicAction)LogicActionFactory.Instance.CreateAction(actionType); if (null == action) { return(false); } action.ActionId = (int)actionType; action.ActParam = param; lock (m_QueueLogicAction) { m_QueueLogicAction.Enqueue(action); } return(true); } catch (Exception ex) { DebugMod.LogException(ex); return(false); } }