The online racing simulator
Sorry, I haven't had time for any off-work programming lately. I'll let you know as soon as I do test them though.
Ok, the admin pass seems to be perfectly fine.

But I have 2 more reports:
1. The color codes I send to LFS, are being shown as text. I send ^1red, and I get a normal, green ^1red.
2 (better version of that explanation is available below). I might join povo's club about the button length. At some random points, my Queue thing (in case you are wondering, yes, Queue thing is how I like to call it :razz shoots out random errors when sending a button. At first I thought that was happening, because of my poorly-tested loop (which deletes buttons from a list after it hands them over to insim.net). But now, I suspect it's because of the length of the text on that button. There's this button of them all, that shows a typical car list (cruise insim style, because it's a cruise insim). And when I surrounded the Send code in a try expression(if it's an expression, if it's not I'm looking stupid, and I'm happy someone can have a laugh at my bs ;d) - that very same button was the only one that didn't show on the screen. (I'm going to need to rewrite that... All done, there it is - below!)
BETTER VERSION of 2: I am suspicious that buttons with long text sometimes don't get sent. I receive this when that happens:
[B]Message[/B]: Index was outside the bounds of the array.
[B]Source[/B]: InSimDotNet
[B]StackTrace[/B]: at InSimDotNet.EncodingHelper.GetBytes(String value, Byte[] buffer, Int32 index, Int32 count)
at InSimDotNet.Packets.PacketWriter.Write(String value, Int32 length)
at InSimDotNet.Packets.IS_BTN.Pack()
at InSimDotNet.InSim.Send(ISendable packet)
at Dizplay_Cruise.Button.Processor.QueueProcessor_Elapsed(Object source, ElapsedEventArgs e) in D:\Loran\Programming\C#\Live for Speed\Dizplay\Cruise A.0.1\Dizplay Cruise\Dizplay Cruise\Button\Processor.cs:line 35
at System.Timers.Timer.MyTimerCallback(Object state)

Ok, after actually reading, and not just scanning through all of the values of the error, it looks like there's a problem with the color codes' encoding, not the length. Maybe, because something evil happened to the '^' char, which could have something to do with the admin passwords being all OK? But... I'm guessing it's something you would have found out before even reading this, and I might just be wrong as well, so, whatever.

PS: Sorry for the messy post.
Quote from broken :1. The color codes I send to LFS, are being shown as text. I send ^1red, and I get a normal, green ^1red.

Same problem for me
Quote from broken :1. The color codes I send to LFS, are being shown as text. I send ^1red, and I get a normal, green ^1red.

me either I tried any solutions but it shows incorrectly

