Example #1
0
 private static Task SendCoflnetException(SocketMessageData data, CoflnetException ex)
 {
     return(data.SendBack(new MessageData("error", JsonConvert.SerializeObject(new { ex.Slug, ex.Message }))
     {
         mId = data.mId
     }));
 }
Example #2
0
 private void ExecuteCommand(SocketMessageData data)
 {
     Task.Run(async() =>
     {
         System.Threading.Interlocked.Increment(ref waiting);
         if (data.Type != "playerName")
         {
             await limiter;
         }
         System.Threading.Interlocked.Decrement(ref waiting);
         try
         {
             await Commands[data.Type].Execute(data);
         }
         catch (CoflnetException ex)
         {
             await SendCoflnetException(data, ex);
         }
         catch (Exception ex)
         {
             var cofl = ex.InnerException as CoflnetException;
             if (cofl != null)
             {
                 // wrapped exception (eg. Theaded)
                 await SendCoflnetException(data, cofl);
                 return;
             }
             dev.Logger.Instance.Error($"Fatal error on Command {JsonConvert.SerializeObject(data)} {ex.Message} {ex.StackTrace} \n{ex.InnerException?.Message} {ex.InnerException?.StackTrace}");
             await data.SendBack(new MessageData("error", JsonConvert.SerializeObject(new { Slug = "unknown", Message = "An unexpected error occured, make sure the format of Data is correct" }))
             {
                 mId = data.mId
             });
         }
     }).ConfigureAwait(false);
 }