diff --git a/Source/Framework/ZyGames.Framework.Common/Configuration/ConfigManager.cs b/Source/Framework/ZyGames.Framework.Common/Configuration/ConfigManager.cs index 20cb74bd..bfc7f9b2 100644 --- a/Source/Framework/ZyGames.Framework.Common/Configuration/ConfigManager.cs +++ b/Source/Framework/ZyGames.Framework.Common/Configuration/ConfigManager.cs @@ -91,10 +91,9 @@ public static IConfigger Configger /// /// /// - /// /// /// - public static void Intialize(string sectionName) + public static bool Intialize(string sectionName) { lock (syncRoot) { @@ -105,11 +104,9 @@ public static void Intialize(string sectionName) instance.Install(); _configgerSet.Add(instance); _configger = instance; + return true; } - else - { - throw new ArgumentException("Not found section node.", "sectionName"); - } + return false; } } diff --git a/Source/Framework/ZyGames.Framework/Cache/Generic/CacheItemSet.cs b/Source/Framework/ZyGames.Framework/Cache/Generic/CacheItemSet.cs index 706c2047..801fc943 100644 --- a/Source/Framework/ZyGames.Framework/Cache/Generic/CacheItemSet.cs +++ b/Source/Framework/ZyGames.Framework/Cache/Generic/CacheItemSet.cs @@ -303,23 +303,39 @@ public void Dispose() } - internal void ProcessExpired(string key) + /// + /// 是否能处理过期 + /// + /// + /// + internal bool TryProcessExpired(string key) { if (_itemData is AbstractEntity) { var t = ((AbstractEntity)_itemData); + if (t.HasChanged) return false; + t.IsInCache = false; t.IsExpired = true; } else if (_itemData is BaseCollection) { + bool hasChanged = false; ((BaseCollection)_itemData).Foreach((k, t) => { + if (t.HasChanged) + { + hasChanged = t.HasChanged; + return false; + } t.IsInCache = false; t.IsExpired = true; return true; }); + + if (hasChanged) return false; } + return true; } } } \ No newline at end of file diff --git a/Source/Framework/ZyGames.Framework/Cache/Generic/CachePeriod.cs b/Source/Framework/ZyGames.Framework/Cache/Generic/CachePeriod.cs index 149a2aa9..81541905 100644 --- a/Source/Framework/ZyGames.Framework/Cache/Generic/CachePeriod.cs +++ b/Source/Framework/ZyGames.Framework/Cache/Generic/CachePeriod.cs @@ -74,8 +74,7 @@ public int PeriodTime /// public bool IsPeriod { - - get { return !IsPersistence && MathUtils.DiffDate(_preAccessTime).TotalSeconds > PeriodTime; } + get { return !IsPersistence && MathUtils.DiffDate(_accessTime).TotalSeconds > PeriodTime; } } /// @@ -117,7 +116,6 @@ public void ResetCounter() /// public void RefreshAccessTime() { - _preAccessTime = _accessTime; _accessTime = DateTime.Now; _preAccessCounter = _accessCounter; diff --git a/Source/Framework/ZyGames.Framework/Cache/Generic/Pool/BaseCachePool.cs b/Source/Framework/ZyGames.Framework/Cache/Generic/Pool/BaseCachePool.cs index 5b62f298..47540032 100644 --- a/Source/Framework/ZyGames.Framework/Cache/Generic/Pool/BaseCachePool.cs +++ b/Source/Framework/ZyGames.Framework/Cache/Generic/Pool/BaseCachePool.cs @@ -465,8 +465,11 @@ public virtual void DisposeCache() itemSet.RemoveExpired(itemPair.Key); continue; } + if (!itemSet.TryProcessExpired(itemPair.Key)) + { + continue; + } TraceLog.ReleaseWrite("Cache item:{0} key:{1} expired has been removed.", containerPair.Key, itemPair.Key); - itemSet.ProcessExpired(itemPair.Key); object temp; if (containerPair.Value.Collection.TryRemove(itemPair.Key, out temp)) { diff --git a/Source/Framework/ZyGames.Framework/RPC/IO/BufferUtils.cs b/Source/Framework/ZyGames.Framework/RPC/IO/BufferUtils.cs index 65a65235..b64e4f25 100644 --- a/Source/Framework/ZyGames.Framework/RPC/IO/BufferUtils.cs +++ b/Source/Framework/ZyGames.Framework/RPC/IO/BufferUtils.cs @@ -59,6 +59,30 @@ static public Byte[] MergeBytes(params Byte[][] args) } + /// + /// + /// + /// + /// + public static Byte[] GetBytes(byte[] data) + { + return GetBytes(data, 0, data.Length); + } + + /// + /// + /// + /// + /// + /// + /// + static public Byte[] GetBytes(byte[] data, int pos, int count) + { + var buffer = new byte[count]; + Buffer.BlockCopy(data, pos, buffer, 0, count); + return buffer; + } + /// /// /// diff --git a/Source/Framework/ZyGames.Framework/RPC/Sockets/MessageHandler.cs b/Source/Framework/ZyGames.Framework/RPC/Sockets/MessageHandler.cs index 923a7355..bdbc603d 100644 --- a/Source/Framework/ZyGames.Framework/RPC/Sockets/MessageHandler.cs +++ b/Source/Framework/ZyGames.Framework/RPC/Sockets/MessageHandler.cs @@ -85,10 +85,15 @@ public override bool TryReadMeaage(DataToken dataToken, byte[] buffer, out List< remainingBytesToProcess = HandlePrefix(buffer, dataToken.bufferSkip, dataToken, remainingBytesToProcess); if (dataToken.prefixBytesDone == 4 && (dataToken.messageLength > 10 * 1024 * 1024 || dataToken.messageLength <= 0)) { - byte[] bufferBytes = BufferUtils.MergeBytes(dataToken.byteArrayForPrefix, dataToken.byteArrayForMessage); + byte[] bufferBytes = dataToken.byteArrayForMessage == null ? + BufferUtils.MergeBytes(dataToken.byteArrayForPrefix, BufferUtils.GetBytes(buffer, dataToken.bufferSkip, buffer.Length - dataToken.bufferSkip)) : + BufferUtils.MergeBytes(dataToken.byteArrayForPrefix, dataToken.byteArrayForMessage, buffer); string data = Encoding.UTF8.GetString(bufferBytes); //消息头已接收完毕,并且接收到的消息长度大于10M,socket传输的数据已紊乱,关闭掉 - TraceLog.ReleaseWriteDebug("Receive Ip {1} message length error:{0}\r\nData:{2}", dataToken.messageLength, (dataToken != null ? dataToken.Socket.RemoteEndPoint.ToNotNullString() : ""), data); + TraceLog.Write("The host[{0}] request parser head byte error, byte len={1}\r\ndata:{2}", + dataToken.Socket.RemoteEndPoint.ToNotNullString(), + dataToken.messageLength, + data); needPostAnother = false; break; } diff --git a/Source/Framework/ZyGames.Framework/RPC/Sockets/SocketListener.cs b/Source/Framework/ZyGames.Framework/RPC/Sockets/SocketListener.cs index 3e29e2f3..f943b3ec 100644 --- a/Source/Framework/ZyGames.Framework/RPC/Sockets/SocketListener.cs +++ b/Source/Framework/ZyGames.Framework/RPC/Sockets/SocketListener.cs @@ -401,7 +401,10 @@ private void ProcessReceive(SocketAsyncEventArgs ioEventArgs) if (ioEventArgs.SocketError != SocketError.Success) {//Socket错误 - TraceLog.Write("IP {0} ProcessReceive:{1}", (dataToken != null ? dataToken.Socket.RemoteEndPoint.ToNotNullString() : ""), ioEventArgs.SocketError); + TraceLog.Write("ProcessReceive IP {0} SocketError:{1}, bytes len:{2}", + (dataToken != null ? dataToken.Socket.RemoteEndPoint.ToNotNullString() : ""), + ioEventArgs.SocketError.ToString(), + ioEventArgs.BytesTransferred); Closing(ioEventArgs); return; } diff --git a/Source/Middleware/AccountServer/AccountServer.csproj b/Source/Middleware/AccountServer/AccountServer.csproj index 4183b775..e7ccf9d7 100644 --- a/Source/Middleware/AccountServer/AccountServer.csproj +++ b/Source/Middleware/AccountServer/AccountServer.csproj @@ -65,12 +65,6 @@ - - ..\..\Framework\ZyGames.Framework\bin\Release\ZyGames.Framework.dll - - - ..\..\Framework\ZyGames.Framework\bin\Release\ZyGames.Framework.Common.dll - @@ -108,6 +102,14 @@ + + {e87a5049-85a1-436b-a5ed-2bc0a4e45bdb} + ZyGames.Framework.Common4.5 + + + {416e2e00-4064-4d7a-87a2-a649ff120274} + ZyGames.Framework4.5 + {de7024b7-7168-4262-a250-6a21b932ec3b} ZyGames.Framework.Game4.5 diff --git a/Source/Middleware/GameServer/GameServer4.5.csproj b/Source/Middleware/GameServer/GameServer4.5.csproj index cc6480dd..273fc537 100644 --- a/Source/Middleware/GameServer/GameServer4.5.csproj +++ b/Source/Middleware/GameServer/GameServer4.5.csproj @@ -66,12 +66,6 @@ - - ..\..\Framework\ZyGames.Framework\bin\Release\ZyGames.Framework.dll - - - ..\..\Framework\ZyGames.Framework\bin\Release\ZyGames.Framework.Common.dll - @@ -107,9 +101,17 @@ + + {e87a5049-85a1-436b-a5ed-2bc0a4e45bdb} + ZyGames.Framework.Common4.5 + + + {416e2e00-4064-4d7a-87a2-a649ff120274} + ZyGames.Framework4.5 + {DE7024B7-7168-4262-A250-6A21B932EC3B} - ZyGames.Framework.Game + ZyGames.Framework.Game4.5 diff --git a/Source/Middleware/ZyGames.Framework.Game/Contract/GameSession.cs b/Source/Middleware/ZyGames.Framework.Game/Contract/GameSession.cs index 9fb2019a..72e57782 100644 --- a/Source/Middleware/ZyGames.Framework.Game/Contract/GameSession.cs +++ b/Source/Middleware/ZyGames.Framework.Game/Contract/GameSession.cs @@ -523,7 +523,12 @@ private void DoHeartbeatTimeout() /// public bool EnterLock(int actionId, object agr1, out object arg2) { +#if LOCK_TEST + arg2 = null; + return true; +#else return _monitorLock.TryEnter(actionId, RequestTimeout, agr1, out arg2); +#endif } /// /// @@ -531,7 +536,10 @@ public bool EnterLock(int actionId, object agr1, out object arg2) /// public void ExitLock(int actionId) { +#if LOCK_TEST +#else _monitorLock.Exit(actionId); +#endif } /// diff --git a/Source/Middleware/ZyGames.Framework.Game/Contract/RemotePackage.cs b/Source/Middleware/ZyGames.Framework.Game/Contract/RemotePackage.cs index 5e9bee11..570a70c6 100644 --- a/Source/Middleware/ZyGames.Framework.Game/Contract/RemotePackage.cs +++ b/Source/Middleware/ZyGames.Framework.Game/Contract/RemotePackage.cs @@ -49,6 +49,14 @@ public RemotePackage() /// 服务器间内部通讯通道 /// public string RouteName { get; set; } + /// + /// + /// + public int ErrorCode { get; set; } + /// + /// + /// + public string ErrorInfo { get; set; } /// /// Message of custom diff --git a/Source/Middleware/ZyGames.Framework.Game/Contract/RemoteService.cs b/Source/Middleware/ZyGames.Framework.Game/Contract/RemoteService.cs index bd8662d2..eb13f20f 100644 --- a/Source/Middleware/ZyGames.Framework.Game/Contract/RemoteService.cs +++ b/Source/Middleware/ZyGames.Framework.Game/Contract/RemoteService.cs @@ -98,27 +98,30 @@ private static void OnNetTcpCallback(object sender, RemoteEventArgs e) { return; } - try + using (var ms = new MessageStructure(e.Data)) { - using (var ms = new MessageStructure(e.Data)) + var head = ms.ReadHeadGzip(); + if (head != null) { - var head = ms.ReadHeadGzip(); - if (head != null) + var package = proxy.Find(head.MsgId); + if (package != null) { - var package = proxy.Find(head.MsgId); - if (package != null) - { - package.Message = ms.ReadBuffer(); - proxy.Remove(head.MsgId); - package.OnCallback(); - return; - } + package.ErrorCode = head.ErrorCode; + package.ErrorInfo = head.ErrorInfo; + package.Message = ms.ReadBuffer(); + proxy.Remove(head.MsgId); + package.OnCallback(); + } + else + { + proxy.OnPushedHandle(e); } } + else + { + proxy.OnErrorHandle(e); + } } - catch (Exception) - { } - proxy.OnPushedHandle(e); } catch (Exception ex) { @@ -143,10 +146,20 @@ private static void OnNetHttpCallback(object sender, RemoteEventArgs e) var package = proxy.Find(head.MsgId); if (package != null) { + package.ErrorCode = head.ErrorCode; + package.ErrorInfo = head.ErrorInfo; package.Message = ms.ReadBuffer(); proxy.Remove(head.MsgId); package.OnCallback(); } + else + { + proxy.OnPushedHandle(e); + } + } + else + { + proxy.OnErrorHandle(e); } } } @@ -164,10 +177,21 @@ private static void OnNetHttpCallback(object sender, RemoteEventArgs e) private string _proxySessionId = ""; private DictionaryExtend _packagePools; /// - /// + /// Server push to data callback /// public event RemoteCallback PushedHandle; + /// + /// + /// + public event RemoteCallback ErrorHandle; + + private void OnErrorHandle(RemoteEventArgs e) + { + RemoteCallback handler = ErrorHandle; + if (handler != null) handler(this, e); + } + private void OnPushedHandle(RemoteEventArgs e) { RemoteCallback handler = PushedHandle; diff --git a/Source/Middleware/ZyGames.Framework.Game/Runtime/EnvironmentSetting.cs b/Source/Middleware/ZyGames.Framework.Game/Runtime/EnvironmentSetting.cs index a29fffa0..2a43cad3 100644 --- a/Source/Middleware/ZyGames.Framework.Game/Runtime/EnvironmentSetting.cs +++ b/Source/Middleware/ZyGames.Framework.Game/Runtime/EnvironmentSetting.cs @@ -53,11 +53,16 @@ public class EnvironmentSetting static EnvironmentSetting() { + bool result; try { - ConfigManager.Intialize("appServerConfigger"); + result = ConfigManager.Intialize("appServerConfigger"); } catch (Exception) + { + result = false; + } + if (!result) { try { @@ -178,7 +183,7 @@ public string RedisHost { get { - var section =ConfigManager.Configger.GetFirstOrAddConfig(); + var section = ConfigManager.Configger.GetFirstOrAddConfig(); return section.Host; } } diff --git a/Source/Middleware/ZyGames.Framework.Game/ZyGames.Framework.Game4.5.csproj b/Source/Middleware/ZyGames.Framework.Game/ZyGames.Framework.Game4.5.csproj index 6c0ed265..a9abb36c 100644 --- a/Source/Middleware/ZyGames.Framework.Game/ZyGames.Framework.Game4.5.csproj +++ b/Source/Middleware/ZyGames.Framework.Game/ZyGames.Framework.Game4.5.csproj @@ -67,14 +67,6 @@ - - False - ..\..\Framework\ZyGames.Framework\bin\Release\ZyGames.Framework.dll - - - False - ..\..\Framework\ZyGames.Framework\bin\Release\ZyGames.Framework.Common.dll - @@ -263,7 +255,16 @@ - + + + {e87a5049-85a1-436b-a5ed-2bc0a4e45bdb} + ZyGames.Framework.Common4.5 + + + {416e2e00-4064-4d7a-87a2-a649ff120274} + ZyGames.Framework4.5 + +