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