forked from SodiumEyes/KerbalLiveFeed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPluginClient.cs
87 lines (71 loc) · 2.14 KB
/
PluginClient.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace KLF {
class PluginClient : Client
{
public delegate void HandleInteropCallback(KLFCommon.ClientInteropMessageID id, byte[] data);
Queue<InteropMessage> interopInQueue;
Queue<InteropMessage> interopOutQueue;
Queue<ServerMessage> serverMessageQueue;
object serverMessageQueueLock = new object();
protected override void connectionStarted()
{
interopInQueue = new Queue<InteropMessage>();
interopOutQueue = new Queue<InteropMessage>();
serverMessageQueue = new Queue<ServerMessage>();
}
protected override void messageReceived(KLFCommon.ServerMessageID id, byte[] data)
{
ServerMessage message;
message.id = id;
message.data = data;
lock (serverMessageQueueLock)
{
serverMessageQueue.Enqueue(message);
}
}
protected override void sendClientInteropMessage(KLFCommon.ClientInteropMessageID id, byte[] data)
{
InteropMessage message = new InteropMessage();
message.id = (int)id;
message.data = data;
interopOutQueue.Enqueue(message);
}
public void updateStep(HandleInteropCallback interop_callback)
{
if (!isConnected)
return;
while (interopInQueue.Count > 0)
{
InteropMessage message = interopInQueue.Dequeue();
handleInteropMessage(message.id, message.data);
}
lock (serverMessageQueueLock)
{
//Handle received messages
while (serverMessageQueue.Count > 0)
{
ServerMessage message = serverMessageQueue.Dequeue();
handleMessage(message.id, message.data);
}
}
throttledShareScreenshots();
writeClientData();
handleConnection();
while (interopOutQueue.Count > 0)
{
InteropMessage message = interopOutQueue.Dequeue();
interop_callback((KLFCommon.ClientInteropMessageID)message.id, message.data);
}
}
public void enqueuePluginInteropMessage(KLFCommon.PluginInteropMessageID id, byte[] data)
{
InteropMessage message = new InteropMessage();
message.id = (int)id;
message.data = data;
interopInQueue.Enqueue(message);
}
}
}