Skip to content
This repository was archived by the owner on Apr 3, 2020. It is now read-only.

Commit a00e1f3

Browse files
committed
Support self distributed version of extension for Firefox
1 parent 734f4d6 commit a00e1f3

File tree

9 files changed

+79
-18
lines changed

9 files changed

+79
-18
lines changed

browser/hostapp/manifest.windows.firefox.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"description": "netcode.io helper",
44
"name": "netcode.io",
55
"allowed_extensions": [
6-
"{1af46c0f-6130-426a-b504-1f5b8295a173}"
6+
"{1af46c0f-6130-426a-b504-1f5b8295a173}",
7+
"{4279ff57-aad6-4990-bf0b-2010a55ed5d5}"
78
],
89
"type": "stdio"
910
}

browser/hostapp/manifest.windows.relative.firefox.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"description": "netcode.io helper",
44
"name": "netcode.io",
55
"allowed_extensions": [
6-
"{1af46c0f-6130-426a-b504-1f5b8295a173}"
6+
"{1af46c0f-6130-426a-b504-1f5b8295a173}",
7+
"{4279ff57-aad6-4990-bf0b-2010a55ed5d5}"
78
],
89
"type": "stdio"
910
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"manifest_version": 2,
3+
"name": "netcode.io support (self-dist)",
4+
"version": "0.1.5",
5+
"description": "Provides netcode.io APIs to websites; this is the version distributed from netcode.redpoint.games",
6+
"applications": {
7+
"gecko": {
8+
"id": "{4279ff57-aad6-4990-bf0b-2010a55ed5d5}",
9+
"strict_min_version": "42.0"
10+
}
11+
},
12+
"content_scripts": [
13+
{
14+
"matches": ["*://*/*"],
15+
"js": ["netcodecs.js"],
16+
"run_at": "document_start",
17+
"all_frames": true
18+
}
19+
],
20+
"background": {
21+
"scripts": ["hostmsg.js"],
22+
"persistent": true
23+
},
24+
"web_accessible_resources": [
25+
"netcode.js"
26+
],
27+
"permissions": [
28+
"nativeMessaging",
29+
"tabs",
30+
"*://*/*"
31+
]
32+
}

build/Build-Win32.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ function ZipFiles( $zipfilename, $sourcedir )
2626
$zipfilename, $compressionLevel, $false)
2727
}
2828

29-
echo "Creating Web Extension ZIP..."
29+
echo "Creating Web Extension ZIP (standard)..."
3030
ZipFiles -zipfilename $root\output\WebExtension.zip -sourcedir $root\browser\webext
3131

32+
echo "Creating Web Extension ZIP (self-dist)..."
33+
cp -Force $root\webext\hostmsg.js $root\webext-selfdist\
34+
cp -Force $root\webext\netcode.js $root\webext-selfdist\
35+
cp -Force $root\webext\netcodecs.js $root\webext-selfdist\
36+
ZipFiles -zipfilename $root\output\WebExtension-SelfDist.zip -sourcedir $root\browser\webext-selfdist
37+
3238
echo "Building netcode.io helper..."
3339
if (Test-Path $root\netcode.io.host\bin\Release) {
3440
rm -Recurse -Force $root\netcode.io.host\bin\Release

netcode.io.demoserver/Program.cs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private static void NetcodeServer()
145145
server.Dispose();
146146
}
147147

148-
public static string SendResponse(HttpListenerRequest request, HttpListenerResponse response)
148+
public static Tuple<int, byte[]> SendResponse(HttpListenerRequest request, HttpListenerResponse response)
149149
{
150150
if (request.Url.AbsolutePath == "/")
151151
{
@@ -155,7 +155,7 @@ public static string SendResponse(HttpListenerRequest request, HttpListenerRespo
155155
var indexPath = Path.Combine(new FileInfo(asmPath).DirectoryName, "index.htm");
156156
using (var reader = new StreamReader(indexPath))
157157
{
158-
return reader.ReadToEnd().Replace("__PROTOCOL__", isServerIpv4 ? "ipv4" : "ipv6");
158+
return new Tuple<int, byte[]>(200, Encoding.UTF8.GetBytes(reader.ReadToEnd().Replace("__PROTOCOL__", isServerIpv4 ? "ipv4" : "ipv6")));
159159
}
160160
}
161161

@@ -167,7 +167,7 @@ public static string SendResponse(HttpListenerRequest request, HttpListenerRespo
167167
var indexPath = Path.Combine(new FileInfo(asmPath).DirectoryName, "basic.htm");
168168
using (var reader = new StreamReader(indexPath))
169169
{
170-
return reader.ReadToEnd().Replace("__PROTOCOL__", isServerIpv4 ? "ipv4" : "ipv6");
170+
return new Tuple<int, byte[]>(200, Encoding.UTF8.GetBytes(reader.ReadToEnd().Replace("__PROTOCOL__", isServerIpv4 ? "ipv4" : "ipv6")));
171171
}
172172
}
173173

@@ -183,10 +183,24 @@ public static string SendResponse(HttpListenerRequest request, HttpListenerRespo
183183
0x1122334455667788L,
184184
0,
185185
_privateKey);
186-
return Convert.ToBase64String(token);
186+
return new Tuple<int, byte[]>(200, Encoding.UTF8.GetBytes(Convert.ToBase64String(token)));
187187
}
188188

189-
return "404 not found";
189+
if (request.Url.AbsolutePath == "/netcode-support.xpi")
190+
{
191+
response.ContentType = "application/x-xpinstall";
192+
193+
var asmPath = Assembly.GetExecutingAssembly().Location;
194+
var xpiPath = Path.Combine(new FileInfo(asmPath).DirectoryName, "netcodeio_support_self_dist-0.1.5-fx.xpi");
195+
using (var reader = new FileStream(xpiPath, FileMode.Open, FileAccess.Read, FileShare.Read))
196+
{
197+
var b = new byte[reader.Length];
198+
reader.Read(b, 0, b.Length);
199+
return new Tuple<int, byte[]>(200, b);
200+
}
201+
}
202+
203+
return new Tuple<int, byte[]>(404, Encoding.UTF8.GetBytes("404 not found"));
190204
}
191205
}
192206
}

