?? client_connect.c
字號:
/* * Copyright (C) 1998,1999,2000,2001 Ross Combs (rocombs@cs.nmsu.edu) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include "common/setup_before.h"#include <stdio.h>#ifdef STDC_HEADERS# include <stdlib.h>#endif#ifdef HAVE_MEMORY_H# include <memory.h>#endif#include "compat/memset.h"#include "compat/memcpy.h"#include <ctype.h>#ifdef HAVE_STRING_H# include <string.h>#endif#include <errno.h>#include "compat/strerror.h"#ifdef TIME_WITH_SYS_TIME# include <sys/time.h># include <time.h>#else# ifdef HAVE_SYS_TIME_H# include <sys/time.h># else# include <time.h># endif#endif#ifdef HAVE_UNISTD_H# include <unistd.h>#endif#include "compat/gethostname.h"#ifdef HAVE_SYS_TYPES_H# include <sys/types.h>#endif#ifdef HAVE_SYS_SOCKET_H# include <sys/socket.h>#endif#include "compat/socket.h"#ifdef HAVE_SYS_PARAM_H# include <sys/param.h>#endif#ifdef HAVE_NETINET_IN_H# include <netinet/in.h>#endif#include "compat/netinet_in.h"#ifdef HAVE_ARPA_INET_H# include <arpa/inet.h>#endif#include "compat/inet_ntoa.h"#ifdef HAVE_NETDB_H# include <netdb.h>#endif#include "compat/psock.h"#include "common/packet.h"#include "common/init_protocol.h"#include "common/udp_protocol.h"#include "common/bnet_protocol.h"#include "common/file_protocol.h"#include "common/tag.h"#include "common/bn_type.h"#include "common/field_sizes.h"#include "common/bnethash.h"#include "common/bnethashconv.h"#include "common/util.h"#ifdef CLIENTDEBUG# include "common/eventlog.h"#endif#include "client.h"#include "udptest.h"#include "common/bnettime.h"#include "common/proginfo.h"#include "client_connect.h"#include "common/setup_after.h"#define COMPNAMELEN 128#ifdef CLIENTDEBUG# define dprintf printf#else# define dprintf if (0) printf#endifstatic int key_interpret(char const * cdkey, unsigned int * productid, unsigned int * keyvalue1, unsigned int * keyvalue2){ /* FIXME: implement... have example code from Eurijk! */ *productid = 0; *keyvalue1 = 0; *keyvalue2 = 0; return 0;}static int get_defversioninfo(char const * progname, char const * clienttag, unsigned int * versionid, unsigned int * gameversion, char const * * exeinfo, unsigned int * checksum){ if (strcmp(clienttag,CLIENTTAG_DIABLORTL)==0) { *versionid = CLIENT_VERSIONID_DRTL; *gameversion = CLIENT_GAMEVERSION_DRTL; *exeinfo = CLIENT_EXEINFO_DRTL; *checksum = CLIENT_CHECKSUM_DRTL; return 0; } if (strcmp(clienttag,CLIENTTAG_STARCRAFT)==0) { *versionid = CLIENT_VERSIONID_STAR; *gameversion = CLIENT_GAMEVERSION_STAR; *exeinfo = CLIENT_EXEINFO_STAR; *checksum = CLIENT_CHECKSUM_STAR; return 0; } if (strcmp(clienttag,CLIENTTAG_SHAREWARE)==0) { *versionid = CLIENT_VERSIONID_SSHR; *gameversion = CLIENT_GAMEVERSION_SSHR; *exeinfo = CLIENT_EXEINFO_SSHR; *checksum = CLIENT_CHECKSUM_SSHR; return 0; } if (strcmp(clienttag,CLIENTTAG_BROODWARS)==0) { *versionid = CLIENT_VERSIONID_SEXP; *gameversion = CLIENT_GAMEVERSION_SEXP; *exeinfo = CLIENT_EXEINFO_SEXP; *checksum = CLIENT_CHECKSUM_SEXP; return 0; } if (strcmp(clienttag,CLIENTTAG_WARCIIBNE)==0) { *versionid = CLIENT_VERSIONID_W2BN; *gameversion = CLIENT_GAMEVERSION_W2BN; *exeinfo = CLIENT_EXEINFO_W2BN; *checksum = CLIENT_CHECKSUM_W2BN; return 0; } if (strcmp(clienttag,CLIENTTAG_DIABLO2DV)==0) { *versionid = CLIENT_VERSIONID_D2DV; *gameversion = CLIENT_GAMEVERSION_D2DV; *exeinfo = CLIENT_EXEINFO_D2DV; *checksum = CLIENT_CHECKSUM_D2DV; return 0; } if (strcmp(clienttag,CLIENTTAG_DIABLO2XP)==0) { *versionid = CLIENT_VERSIONID_D2XP; *gameversion = CLIENT_GAMEVERSION_D2XP; *exeinfo = CLIENT_EXEINFO_D2XP; *checksum = CLIENT_CHECKSUM_D2XP; return 0; } if (strcmp(clienttag,CLIENTTAG_WARCRAFT3)==0 || strcmp(clienttag,CLIENTTAG_WAR3XP)==0) { *versionid = CLIENT_VERSIONID_WAR3; *gameversion = CLIENT_GAMEVERSION_WAR3; *exeinfo = CLIENT_EXEINFO_WAR3; *checksum = CLIENT_CHECKSUM_WAR3; return 0; } *versionid = 0; *gameversion = 0; *exeinfo = ""; *checksum = 0; fprintf(stderr,"%s: unsupported clienttag \"%s\"\n",progname,clienttag); // aaron: dunno what we should return in case of this.. but returning nothing was definetly wrong return -1;}extern int client_connect(char const * progname, char const * servname, unsigned short servport, char const * cdowner, char const * cdkey, char const * clienttag, struct sockaddr_in * saddr, unsigned int * sessionkey, unsigned int * sessionnum, char const * archtag, char const * gamelang){ struct hostent * host; char const * username; int sd; t_packet * packet; t_packet * rpacket; char compname[COMPNAMELEN]; int lsock; unsigned short lsock_port; unsigned int versionid; unsigned int gameversion; char const * exeinfo; unsigned int checksum; if (!progname) { fprintf(stderr,"got NULL progname\n"); return -1; } if (!saddr) { fprintf(stderr,"%s: got NULL saddr\n",progname); return -1; } if (!sessionkey) { fprintf(stderr,"%s: got NULL sessionkey\n",progname); return -1; } if (!sessionnum) { fprintf(stderr,"%s: got NULL sessionnum\n",progname); return -1; } if (psock_init()<0) { fprintf(stderr,"%s: could not inialialize socket functions\n",progname); return -1; } if (!(host = gethostbyname(servname))) { fprintf(stderr,"%s: unknown host \"%s\"\n",progname,servname); return -1; } if (host->h_addrtype!=PSOCK_AF_INET) fprintf(stderr,"%s: host \"%s\" is not in IPv4 address family\n",progname,servname); if (gethostname(compname,COMPNAMELEN)<0) { fprintf(stderr,"%s: could not get host name (gethostname: %s)\n",progname,pstrerror(errno)); return -1; }#ifdef HAVE_GETLOGIN if (!(username = getlogin()))#endif { username = "unknown"; dprintf("%s: could not get login name, using \"%s\" (getlogin: %s)\n",progname,username,pstrerror(errno)); }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -