diff --git a/src/Zirconium/Core/Router.cs b/src/Zirconium/Core/Router.cs index 3d215ae..a969d8e 100644 --- a/src/Zirconium/Core/Router.cs +++ b/src/Zirconium/Core/Router.cs @@ -40,6 +40,7 @@ namespace Zirconium.Core session.ConnectionHandler.SendMessage(serializedMsg); return; } + var handlerTasks = new List(); foreach (var h in handlers) { if (h.IsAuthorizationRequired()) @@ -59,15 +60,15 @@ namespace Zirconium.Core catch (Exception e) { Log.Warning(e.Message); + var errorMsg = OtherUtils.GenerateProtocolError( + message, + "unauthorized", + "Unauthorized access", + new Dictionary() + ); + errorMsg.From = _app.Config.ServerID; + var serializedMsg = JsonConvert.SerializeObject(errorMsg); - var serializedMsg = JsonConvert.SerializeObject( - OtherUtils.GenerateProtocolError( - message, - "unauthorized", - "Unauthorized access", - new Dictionary() - ) - ); session.ConnectionHandler.SendMessage(serializedMsg); return; } @@ -77,11 +78,17 @@ namespace Zirconium.Core } } - Task.Run(() => + var task = Task.Run(() => { // probably need to wrap whole foreach body, not only HandleMessage call - need to investigate h.HandleMessage(session, message); }); + handlerTasks.Add(task); + } + try { + Task.WaitAll(handlerTasks.ToArray()); + } catch (Exception e) { + Log.Error(e.ToString()); } }