Well, this post is all about how I am programming the networks, and hopefully, how I think I am being "smart". Hopefully it doesn't all backfire into my face.

First of all... the way that the server and the client will be "sending" messages will be very, very similar. Thus, if the messages what they send will be similar, so will the messages they receive. The BIG difference comes in how they respond once the message is received.

For instance. The Client will request "DrawCard","Library" (Because I want the commands to look similar I added Library... Library is actually "Implied" with "DrawCard".) Then the server will send a reply "DrawCard","Forest"... In this case the "implied" position (the hand) is not used. So the message sent was the same, but the server will respond differently than the client will...

So what I've done to help me code cleanly, and hopefully smartly, is I've used the Lazarus feature of "including" files. So my generic send code can be used (NetSend.inc) for both the server and the client... both have "command","parameter" sending, it's just that the client is saying "DrawCard","Library", whilst the server is saying "DrawCard","Forest"... but they both use the exact (letter for letter) same code.

Even the receiving (NetReceive.inc) code can be reused, up to the point where the *interpretation* of "DrawCard" needs to happen. That then is seperated into the server's code, and the Client's code.

It does mean though that I'll have some "dead" commands on both sides... like "RequestNewTable"... the Server won't be sending a table request back... It does something else. This is few and far between though, so hopefully not too many dead alleys in my code.

Looking forward to hopefully be able to do some connecting to tables, and talking away soon. (And after that... who knows? Drawing and playing cards!)

1 comments:

Hey there, I saw your program on slightlymagic.net and thought I'd come take a look.

I help work on a program called Incantus (also at slightlymagic.net), although the main programmer is Incantus (well, incantus1 to be specific, but he goes by Incantus... probably just to make conversations really confusing), but I still do a lot of work with the source code. The way Incantus' network code works is somewhat similar... it sends actions like "PlayLand" or "PassPriority", usually containing an "argument" (actually a parameter, but it's sort of the same in this case) which is the key of the card in question.

Since "Forest" could refer to any of the Forests in your deck (which could be hundreds, depending on the type of deck), the key is composed of a number (which is the order in which the card object was created) and the name (or, in the case of tokens, a special tag used to find an image for that token), so the game replay will read like "PlayAction ((52, "Nightmare")) 65213" (the number on the end is the ID of the action itself, and in this case, I just made something up at random) (I use the replay as the example because the network code goes even farther and sends a pickle of the action... I haven't had to do anything with the network code, so I don't know much more about how it works). Obviously, your post doesn't make it clear if you're actually using "Forest" or if you're just shortening whatever you actually send, but since you didn't specify, I just thought I'd let you know that a key system can be a great help.

Good luck with your project.

March 20, 2009 at 1:02 AM  

Newer Post Older Post Home

Blogger Template by Blogcrowds.