-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSubscribe.cs
More file actions
53 lines (49 loc) · 1.54 KB
/
Copy pathSubscribe.cs
File metadata and controls
53 lines (49 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using Lidgren.Network;
using Serilog;
using ServerCommon;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Server
{
public class Subscribe
{
public static void Do(NetServer svr)
{
for (int i = 0; i < ChannelUpdater.Instance.channel_list.Length; ++i)
{
string subscript_key = $"channel_msg:{ChannelUpdater.Instance.channel_list[i].channel_id}";
RegisterSubscribe(subscript_key, svr);
}
}
public static void RegisterSubscribe(string subscript_key, NetServer svr)
{
try
{
Log.Information("sub {0}", subscript_key);
ISubscriber sub = Cache.Instance.cache.GetSubscriber();
sub.Subscribe(subscript_key, (channel, message) =>
{
try
{
Log.Information($"redis msg {message}");
var msg = svr.CreateMessage();
msg.Write((string)message);
svr.SendUnconnectedToSelf(msg, true);
}
catch(Exception ex)
{
Log.Error($"redis sub callback error {ex.ToString()}");
}
});
}
catch(Exception ex)
{
Log.Error($"redis sub error {ex.ToString()}");
}
}
}
}