GPWiki.org
GPWiki.org
It is currently Mon May 20, 2013 8:29 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Dec 06, 2011 3:33 am 
Grand Optimizer
User avatar

Joined: Mon Jan 17, 2005 6:01 pm
Posts: 352
Location: Canada
I'm writing the server for my game, but have run into a problem. The clients connect correctly, however in Lidgren's examples he interfaces with each connection *directly* through a connections property in the server class. The example gets away with this because all he's doing is moving a sprite around the screen. Unfortunately this isn't suitable for my setup as the complexity of my game demands that I interface with the class instance behind the sprite, and not with the socket connection directly. I read something about a 'command structure' setup where every time a new player connects, a new instance of a 'player' class is created, and the actual socket connection resides within that class. The result is that interfacing with each connection is simple, clean and efficient.

Now that's all well and good in theory, but I've been racking my brain now for a couple days trying to figure out just *how* to do it. I have the server spawning a new player class every time a connection happens, but I'm quite stuck on the logic of how to bind that particular instance to the connection that just arrived, because the list of connections seems to be buried in server.Connections. The documentation hasn't proven terribly helpfull either.

I'm not sure if I've explained it clearly, but basically I'm not sure how to differentiate between connections in server.Connections so that I can bind, say, player[2] to it's corresponding connection in server.Connections. This way, I can say things like, "players[4].SendMessage(whatever);" etc rather than having to do it all messy like.

Anyone familiar with this sort of thing?

Thanks!

_________________
"None are more hopelessly enslaved than those who falsely believe they are free."
"It is no measure of health to be well adjusted to a profoundly sick society."
"Hope is the first step on the road to dissapointment." -Jonah Orion
http://tankzgame.blogspot.com


Top
 Profile  
 
PostPosted: Tue Dec 06, 2011 12:25 pm 
King Code Monkey
User avatar

Joined: Wed Sep 01, 2004 3:05 pm
Posts: 11182
Location: Abingdon, MD
Why not just have the client send an ID bit with each packet so you can tell who it it? The server assigns the ID when the client connects to it and send it to the client. Keep a Dictionary<int, Player> list on the server.

_________________
Bored? Head on over to my blog and see what I'm up to.

Microsoft XNA MVP


Top
 Profile  
 
PostPosted: Tue Dec 06, 2011 10:27 pm 
Grand Optimizer
User avatar

Joined: Mon Jan 17, 2005 6:01 pm
Posts: 352
Location: Canada
Yes! That's a good idea, the server keeps track of the "UniqueIdentifier" when a player connects, I could tie that into a dictionary object and setup my cross-reference that way! Thank you! I think that may just work!

EDIT: Actually that wont work as I still need to associate the actual Connection in the server.Connections list with the player number.. But if i was to make a dictionary of say, <int, Connection>... i wonder if that would work!

EDIT2: I think the original idea will work out after all, just going to take a boat load of encapsulation/cross-referencing code. I think thats how il do it.

_________________
"None are more hopelessly enslaved than those who falsely believe they are free."
"It is no measure of health to be well adjusted to a profoundly sick society."
"Hope is the first step on the road to dissapointment." -Jonah Orion
http://tankzgame.blogspot.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group