mirror of
https://github.com/cadmium-im/zirconium-sharp.git
synced 2024-11-22 02:12:22 +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);
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user