On Wed, Sep 19, 2012 at 12:23:24PM -0500, Bob Tanner wrote:
> Long story short, I want to improve my Cocoa and objective-c skill
> set. I've combined 2 of my favorite FOSS projects together. 1
> (obviously) is netrek and the other is Adium (http://adium.im/).
> 
> What I want to get out of this coding adventure is an Adium plugin
> that can connect to a netrek server and act as an observer.

I hope you'll take it further so that people can play.

> 
> I got the view (gui) stuff and socket stuff done (gratitious
> concepts takes from pygame and MacTrek).
> 
> What I'm failing to get to work properly is the "game packet" processing.
> 
> Looking at packet.h there's a general protocol state outline.
> 
> Starting states
>        CP_SOCKET
>        CP_FEATURE, optional, to indicate feature packets are known
>        SP_MOTD
>        SP_FEATURE, only if CP_FEATURE was seen
>        SP_QUEUE, optional, repeats until slot is available
>        SP_YOU, indicates slot number assigned
> 
> Login states
>        CP_LOGIN
>        CP_FEATURE
>        SP_LOGIN
>        SP_YOU
>        SP_PLAYER_INFO
> 
> My netrek-game-protocol-fu is rusty (working in objective-c isn't
> helping me).  I assume "short-cut" some states if all I want to do
> is connect as observer?

No, not really.  Observer mode was tacked on.  It is the same protocol
with very few differences.

> 
> My packet trace looks nothing like a real client so I'm looking for
> help on what I'm doing wrong (pseudocode):
> 
> connect to server port 2593
> send CP_SOCKET
> assume I don't need to send CP_FEATURE?
> read SP_MOTD
> 
> Assuming the above is correct, the problem  is I get a 1340 byte
> payload and the first byte is not 0x0b (11, aka SP_MOTD) so either
> my state stuff is wrong OR my socket code is wrong.

That seems likely.  What is the payload?
 
> I see a spiffy tool called lurk.py (James?) in the cow code base.
> Sadly it doesn't work on Mountain Lion/Python 2.7.2 (haven't really
> looked at it yet). If I read the code right is this effectively a
> netrek-game protocol sniffer?

It is a scriptable observer client without a graphics head.  It was
cut down from an earlier version of Gytha.  It can be used as the
basis for a protocol sniffer, but by far the best sniffer we have at
the moment is Gytha.

(I'm preparing for the usual holiday camp a week and a half away where
we will play organised Netrek games for a couple of hours).

-- 
James Cameron
http://quozl.linux.org.au/