The online racing simulator
#1 - jackd
*Help Needed* Admin System In Insim
I have used this thread to make my insim system
http://www.lfsforum.net/showthread.php?t=39706&highlight=admin+insim

The one issue i have is that i cant make an admin part, like the one you would get so u can have all cars or assign people money or refund people etc. Any help would be much apriceated.
You will need to need to store the "admin" users somewhere and then check it when someone does a command or something that is "protected".
Permissions system. Recommend a making a user class to handle permissions.
LFS_External already stores people as an admin, if they connect with the admin password. To check their admin status, use:

Connections[GetConnIDX([B]UCID[/B])].IsAdmin

that'll return a byte, I think...

Then it's just a matter of checking the Admin status of someone before they do the restricted action...Hope that helps
#5 - sun
Thanks Rob, it helped me

but i get an error when i put this in the NCN packet

InSim.Send_BTN_CreateButton("^7Admin" + Connections[GetConnIDX(UCID)].IsAdmin, NCN.UCID, 0);

i'am trying to check if someones an admin, then display a button so they know they are
Quote from sun :Thanks Rob, it helped me

but i get an error when i put this in the NCN packet

InSim.Send_BTN_CreateButton("^7Admin" + Connections[GetConnIDX(UCID)].IsAdmin, NCN.UCID, 0);

i'am trying to check if someones an admin, then display a button so they know they are

if (Connections[GetConnIdx(NCN.UCID)].IsAdmin == 1)
{
InSim.Send_BTN_CreateButton("^7Admin " + Connections[GetConnIdx(NCN.UCID)].Username, Flags.ButtonStyles.ISB_DARK, 5, 20, 0, 15, 45, NCN.UCID, 2, false);
}

i think thats it im not so good at this yet
#7 - sun
Thanks Rob, you might want to check the if statement because i had errors on that. the button code works but when your not an admin it displays Admin 0. But when you are an admin it shows Admin 1.
Quote from sun :Thanks Rob, you might want to check the if statement because i had errors on that. the button code works but when your not an admin it displays Admin 0. But when you are an admin it shows Admin 1.

fix it then?
Quote from sun :Thanks Rob, you might want to check the if statement because i had errors on that. the button code works but when your not an admin it displays Admin 0. But when you are an admin it shows Admin 1.

No! That is not a bug in the "if" statement. The so called bug is not a bug, its doing what it is intented. The reason you think its a bug is because you dont understand it.

Connections[GetConnIDX(UCID)].IsAdmin

That code returns a byte and its upto you to work out if they are an admin or not. if that returns 1 then they are. If it returns 0 then they are not. You cant just send that in a button and expect it to show everyone who is admin. The code that robbo posted will only show a button to a NewConnection if they are admin, Even then it will only report there admin status on the server. So please learn before calling this a bug.
:ices_rofl...

You do know what a byte is, right?
Quote from dougie-lampkin ::ices_rofl...

You do know what a byte is, right?

Are you freaking kidding me? Of course i know..
Not you...obviously
Today's lesson:

A byte is a method for storing a unit of information, which nowadays is most commonly a value made up of eight bits (binary digits) that can store an integer between 0 and 255. This can vary of course between different platforms, although it's pretty standardised these days.

Edit:

Useless Fact:

In bygone days the size of a byte on a specific platform was however large it needed to be to store all the characters on that platforms character sheet, meaning the size could vary from computer to computer. With the advent of the IBM's 8-bit microprocessor and popularisation of 8-bit ANSI characters, it become more or less fixed at 8 bits to a byte. As a byte was sized for storing characters, the size of the next value-type above it became known as a 'word', as a word could store multiple characters.
Quote from DarkTimes :Today's lesson:

A byte is a method for storing a unit of information, which nowadays is most commonly a value made up of eight bits (Binary DigITs) that can store an integer between 0 and 255. This can vary of course between different platforms, although it's pretty standardised these days.

LOL, Also dont forgot that a byte uses less space in memory then an int and an sbyte uses even less
Quote from mcgas001 :LOL, Also dont forgot that a byte uses less space in memory then an int and an sbyte uses even less

Are you sure about that? Have you checked to see if that's true? I don't know, but I'm pretty sure memory on a 32 bit microprocessor is designed for 32 bit values, or Int32's in C#. Whether you are storing a byte or an int, it will still take up the same space in memory. I could very well be wrong, but something at the back of my mind tells me I'm not.

Queue someone who knows way more about this than I do correcting me.

Edit: In fact, thinking about it more, I'm pretty sure this is the reason for the loss of precision when using float values.

EDit2: Also whether a value is signed or unsigned, it still uses the same amount of bytes...
This seems this think differently, Check pic...

byte = 1 byte in memory
int = 4 bytes in memory
Attached images
byte.PNG
That pic mentions nothing about how a specific computer platform allocates memory, only how many bytes are used to describe each of the values. Anyway, I may be wrong, I never studied computer science, I just hack code together.
Quote from DarkTimes :That pic mentions nothing about how a specific computer platform allocates memory, only how many bytes are used to describe each of the values. Anyway, I may be wrong, I never studied computer science, I just hack code together.

