The online racing simulator
Restriction check
Can any one help me?

I want to make a race with restricted cars, how do i go about checking, or disallowing cars that are not restricted enough, i need two different cars, with different restrictions...

Hope someone can help me !!!

Kind reagards
Franke... Click
If you're looking to program it yourself, you need to make an InSim client that connects to LFS and listens for the IS_NPL packets, which hold the restrictions. You then check against a predefined parameter, and if they don't match, send them to spectate by sending an IS_MST with the /spec PLAYERNAME command

If you're after someone to put together the program for you, let us know...
Thanks the_angry_angel,

your reply tells me that i am looking for someone to make this, cos i didn't understand much of what you told me there...

So I am now looking for someone to put it together... I would like to do it myself, but i need it a bit before i could finish it myself, by the looks of it. I have done a lot of programming, Delphi and ASP, but have not yet started with Insim/LFS.

A bit more info is needed then i guess... I would like to be able to test and race the babyR's mentioned elsewhere on the forum, so i need it to check that UFR has applied a 45% restriction and XFR has a 43% restriction. I know that am an not allowed to call it babyR... And if possible a restriction for the GTR's. FXR and XRR 25%, and FZR 20%, according to MoE... And if possible on a dedi server...

Kind regards
Franke.. Click
#4 - J@tko
Quote from Franke :A bit more info is needed then i guess... I would like to be able to test and race the babyR's mentioned elsewhere on the forum, so i need it to check that UFR has applied a 45% restriction and XFR has a 43% restriction. I know that am an not allowed to call it babyR... And if possible a restriction for the GTR's. FXR and XRR 25%, and FZR 20%, according to MoE... And if possible on a dedi server...

Yey! Someone is using the XF-Junior-R! I also might need a programme like this for the LFSBC, as the one I have only does one car's restriction. If not - no worries, I'll check them myself.
i made a program to do kinda this a while back. Ive been mearning to update it to support more cars etc etc

http://www.lfsforum.net/showthread.php?t=33323

Edit: f*** i just realised this doesnt work with Y...
Well, i am now taking a crack at programming it myself... Will maybe return for a few questions, but TAA's pust should do, will postwhatever i get done...

Regards and thanks for your answers...
Franke... Click
yeh, its acutally easy. Just make a simple if statement as a player joins or leaves pits. if the value in there intake and/or mass is lower then your's, Spec them
Problem is that i have not setup any programming tools for it, so have to get that to work first, then find out how to do everything, so the solution to my problem might be easy, but i "just" have to get everything to work, the programming itself is no problem, as i said i have many years experience in programming, but none for LFS

Franke... Click
Ok... Almost 4 hours later... And progress

I can easily make the restriction checks now, BUT i can for the life of me not find out how this file system works, would like to make an ini file like setup for restrictions, used inifiles a lot in Delphi, cos its easy peasy to find something, but i have now searched the help, but nothing...

It took me, by the help of TAA's post, about 10 minutes to figure out how to make the restriction, and an hour to /spec player, had difficulty finding the right variable to spectate... But thats done, but 2 hours to figure out how to read it EASILY from a file LOL... TOTAL C# NOOB...

If someone can make a function where i can put in Filename, Car, Restrictiontype and return me the value, i will make the app publicly available, with source code and everything

Can you help? Or point me in the right direction on file system in Visual C# 2008 EE... Will continue to look for a while... otherwise i will give up on file thingy, and just make it blocked, but then it will be worthless to the rest of you, as password is even hardcoded... Man i feel stupid 15 years programming experience and stuck on a simple thing like files... Tsk...

Kind regards
Franke... Click
For things like this I just use a simple C# class similar to the one below for reading and writing to a config file.

using System;
using System.Collections.Generic;
using System.IO;

namespace ConfigHandler
{
public class Config
{
private Dictionary<string, string> keyValues =
new Dictionary<string, string>();

public Config() { }

public Config(string path)
{
Load(path);
}

public void Load(string path)
{
using (StreamReader sr = new StreamReader(path))
{
string line = null;
while ((line = sr.ReadLine()) != null)
{
string[] kv = line.Split('=');
keyValues.Add(kv[0], kv[1]);
}
}
}

public void Save(string path)
{
using (StreamWriter sw = new StreamWriter(path))
{
foreach (KeyValuePair<string, string> kv in keyValues)
{
sw.WriteLine(
"{0}={1}",
kv.Key,
kv.Value);
}
}
}

public void Set(string key, string value)
{
if (keyValues.ContainsKey(key))
keyValues[key] = value;
else
keyValues.Add(key, value);
}

public void Set(string key, bool value)
{
Set(key, value.ToString());
}

public void Set(string key, int value)
{
Set(key, value.ToString());
}

public string GetString(string key)
{
return keyValues[key];
}

public int GetInt32(string key)
{
return Int32.Parse(GetString(key));
}

public bool GetBool(string key)
{
return Boolean.Parse(GetString(key));
}
}
}