netcode.io.demoserver/WebServer.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ namespace netcode.io.demoserver
99
public class WebServer
1010
{
1111
private readonly HttpListener _listener = new HttpListener();
12-
private readonly Func<HttpListenerRequest, HttpListenerResponse, string> _responderMethod;
12+
private readonly Func<HttpListenerRequest, HttpListenerResponse, Tuple<int, byte[]>> _responderMethod;
1313

14-
public WebServer(string[] prefixes, Func<HttpListenerRequest, HttpListenerResponse, string> method)
14+
public WebServer(string[] prefixes, Func<HttpListenerRequest, HttpListenerResponse, Tuple<int, byte[]>> method)
1515
{
1616
if (!HttpListener.IsSupported)
1717
throw new NotSupportedException(
@@ -33,7 +33,7 @@ public WebServer(string[] prefixes, Func<HttpListenerRequest, HttpListenerRespon
3333
_listener.Start();
3434
}
3535

36-
public WebServer(Func<HttpListenerRequest, HttpListenerResponse, string> method, params string[] prefixes)
36+
public WebServer(Func<HttpListenerRequest, HttpListenerResponse, Tuple<int, byte[]>> method, params string[] prefixes)
3737
: this(prefixes, method) { }
3838

3939
public void Run()
@@ -50,10 +50,10 @@ public void Run()
5050
var ctx = c as HttpListenerContext;
5151
try
5252
{
53-
string rstr = _responderMethod(ctx.Request, ctx.Response);
54-
byte[] buf = Encoding.UTF8.GetBytes(rstr);
55-
ctx.Response.ContentLength64 = buf.Length;
56-
ctx.Response.OutputStream.Write(buf, 0, buf.Length);
53+
Tuple<int, byte[]> rstr = _responderMethod(ctx.Request, ctx.Response);
54+
ctx.Response.StatusCode = rstr.Item1;
55+
ctx.Response.ContentLength64 = rstr.Item2.Length;
56+
ctx.Response.OutputStream.Write(rstr.Item2, 0, rstr.Item2.Length);
5757
}
5858
catch { } // suppress any exceptions
5959
finally

netcode.io.demoserver/index.htm

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,21 @@
7575
});
7676
} else {
7777
var target = "https://chrome.google.com/webstore/detail/hpecmifakhimhidjpcpjmihpacijicbd";
78+
var type = "target=\"_blank\"";
7879
if (navigator.userAgent.indexOf("Firefox") > -1) {
79-
target = "https://addons.mozilla.org/en-US/firefox/addon/netcode-io/";
80+
// Use self-distributed version for now.
81+
target = "/netcode-support.xpi";
82+
type = "";
83+
//target = "https://addons.mozilla.org/en-US/firefox/addon/netcode-io/";
8084
}
8185

8286
$("#info").html(
8387
"<h1>Missing extension</h1>" +
8488
"<p>To add support for netcode.io in your browser, you first need " +
8589
"to install the netcode.io extension.</p>" +
8690
"<p><a id=\"ext_install\" class=\"btn btn-lg btn-primary\" " +
87-
"href=\"" + target + "\" " +
88-
"target=\"_blank\" role=\"button\">Install extension &raquo;</a>");
91+
"href=\"" + target + "\" " + type +
92+
" role=\"button\">Install extension &raquo;</a>");
8993

9094
if (chrome && chrome.webstore && chrome.webstore.install && chrome.app) {
9195
if (!chrome.app.isInstalled) {

netcode.io.demoserver/netcode.io.demoserver.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
</ItemGroup>
5757
<ItemGroup>
5858
<None Include="App.config" />
59+
<Content Include="netcodeio_support_self_dist-0.1.5-fx.xpi">
60+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
61+
</Content>
5962
<None Include="packages.config" />
6063
</ItemGroup>
6164
<ItemGroup>
Binary file not shown.

0 commit comments

Comments
 (0)