The online racing simulator
Insim won't connect
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.

try to make try {} catch {} on it?
i think i already have it m8 can you go msn?
Quote from mariuba2 :i think i already have it m8 can you go msn?

dat accnt is disabled due too many people adding me for an cruise insim request i got pissed
damn......i can't find the bug in this thingy and im sooo pissed cause right now i would be codeing
finally
{
if ([B][COLOR="Red"]InSim != null &&[/COLOR][/B] InSim.State == and continue your code

I don't know if this is the best solution to the problem, but it's how I'm doing it anyway. Object reference not set to an instance of an object, means that one of your objects is nothing/not set/null/empty/etc.

Hope I've helped.

[E] Actually... If your InSim object is not set there, then you won't be able to connect really. Find out where the problem for that is. It seems to be a really big issue.
The code above will avoid crashes, but it will not make it connect. =/
nice it worked but it cnt close it say somthing wrong with close thingy and it show that its connected but when i check my dedi it dnt show the insim
ok its working now =) my buddy helped
Didn´t he said it´s fixed?
Quote from marcel1 :Didn´t he said it´s fixed?

And broken asked him to post the solution so others who might encounter the same issue can apply it to their code.
ops Then... ignore my post
what we did is ,we removed the configfile code , thats all. that file is only helpfull when u give the insim in public.we set the ip and pass once and it works for a long time.


example indead of using
string AdminPW = "";
ushort Port = ;
string IPAddress = "";

we use
InSimSettings Settings = new InSimSettings(IPAddress, Port, 0, Flags.InSimFlags.ISF_MSO_COLS | Flags.InSimFlags.ISF_MCI, '!', 500, AdminPW, "^2[UGC] Insim", 5);

Quote from mariuba2 :what we did is ,we removed the configfile code , thats all.

If you think that's a real solution to the problem you need to learn more about "codeing". Why couldn't you fix it so it worked with the config file?
tbh, i wasn't using this library. probably clarky you put a code that blocks up the settings.ini to load the insim.

EDIT: i've been with that error before but i can't remember how do i fix this anymore..
Quote from amp88 :If you think that's a real solution to the problem you need to learn more about "codeing". Why couldn't you fix it so it worked with the config file?

idk if its the real solution but i think a code was blocking it same as skywatcher said so i removed some codes and it start working
Quote from amp88 :If you think that's a real solution to the problem you need to learn more about "codeing". Why couldn't you fix it so it worked with the config file?

hey

its me that helped him

ofcourse its wrong what i did , but i didnt had time to solve the bug. this is a temporary quick fix.

but the weird part is.
that we didnt changed anything on the insim connect code.
and after sometime i wont work anymore.
i will look into this later.
#19 - PoVo
Clearly it's a coding fail, since I use the same code for loading my configs... Perhaps a mistake in settings.ini?
Quote from Bass-Driver :
but the weird part is.
that we didnt changed anything on the insim connect code.
and after sometime i wont work anymore.
i will look into this later.

I'm sure that you know very well that it can't just stop working. Something has changed. In 90% of these cases(just personal experience), it's always a stupid thing you've changed and just didn't expect to affect anything else. But it has.

Anyway, if you fix it at some point and it's stable, I believe that it would be a good thing to post the solution here, because when you provide the "right" solution on how to fix something, you donate 1 example to the "disoriented programmers" foundation, and you help one confused little programmer learn something more.
i can remember something with the adminpass because i removed the // before :
MessageBox.Show(ex.Message);
and i think mariuba2 had the same problem. but didnt get a message because his MessageBox.Show(ex.Message); is turned off

But the insim wont connect even the serveradminpass is equal with the adminpass in settings.ini and Form1.cs.

i will do some tests tommorow
i hope i can find a solution for it if the bug comes back.
#22 - PoVo
Post your config reading code.
i have set the code back again
and it works for now.



// 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");
}
}
}


Whoever wrote that code didn't understand what finally blocks were for, or try/catch blocks for that matter.
Quote from DarkTimes :Whoever wrote that code didn't understand what finally blocks were for, or try/catch blocks for that matter.

I think that's the dougie's original code there. But, he seems to have understood how finally works. Who I think doesn't understand is the person that suggested a try/catch in the finally handler(if that's what it is - a handler). Which will probably work, but finally loses it's point then, imo.

Why don't we give a simple example then on how try/catch/finally works then? I'll start, and if something is wrong or not efficient enough, someone will hopefully correct me.

So, there's my idea of how it works:

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.
}

That's my idea of how it all works. I know that it probably doesn't do exactly what I've said, but I admit - I don't know how does it exactly work.

That's why, imo, in a finally handler(if that's what it is, once again), you need to get all of the possible problems out of the way.

I know that my terminology sucks, so you will either have to get over it, or nicely correct me.
1

FGED GREDG RDFGDR GSFDG