Connect fix
This commit is contained in:
@ -34,7 +34,7 @@ namespace RageCoop.Client.Menus
|
||||
private static readonly NativeItem _passwordItem = new NativeItem("Password") { AltTitle = new string('*',Main.Settings.Password.Length) };
|
||||
|
||||
public static readonly NativeItem ServerIpItem = new NativeItem("Server IP") { AltTitle = Main.Settings.LastServerAddress };
|
||||
private static readonly NativeItem _serverConnectItem = new NativeItem("Connect");
|
||||
internal static readonly NativeItem _serverConnectItem = new NativeItem("Connect");
|
||||
private static readonly NativeItem _aboutItem = new NativeItem("About", "~y~SOURCE~s~~n~" +
|
||||
"https://github.com/RAGECOOP~n~" +
|
||||
"~y~VERSION~s~~n~" +
|
||||
|
@ -76,9 +76,14 @@ namespace RageCoop.Client
|
||||
Client = new NetClient(config);
|
||||
Client.Start();
|
||||
Main.QueueAction(() => { GTA.UI.Notification.Show($"~y~Trying to connect..."); });
|
||||
Menus.CoopMenu._serverConnectItem.Enabled=false;
|
||||
Security.Regen();
|
||||
GetServerPublicKey(address);
|
||||
|
||||
if(!GetServerPublicKey(address))
|
||||
{
|
||||
Menus.CoopMenu._serverConnectItem.Enabled=true;
|
||||
throw new TimeoutException("Failed to retrive server's public key");
|
||||
}
|
||||
|
||||
// Send HandshakePacket
|
||||
NetOutgoingMessage outgoingMessage = Client.CreateMessage();
|
||||
var handshake = new Packets.Handshake()
|
||||
@ -96,8 +101,8 @@ namespace RageCoop.Client
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Main.Logger.Error("Cannot connect to server", ex);
|
||||
Main.QueueAction(() => GTA.UI.Notification.Show("Cannot connect to server"+ex.Message));
|
||||
Main.Logger.Error("Cannot connect to server: ", ex);
|
||||
Main.QueueAction(() => GTA.UI.Notification.Show("Cannot connect to server: "+ex.Message));
|
||||
}
|
||||
|
||||
});
|
||||
@ -134,13 +139,13 @@ namespace RageCoop.Client
|
||||
|
||||
#endregion // -- PLAYER --
|
||||
|
||||
private static void GetServerPublicKey(string address,int timeout=10000)
|
||||
private static bool GetServerPublicKey(string address,int timeout=10000)
|
||||
{
|
||||
var msg=Client.CreateMessage();
|
||||
new Packets.PublicKeyRequest().Pack(msg);
|
||||
var adds =address.Split(':');
|
||||
Client.SendUnconnectedMessage(msg,adds[0],int.Parse(adds[1]));
|
||||
PublicKeyReceived.WaitOne(timeout);
|
||||
return PublicKeyReceived.WaitOne(timeout);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
Reference in New Issue
Block a user