Register for your free account! | Forgot your password?

You last visited: Today at 02:36

  • Please register to post and access all features, it's quick, easy and FREE!


Converting a string to an uint

Reply
 
Old   #1
 
elite*gold: 20
Join Date: Jun 2006
Posts: 3,293
Received Thanks: 919
Converting a string to an uint

The authresponse packet sends 2 values that can be practically anything and the 1052 packet uses those values for decryption reasons (5017). Now I want to send the account ID with the authresponse packet, the issue here is that the authresponse packet requires an uint and the account ID is obviously a string so is there a way to convert the string to an uint and back again when needed?
When googling I came across a slightly roundabout way that didn't really work as intended, it was along the lines of string -> byte array -> uint but when converting back, it came out a bit... weird, the string ended up being halved.

//edit Posted this in the wrong section, should be moved to the pserver section or programming section.



Kiyono is offline  
Old 01/04/2012, 22:55   #2
 
elite*gold: 0
Join Date: May 2005
Posts: 1,892
Received Thanks: 913
The account ID is also an unsigned 4 byte value, not a string. With that being said, you can convert a string to any type by using the Parse or TryParse methods for that type.


Lateralus is offline  
Old 01/04/2012, 23:26   #3

 
elite*gold: 0
Join Date: Jan 2008
Posts: 1,394
Received Thanks: 1,053
Quote:
Originally Posted by Kiyono View Post
The authresponse packet sends 2 values that can be practically anything and the 1052 packet uses those values for decryption reasons (5017). Now I want to send the account ID with the authresponse packet, the issue here is that the authresponse packet requires an uint and the account ID is obviously a string so is there a way to convert the string to an uint and back again when needed?
When googling I came across a slightly roundabout way that didn't really work as intended, it was along the lines of string -> byte array -> uint but when converting back, it came out a bit... weird, the string ended up being halved.

//edit Posted this in the wrong section, should be moved to the pserver section or programming section.
As Lateralus said, the Account ID is really an integer. It must be an unique ID generated at the account creation and linked to the account name. Anyway, if your account ID is a string because you consider the account name as the ID, there is three solutions.

The first one. An (U)Int32 is constructed of 4 octets. An ASCII string is formed by an array of octet. So, if your string is 1-4 characters, you'll be able to take their ASCII code an construct an (U)Int32. But it isn't realistic...

The second one. If all your account name are numbers, you'll be able to parse them to an (U)Int32. But it isn't realistic...

As you see, there isn't any reversible way to convert a string to an integer. You'll have to go with an hash function. The FNV-1(a) hash can generate a 32 bits hash, so it'll fit in an (U)Int32. The GetHashCode() function will also generate a 32 bits hash, but I'm not sure of the dispersion... It may be really bad. Anyway, when checking for the account, you'll have to hash every account in the database for finding the right one. It's not a really great solution.

The best solution is to go with the real AccID as it should be. The AccID is already an integer if you implemented it right.
CptSky is offline  
Old 01/04/2012, 23:50   #4
 
elite*gold: 20
Join Date: Jun 2006
Posts: 3,293
Received Thanks: 919
Oh, I considered the account ID and account name to be the same thing and I was actually referring to the account name which is [I think] also the account ID in the Project Manifest source. So how would I check to see if the account ID is implemented right? As I honestly don't know where to look.


Kiyono is offline  
Old 01/05/2012, 01:06   #5
 
elite*gold: 0
Join Date: May 2005
Posts: 1,892
Received Thanks: 913
Quote:
Originally Posted by Kiyono View Post
Oh, I considered the account ID and account name to be the same thing and I was actually referring to the account name which is [I think] also the account ID in the Project Manifest source. So how would I check to see if the account ID is implemented right? As I honestly don't know where to look.
The account ID can't be the same as the account name, as the two are different types. I really don't understand what you're trying to do...
Lateralus is offline  
Old 01/05/2012, 11:58   #6
 
elite*gold: 20
Join Date: Jun 2006
Posts: 3,293
Received Thanks: 919
Guess I'll need to clarify it about then.
I want to send the account name in the authresponse packet as one of the keys (authserver) and want to be able to convert it back to string in the gameserver but it seems to be... well not possible.
Kiyono is offline  
Old 01/05/2012, 12:09   #7
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,124
Received Thanks: 2,498
Well its not that its not possible.

You would need to create a unique number based on the string by way of a method, i guess something like a checksum could work.

The problem is that you need the number to be unique, otherwise you will get issues when you get to the game server, and doing that with 4 bytes, or even 8 if you use both fields would be difficult.


Korvacs is offline  
Reply



« Previous Thread | Next Thread »

Similar Threads
[VB08]String in String mit mehreren Funden
Hey, bin gerade auf ein Problem gestoßen, an dem ich mir seit 3 Stunden die Zähne ausbeiße. Ich will eine Funktion schreiben, die der...
6 Replies - .NET Languages
Converting
So I'm converting this Trade Partner to NCOS 5165, and having trouble with saving, deleting. On this other source, it's for sql. The source I use...
1 Replies - CO2 PServer - Discussions / Questions
[C++] string zwischen string
tag gibts direkt ne funktion, mit der man einen passenden string zwischen dem string suchen kann? also meine net .find() sondern sowas ähnliches,...
6 Replies - C/C++
Converting !
I want to know how to Convert a LOTF Source that is .ini into a Non ini Source Any Guides? Tips, ty. Co B,c,
13 Replies - CO2 PServer - Discussions / Questions
[Question]Other.ItemType(uint item)
newbie coder (\scriptkiddie) here rewriting ShadowCO to learn C#.. I was wondering if someone could explain the following part to me: ...
1 Replies - CO2 PServer - Discussions / Questions



All times are GMT +2. The time now is 02:36.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Abuse
Copyright ©2018 elitepvpers All Rights Reserved.