Here is an example of using the class:

using ConfigHandler;

class Program
{
static void Main()
{
// The path to the config file.
string path = "Config.txt";

// Create a config
Config config = new Config();

// Saving a config.
config.Set("MyInt", 3635);
config.Set("MyString", "Hello, world!");
config.Set("MyBool", false);

config.Save(path);

// Loading a config.
config.Load(path);

int myInt = config.GetInt32("MyInt");
string myStr = config.GetString("MyString");
bool myBool = config.GetBool("MyBool");
}
}

It doesn't have any exception handling, but generally it should work OK. It also only does some basic data types, but it's easy to add more. Hope this helps.
First of all..... I DID IT, though i did whine A LOT... But that aside i made it... Thanks mostly to the_angry_angel and DarkTimes... Thanks a million couldn't have done it without you... YOU GUYS ROCK...

(DarkTimes i made an extra param for your source so i could use ushort, and a check so it allows for using linebreaks and comment lines)

Though its not completely testet... Means i have not done other testing than selecting a car with wrong settings...

Well i have included the App, dunno if its too many files, but you can setup the essentials in the Restrictions.txt file, and it works on local servers AND Dedicated server...

If you setup 0 KG restrictions, then any KG restriction is allowed, if you set >0 kg, it MUST be that setting on the car...

If you setup 0% restrictions, then any % restriction is allowed, if you set >0 %, it MUST be that setting on the car...

Have also included my C# project as well, didn't have time to clean it up, and is based on the Example from T-RonX's LFS External http://www.lfsforum.net/showthread.php?t=30012 Nice little tool, Thanks. So install that and use the enclosed source... Not cleaned, don't know what to clean and what not to

Kind regards
Franke... Click

EDIT: The program MUST be started after insim has been set in LFS, and the app MUST be closed before closing LFS, otherwise it fails...
Attached files
LFSCarRestrictor.zip - 35.1 KB - 512 views
LFSCarRestrictor (Source).zip - 164.6 KB - 487 views
Not bad, but make use of class's. all that stuff you put for getting the restrictions, could be in a class
Glad you found the Config class useful. I have another one which uses LINQ to XML which is quite nice too.

When you click the Close button without connecting it crashes. I guess this line:

inSim.Close();

Should be:

if (inSim != null)
inSim.Close();

Aside from that, I'd move all the InSim initialisation stuff out of the Form.Load event handler and just put it in the Form1 constructor.

Also you shouldn't wrap everything in one big try/catch block, this is bad practice and probably isn't doing what you think it's doing anyway (E.G. it won't catch all the exceptions). Just catch specific errors where they will occur, or better yet deal with the things that cause errors through logic before they can happen.

As macgas says, a lot of it could be refactored into separate classes, which will make the code easier to handle and cause less bugs. Also it's my personal preference that separate classes should be in separate files, but this is just my preference.
Can i get a copy of that class for XML and LinQ, that would help me

Also theres another reason i said put it in a class. if you put methods etc etc in a class, there also accessable all over the program. meaning you can reuse the same bit of code over and over again without writing it over and over again, thats one of the beautys of OOP
Thanks, i have to admit the creators of LinQ have done a great Job making it work how it does.
Well, as said earlier, i haven't cleaned up the code, the result posted was made from no knowledge of C# in 7 hours, where the goal was to make a restriction checker, that i needed like 3 days ago, so when i got it to work and it did the basics, i had to stop for the night... I have to find out how to add files in projects, make classes and about a million other different things, and being a Delphi programmer, i know about classes, units ond the importance of keeping it nice and neat, hence i wrote that i didn't have the time to clean up... Have to learn a bit more c# before that is possible. But the will be a priority when i get back to it... Could just have made the easy solution and let everything be static in the program, but that wouldn't have been nice, as i promissed to publizise the app, as lots of people seem to want the functionality... Found 3 or 4 treads regarding this, once i got into what it really was...

Regards Franke

PS! I will update the source when it has been cleaned
I've tested it and it works right, i've added FXO restriction and it works.

The only problem i have is that our dedi server is on a linux OS, and if i try to start the tool on linux i can't...

I've used mono and also wineconsole but both of them gives me an error..

Anyone of u tried to run the tool on linux? (i've Debian distro on the server).

Thanks.
Cr45h

FGED GREDG RDFGDR GSFDG