E: when I use the car list to show on the button (yh its a string I'm creating it by using cruise insim) it seems the button won't show up or the packet stops working after the line is being read by the connection
Hi all insim makers ,

i know i m here new person but i try to make buttons which disabled when user speed is someting and i have looked all help but not that work?
is that too much asked someone show me example how that can do.

Thanks if someone wanna use time and help new coder.
Quote from DarkTimes :Car Updates

The library also supports MCI updates, without the need for any hacks . Here we check the speed of each player on track and spectate anyone who goes above 80 Kph.

using System;
using System.Collections.Generic;
using Spark;
using Spark.Packets;
using Spark.Helpers;

namespace Spark.Example5
{
class Program
{
static InSim _insim;
// We store the players in a dictionary.
static Dictionary<int, IS_NPL> _players = new Dictionary<int, IS_NPL>();

static void Main()
{
// Create new InSim object.
using (_insim = new InSim())
{
// Bind handlers.
_insim.Bind<IS_ISM>(MultiPlayerInfo);
_insim.Bind<IS_NPL>(NewPlayer);
_insim.Bind<IS_PLL>(PlayerLeft);
_insim.Bind<IS_MCI>(MultiCarInfo);

// Establish the InSim connection.
_insim.Connect("127.0.0.1", 29999);

// Initialize InSim.
_insim.Send(new IS_ISI { IName = "^3Example", Flags = InSimFlags.ISF_MCI, Interval = 500, Admin = string.Empty });

// Request for multiplayer info packet to be sent.
_insim.Send(new IS_TINY { SubT = TinyType.TINY_ISM, ReqI = 255 });

// Prevent program from exiting.
_insim.Run();
}
}

static void MultiPlayerInfo(IS_ISM ism)
{
// When joining multiplayer request for all connections and players to be sent.
_insim.Send(new IS_TINY { SubT = TinyType.TINY_NCN, ReqI = 255 });
_insim.Send(new IS_TINY { SubT = TinyType.TINY_NPL, ReqI = 255 });
}

static void NewPlayer(IS_NPL npl)
{
if (_players.ContainsKey(npl.PLID))
{
// Leaving pits, just update NPL object.
_players[npl.PLID] = npl;
}
else
{
// Add new player.
_players.Add(npl.PLID, npl);
}
}

static void PlayerLeft(IS_PLL pll)
{
// Remove player.
_players.Remove(pll.PLID);
}

static void MultiCarInfo(IS_MCI mci)
{
// Loop through each car on track.
foreach (var car in mci.CompCars)
{
// Get the player driving this car.
IS_NPL npl;
if (_players.TryGetValue(car.PLID, out npl))
{
// Check cars speed.
var kph = MathHelper.SpeedToKph(car.Speed);
if (kph > 80)
{
// Spectate player and send chat message.
_insim.Send("/spec {0}", npl.PName);
_insim.Send("{0} ^3spectated for speeding", npl.PName);
}
}
}
}
}
}


Use this code from DarkTimes. Where it says "// Spectate player and send chat message." output the "kph" variable on a button.
Oh thanks Povo. offcourse that make tricks thx , but i realy need help with this command IS_BFN

my problem is i can make that button when example speed is over 20 but i cant get that off when speed is lower than 20

ps i user spark 1.0.10 version this moment
if someone can give short example how i can remove buttons on screen pls.
You need to send a BFN packet with a SubT of BFN_DEL_BTN to delete one button, or BFN_CLEAR to delete all of them.


// To delete one button.
insim.Send(new IS_BFN
{
SubT = ButtonFunction.BFN_DEL_BTN,
ClickID = 1, // ID of button to delete
UCID = 0, // User to delete the button for
});

// Delete them all
insim.Send(new IS_BFN
{
SubT = ButtonFunction.BFN_CLEAR,
UCID = 0, // User to delete the buttons for
});

Quote from broken :Ok, the admin pass seems to be perfectly fine.

But I have 2 more reports:
1. The color codes I send to LFS, are being shown as text. I send ^1red, and I get a normal, green ^1red.
2 (better version of that explanation is available below). I might join povo's club about the button length. At some random points, my Queue thing (in case you are wondering, yes, Queue thing is how I like to call it :razz shoots out random errors when sending a button. At first I thought that was happening, because of my poorly-tested loop (which deletes buttons from a list after it hands them over to insim.net). But now, I suspect it's because of the length of the text on that button. There's this button of them all, that shows a typical car list (cruise insim style, because it's a cruise insim). And when I surrounded the Send code in a try expression(if it's an expression, if it's not I'm looking stupid, and I'm happy someone can have a laugh at my bs ;d) - that very same button was the only one that didn't show on the screen. (I'm going to need to rewrite that... All done, there it is - below!)
BETTER VERSION of 2: I am suspicious that buttons with long text sometimes don't get sent. I receive this when that happens:
[B]Message[/B]: Index was outside the bounds of the array.
[B]Source[/B]: InSimDotNet
[B]StackTrace[/B]: at InSimDotNet.EncodingHelper.GetBytes(String value, Byte[] buffer, Int32 index, Int32 count)
at InSimDotNet.Packets.PacketWriter.Write(String value, Int32 length)
at InSimDotNet.Packets.IS_BTN.Pack()
at InSimDotNet.InSim.Send(ISendable packet)
at Dizplay_Cruise.Button.Processor.QueueProcessor_Elapsed(Object source, ElapsedEventArgs e) in D:\Loran\Programming\C#\Live for Speed\Dizplay\Cruise A.0.1\Dizplay Cruise\Dizplay Cruise\Button\Processor.cs:line 35
at System.Timers.Timer.MyTimerCallback(Object state)

Ok, after actually reading, and not just scanning through all of the values of the error, it looks like there's a problem with the color codes' encoding, not the length. Maybe, because something evil happened to the '^' char, which could have something to do with the admin passwords being all OK? But... I'm guessing it's something you would have found out before even reading this, and I might just be wrong as well, so, whatever.

PS: Sorry for the messy post.

I've pushed a bug fix onto the repository (not ready to make a release) with a small fix for the color codes. It would be helpful if you could actually post an example of a button that doesn't get sent, as I'm not sure exactly what the problem is. The fix I've made should help things.

You can download the latest changeset from the repository.

http://insimdotnet.codeplex.co ... ceControl/list/changesets
thanks darktimes that work , and btw big big big thanks to make so nice library like this , this make insim making so easy.
Nice to see your still keeping things going for LFS, DarkTimes!
oh well , i learned much and now i can remove buttons too , next problem is how i can make button where is inside other buttons?

