The online racing simulator
Different encoding in MSO messages
Hey, I'm trying to extract player names from MSO packets' message and it gives me literal headache for few days now.

So NPL returns a proper PName, for example: [¥€€†]s°
But for some reason MSO message has problems with encoding (I guess) and shows it as: [・€€?sー

This is a big problem as soon as I try to match that PName from MSO with PName in my collection (which was stored from NPL packet) as it's different.

Can somebody please explain me why it's different and what can I do about it? I'm using InSimDotNet if it's related.

EDIT:
My InSim is local and I rely on host chat messages, I don't really see any language related escape codes (like ^L, ^G, ^C)

EDIT 2:
Seems like it's happening for only few of host messages. Some messages host sends are with correct encoding and some are not. How is this possible?
Hi, the MSO package does not contain a name, only a PLID, which you should have stored in your program somewhere when you got the NPL.

So you get the NPL package, save the plids and it's nicknames, and match the PLID of the MSO to a PLID in the list
Quote from kipieslim :Hi, the MSO package does not contain a name, only a PLID, which you should have stored in your program somewhere when you got the NPL.

So you get the NPL package, save the plids and it's nicknames, and match the PLID of the MSO to a PLID in the list

Hm, let me clarify. I'm extracting player name from MSO packets' message.
It means that message has no PLID (it's sent by host, so it's always 0), it has text: Player A has sent money to Player B.
What I'm doing is extracting these names and making events on these, like OnPlayerSendMoney(Sender, Receiver).
Right, a bit more info would be nice to have.
  • What Flags did you set when Initializing insim, just ISF_LOCAL, or did you also set ISF_MSO_COLS?
  • Are you altering the NPL.PName or the MSO.Message at all before comparing them?
  • Are you using the InSimDotNet NuGet version or the last build from Github?
Maybe you can share some code if these hints don't help you in the right direction?

EDIT:
I've written a program that does lookup based on PName myself, this is what i do:

The class i store the user data in looks something like this:

class user{
public string Nickname {get;set;}
public string CleanNickname => Clean(Nickname); //strips any escape characters left

private string Clean(string nickname)
{
Regex hashtag = new Regex(@"\^h"); //since the InSimDotNet NuGet version doesn't seem to catch this
Regex cc = new Regex(@"\^\d"); //strip any color codes

return cc.Replace(hashtag.Replace(nickname, "#"), string.Empty);
}
}

And i guess your code for the message handling should look something like this.

private void OnMessage(InSim i, IS_MSO msg){
Regex moneySentQuery = new Regex(@"[/d/s/W]{1,3}has sent money to "); //should only hit on msgs with the matching string, any possible color codes are also handled
string cleanMessage = msg.Msg.Substring(msg.TextStart); //we only want the text of the message

if(moneySentQuery.IsMatch(cleanMessage)){ //check if the MSO message has certain text
string [] subStrings = moneySentQuery.Split(cleanMessage); //split message so we can extract users

//PlayerList is some List<user> you're maintaining somewhere in your program
user FirstUser = PlayerList.SingleOrDefault(u=>u.CleanNickname == subStrings.First()); //should be Player A or null
user SecondUser = PlayerList.SingleOrDefault(u=>u.CleanNickname == subStrings.Last()); //should be player B or null
}
}

It's pretty messy code, so I'm sure it has some false hits, or lack of hits, so it might need some altering to your specific use-case, but it should come close.

I hope this helps.
Quote from kipieslim :Right, a bit more info would be nice to have.
  • What Flags did you set when Initializing insim, just ISF_LOCAL, or did you also set ISF_MSO_COLS?
  • Are you altering the NPL.PName or the MSO.Message at all before comparing them?
  • Are you using the InSimDotNet NuGet version or the last build from Github?
Maybe you can share some code if these hints don't help you in the right direction?

EDIT:
I've written a program that does lookup based on PName myself, this is what i do:

The class i store the user data in looks something like this:

class user{
public string Nickname {get;set;}
public string CleanNickname => Clean(Nickname); //strips any escape characters left

private string Clean(string nickname)
{
Regex hashtag = new Regex(@"\^h"); //since the InSimDotNet NuGet version doesn't seem to catch this
Regex cc = new Regex(@"\^\d"); //strip any color codes

return cc.Replace(hashtag.Replace(nickname, "#"), string.Empty);
}
}

And i guess your code for the message handling should look something like this.

private void OnMessage(InSim i, IS_MSO msg){
Regex moneySentQuery = new Regex(@"[/d/s/W]{1,3}has sent money to "); //should only hit on msgs with the matching string, any possible color codes are also handled
string cleanMessage = msg.Msg.Substring(msg.TextStart); //we only want the text of the message

if(moneySentQuery.IsMatch(cleanMessage)){ //check if the MSO message has certain text
string [] subStrings = moneySentQuery.Split(cleanMessage); //split message so we can extract users

//PlayerList is some List<user> you're maintaining somewhere in your program
user FirstUser = PlayerList.SingleOrDefault(u=>u.CleanNickname == subStrings.First()); //should be Player A or null
user SecondUser = PlayerList.SingleOrDefault(u=>u.CleanNickname == subStrings.Last()); //should be player B or null
}
}

It's pretty messy code, so I'm sure it has some false hits, or lack of hits, so it might need some altering to your specific use-case, but it should come close.

I hope this helps.

Thanks for your help, but the problem was with InsimDotNet encoding and MSO colours. Removed ISF_MSO_COLS and using LfsUnicodeEncoding2 class seems to solve the issue.

FGED GREDG RDFGDR GSFDG