mirror of
https://github.com/cadmium-im/zirconium-sharp.git
synced 2024-11-22 10:22:23 +00:00
Add SendMessage with automatic json serialization in ConnectionHandler
This commit is contained in:
parent
dc030c0521
commit
ce8ed0d7ad
@ -82,6 +82,11 @@ namespace Zirconium.Core
|
|||||||
this.Send(message);
|
this.Send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SendMessage(BaseMessage message)
|
||||||
|
{
|
||||||
|
this.Send(JsonConvert.SerializeObject(message));
|
||||||
|
}
|
||||||
|
|
||||||
public void CloseConnection() {
|
public void CloseConnection() {
|
||||||
this.Sessions.CloseSession(this.ID); // TODO need to clarify if CloseSession also calls OnClose callback
|
this.Sessions.CloseSession(this.ID); // TODO need to clarify if CloseSession also calls OnClose callback
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Zirconium.Core.Logging;
|
|
||||||
using Zirconium.Core.Models;
|
using Zirconium.Core.Models;
|
||||||
using Zirconium.Core.Plugins.Interfaces;
|
using Zirconium.Core.Plugins.Interfaces;
|
||||||
using Zirconium.Utils;
|
using Zirconium.Utils;
|
||||||
@ -98,8 +97,7 @@ namespace InBandLogin
|
|||||||
p.DeviceID = deviceID;
|
p.DeviceID = deviceID;
|
||||||
reply.Payload = p.ToDictionary();
|
reply.Payload = p.ToDictionary();
|
||||||
reply.Ok = true;
|
reply.Ok = true;
|
||||||
var msg = JsonConvert.SerializeObject(reply);
|
session.ConnectionHandler.SendMessage(reply);
|
||||||
session.ConnectionHandler.SendMessage(msg);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -108,9 +106,8 @@ namespace InBandLogin
|
|||||||
errID,
|
errID,
|
||||||
"Username/password isn't valid",
|
"Username/password isn't valid",
|
||||||
new Dictionary<string, object>()
|
new Dictionary<string, object>()
|
||||||
).ToDictionary();
|
);
|
||||||
var msg = JsonConvert.SerializeObject(reply);
|
session.ConnectionHandler.SendMessage(reply);
|
||||||
session.ConnectionHandler.SendMessage(msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,8 +167,7 @@ namespace InBandLogin
|
|||||||
new Dictionary<string, object>()
|
new Dictionary<string, object>()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
var errorMsg = JsonConvert.SerializeObject(errorReply);
|
session.ConnectionHandler.SendMessage(errorReply);
|
||||||
session.ConnectionHandler.SendMessage(errorMsg);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BaseMessage reply = new BaseMessage(message, true);
|
BaseMessage reply = new BaseMessage(message, true);
|
||||||
@ -185,8 +181,7 @@ namespace InBandLogin
|
|||||||
}
|
}
|
||||||
reply.Payload = p.ToDictionary();
|
reply.Payload = p.ToDictionary();
|
||||||
reply.Ok = true;
|
reply.Ok = true;
|
||||||
var msg = JsonConvert.SerializeObject(reply);
|
session.ConnectionHandler.SendMessage(reply);
|
||||||
session.ConnectionHandler.SendMessage(msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsAuthorizationRequired()
|
public bool IsAuthorizationRequired()
|
||||||
|
Loading…
Reference in New Issue
Block a user