Thats true, but i just assumed that it was the size in memory. The previous statement in the book says this...

Quote from C# For Dummies :

Most simple variables are of type
int. However, C# provides a number of
twists to the int variable type for special occasions.
All integer variable types are limited to whole numbers. The int type suffers
from other limitations as well. For example, an int variable can only store
values in the range from roughly –2 billion to 2 billion.
A distance of 2 billion inches is greater than the circumference of the Earth.
In case 2 billion isn’t quite large enough for you, C# provides an integer type
called long (short for long int) that can represent numbers as large as you
can imagine. The only problem with a long is that takes a larger train locker:
A long consumes 8 bytes (64 bits) — twice as much as a garden-variety int.


That was my shove towards memory...
Processors can handle different size data types. For example a 32bit register can be used by 4 8bit values, or 2 16bit values.

That is from my limited understanding of the Assembler language.
In most modern computer systems, the memory addressing is single-byte addressing, meaning that each byte (8 bits) is addressed, rather than any bigger chunk - so there's no cost to storing something of a single byte in length. Additionally, storing a 4-byte (32-bit) integer, for example, is no real cost, as it's only the first memory address that's of much use to you anyway. If you know it's a 32-bit data type, you just read 4 bytes from the memory address. The only problem with addressing comes when using things like packed booleans, (or other packed data types), as the addressing unit encompasses multiple data items.

As for the signed/unsigned, there is no difference in size between a data type's signed and unsigned permutations - and they do exactly what they say, one allows for signs (i.e. allows for negative numbers) by 'putting' zero in the middle of the range and the other doesn't (with zero at the lower end).

With 32-bit systems, the 32-bit aspect of it basically means (considering memory usage only, in this case) that 32-bit memory addresses are used, rather than can only assign 32-bit blocks. What this means is that a 64-bit machine can address that many more memory locations than a 32-bit system - because the address bus is larger The addressed unit is still relatively standardised at 1 byte. (However, it must be said that just because something is 32-bit, doesn't mean it's memory addressing is 32-bit, it can be higher or lower - but the above is a general rule.)

32-bit addressing allows 2^32 addresses (4GiB), whilst 64-bit allows 2^64 (16EiB). One of the primary reasons the change to 64-bit was made was to increase the memory addressing space. And if we reach 16 Exbibytes any time in the next several hundred years, I'll be surprised.
#21 - vane
i understand how to get it to come up on certain player's screens (record the admins), but i dont know how to get the actual info, i tried doing e.g a button for a username [0] one for [1] [2] [3] [4] etc, but what would you do when you reach 8?
also, is there a bit that is like an integer(int) except it sends text instead of numbers, is this a string?
what i mean is if you wantri a whole number you put an 'int' infront of it and 'decimal' infront if you want a decimal but do you need to put anything if it is for text?
Quote from vane :what i mean is if you wantri a whole number you put an 'int' infront of it and 'decimal' infront if you want a decimal but do you need to put anything if it is for text?

Not really, the things you put before a piece of data in a programming language is called the data type. For a whole number, you tend to use 'int' (or 'double'/'long' for much larger numbers), for a decimal you tend to use 'float', and for text you use String

Best thing to do is to go and read up on Data Types in <your language here> and see what it has to say
#23 - vane
is there a piece of data in the MCI.Info bit about which set of 8 it is so you can do more than 8? so if there is more than 8 players/connections

EDIT: i have found this in the insim .txt

"#define CCI_FIRST 64 // this is the first compcar in this set of MCI packets
#define CCI_LAST 128 // this is the last compcar in this set of MCI packets

// NOTE 2) Heading : 0 = world y axis direction, 32768 = 180 degrees, anticlockwise from above
// NOTE 3) AngVel : 0 = no change in heading, 8192 = 180 degrees per second anticlockwise

struct IS_MCI // Multi Car Info - if more than 8 in race then more than one of these is sent
{
byte Size; // 4 + NumP * 28
byte Type; // ISP_MCI
byte ReqI; // 0 unless this is a reply to an TINY_MCI request
byte NumC; // number of valid CompCar structs in this packet

CompCar Info[8]; // car info for each player, 1 to 8 of these (NumC)"

could someone try their best to explain how you would get all their info up past 8
AFAIK, it will do it itself. Example: You are using MCI.Info[0].Speed. This is the speed of connection 1. But if there are more than 8 people, more than one packet is sent. So MCI.Info[0].Speed it would work for Connection 9, 17, 25, etc.

That's what I think happens anyways...

It was said to me many times, but it's only now I actually see how it happens
Vane, don't be confused by my post. My post was not referring to how InSim handles things, it was referring to the general principle of memory addressing and data types as brought up by DarkTimes You need not worry about the number 8, as it will have little or no effect on you in the scope of InSim development. As dougie says, you MCI.Info[] works for any number

FGED GREDG RDFGDR GSFDG