Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 22:43

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

Advertisement



Converting a string to an uint

Discussion on Converting a string to an uint within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1

 
Kiyono's Avatar
 
elite*gold: 20
Join Date: Jun 2006
Posts: 3,296
Received Thanks: 924
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
 
Lateralus's Avatar
 
elite*gold: 0
Join Date: May 2005
Posts: 1,892
Received Thanks: 918
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


 
CptSky's Avatar
 
elite*gold: 0
Join Date: Jan 2008
Posts: 1,434
Received Thanks: 1,146
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

 
Kiyono's Avatar
 
elite*gold: 20
Join Date: Jun 2006
Posts: 3,296
Received Thanks: 924
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
 
Lateralus's Avatar
 
elite*gold: 0
Join Date: May 2005
Posts: 1,892
Received Thanks: 918
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

 
Kiyono's Avatar
 
elite*gold: 20
Join Date: Jun 2006
Posts: 3,296
Received Thanks: 924
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


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
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


Similar Threads Similar Threads
[VB08]String in String mit mehreren Funden
08/08/2011 - .NET Languages - 6 Replies
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 _StringBetween Funktion von AutoIt gleich ist. _StringBetween gibt in einem Array alle Strings zwischen zwei SubStrings und dem ganzen String aus. Die Ausgabe bei _StringBetween("<h1>test1</h1>&l t;h1>test2</h1>", "<h1>", "</h1>") wäre also idealer Weiße ein Array (x = "test1", x = "test2")... da man in VB08 kein Array returnen kann, komme ich aber einfach...
Converting
06/21/2011 - CO2 Private Server - 1 Replies
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 (NCOS), is not sql. So basically I need help converting. Here is what I need converted (I'm not asking to be spoon fed, just any help will be appreciated). public static void DelPartner(uint UID, uint IDYou) { MySqlCommand Cmd = new MySqlCommand(MySqlCommandType.DELETE); Cmd.Delete("TradePartner",...
[C++] string zwischen string
11/11/2010 - C/C++ - 6 Replies
tag gibts direkt ne funktion, mit der man einen passenden string zwischen dem string suchen kann? also meine net .find() sondern sowas ähnliches, die in diesem beispiel "mein string sucht" Bsp: "<span id=\"lalala\">"+string mein_string+"</span>" understanden? :-)
Converting !
10/24/2009 - CO2 Private Server - 13 Replies
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,
[Question]Other.ItemType(uint item)
09/02/2008 - CO2 Private Server - 1 Replies
newbie coder (\scriptkiddie) here rewriting ShadowCO to learn C#.. I was wondering if someone could explain the following part to me: public static int ItemType(uint item) { string Item = Convert.ToString(item); string type = Item.Remove(1, Item.Length - 1); return int.Parse(type); }



All times are GMT +1. The time now is 22:43.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.