Fixing eventflow
This commit is contained in:
1 parent
fc25760c2f
commit
3c17ee228b
7 files changed
+80
-29
No files matched your search
+41
-23
@@ -10,7 +10,7 @@ var lobbyClient = new LobbyClient();
|
||||
var cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
List<LobbyInfo> openLobbies = new List<LobbyInfo>();
|
||||
|
||||
LobbyHostInfo? currentLobbyHostInfo = null;
|
||||
lobbyClient.Connect("lobby.incobyte.de" /*"localhost"*/, 8088, cancellationTokenSource.Token);
|
||||
|
||||
FakeGameHost fakeGameHost = new FakeGameHost();
|
||||
@@ -73,35 +73,53 @@ _ = Task.Run(async () =>
|
||||
running = false;
|
||||
}
|
||||
break;
|
||||
case LobbyClientEventTypes.LobbyHostInfo:
|
||||
case LobbyClientEventTypes.DirectConnectionTestComplete:
|
||||
var result = lobbyEvent.EventData as DirectConnectionTestResult;
|
||||
if (result != null && result.DirectConnectionPossible)
|
||||
{
|
||||
var lobbyHostInfo = lobbyEvent.EventData as LobbyHostInfo;
|
||||
var p = Console.GetCursorPosition();
|
||||
Console.SetCursorPosition(0, p.Top);
|
||||
Console.WriteLine($"Host info for lobby {lobbyHostInfo!.LobbyId} is {(lobbyHostInfo.HostIps != null && lobbyHostInfo.HostIps.Length > 0 ? lobbyHostInfo.HostIps[0].ToString() : "")}:{lobbyHostInfo.HostPort}!");
|
||||
|
||||
//Try direct connection
|
||||
if (lobbyHostInfo.HostIps != null && lobbyHostInfo.HostIps.Length > 0)
|
||||
{
|
||||
Console.WriteLine($"Trying direct connection to {string.Join<IPAddress>(",", lobbyHostInfo.HostIps)} on port {lobbyHostInfo.HostTryPort}!");
|
||||
var reachableIp = await lobbyClient.TryDirectConnection(lobbyHostInfo.HostIps, lobbyHostInfo.HostTryPort);
|
||||
if(reachableIp != null)
|
||||
{
|
||||
Console.WriteLine($"Direct connection to {reachableIp.ToString()} possible, using direct connection!");
|
||||
Console.WriteLine($"Connecting game client!");
|
||||
fakeGameHost.Send(new IPEndPoint(reachableIp, lobbyHostInfo.HostPort), "Hello from Game Client!");
|
||||
Console.Write(">");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"Direct connection to {result.IPAddress!.ToString()} possible, using direct connection!");
|
||||
Console.WriteLine($"Connecting game client!");
|
||||
fakeGameHost.Send(new IPEndPoint(result.IPAddress!, currentLobbyHostInfo!.HostPort), "Hello from Game Client!");
|
||||
Console.Write(">");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Direct connection no route found!");
|
||||
Console.WriteLine($"Requesting nat punch to me!");
|
||||
lobbyClient.RequestLobbyNatPunch(lobbyHostInfo.LobbyId, null, (remoteEndpoint, messageBuffer, messageLength) => {
|
||||
|
||||
lobbyClient.RequestLobbyNatPunch(currentLobbyHostInfo!.LobbyId, null, (remoteEndpoint, messageBuffer, messageLength) =>
|
||||
{
|
||||
fakeGameHost.Send(remoteEndpoint, messageBuffer, messageLength);
|
||||
});
|
||||
Console.Write(">");
|
||||
}
|
||||
break;
|
||||
case LobbyClientEventTypes.LobbyHostInfo:
|
||||
{
|
||||
var lobbyHostInfo = lobbyEvent.EventData as LobbyHostInfo;
|
||||
currentLobbyHostInfo = lobbyHostInfo;
|
||||
|
||||
var p = Console.GetCursorPosition();
|
||||
Console.SetCursorPosition(0, p.Top);
|
||||
Console.WriteLine($"Host info for lobby {lobbyHostInfo!.LobbyId} is {(lobbyHostInfo.HostIps != null && lobbyHostInfo.HostIps.Length > 0 ? lobbyHostInfo.HostIps[0].ToString() : "")}:{lobbyHostInfo.HostPort}!");
|
||||
|
||||
//Try direct connection
|
||||
if (lobbyHostInfo.HostIps != null && lobbyHostInfo.HostIps.Length > 0)
|
||||
{
|
||||
Console.WriteLine($"Trying direct connection to {string.Join<IPAddress>(",", lobbyHostInfo.HostIps)} on port {lobbyHostInfo.HostTryPort}!");
|
||||
_ = lobbyClient.TryDirectConnection(lobbyHostInfo.HostIps, lobbyHostInfo.HostTryPort);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Requesting nat punch to me!");
|
||||
lobbyClient.RequestLobbyNatPunch(lobbyHostInfo.LobbyId, null, (remoteEndpoint, messageBuffer, messageLength) =>
|
||||
{
|
||||
fakeGameHost.Send(remoteEndpoint, messageBuffer, messageLength);
|
||||
});
|
||||
Console.Write(">");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LobbyClientEventTypes.ExternalIpAndPort:
|
||||
{
|
||||
var seenExternalIpAndPort = lobbyEvent.EventData as SeenExternalIpAndPort;
|
||||
|
||||
Reference in new issue
Block a user