[CF-Devel] Protocol Questions (Server to Client)

pstolarc at theperlguru.com pstolarc at theperlguru.com
Sat Aug 31 17:04:53 CDT 2002


On Fri, 30 Aug 2002, Mark Wedel wrote:

>
     
     Bjoern Becker wrote:
     
     >>
     
      I'm currently working on the S2C Protocol of the Win-Client I'm coding.
     
     ...
>
     
       Unless there is good reason not to do so (eg, you want to keep your client 
     
     >
     
     closed source), I would strongly suggest you look at the common directory in the 
     
     >
     
     'unix' client.  That directory, which generates a library that handles most all 
     
     >
     
     the packet communication, but makes calls to the graphical/more machine specific 
     
     >
     
     areas.  The common area should hopefully be pretty cross platform.
     
     ...

Please excuse the long reply, and the large amount of code.

I'm currently working on porting the client common files over to win32.
These are the changes I've made so far.  In all instances, the original
code is in the else half of the #ifdef/#else/#endif.  Oh, and it's
necessary to define #CF_WIN32 in config.h when compiling under win32.

I'm not done going through everything, but with these changes, there seem
to be only a few niggling incompatibilities left.  It doesn't build yet,
but almost.  And I know, the sprintf with only constants isn't really
necessary, but it seems more readable to me.

I'm wondering, would it be better to have these inline with #ifdef
wrappers, or as seperate files, ie. "metaserver-w32.c", and forget the
#ifdefs?  Also, do any of the changes I made to get it to work relate to
any other OSes, that we will eventually target?  

-Philip

----------------------------------------------------------------
In client.c, wrapped these #includes up a bit.

#ifdef CF_WIN32
/* Windows specific include files for networking */
#include <WINSOCK2.H>

#else
/* Unix specific include files for networking */
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <ctype.h>
#include <arpa/inet.h>
#define CF_SOCKET_ERROR (-1)
#endif


----------------------------------------------------------------
Then later on in the same file

#ifdef CF_WIN32
/* Windows specific code */
	{
		long c_ONDELAY=1;
		if (ioctlsocket(fd, FIONBIO, &c_ONDELAY)==-1) {
		fprintf(stderr,"InitConnection:  Error on fcntl.\n");
		}
	}
#ifdef TCP_NODELAY
    /* turn off nagle algorithm */
    if (use_config[CONFIG_FASTTCP]) {
	char i=1;

	if (setsockopt(fd, SOL_TCP, TCP_NODELAY, &i, sizeof(i)) == -1)
	    perror("TCP_NODELAY");
    }
#endif

#else
/* Unix specific code */
	if (fcntl(fd, F_SETFL, O_NDELAY)==-1) {
	fprintf(stderr,"InitConnection:  Error on fcntl.\n");
    }

#ifdef TCP_NODELAY
    /* turn off nagle algorithm */
    if (use_config[CONFIG_FASTTCP]) {
	int i=1;

	if (setsockopt(fd, SOL_TCP, TCP_NODELAY, &i, sizeof(i)) == -1)
	    perror("TCP_NODELAY");
    }
#endif
#endif

----------------------------------------------------------------
In Image.c, wrapped these includes up, and define some things

#ifdef CF_WIN32
/* Windows specific include files */
#include <io.h>
#include <direct.h>
/* Windows specific defines */
#define W_OK 02
#define R_OK 04
#define X_OK 00 /* Not supported */
#define F_OK 00

#else
/* Unix specific include files */
#include <unistd.h>
#endif

----------------------------------------------------------------
In the same file, wrapped this up

#ifdef CF_WIN32
    sprintf(bmaps,"%s/bmaps.client",".");
#else
    sprintf(bmaps,"%s/bmaps.client",DATADIR);
#endif
----------------------------------------------------------------
And this

#ifdef CF_WIN32
		sprintf(filename,"%s/%s",
		    ".", ce->filename);
#else
	    sprintf(filename,"%s/%s",
		    DATADIR, ce->filename);
#endif
----------------------------------------------------------------
And (in the same file), changed this code twice. 

#ifdef CF_WIN32
		mkdir(filename);
#else
		mkdir(filename, 0755);
#endif

----------------------------------------------------------------
And lastly, in metaserver.c, I had to move this code to after the #include
<external.h>, and then wrap it.

#ifdef CF_WIN32
/* Windows specific include files for networking */
#include <WINSOCK2.H>
#define CF_SOCKET_ERROR INVALID_SOCKET
#else
/* Unix specific include files for networking */
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <ctype.h>
#include <arpa/inet.h>
#define CF_SOCKET_ERROR (-1)
#endif

----------------------------------------------------------------
And I had to wrap

#if CF_WIN32
static int meta_sort(const Meta_Info *m1, const Meta_Info *m2) { return
strcasecmp(m1->hostname, m2->hostname); }
#else
static int meta_sort(Meta_Info *m1, Meta_Info *m2) { return
strcasecmp(m1->hostname, m2->hostname); 
#endif

----------------------------------------------------------------
And finally, wrapped this.

#ifdef CF_WIN32
    qsort(meta_servers, meta_numservers, sizeof(Meta_Info), meta_sort);
#else
    qsort(meta_servers, meta_numservers, sizeof(Meta_Info), (int
(*)())meta_sort);
#endif


    
    


More information about the crossfire mailing list