forked from dadur604/RocksmithScrobbler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddonService.cs
34 lines (27 loc) · 1.07 KB
/
AddonService.cs
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
using RockSnifferLib.Sniffing;
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace RocksmithScrobbler.Addons {
internal class AddonService {
private AddonServiceListener listener;
private Thread listenThread;
public AddonService(string ipStr, int port) {
if (!IPAddress.TryParse(ipStr, out IPAddress ip)) {
throw new Exception($"IP Address '{ipStr}' is not valid");
}
Console.WriteLine("Starting AddonService listener on {0}:{1}", ip.ToString(), port);
TcpListener l = new TcpListener(ip, port);
l.Start();
listener = new AddonServiceListener(l);
listenThread = new Thread(new ThreadStart(listener.Listen));
listenThread.Start();
}
public void SetSniffer(Sniffer sniffer) {
sniffer.OnSongChanged += listener.OnCurrentSongChanged;
sniffer.OnMemoryReadout += listener.OnMemoryReadout;
sniffer.OnStateChanged += listener.OnStateChanged;
}
}
}