Jump to content

  • Log In with Google      Sign In   
  • Create Account

Finding specific data on server provided from client


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 savail   Members   -  Reputation: 333

Like
0Likes
Like

Posted 31 January 2013 - 08:58 AM

Hey,

I have a lobby server and I'm adding data about online users in a vector. So far, when it comes to activities in which I must set a state for only one particular user I've been iterating through my vector to find the specific user by the nick. I'm doing so everytime and I'm wondering if there's any better solution? I don't want to iterate through all my users each time I have to set something to only one of them. If a client could send his genuine index of his place in my server's vector that would be cool but once client sent a message with his index, other users could disconnect - server's vector would be shortened and therefore the index wouldn't be correct anymore. I can't think on how to implement such mechanism. It needs a lot of synchronisation but maybe there are better means?

I will be grateful for any suggestions!



Sponsor:

#2 Gava   Members   -  Reputation: 277

Like
1Likes
Like

Posted 31 January 2013 - 07:19 PM

You should take a look at a map container (or however a hashed table/tree is called in the coding language you are using, std::map is c++).

If you are using c++ take a look at this: http://www.cplusplus.com/reference/map/map/

When you search in a map It does something similar to looking in a vector but it scales better (it's faster when you have a lot of entries (a lot being a few usualy)).

You could use the nikname as a key or (faster search usually) generate a unique ID (uint) for every player and use that.

 

btw, i dont think this is a networking question but w/e.



#3 savail   Members   -  Reputation: 333

Like
0Likes
Like

Posted 02 February 2013 - 02:29 AM

How would I generate a unique ID then? I have few ideas but none of them seems 100% efficient. Can you give me some glimpse on that?



#4 rip-off   Moderators   -  Reputation: 8737

Like
1Likes
Like

Posted 02 February 2013 - 06:23 AM

First of all, you cannot trust any identifier found in a packet, because the client might be spoofing*. The good news is that each client already has a unique identifier! The IP address and port number uniquely identify that connection. You can use this combination as a key to lookup a map data structure, or because the number of clients is not large you could use a linear search of a client array, too.

 

* Exceptions include something like a username and password, because the password is a shared secret that malicious users should not be capable of spoofing.



#5 Mussi   Crossbones+   -  Reputation: 2100

Like
0Likes
Like

Posted 02 February 2013 - 06:40 AM

You can store a unique IPv4 address and port combination in a single 64 bit integer:
__int64 id = __int64(ip) << 16 | port;

Edited by Mussi, 02 February 2013 - 06:41 AM.


#6 savail   Members   -  Reputation: 333

Like
0Likes
Like

Posted 02 February 2013 - 11:26 AM

alright, thanks for answers






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS