-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into tai/SettingsChanged
- Loading branch information
Showing
24 changed files
with
304 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
namespace OWML.Common | ||
using System; | ||
|
||
namespace OWML.Common | ||
{ | ||
public interface IModConsole | ||
{ | ||
void WriteLine(string s); | ||
void WriteLine(params object[] s); | ||
[Obsolete("Use WriteLine(string) or WriteLine(string, MessageType) instead.")] | ||
void WriteLine(params object[] objects); | ||
|
||
void WriteLine(string line); | ||
void WriteLine(string line, MessageType type); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace OWML.Common | ||
{ | ||
public enum MessageType | ||
{ | ||
Message = 0, | ||
Error = 1, | ||
Warning = 2, | ||
Info = 3, | ||
Success = 4, | ||
Quit = 5 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"gamePath": "C:/Program Files/Epic Games/OuterWilds", | ||
"verbose": true, | ||
"combinationsBlockInput": false | ||
"combinationsBlockInput": false, | ||
"socketPort": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using Newtonsoft.Json; | ||
using OWML.Common; | ||
using OWML.ModHelper; | ||
using System; | ||
using System.Net; | ||
using System.Net.Sockets; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace OWML.Launcher | ||
{ | ||
public class SocketListener | ||
{ | ||
private const int BufferSize = 1024; | ||
private static int _port; | ||
private static TcpListener _server; | ||
private static IOwmlConfig _config; | ||
|
||
public SocketListener(IOwmlConfig config) | ||
{ | ||
_config = config; | ||
} | ||
|
||
public void Init() | ||
{ | ||
var listener = new TcpListener(IPAddress.Loopback, 0); | ||
listener.Start(); | ||
_port = ((IPEndPoint)listener.LocalEndpoint).Port; | ||
listener.Stop(); | ||
_config.SocketPort = _port; | ||
JsonHelper.SaveJsonObject(Constants.OwmlConfigFileName, _config); | ||
|
||
new Task(SetupSocketListener).Start(); | ||
} | ||
|
||
private void SetupSocketListener() | ||
{ | ||
try | ||
{ | ||
ListenToSocket(); | ||
} | ||
catch (SocketException ex) | ||
{ | ||
ConsoleUtils.WriteByType(MessageType.Error, $"Error in socket listener: {ex}"); | ||
} | ||
finally | ||
{ | ||
_server?.Stop(); | ||
} | ||
} | ||
|
||
private void ListenToSocket() | ||
{ | ||
var localAddress = IPAddress.Parse(Constants.LocalAddress); | ||
|
||
_server = new TcpListener(localAddress, _port); | ||
_server.Start(); | ||
|
||
var bytes = new byte[BufferSize]; | ||
|
||
while (true) | ||
{ | ||
var client = _server.AcceptTcpClient(); | ||
|
||
ConsoleUtils.WriteByType(MessageType.Success, "Console connected to socket!"); | ||
|
||
var stream = client.GetStream(); | ||
|
||
int i; | ||
|
||
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0) | ||
{ | ||
ProcessMessage(bytes, i); | ||
} | ||
|
||
client.Close(); | ||
} | ||
} | ||
|
||
private void ProcessMessage(byte[] bytes, int count) | ||
{ | ||
var json = Encoding.UTF8.GetString(bytes, 0, count); | ||
|
||
var data = JsonConvert.DeserializeObject<SocketMessage>(json); | ||
|
||
if (data.Type == MessageType.Quit) | ||
{ | ||
Environment.Exit(0); | ||
} | ||
|
||
ConsoleUtils.WriteByType(data.Type, | ||
$"[{data.SenderName}.{data.SenderType}] : {data.Message}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using OWML.Common; | ||
using System; | ||
|
||
namespace OWML.ModHelper | ||
{ | ||
public static class ConsoleUtils | ||
{ | ||
public static void WriteByType(MessageType type, string line) | ||
{ | ||
switch (type) | ||
{ | ||
case MessageType.Error: | ||
Console.ForegroundColor = ConsoleColor.Red; | ||
break; | ||
case MessageType.Warning: | ||
Console.ForegroundColor = ConsoleColor.Yellow; | ||
break; | ||
case MessageType.Success: | ||
Console.ForegroundColor = ConsoleColor.Green; | ||
break; | ||
case MessageType.Message: | ||
Console.ForegroundColor = ConsoleColor.Gray; | ||
break; | ||
case MessageType.Info: | ||
Console.ForegroundColor = ConsoleColor.Cyan; | ||
break; | ||
} | ||
Console.WriteLine(line); | ||
Console.ForegroundColor = ConsoleColor.Gray; | ||
} | ||
} | ||
} |
Oops, something went wrong.