PDA

View Full Version : New player joins host problem


Thijs-boy
23rd February 2011, 13:11
I have a problem, if a new player joins the host, I get a error: NCN - Index & length must to a location within the string related.
Parameter name: Lenght

I've copied the orginial NCN of Open Source InSim, but still got the error, here I've my code:// A new client joined the server.
private void NCN_ClientJoinsHost(Packets.IS_NCN NCN)
{
try
{
InSim.Send_BTN_CreateButton("", Flags.ButtonStyles.ISB_LIGHT, 12, 135, 0, 63, 1, NCN.UCID, 2, false);

FileInfo.NewUser(NCN.UName);
InSim.Send_BTN_CreateButton("^7Today: ^2€^7 0", Flags.ButtonStyles.ISB_DARK, 5, 30, 6, 106, 139, NCN.UCID, 2, false);

AddToConnectionsList(NCN); // Update Connections[] list (don't remove this line!)

if (Connections[GetConnIdx(NCN.UCID)].Cash >= 0)
{
InSim.Send_BTN_CreateButton("^7Total: ^2€^7 " + Connections[GetConnIdx(NCN.UCID)].Cash, Flags.ButtonStyles.ISB_DARK, 5, 25, 6, 64, 5, NCN.UCID, 2, false);
}
if (Connections[GetConnIdx(NCN.UCID)].Cash < 0)
{
InSim.Send_BTN_CreateButton("^7Total: ^2€^1 " + Connections[GetConnIdx(NCN.UCID)].Cash, Flags.ButtonStyles.ISB_DARK, 5, 25, 6, 64, 5, NCN.UCID, 2, false);
}
InSim.Send_MTC_MessageToConnection("^7Welcome to the ^1DFT^7-Training^4 Server!", NCN.UCID, 0);
InSim.Send_MTC_MessageToConnection("^6|^7 Cash: €" + Connections[GetConnIdx(NCN.UCID)].Cash, NCN.UCID, 0);

if (Connections[GetConnIdx(NCN.UCID)].Cars.Length == 79)
{
InSim.Send_MTC_MessageToConnection("^6|^7 Cars: ALL", NCN.UCID, 0);
}
if ((Connections[GetConnIdx(NCN.UCID)].Cars.Length > 52) && (Connections[GetConnIdx(NCN.UCID)].Cars.Length < 79))
{
InSim.Send_MTC_MessageToConnection("^6|^7 Cars: " + Connections[GetConnIdx(NCN.UCID)].Cars.Remove(39, Connections[GetConnIdx(NCN.UCID)].Cars.Length - 39), NCN.UCID, 0);
InSim.Send_MTC_MessageToConnection("^6|^7 " + Connections[GetConnIdx(NCN.UCID)].Cars.Remove(0, 40), NCN.UCID, 0);
}
else if (Connections[GetConnIdx(NCN.UCID)].Cars.Length < 52)
{
InSim.Send_MTC_MessageToConnection("^6|^7 Cars: " + Connections[GetConnIdx(NCN.UCID)].Cars, NCN.UCID, 0);
}

InSim.Send_BTN_CreateButton("^7WELCOME TO ^1DFT^7-Training ^4Server v1.07", Flags.ButtonStyles.ISB_LEFT | Flags.ButtonStyles.ISB_DARK | Flags.ButtonStyles.ISB_DARK, 6, 35, 20, 20, 50, NCN.UCID, 40, false);
InSim.Send_BTN_CreateButton("^7This is ^1DFT^7-Training, where you learn to be Tow/Police.", Flags.ButtonStyles.ISB_LEFT | Flags.ButtonStyles.ISB_DARK | Flags.ButtonStyles.ISB_DARK, 5, 125, 26, 20, 51, NCN.UCID, 40, false);
InSim.Send_BTN_CreateButton("^7While on our server, please follow our rules. You can view the rules by typing ^2!serverrules.", Flags.ButtonStyles.ISB_LEFT | Flags.ButtonStyles.ISB_DARK | Flags.ButtonStyles.ISB_DARK, 5, 125, 30, 20, 52, NCN.UCID, 40, false);
InSim.Send_BTN_CreateButton("^7Please make sure to respect all players, as inappropriate comments/actions will be punished.", Flags.ButtonStyles.ISB_LEFT | Flags.ButtonStyles.ISB_DARK | Flags.ButtonStyles.ISB_DARK, 5, 125, 34, 20, 53, NCN.UCID, 40, false);
InSim.Send_BTN_CreateButton("^7^1Officers ^7have the power to kick and ban you, so make sure to follow the rules.", Flags.ButtonStyles.ISB_LEFT | Flags.ButtonStyles.ISB_DARK | Flags.ButtonStyles.ISB_DARK, 5, 125, 38, 20, 54, NCN.UCID, 40, false);
InSim.Send_BTN_CreateButton("^7Above all, have fun! For more info, visit us at ^7" + Website, Flags.ButtonStyles.ISB_LEFT | Flags.ButtonStyles.ISB_DARK | Flags.ButtonStyles.ISB_DARK, 5, 125, 46, 20, 55, NCN.UCID, 40, false);
InSim.Send_BTN_CreateButton("^1CLOSE [X]", Flags.ButtonStyles.ISB_LEFT | Flags.ButtonStyles.ISB_DARK | Flags.ButtonStyles.ISB_CLICK, 6, 13, 20, 132, 56, NCN.UCID, 40, false);

Connections[GetConnIdx(NCN.UCID)].AddedBankTime = 600;

string TempCars1 = "^1UF1 ^1XFG ^1XRG ^1LX4 ^1LX6 ^1RB4 ^1FXO ^1XRT ^1RAC ^1FZ5";
string TempCars2 = "^1UFR ^1XFR ^1FXR ^1XRR ^1FZR ^1MRT ^1FBM ^1FOX ^1FO8 ^1BF1";
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("UF1"))
{
TempCars1 = TempCars1.Replace("^1UF1", "^2UF1");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("XFG"))
{
TempCars1 = TempCars1.Replace("^1XFG", "^2XFG");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("XRG"))
{
TempCars1 = TempCars1.Replace("^1XRG", "^2XRG");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("LX4"))
{
TempCars1 = TempCars1.Replace("^1LX4", "^2LX4");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("LX6"))
{
TempCars1 = TempCars1.Replace("^1LX6", "^2LX6");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("RB4"))
{
TempCars1 = TempCars1.Replace("^1RB4", "^2RB4");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("FXO"))
{
TempCars1 = TempCars1.Replace("^1FXO", "^2FXO");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("XRT"))
{
TempCars1 = TempCars1.Replace("^1XRT", "^2XRT");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("RAC"))
{
TempCars1 = TempCars1.Replace("^1RAC", "^2RAC");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("FZ5"))
{
TempCars1 = TempCars1.Replace("^1FZ5", "^2FZ5");
}
// Second Set
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("UFR"))
{
TempCars2 = TempCars2.Replace("^1UFR", "^2UFR");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("XFR"))
{
TempCars2 = TempCars2.Replace("^1XFR", "^2XFR");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("FXR"))
{
TempCars2 = TempCars2.Replace("^1FXR", "^2FXR");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("XRR"))
{
TempCars2 = TempCars2.Replace("^1XRR", "^2XRR");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("FZR"))
{
TempCars2 = TempCars2.Replace("^1FZR", "^2FZR");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("MRT"))
{
TempCars2 = TempCars2.Replace("^1MRT", "^2MRT");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("FBM"))
{
TempCars2 = TempCars2.Replace("^1FBM", "^2FBM");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("FOX"))
{
TempCars2 = TempCars2.Replace("^1FOX", "^2FOX");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("FO8"))
{
TempCars2 = TempCars2.Replace("^1FO8", "^2FO8");
}
if (Connections[GetConnIdx(NCN.UCID)].Cars.Contains("BF1"))
{
TempCars2 = TempCars2.Replace("^1BF1", "^2BF1");
}
InSim.Send_BTN_CreateButton("" + TempCars1, Flags.ButtonStyles.ISB_DARK, 5, 60, 0, 137, 140, NCN.UCID, 2, false);
InSim.Send_BTN_CreateButton("" + TempCars2, Flags.ButtonStyles.ISB_DARK, 5, 60, 6, 137, 141, NCN.UCID, 2, false);

