Added CORS support

This commit is contained in:
Derek S 2021-04-14 21:02:27 -05:00
parent eab32b2233
commit da2928e9e5
9 changed files with 238 additions and 103 deletions

View file

@ -143,6 +143,18 @@ namespace LightReflectiveMirror.LoadBalancing
await context.Response.SendResponseAsync(low.Key.address != "Dummy" ? JsonConvert.SerializeObject(low.Key) : HttpStatusCode.InternalServerError); await context.Response.SendResponseAsync(low.Key.address != "Dummy" ? JsonConvert.SerializeObject(low.Key) : HttpStatusCode.InternalServerError);
} }
[RestRoute("Options", "/api/join/")]
public async Task JoinRelayOptions(IHttpContext context)
{
var originHeaders = context.Request.Headers["Access-Control-Request-Headers"];
context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
context.Response.Headers.Add("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
context.Response.Headers.Add("Access-Control-Allow-Headers", originHeaders);
await context.Response.SendResponseAsync(HttpStatusCode.Ok);
}
/// <summary> /// <summary>
/// Returns all the servers on all the relay nodes. /// Returns all the servers on all the relay nodes.
/// </summary> /// </summary>
@ -163,6 +175,18 @@ namespace LightReflectiveMirror.LoadBalancing
await context.Response.SendResponseAsync(_cachedRegionRooms[LRMRegions.Any]); await context.Response.SendResponseAsync(_cachedRegionRooms[LRMRegions.Any]);
} }
[RestRoute("Options", "/api/masterlist/")]
public async Task GetMasterServerListOptions(IHttpContext context)
{
var originHeaders = context.Request.Headers["Access-Control-Request-Headers"];
context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
context.Response.Headers.Add("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
context.Response.Headers.Add("Access-Control-Allow-Headers", originHeaders);
await context.Response.SendResponseAsync(HttpStatusCode.Ok);
}
/// <summary> /// <summary>
/// Returns stats. you're welcome /// Returns stats. you're welcome
/// </summary> /// </summary>

View file

@ -68,6 +68,9 @@ namespace LightReflectiveMirror.Endpoints
[RestRoute("Get", "/api/compressed/servers")] [RestRoute("Get", "/api/compressed/servers")]
public async Task ServerListCompressed(IHttpContext context) public async Task ServerListCompressed(IHttpContext context)
{ {
context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
context.Response.Headers.Add("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
if (Program.conf.EndpointServerList) if (Program.conf.EndpointServerList)
{ {
await context.Response.SendResponseAsync(_cachedCompressedServerList); await context.Response.SendResponseAsync(_cachedCompressedServerList);
@ -75,6 +78,18 @@ namespace LightReflectiveMirror.Endpoints
else else
await context.Response.SendResponseAsync(HttpStatusCode.Forbidden); await context.Response.SendResponseAsync(HttpStatusCode.Forbidden);
} }
[RestRoute("Options", "/api/compressed/servers")]
public async Task ServerListCompressedOptions(IHttpContext context)
{
var originHeaders = context.Request.Headers["Access-Control-Request-Headers"];
context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
context.Response.Headers.Add("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
context.Response.Headers.Add("Access-Control-Allow-Headers", originHeaders);
await context.Response.SendResponseAsync(HttpStatusCode.Ok);
}
} }
public class EndpointServer public class EndpointServer

View file

@ -1,61 +1,90 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 6a3c684705042f345975d924f6983e36 guid: 6a3c684705042f345975d924f6983e36
timeCreated: 1466788352
licenseType: Store
PluginImporter: PluginImporter:
serializedVersion: 1 externalObjects: {}
serializedVersion: 2
iconMap: {} iconMap: {}
executionOrder: {} executionOrder: {}
defineConstraints: []
isPreloaded: 0 isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData: platformData:
Android: - first:
: Linux
second:
enabled: 0
settings:
CPU: x86
- first:
: OSXIntel
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
: OSXIntel64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
: SamsungTV
second:
enabled: 1
settings:
STV_MODEL: STANDARD_13
- first:
: Tizen
second:
enabled: 1
settings: {}
- first:
Android: Android
second:
enabled: 1 enabled: 1
settings: settings:
CPU: AnyCPU CPU: AnyCPU
- first:
Any: Any:
second:
enabled: 0 enabled: 0
settings: {} settings: {}
Editor: - first:
Editor: Editor
second:
enabled: 0 enabled: 0
settings: settings:
CPU: AnyCPU CPU: AnyCPU
DefaultValueInitialized: true DefaultValueInitialized: true
OS: AnyOS OS: AnyOS
Linux: - first:
enabled: 0 Standalone: Linux64
settings: second:
CPU: x86
Linux64:
enabled: 0
settings:
CPU: x86_64
OSXIntel:
enabled: 0 enabled: 0
settings: settings:
CPU: AnyCPU CPU: AnyCPU
OSXIntel64: - first:
Standalone: Win
second:
enabled: 0 enabled: 0
settings: settings:
CPU: AnyCPU CPU: AnyCPU
SamsungTV: - first:
enabled: 1 Standalone: Win64
second:
enabled: 0
settings: settings:
STV_MODEL: STANDARD_13 CPU: AnyCPU
Tizen: - first:
WebGL: WebGL
second:
enabled: 1 enabled: 1
settings: {} settings: {}
WebGL: - first:
enabled: 1 Windows Store Apps: WindowsStoreApps
settings: {} second:
Win:
enabled: 0
settings:
CPU: AnyCPU
Win64:
enabled: 0
settings:
CPU: AnyCPU
WindowsStoreApps:
enabled: 1 enabled: 1
settings: settings:
CPU: AnyCPU CPU: AnyCPU
@ -63,12 +92,16 @@ PluginImporter:
PlaceholderPath: Assets/JsonDotNet/Assemblies/Standalone/Newtonsoft.Json.dll PlaceholderPath: Assets/JsonDotNet/Assemblies/Standalone/Newtonsoft.Json.dll
SDK: AnySDK SDK: AnySDK
ScriptingBackend: Il2Cpp ScriptingBackend: Il2Cpp
iOS: - first:
iPhone: iOS
second:
enabled: 1 enabled: 1
settings: settings:
CompileFlags: CompileFlags:
FrameworkDependencies: FrameworkDependencies:
tvOS: - first:
tvOS: tvOS
second:
enabled: 1 enabled: 1
settings: {} settings: {}
userData: userData:

View file

@ -1,63 +1,92 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 17aef65a15b471f468b5fbeb4ff0c6a1 guid: 17aef65a15b471f468b5fbeb4ff0c6a1
timeCreated: 1466788349
licenseType: Store
PluginImporter: PluginImporter:
serializedVersion: 1 externalObjects: {}
serializedVersion: 2
iconMap: {} iconMap: {}
executionOrder: {} executionOrder: {}
defineConstraints: []
isPreloaded: 0 isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData: platformData:
Android: - first:
: Linux
second:
enabled: 1
settings:
CPU: x86
- first:
: LinuxUniversal
second:
enabled: 1
settings:
CPU: AnyCPU
- first:
: OSXIntel
second:
enabled: 1
settings:
CPU: AnyCPU
- first:
: OSXIntel64
second:
enabled: 1
settings:
CPU: AnyCPU
- first:
: SamsungTV
second:
enabled: 0
settings:
STV_MODEL: STANDARD_13
- first:
Android: Android
second:
enabled: 0 enabled: 0
settings: settings:
CPU: AnyCPU CPU: AnyCPU
- first:
Any: Any:
second:
enabled: 0 enabled: 0
settings: {} settings: {}
Editor: - first:
Editor: Editor
second:
enabled: 1 enabled: 1
settings: settings:
CPU: AnyCPU CPU: AnyCPU
DefaultValueInitialized: true DefaultValueInitialized: true
OS: AnyOS OS: AnyOS
Linux: - first:
enabled: 1 Standalone: Linux64
settings: second:
CPU: x86
Linux64:
enabled: 1
settings:
CPU: x86_64
LinuxUniversal:
enabled: 1 enabled: 1
settings: settings:
CPU: AnyCPU CPU: AnyCPU
OSXIntel: - first:
Standalone: OSXUniversal
second:
enabled: 1 enabled: 1
settings: settings:
CPU: AnyCPU CPU: AnyCPU
OSXIntel64: - first:
Standalone: Win
second:
enabled: 1 enabled: 1
settings: settings:
CPU: AnyCPU CPU: AnyCPU
OSXUniversal: - first:
Standalone: Win64
second:
enabled: 1 enabled: 1
settings: settings:
CPU: AnyCPU CPU: AnyCPU
SamsungTV: - first:
enabled: 0 Windows Store Apps: WindowsStoreApps
settings: second:
STV_MODEL: STANDARD_13
Win:
enabled: 1
settings:
CPU: AnyCPU
Win64:
enabled: 1
settings:
CPU: AnyCPU
WindowsStoreApps:
enabled: 0 enabled: 0
settings: settings:
CPU: AnyCPU CPU: AnyCPU
@ -65,7 +94,9 @@ PluginImporter:
PlaceholderPath: PlaceholderPath:
SDK: AnySDK SDK: AnySDK
ScriptingBackend: Il2Cpp ScriptingBackend: Il2Cpp
iOS: - first:
iPhone: iOS
second:
enabled: 0 enabled: 0
settings: settings:
CompileFlags: CompileFlags:

View file

@ -1,55 +1,80 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 9b6ba260dada0ea4a871a42011f8b87d guid: 9b6ba260dada0ea4a871a42011f8b87d
timeCreated: 1466788355
licenseType: Store
PluginImporter: PluginImporter:
serializedVersion: 1 externalObjects: {}
serializedVersion: 2
iconMap: {} iconMap: {}
executionOrder: {} executionOrder: {}
defineConstraints: []
isPreloaded: 0 isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData: platformData:
Android: - first:
: Linux
second:
enabled: 0
settings:
CPU: x86
- first:
: OSXIntel
second:
enabled: 0 enabled: 0
settings: settings:
CPU: AnyCPU CPU: AnyCPU
- first:
: OSXIntel64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
: SamsungTV
second:
enabled: 0
settings:
STV_MODEL: STANDARD_13
- first:
Android: Android
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Any: Any:
second:
enabled: 0 enabled: 0
settings: {} settings: {}
Editor: - first:
Editor: Editor
second:
enabled: 0 enabled: 0
settings: settings:
CPU: AnyCPU CPU: AnyCPU
DefaultValueInitialized: true DefaultValueInitialized: true
OS: AnyOS OS: AnyOS
Linux: - first:
enabled: 0 Standalone: Linux64
settings: second:
CPU: x86
Linux64:
enabled: 0
settings:
CPU: x86_64
OSXIntel:
enabled: 0 enabled: 0
settings: settings:
CPU: AnyCPU CPU: AnyCPU
OSXIntel64: - first:
Standalone: Win
second:
enabled: 0 enabled: 0
settings: settings:
CPU: AnyCPU CPU: AnyCPU
SamsungTV: - first:
enabled: 0 Standalone: Win64
settings: second:
STV_MODEL: STANDARD_13
Win:
enabled: 0 enabled: 0
settings: settings:
CPU: AnyCPU CPU: AnyCPU
Win64: - first:
enabled: 0 Windows Store Apps: WindowsStoreApps
settings: second:
CPU: AnyCPU
WindowsStoreApps:
enabled: 1 enabled: 1
settings: settings:
CPU: AnyCPU CPU: AnyCPU
@ -57,7 +82,9 @@ PluginImporter:
PlaceholderPath: Assets/JsonDotNet/Assemblies/Standalone/Newtonsoft.Json.dll PlaceholderPath: Assets/JsonDotNet/Assemblies/Standalone/Newtonsoft.Json.dll
SDK: AnySDK SDK: AnySDK
ScriptingBackend: DotNet ScriptingBackend: DotNet
iOS: - first:
iPhone: iOS
second:
enabled: 0 enabled: 0
settings: settings:
CompileFlags: CompileFlags:

View file

@ -80,10 +80,17 @@ namespace LightReflectiveMirror
_clientSendBuffer.WriteString(ref pos, address); _clientSendBuffer.WriteString(ref pos, address);
_clientSendBuffer.WriteBool(ref pos, _directConnectModule != null); _clientSendBuffer.WriteBool(ref pos, _directConnectModule != null);
if (_directConnectModule == null)
{
_clientSendBuffer.WriteString(ref pos, "0.0.0.0");
}
else
{
if (GetLocalIp() == null) if (GetLocalIp() == null)
_clientSendBuffer.WriteString(ref pos, "0.0.0.0"); _clientSendBuffer.WriteString(ref pos, "0.0.0.0");
else else
_clientSendBuffer.WriteString(ref pos, GetLocalIp()); _clientSendBuffer.WriteString(ref pos, GetLocalIp());
}
_isClient = true; _isClient = true;

View file

@ -185,10 +185,6 @@ namespace LightReflectiveMirror
using (UnityWebRequest webRequest = UnityWebRequest.Get(uri)) using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
{ {
webRequest.SetRequestHeader("Access-Control-Allow-Credentials", "true");
webRequest.SetRequestHeader("Access-Control-Allow-Headers", "Accept, X-Access-Token, X-Application-Name, X-Request-Sent-Time");
webRequest.SetRequestHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
webRequest.SetRequestHeader("Access-Control-Allow-Origin", "*");
webRequest.SetRequestHeader("x-Region", ((int)region).ToString()); webRequest.SetRequestHeader("x-Region", ((int)region).ToString());
// Request and wait for the desired page. // Request and wait for the desired page.
yield return webRequest.SendWebRequest(); yield return webRequest.SendWebRequest();

View file

@ -263,7 +263,7 @@ namespace LightReflectiveMirror
break; break;
case OpCodes.RequestNATConnection: case OpCodes.RequestNATConnection:
// Called when the LRM node would like us to establish a NAT puncher connection. Its safe to ignore if NAT punch is disabled. // Called when the LRM node would like us to establish a NAT puncher connection. Its safe to ignore if NAT punch is disabled.
if (GetLocalIp() != null && _directConnectModule != null && useNATPunch) if (useNATPunch && GetLocalIp() != null && _directConnectModule != null)
{ {
byte[] initalData = new byte[150]; byte[] initalData = new byte[150];
int sendPos = 0; int sendPos = 0;

View file

@ -514,6 +514,7 @@ PlayerSettings:
webGLWasmStreaming: 0 webGLWasmStreaming: 0
scriptingDefineSymbols: scriptingDefineSymbols:
1: MIRROR;MIRROR_17_0_OR_NEWER;MIRROR_18_0_OR_NEWER;MIRROR_24_0_OR_NEWER;MIRROR_26_0_OR_NEWER;MIRROR_27_0_OR_NEWER;MIRROR_28_0_OR_NEWER;MIRROR_29_0_OR_NEWER;MIRROR_30_0_OR_NEWER;MIRROR_30_5_2_OR_NEWER;MIRROR_32_1_2_OR_NEWER;MIRROR_32_1_4_OR_NEWER;MIRROR_35_0_OR_NEWER;MIRROR_35_1_OR_NEWER 1: MIRROR;MIRROR_17_0_OR_NEWER;MIRROR_18_0_OR_NEWER;MIRROR_24_0_OR_NEWER;MIRROR_26_0_OR_NEWER;MIRROR_27_0_OR_NEWER;MIRROR_28_0_OR_NEWER;MIRROR_29_0_OR_NEWER;MIRROR_30_0_OR_NEWER;MIRROR_30_5_2_OR_NEWER;MIRROR_32_1_2_OR_NEWER;MIRROR_32_1_4_OR_NEWER;MIRROR_35_0_OR_NEWER;MIRROR_35_1_OR_NEWER
13: MIRROR;MIRROR_17_0_OR_NEWER;MIRROR_18_0_OR_NEWER;MIRROR_24_0_OR_NEWER;MIRROR_26_0_OR_NEWER;MIRROR_27_0_OR_NEWER;MIRROR_28_0_OR_NEWER;MIRROR_29_0_OR_NEWER;MIRROR_30_0_OR_NEWER;MIRROR_30_5_2_OR_NEWER;MIRROR_32_1_2_OR_NEWER;MIRROR_32_1_4_OR_NEWER;MIRROR_35_0_OR_NEWER;MIRROR_35_1_OR_NEWER
platformArchitecture: {} platformArchitecture: {}
scriptingBackend: {} scriptingBackend: {}
il2cppCompilerConfiguration: {} il2cppCompilerConfiguration: {}
@ -526,6 +527,7 @@ PlayerSettings:
gcWBarrierValidation: 0 gcWBarrierValidation: 0
apiCompatibilityLevelPerPlatform: apiCompatibilityLevelPerPlatform:
Standalone: 3 Standalone: 3
WebGL: 3
m_RenderingPath: 1 m_RenderingPath: 1
m_MobileRenderingPath: 1 m_MobileRenderingPath: 1
metroPackageName: UnityProject metroPackageName: UnityProject