2 "$Id: client.c 9215 2008-06-02 18:31:04Z anmaster $";
81 "armor",
"magic",
"fire",
"elec",
82 "cold",
"conf",
"acid",
"drain",
83 "ghit",
"pois",
"slow",
"para",
84 "t undead",
"fear",
"depl",
"death",
87 typedef void (*
CmdProc)(
unsigned char *,
int len);
147 #define NCOMMANDS ((int)(sizeof(commands)/sizeof(struct CmdMapping)))
159 closesocket(csocket->
fd);
170 while ((*data !=
' ') && (*data !=
'\0')) ++data;
185 if (i == NCOMMANDS) {
186 printf(
"Bad command from server (%s)\n",csocket->
inbuf.
buf+2);
192 #define socklen_t int
195 #include <sys/types.h>
196 #include <sys/socket.h>
197 #include <netinet/in.h>
198 #include <netinet/tcp.h>
200 #include <arpa/inet.h>
207 int fd = -1, oldbufsize, newbufsize=65535;
208 socklen_t buflen=
sizeof(int);
209 #if !HAVE_GETADDRINFO || WIN32
210 struct sockaddr_in insock;
211 struct protoent *protox;
220 if (!strcmp(host,
"(null)"))
return -1;
222 protox = getprotobyname(
"tcp");
223 if (protox == (
struct protoent *) NULL)
225 LOG (
LOG_ERROR,
"common::init_connection",
"Error getting protobyname (tcp)");
228 fd = socket(PF_INET, SOCK_STREAM, protox->p_proto);
230 perror(
"init_connection: Error on socket command.\n");
231 LOG (
LOG_ERROR,
"common::init_connection",
"Error on socket command");
234 insock.sin_family = AF_INET;
235 insock.sin_port = htons((
unsigned short)port);
237 insock.sin_addr.s_addr = inet_addr(host);
239 struct hostent *hostbn = gethostbyname(host);
240 if (hostbn == (
struct hostent *) NULL)
242 LOG (
LOG_ERROR,
"common::init_connection",
"Unknown host: %s",host);
245 memcpy(&insock.sin_addr, hostbn->h_addr, hostbn->h_length);
247 if (connect(fd,(
struct sockaddr *)&insock,
sizeof(insock)) == (-1))
249 LOG (
LOG_ERROR,
"common::init_connection",
"Can't connect to server");
250 perror(
"Can't connect to server");
254 struct addrinfo hints;
255 struct addrinfo *res = NULL, *ai;
259 if (!strcmp(host,
"(null)"))
return -1;
261 snprintf(port_str,
sizeof(port_str),
"%d", port);
263 memset(&hints, 0,
sizeof(hints));
264 hints.ai_family = AF_UNSPEC;
265 hints.ai_socktype = SOCK_STREAM;
266 hints.ai_protocol = IPPROTO_TCP;
268 if (getaddrinfo(host, port_str, &hints, &res) != 0)
271 for (ai = res; ai != NULL; ai = ai->ai_next) {
272 fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
276 if (connect(fd, ai->ai_addr, ai->ai_addrlen) != 0) {
291 csocket.
servername = malloc(
sizeof(
char)*(strlen(host)+1));
295 if (fcntl(fd, F_SETFL, O_NDELAY)==-1) {
296 LOG (
LOG_ERROR,
"common::init_connection",
"Error on fcntl.");
300 unsigned long tmp = 1;
301 if (ioctlsocket(fd, FIONBIO, &tmp)<0) {
302 LOG (
LOG_ERROR,
"common::init_connection",
"Error on ioctlsocket.");
313 if (setsockopt(fd,
SOL_TCP, TCP_NODELAY, (
const char* )&i,
sizeof(i)) == -1)
314 perror(
"TCP_NODELAY");
316 if (setsockopt(fd,
SOL_TCP, TCP_NODELAY, &i,
sizeof(i)) == -1)
317 perror(
"TCP_NODELAY");
322 if (getsockopt(fd,SOL_SOCKET,SO_RCVBUF, (
char*)&oldbufsize, &buflen)==-1)
325 if (oldbufsize<newbufsize) {
326 if(setsockopt(fd,SOL_SOCKET,SO_RCVBUF, (
char*)&newbufsize,
sizeof(&newbufsize))) {
327 LOG(
LOG_WARNING,
"InitConnection: setsockopt",
" unable to set output buf size to %d", newbufsize);
328 setsockopt(fd,SOL_SOCKET,SO_RCVBUF, (
char*)&oldbufsize,
sizeof(&oldbufsize));
354 if (csocket.
fd == -1)
return;
361 closesocket(csocket.
fd);
371 LOG (
LOG_WARNING,
"common::negotiate_connection",
"Server does not support PNG images, yet that is all this client");
372 LOG (
LOG_WARNING,
"common::negotiate_connection",
"supports. Either the server needs to be upgraded, or you need to");
373 LOG (
LOG_WARNING,
"common::negotiate_connection",
"downgrade your client.");
382 "setup map2cmd 1 tick 1 sound %d%s sexp %d darkness %d newmapcmd 1 spellmon 1 faceset %d facecache %d exp64 1 itemcmd 2",
413 int last_end=0, last_start=-99;
426 if (csocket.
fd == -1)
return;
456 cs_print_string(csocket.
fd,
"requestinfo image_sums %d %d", last_start, last_end);
474 snprintf(buf,
sizeof(buf),
"Download of images complete. Found %d locally, downloaded %d from server\n",
void negotiate_connection(int sound)
void(* cmdproc)(unsigned char *, int)
void DeleteItem(unsigned char *data, int len)
void handle_query(char *data, int len)
void SetupCmd(char *buf, int len)
void DrawInfoCmd(char *data, int len)
void Sound2Cmd(unsigned char *data, int len)
void AddMeFail(char *data, int len)
void ExtendedInfoSetCmd(char *data, int len)
Face_Information face_info
void DeleteSpell(unsigned char *data, int len)
void MagicMapCmd(unsigned char *data, int len)
sint16 want_config[CONFIG_NUMS]
const char *const resists_name[NUM_RESISTS]
void MusicCmd(const char *data, int len)
void DeleteInventory(unsigned char *data, int len)
void Image2Cmd(uint8 *data, int len)
char * skill_names[MAX_SKILL]
void Item2Cmd(unsigned char *data, int len)
void Face2Cmd(uint8 *data, int len)
int init_connection(char *host, int port)
void LOG(LogLevel level, const char *origin, const char *format,...)
void Map2Cmd(unsigned char *data, int len)
void SinkCmd(unsigned char *data, int len)
int SockList_ReadPacket(int fd, SockList *sl, int len)
void SmoothCmd(unsigned char *data, int len)
void TickCmd(uint8 *data, int len)
int cs_print_string(int fd, const char *str,...)
sint16 use_config[CONFIG_NUMS]
const char *const rcsid_common_client_c
void UpdateItemCmd(unsigned char *data, int len)
void PickupCmd(uint8 *data, int len)
void(* CmdProc)(unsigned char *, int len)
void StatsCmd(unsigned char *data, int len)
void NewmapCmd(unsigned char *data, int len)
int last_used_skills[MAX_SKILL+1]
void GoodbyeCmd(char *data, int len)
void SendAddMe(ClientSocket csock)
void VersionCmd(char *data, int len)
void script_watch(const char *cmd, const uint8 *data, const int data_len, const enum CmdFormat format)
void AddMeSuccess(char *data, int len)
void map_scrollCmd(char *data, int len)
void AnimCmd(unsigned char *data, int len)
void DrawExtInfoCmd(char *data, int len)
void UpdspellCmd(unsigned char *data, int len)
void PlayerCmd(unsigned char *data, int len)
void ReplyInfoCmd(uint8 *buf, int len)
void AddspellCmd(unsigned char *data, int len)
void draw_info(const char *str, int color)
void CompleteCmd(unsigned char *data, int len)
void DoClient(ClientSocket *csocket)
void SoundCmd(unsigned char *data, int len)
void SendVersion(ClientSocket csock)
void mapdata_set_size(int viewx, int viewy)
void image_update_download_status(int start, int end, int total)
void MapExtendedCmd(unsigned char *data, int len)
struct CmdMapping commands[]