or i m total lost how i can make some sort list example players in server and all of them are own buttons?
So sorry for asking maybe stupid questions but i realy wanna learn make imsim stuff and best way how im learn try and try and try , but sometimes im out of ideas

so if there is some nice ppl who can throw me with code
im so happy then
OK, I think I've fixed the bug with the BTN text. What was happening is the BTN code wasn't correctly taking into account the NULL terminator when figuring out the length of the string. Because there was no NULL terminator LFS was discarding the string and not showing it, which is why some buttons appeared to not be sent.

I've uploaded a new release of the BETA to CodePlex.

Note: Entertainingly this fix required the change of only a single-character in the source code, changing a 2 to a 3.
Great work! Will test the 220 character button in a few mins.

Edit: Long character buttons finally work!

One thing that doesn't work is, sending a button with no Text in it. e.g Text = "" or not declaring the Text at all, throws an exception:


System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
at System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy)
at System.String.Substring(Int32 startIndex, Int32 length)
at InSimDotNet.Packets.PacketWriter.Write(String value, Int32 length)
at InSimDotNet.Packets.IS_BTN.Pack()
at InSimDotNet.InSim.Send(ISendable packet)
at DriftProject.Button.Control.NewButton(Vars Conn, Int32 currentID, IS_BTN Button) in G:\Users\Povilas\documents\visual studio 2010\Projects\DriftProject\DriftProject\Button\Control.cs:line 20
at DriftProject.Packets.MCI.Update(Vars Conn) in G:\Users\Povilas\documents\visual studio 2010\Projects\DriftProject\DriftProject\Packets\MCI.cs:line 50

Setting the Text to " " (A simple space) solves the problem. Not much of a big deal, but it worked before
Working perfect
Confirmed.
Text colors are working flawlessly, and so are the buttons. No matter with long/normal or without any text.

Also, sorry for the late reply. If for whatever reason you still need the text of the (what used to be a) problematic button, there it is:
UF1 XFG ^7XRG LX4 LX6 RB4 ^8FXO XRT ^7RAC ^8VWS FZ5 ^7UFR XFR FXR XRR FZR ^8MRT

thanks the long button character strings is now supported
OK - good to hear it's working OK. What you all won't be glad to hear is that I've just completely rewritten all the string encoding code! Yay, more bugs!

I suddenly had a brainwave about how to implement full string encoding support and it seems to be working well. I've pushed the changes onto the repository, but I'll hold back on pushing out a release until I've made sure it's all working OK.

The new string encoding now correctly handles all LFS codepages, including single-byte and double-byte character sets, which means full Japanese, Korean, Simplified Chinese and Traditional Chinese support. I had talked about this before, but in the version of the library I release I only included support for single-byte character sets. Obviously that sort of thing is not good enough.

In my previous attempts to write this code I had been performing the lookup myself (with giant hash tables), which was proving problematic, but I'm now p/invoking the WideCharToMultiByte function in kernel32.dll, which seems to provide a simple and fast lookup for the various encodings. It is slightly slower than the old string encoding, but we're still talking about fractions of a millisecond for even complex strings.

I'd appreciate it if anyone would be willing to pull the latest revision from the repository and report back if it's working OK.
Well, I've downloaded the latest Source from repository. If any thing wrong pops up, I'll let you know.

Continue the speedy work
well i have learning more that c# plus insim stuff and i learn much

but now i have stucked and if someone can help me somehow i m so glad

how i can list server players in buttons , ofcourse i can make that manual but i hope there is some trick that program look howmany players is online and if there is example 5 ppl online insim make 5 button in screen where is they usernames?

im glaad if i get any tip how to do that , and yeah im total noob in programming stuff but i realy wanna learn make good insim stuff
Quote from janne79_1 :well i have learning more that c# plus insim stuff and i learn much

but now i have stucked and if someone can help me somehow i m so glad

how i can list server players in buttons , ofcourse i can make that manual but i hope there is some trick that program look howmany players is online and if there is example 5 ppl online insim make 5 button in screen where is they usernames?

im glaad if i get any tip how to do that , and yeah im total noob in programming stuff but i realy wanna learn make good insim stuff

That's not really the place to ask. But anyway.

First of all, you would need a list, or an array, or any other type of variable(or.. simply said - holder), with similar functionality. I am not aware of all the possibilities, tbh.
Then, you simply iterate(loop(do a for/foreach)) through that holder, and in that loop you simply send a button. It will be a good thing to declare a variable before the loop, which you will increase, so that each button you send, does not overlap the previous one. Also, ClickIds do not have to be the same, or the button will be overwritten on the screen.
Pushed a few more changes to the repository, although not made a proper release yet.

