2017-07-17 19:42:36 +00:00
|
|
|
|
using System;
|
2017-06-19 13:42:10 +00:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 19:42:36 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2017-10-09 22:04:02 +00:00
|
|
|
|
using NadekoBot.Services;
|
2017-06-19 13:42:10 +00:00
|
|
|
|
|
2017-07-17 19:42:36 +00:00
|
|
|
|
namespace NadekoBot.Common.ShardCom
|
2017-06-19 13:42:10 +00:00
|
|
|
|
{
|
2017-10-09 22:04:02 +00:00
|
|
|
|
public class ShardComServer
|
2017-06-19 13:42:10 +00:00
|
|
|
|
{
|
2017-10-09 22:04:02 +00:00
|
|
|
|
private readonly IDataCache _cache;
|
2017-06-25 04:09:23 +00:00
|
|
|
|
|
2017-10-09 22:04:02 +00:00
|
|
|
|
public ShardComServer(IDataCache cache)
|
2017-06-25 04:09:23 +00:00
|
|
|
|
{
|
2017-10-09 22:04:02 +00:00
|
|
|
|
_cache = cache;
|
2017-06-25 04:09:23 +00:00
|
|
|
|
}
|
2017-06-19 13:42:10 +00:00
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
2017-10-09 22:04:02 +00:00
|
|
|
|
var sub = _cache.Redis.GetSubscriber();
|
|
|
|
|
sub.SubscribeAsync("shardcoord_send", (ch, data) =>
|
2017-06-19 13:42:10 +00:00
|
|
|
|
{
|
2017-10-09 22:04:02 +00:00
|
|
|
|
var _ = OnDataReceived(JsonConvert.DeserializeObject<ShardComMessage>(data));
|
|
|
|
|
}, StackExchange.Redis.CommandFlags.FireAndForget);
|
2017-06-19 13:42:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public event Func<ShardComMessage, Task> OnDataReceived = delegate { return Task.CompletedTask; };
|
|
|
|
|
}
|
|
|
|
|
}
|