-
Notifications
You must be signed in to change notification settings - Fork 0
/
EddFcmsPlugin.cs
158 lines (134 loc) · 5.54 KB
/
EddFcmsPlugin.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using QuickJSON;
namespace EddFcmsPlugin
{
public class EDDClass
{
private string CmdrName { get; set; }
private JObject FcmsCredentials { get; set; }
private static readonly HttpClient FcmsClient = new HttpClient();
public EDDClass()
{
System.Diagnostics.Debug.WriteLine("EddFcmsPlugin Made DLL instance");
}
EDDDLLInterfaces.EDDDLLIF.EDDCallBacks callbacks;
public string EDDInitialise(string vstr, string dllfolder, EDDDLLInterfaces.EDDDLLIF.EDDCallBacks cb)
{
System.Diagnostics.Debug.WriteLine("EddFcmsPlugin Init func " + vstr + " " + dllfolder);
CmdrName = null;
callbacks = cb;
return "1.0.0.0";
}
public void EDDTerminate()
{
System.Diagnostics.Debug.WriteLine("EddFcmsPlugin Unload");
}
public void EDDRefresh(string cmdname, EDDDLLInterfaces.EDDDLLIF.JournalEntry lastje)
{
System.Diagnostics.Debug.WriteLine("EddFcmsPlugin Refresh");
CmdrName = cmdname;
}
public void EDDMainFormShown()
{
System.Diagnostics.Debug.WriteLine("EddFcmsPlugin Main form shown");
}
void PostCarrierJumpAction(EDDDLLInterfaces.EDDDLLIF.JournalEntry je)
{
if ((FcmsCredentials[je.cmdrname] == null) ||
(FcmsCredentials[je.cmdrname]["FcmsEmailAddress"].Str() == "") ||
(FcmsCredentials[je.cmdrname]["FcmsApiKey"].Str() == ""))
{
System.Diagnostics.Debug.WriteLine("EddFcmsPlugin skipping PostCarrierJumpAction due to missing credentials");
return;
}
JObject js = new JObject();
js["cmdr"] = je.cmdrname;
js["system"] = je.systemname;
js["station"] = je.stationname;
js["data"] = JObject.Parse(je.json);
js["is_beta"] = je.beta;
js["user"] = FcmsCredentials[je.cmdrname]["FcmsEmailAddress"].Str();
js["key"] = FcmsCredentials[je.cmdrname]["FcmsApiKey"].Str();
// encode the data and post it to the API endpoint
StringContent content = new StringContent(js.ToString(), Encoding.UTF8, "application/json");
try
{
HttpResponseMessage response = FcmsClient.PostAsync("https://fleetcarrier.space/api", content).Result;
}
catch (Exception)
{
// no op
}
}
public void EDDNewJournalEntry(EDDDLLInterfaces.EDDDLLIF.JournalEntry je)
{
System.Diagnostics.Debug.WriteLine("EddFcmsPlugin New Journal Entry " + je.utctime);
string type = je.eventid;
switch (type)
{
case "CarrierJumpRequest":
case "CarrierJumpCancelled":
Task.Run(() => PostCarrierJumpAction(je));
break;
}
}
public void EDDNewUnfilteredJournalEntry(EDDDLLInterfaces.EDDDLLIF.JournalEntry je)
{
System.Diagnostics.Debug.WriteLine("EddFcmsPlugin New Unfiltered Journal Entry " + je.utctime);
}
public string EDDActionCommand(string cmdname, string[] paras)
{
System.Diagnostics.Debug.WriteLine("EddFcmsPlugin EDD Action Command");
return "";
}
public void EDDActionJournalEntry(EDDDLLInterfaces.EDDDLLIF.JournalEntry je)
{
System.Diagnostics.Debug.WriteLine("EddFcmsPlugin EDD Action journal entry");
}
public void EDDNewUIEvent(string json)
{
System.Diagnostics.Debug.WriteLine("EddFcmsPlugin EDD UI Event" + json);
}
public string EDDConfig(string istr, bool editit)
{
// deserialize the list of FCMS credentials
FcmsCredentials = JObject.Parse(istr);
if (FcmsCredentials == null)
{
// parsing failed, don't care why, just start over
FcmsCredentials = new JObject();
}
if (editit && CmdrName != null)
{
if (FcmsCredentials[CmdrName] == null)
{
// init credentials for this CMDR
FcmsCredentials[CmdrName] = new JObject();
FcmsCredentials[CmdrName]["FcmsEmailAddress"] = "";
FcmsCredentials[CmdrName]["FcmsApiKey"] = "";
}
// ask this CMDR for new credentials
ConfigPanel prompt = new ConfigPanel(FcmsCredentials[CmdrName]["FcmsEmailAddress"].Str(), FcmsCredentials[CmdrName]["FcmsApiKey"].Str());
prompt.ShowDialog();
// store them
FcmsCredentials[CmdrName]["FcmsEmailAddress"] = prompt.FcmsEmailAddress;
FcmsCredentials[CmdrName]["FcmsApiKey"] = prompt.FcmsApiKey;
}
else if (editit && CmdrName == null)
{
MessageBox.Show("Please wait for the history refresh to finish and try again.");
}
// serialize the list of FCMS credentials
string outconfig = FcmsCredentials.ToString();
System.Diagnostics.Debug.WriteLine("EddFcmsPlugin EDD Config Event:" + outconfig);
return outconfig;
}
}
}