InSim.Send_BTN_CreateButton("^2Pit Lane", Flags.ButtonStyles.ISB_DARK, 5, 25, 0, 64, 171, NCN.UCID, 2, false);
InSim.Send_BTN_CreateButton("^7Speed: 0km/h / 80km/h", Flags.ButtonStyles.ISB_DARK, 5, 30, 0, 106, 169, NCN.UCID, 2, false);
InSim.Send_BTN_CreateButton("^2Pit Safe!", Flags.ButtonStyles.ISB_DARK, 5, 15, 0, 90, 7, NCN.UCID, 2, false);
InSim.Send_BTN_CreateButton("^7" + Website, Flags.ButtonStyles.ISB_DARK, 5, 15, 6, 90, 6, NCN.UCID, 2, false);

if (NCN.Flags == 0)
{
Connections[GetConnIdx(NCN.UCID)].IsLocal = 1;
}
}
catch (Exception EX)
{
MessageBox.Show("NCN - " + EX.Message);
}
}

Who can help me?
Thanks

broken
23rd February 2011, 15:58
Could you provide a little more details please?

Like:
What are you using as a base? Meaning - what are you using to build up your insim app. from?
Exactly where did you copy the code from?

How have you made sure the new code is compatible with the current source?

I think that should be enough for now. :)

Thijs-boy
23rd February 2011, 16:03
I'm using Visual C# 2010 Express
And I copied the code from .NET (C#) - Open Source Cruise Server, dougie-lampkin

broken
23rd February 2011, 16:07
Okay, but you misunderstood my initial question. Let me ask in another way: Where did you download the source, you are copying to?

Thijs-boy
23rd February 2011, 16:51
I downloaded this InSim http://www.lfsforum.net/showthread.php?t=43103 and I was going to edite this to my own, I have nothing did with the NCN part, only the name changed.
I was adding a new command or something, I build the InSim and get this. Its weird but some players see the insim, and other players not.