Breaking Change:

As it's still a beta I've introduced a breaking-change, namely that you now send messages to InSim a bit differently. I really missed the old style of sending formatted messages, so I've reverted it back to the InSim.Send(string, params object[]) method of old.

// Send message
insim.Send("Hello!");

// Send formatted message
insim.Send("Hello, {0}", name);

// Send message to specific connection
insim.Send(ucid, "Hello!");

// Send formatted message to specific connection
insim.Send(ucid, "Hello, {0}", name);

// Send message to specific connection or player
insim.Send(ucid, plid, "Hello!";

// Send formatted message to specific connection or player
insim.Send(ucid, plid, "Hello, {0}", name);

// etc.. etc..

Here is a most general list of changes in the repository.

Changes
  • Can now set your own IPacketFactory and ISocket on the InSim class again, if you need to implement your own packet code (this is kinda advanced stuff, but very useful)
  • Improved and optimized the string handling code (yay more fun!)
  • Improved InSim.Send(IEnumerable<ISendable>) method, which allows you to batch send packets for improved performance (useful if you need to send lots of buttons or messages in one go) (see below)
  • Rewrote BindingCollection, making it cleaner and faster (although not something most people will notice)
  • Can now save/load InSimSettings (see below)
  • Fixed a few really big bugs in OutSim and OutGauge code.
To save the InSimSettings:

InSimSettings settings = new InSimSettings {
Host = "127.0.0.1",
Port = 29999,
Admin = "Whatever",
};

// Save to XML
InSimSettings.Save(settings, "mySettings.xml");

// Load from XML
InSimSettings settings = InSimSettings.Load("mySettings.xml");

// The InSimSettings are saved and loaded from disk using the
// XmlSerializer class, which is simple but effective.

To batch send packets (for extra network performance):

insim.Send(new List<ISendable> {
new IS_MST { Msg = "Hello" },
new IS_MST { Msg = "World" },
new IS_MST { Msg = "How" },
new IS_MST { Msg = "Are" },
new IS_MST { Msg = "You?" },
});

// All these packets get sent in a single call, instead of five
// separate calls, improving network throughput.

It is almost finished now, I only have a couple of small changes left to consider before I release InSim.NET 2.0 final. As always I invite and encourage people to pull the latest revision from CodePlex and let me known of any issues before I push it out to the world.
-
(DarkTimes) DELETED by DarkTimes
As mentioned previously you can now set your own IPacketFactory, which allows you to reimplement the way packet are built.

public class CustomPacketFactory : IPacketFactory {
public IPacket BuildPacket(byte[] buffer) {
// Implement your own packet handling code here. You can
// create your own packets or do whatever you need to,
// so long as your new packet inherits from IPacket.
return null;
}
}

InSim insim = new InSim();

// Set your custom packet factory
insim.PacketFactory = new CustomPacketFactory();

// Exists here normal InSim.NET code...

If you need to you can completely reimplement the socket code, by implementing ISocket on your own custom class.

public class CustomSocket : ISocket{
// Custom implementation of ISocket.
}

InSim insim = new InSim();

// Set your custom socket.
insim.Socket = new CustomSocket();

// Whatever...

Your custom socket could read InSim data from a file, or from a Windows Service, if you so choose. You can create any source you like, so long as you inherit from ISocket. This is one of the many things that make InSim.NET very flexible, as although it's designed to work with zero configuration, it's also designed to let you reimplement stuff that's important to your app.

Maybe you need to access the raw byte data from InSim? InSim.NET lets you do that...

InSim insim = new InSim();

// You have complete access to underlying socket.
insim.Socket.PacketDataReceived += insim_PacketDataReceived;

private void insim_PacketDataReceived(object sender, PacketDataEventArgs e) {
// Now you have raw byte data...
byte[] data = e.GetData();
}

Or maybe you'd like to ignore InSim.NET and go straight to the TCP socket itself?

// You can access the underlying socket without the InSim abstraction
TcpSocket sock = new TcpSocket();

// It handles the TCP receive stream for you, basically makes TCP act like UDP...
sock.PacketDataReceived += insim_PacketDataReceived;

// You can create a connection.
sock.Connect("127.0.0.1", 29999);

// And send raw packets...
sock.Send(new IS_ISI {
Admin = String.Empty;
IName = "Test!",
}.Pack());

private void insim_PacketDataReceived(object sender, PacketDataEventArgs e) {
// And handle them however you like...
byte[] data = e.GetData();

}

This should give you an idea of just how flexible InSim.NET is.

FGED GREDG RDFGDR GSFDG