hey guys my insim wont connect i was thinking if somthing was wrong with stat or i put a wrong code or somthing but no error showed + no warning.
finally
{
if ([B][COLOR="Red"]InSim != null &&[/COLOR][/B] InSim.State == and continue your code
string AdminPW = "";
ushort Port = ;
string IPAddress = "";
InSimSettings Settings = new InSimSettings(IPAddress, Port, 0, Flags.InSimFlags.ISF_MSO_COLS | Flags.InSimFlags.ISF_MCI, '!', 500, AdminPW, "^2[UGC] Insim", 5);
// Note - do NOT change the settings here. Use the settings.ini file instead!
string AdminPW = "";
ushort Port = 29999;
string IPAddress = "";
public void InSimConnect()
{
try
{
#region Read Settings File
if (System.IO.File.Exists(@"settings.ini") == false)
{
File.Create(@"settings.ini");
}
StreamReader Sr = new StreamReader("settings.ini");
string line = null;
while ((line = Sr.ReadLine()) != null)
{
if (line.Substring(0, 5) == "Admin")
{
try
{
AdminPW = line.Remove(0, 8).Trim();
}
catch
{
}
}
if (line.Substring(0, 4) == "Port")
{
try
{
Port = Convert.ToUInt16(line.Remove(0, 7));
}
catch
{
}
}
if (line.Substring(0, 2) == "IP")
{
try
{
IPAddress = (line.Remove(0, 5));
}
catch
{
}
}
}
Sr.Close();
// InSim connection settings
InSimSettings Settings = new InSimSettings("192.168.0.104", 29999, 0, Flags.InSimFlags.ISF_MSO_COLS | Flags.InSimFlags.ISF_MCI, '!', 500, "pass", "^3LFS External", 5);
InSim = new InSimInterface(Settings);
InSim.ConnectionLost += new InSimInterface.ConnectionLost_EventHandler(LostConnectionToInSim);
InSim.Reconnected += new InSimInterface.Reconnected_EventHandler(ReconnectedToInSim);
InitializeInSimEvents();
InSim.Connect();
#endregion Read Settings File
}
}
catch (InvalidConfigurationException ex)
{
MessageBox.Show(ex.Message);
}
catch (UnableToConnectToInSimException ex)
{
MessageBox.Show(ex.Message);
InSim.Connect();
}
catch (AdminPasswordDoesNotMatchException ex)
{
MessageBox.Show(ex.Message);
}
catch (UDPListenPortAlreadyInUseException ex)
{
MessageBox.Show(ex.Message);
}
catch (AutoReconnectFailedException ex)
{
MessageBox.Show(ex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (InSim.State == LFS_External.InSim.InSimInterface.InSimState.Connected)
{
InSim.Request_NCN_AllConnections(255);
InSim.Request_NPL_AllPlayers(255);
InSim.Send_MST_Message("/wind=1");
InSim.Send_MST_Message("/wind=0");
}
}
}
try
{
Try to execute the code here, and prevent the program from crashing, by redirecting the exception to another handler.
}
catch (Exception E)
{
Catch any thrown exceptions here, and do whatever you want to do with them.
}
finally
{
If you need to perform a vital task no matter if the code above has failed or not, you do it here, but there is no more "crash-protection". Every thrown exception will cause the program to stop execution and the popular "send/don't sent" window will appear. There is a solution for this too, I think. If you catch all the unhandled exceptions in the Program class, this could be prevented too, if I'm right.
}