More Chaos!


Welcome to the fake int13h Finger Service

Name: Nightmare
Description: Chaos Eng Net Alpha X Hyper Fighters World Edition
Project: Chaos-Eng
Last Updated: 18/06/2008 16:42:45 (GMT)

Quick update..

Yet more Chaos-eng \o/

Yeah, yeah, shut up talking about it and get it done FGS! On with the line count:

Sprout# wc -l Makefile *.c *.h data/*.dat | grep total
18400 total

Christ on a pogo-stick wearing a frilly pink tutu. I thought this programming malarkey was supposed to be fairly swift? Seems like a never ending slog, just as you get through doing something seemingly big, you realise that its really just a small bit of the big picture.

So, basically the main core was finished, or so I thought, 1.0-Final kinda happened but after play testing it even just a little there were some nasties still showing up. Its just a bit awkward to get a lot of people huddled around 1 keyboard to play and even running in a multi-session 'Screen' session isn't quite what it needs to be mass play tested so fuck it, onto the networking version.

Which really isn't all that scary so far, lots to learn and its got that cool 'something new' feel to it which is nice on a project that has been going on and off for years now. As much as we like to take the piss out of ourselves for never finishing any projects, half the time it is just the simple programmer issue of getting sick of crunching away on the same bit of code for months.

It really is more fun spending a few hours/days working on something new cool and interesting, fighting a small simple problem rather than the monotonous task of cleaning up all the loose ends and fixing smaller unpredicted problems. I suppose thats why there are so many projects on Sourceforge =P

That being said there is a lot of enjoyment getting so far into a project and seeing a lot of design decisions from the very first draft paying off and working how you planned all that time ago. Things like modular input/display/sound systems, as simple as creating input_<newsystem>.c/display_<newsystem>.c/sound_<newsystem>.c and calling them from a common_*.c loop is really nice.

The downfall of that of course is maintaining them all when you add new features. For example I am adding some screens for joining/hosting/chatting/etc in a network game and of course I need to do both a X11 and Ncurses version of all of it. So far its pretty much all been developed in ncurses and I'll bung the x11 stuff in after its all working decently in ncurses.

Ncurses makes it easier for connecting lots of clients from remote machines as I can just SSH to various boxes on the int13h-network and fire up code... That and ncurses is nicer to position text in.

Here's a snifter at some of the new network gubbins...

Waiting for Players Screen.

Let the banter fly.

History log of whats going on.

The History log has some good stuff in it, basically it can log events during the game like if a spell failed or if a monster or player died and so on, not just a log of network events.

The networking side of things has been a real eye opener, luckily it seems to be holding up quite well and after a lot of work on the foundation of it (net_send() , net_check_server() etc) it seems to just be a case of constructing some strings and firing them at connected sockets.

Not to say there weren't any pitfalls, as there have been many, a lot of things that aren't obvious can catch you off guard in the beginning. You'd (well I) think that if you fire some data at the send() function in C, it would send the data to that socket. Well that's not quite the case.. it'll send as much as it can. What that 'much' is, is anyones guess. So basically you have to keep track of what is sent and keep going until its all gone.

while(left > 0){
if((ret = send(socket, data_sent, left, 0)) == -1){
console_log(__FILE__,__func__,__LINE__,LOG_WARNING, sprintf(log_message,
"Net - Send Error : %d (Left to Send: %d)",ret,left));

console_log(__FILE__,__func__,__LINE__,LOG_NOTICE, sprintf(log_message,
"Net - Sent %d of %d",ret,left));

left -= ret;
data_sent += ret;

Problem solved eh? Are you assuming the client will receive it all in one tidy chunk? <Matrix>WRONG!</Matrix>. When the client checks for data it might have several chucks of data to deal with. Even then if the server sends two separate requests (say a list of players and the current chat log) to the client, if the client hasn't recv()'d the first bit of data before the next one comes through, it will have both bits of data in the same buffer... DOH!

So you need to devise a string that will be digested as individual requests. For example, here we have a cut down chat log packet :

5|69|0~16:04:01~Welcome to Chaos!,1~16:04:34~Sprout has joined the server!|CRCLOLZ;

The 'request' can be cut up into fields using the '|'. This gives us 4 fields. The first is out request type, which out net.h header lists as :


/* Info */

/* Commands */

The next field will be a simple length calculation for the next field, our data field. Because the 3rd field can contain anything in a string format its a good idea to know how long it is. The last field is the CRC field, which as you can see isn't quite implemented yet. This CRC hash will be made up of various calculations to help validate the data, not so much from a 'omgzhax' perspective but from a way to ensure the data arrived right and is acceptible by the server receiving it. Adding something as simple as the SERVER_VERSION to the CRC can stop incompatible servers and clients talking.

There is still arse loads to be done, but at the moment I've got clients connecting to the server and retrieving a playerlist, a world list (current mode, whos turn it is etc) and both the history and chat logs. The clients and server can use the chat screen and natter and there is some basic connection handling stuff for connecting to servers that don't reply really quickly (like on a wan/vpn) and stuff to stop the client 'shitting bricks' when the server buggers off or sends them bogus data.

No doubt more to come in a few months =P



[_] Do the next round for WWW. (Actually in draft!)
[_] More Guides!
[_] More FSL!
[X] Anything Productive \o/

[X] Finish Chaos-Eng 1.0-RELEASE
[X] Start Chaos-Eng-Net Alpha
[_] Tank game thing!
[_] Project 10.5
[_] Project 21
[_] Project 42


Heavy Engine Console
Loading Page... /1059-More-Chaos