Add SendMessage with automatic json serialization in ConnectionHandler

This commit is contained in:
ChronosX88 2020-10-09 17:12:02 +04:00
parent dc030c0521
commit ce8ed0d7ad
Signed by: ChronosXYZ
GPG Key ID: 085A69A82C8C511A
2 changed files with 10 additions and 10 deletions

View File

@ -82,6 +82,11 @@ namespace Zirconium.Core
this.Send(message);
}
public void SendMessage(BaseMessage message)
{
this.Send(JsonConvert.SerializeObject(message));
}
public void CloseConnection() {
this.Sessions.CloseSession(this.ID); // TODO need to clarify if CloseSession also calls OnClose callback
}

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Zirconium.Core.Logging;
using Zirconium.Core.Models;
using Zirconium.Core.Plugins.Interfaces;
using Zirconium.Utils;
@ -98,8 +97,7 @@ namespace InBandLogin
p.DeviceID = deviceID;
reply.Payload = p.ToDictionary();
reply.Ok = true;
var msg = JsonConvert.SerializeObject(reply);
session.ConnectionHandler.SendMessage(msg);
session.ConnectionHandler.SendMessage(reply);
}
else
{
@ -108,9 +106,8 @@ namespace InBandLogin
errID,
"Username/password isn't valid",
new Dictionary<string, object>()
).ToDictionary();
var msg = JsonConvert.SerializeObject(reply);
session.ConnectionHandler.SendMessage(msg);
);
session.ConnectionHandler.SendMessage(reply);
}
}
@ -170,8 +167,7 @@ namespace InBandLogin
new Dictionary<string, object>()
);
}
var errorMsg = JsonConvert.SerializeObject(errorReply);
session.ConnectionHandler.SendMessage(errorMsg);
session.ConnectionHandler.SendMessage(errorReply);
return;
}
BaseMessage reply = new BaseMessage(message, true);
@ -185,8 +181,7 @@ namespace InBandLogin
}
reply.Payload = p.ToDictionary();
reply.Ok = true;
var msg = JsonConvert.SerializeObject(reply);
session.ConnectionHandler.SendMessage(msg);
session.ConnectionHandler.SendMessage(reply);
}
public bool IsAuthorizationRequired()