 |
Crossfire Client, Trunk
|
Go to the documentation of this file.
37 #ifdef HAVE_GIO_GNETWORKING_H
38 #include <gio/gnetworking.h>
71 static GInputStream *
in;
74 "armor",
"magic",
"fire",
"elec",
75 "cold",
"conf",
"acid",
"drain",
76 "ghit",
"pois",
"slow",
"para",
77 "t undead",
"fear",
"depl",
"death",
81 typedef void (*
CmdProc)(
unsigned char *,
int len);
167 #define NCOMMANDS ((int)(sizeof(commands)/sizeof(struct CmdMapping)))
176 LOG(
LOG_DEBUG,
"close_server_connection",
"Closing server connection");
177 g_io_stream_close(G_IO_STREAM(
csocket.
fd), NULL, NULL);
187 char *buf = (
char *)malloc(len+1);
189 memcpy(buf, data, len);
190 for (
int i = 0; i < len; i++) {
191 if (!isprint(buf[i])) {
193 }
else if (buf[i] ==
'\n' || buf[i] ==
'\r') {
218 if (inbuf.
len == 0) {
226 inbuf.
buf[inbuf.
len] =
'\0';
227 unsigned char* data = inbuf.
buf + 2;
233 while ((*data !=
' ') && (*data !=
'\0')) {
240 len = inbuf.
len - (data - inbuf.
buf);
250 const char *cmdin = (
char *)inbuf.
buf + 2;
253 if (data_print != NULL) {
254 LOG(
LOG_INFO,
"S->C",
"len=%d cmd=%s |%s|", len, cmdin, data_print);
276 LOG(
LOG_ERROR,
"client_run",
"Unrecognized command from server (%s)\n",
279 "The server sent an unrecognized command. "
280 "Crossfire Client will now disconnect."
281 "\n\nIf this problem persists with a particular "
282 "character, try playing another character, and without "
283 "disconnecting, playing the problematic character again.");
290 GSocketClient *sclient = g_socket_client_new();
299 csocket.
fd = g_socket_client_connect_to_host(
301 g_object_unref(sclient);
306 GSocket *socket = g_socket_connection_get_socket(
csocket.
fd);
307 int i = 1, fd = g_socket_get_fd(socket);
309 #ifdef HAVE_GIO_GNETWORKING_H
311 if (setsockopt(fd,
SOL_TCP, TCP_NODELAY, &i,
sizeof(i)) == -1) {
312 perror(
"TCP_NODELAY");
317 in = g_io_stream_get_input_stream(G_IO_STREAM(
csocket.
fd));
325 return g_pollable_input_stream_create_source(
326 G_POLLABLE_INPUT_STREAM(
in), NULL);
351 LOG (
LOG_ERROR,
"common::negotiate_connection",
"Connection timed out");
358 LOG (
LOG_WARNING,
"common::negotiate_connection",
"Server does not support PNG images, yet that is all this client");
359 LOG (
LOG_WARNING,
"common::negotiate_connection",
"supports. Either the server needs to be upgraded, or you need to");
360 LOG (
LOG_WARNING,
"common::negotiate_connection",
"downgrade your client.");
379 "map2cmd 1 tick %d sound2 %d darkness %d spellmon 1 spellmon 2 "
380 "faceset %d facecache %d want_pickup 1 loginmethod %d newmapcmd 1 extendedTextInfos 1",
410 int last_end=0, last_start=-99;
475 snprintf(buf,
sizeof(buf),
"Download of images complete. Found %d locally, downloaded %d from server\n",
void DeleteSpell(unsigned char *data, int len)
bool SockList_ReadPacket(GSocketConnection c[static 1], SockList sl[static 1], size_t len, GError **error)
Reads from the socket and puts data into a socklist.
@ LOG_INFO
Minor, non-harmful issues.
#define MSG_TYPE_CLIENT
Client originated Messages.
void script_watch(const char *cmd, const guint8 *data_initial, const int data_len, const enum CmdFormat format)
#define NUM_RESISTS
Translation of the STAT_RES names into printable names, in matching order.
void TickCmd(guint8 *data, int len)
Got a tick from the server.
@ LOG_WARNING
Warning that something might not work.
#define CONFIG_PORT
Is this useful any more?
Holds the names that correspond to skill and resistance numbers.
#define CONFIG_SERVER_TICKS
void(* CmdProc)(unsigned char *, int len)
void client_disconnect()
Closes the connection to the server.
void GoodbyeCmd(char *data, int len)
struct CmdMapping commands[]
The list of server commands that this client supports along with pointers to the function that handle...
void DeleteItem(unsigned char *data, int len)
void handle_query(char *data, int len)
Prompts the user for input.
NameMapping resist_mapping[NUM_RESISTS]
Face_Information face_info
void DrawExtInfoCmd(char *data, int len)
We must extract color, type, subtype and dispatch to callback.
#define MAXSOCKBUF
Maximum size of a packet the client expects to get and that the server can send.
void ReplyInfoCmd(unsigned char *buf, int len)
Handles the response from a 'requestinfo' command.
bool client_is_connected()
Links server commands to client functions that implement them, and gives a rough indication of the ty...
void AddMeFail(char *data, int len)
Handles when the server says we can't be added.
const char *const resists_name[NUM_RESISTS]
void PlayerCmd(unsigned char *data, int len)
Gets the player information.
int sc_version
Server versions of these.
void SmoothCmd(unsigned char *data, int len)
Receives the smooth mapping from the server.
void client_connect(const char hostname[static 1])
void MapExtendedCmd(unsigned char *data, int len)
Handle MapExtended command Warning! if you add commands to extended, take care that the 'layer' argum...
char VERSION_INFO[MAX_BUF]
NameMapping skill_mapping[MAX_SKILL]
void SinkCmd(unsigned char *data, int len)
void NewmapCmd(unsigned char *data, int len)
int last_used_skills[MAX_SKILL+1]
maps position to skill id with trailing zero as stop mark.
void FailureCmd(char *buf, int len)
Handles a failure return from the server.
GSource * client_get_source()
Return a source triggered when input from the server is available.
#define NCOMMANDS
The number of entries in commands.
void SendAddMe(ClientSocket csock)
void MusicCmd(const char *data, int len)
Parse the data contained by a music command coming from the server and pass the name along to cfsndse...
void image_update_download_status(int start, int end, int total)
Draws a status bar showing where we our in terms of downloading all the image data.
void Map2Cmd(unsigned char *data, int len)
void PickupCmd(guint8 *data, int len)
Server gives us current player's pickup.
void client_run()
Read available packets from the server and handle commands until there are no more,...
void(* cmdproc)(unsigned char *, int)
#define MAX_SKILL
How many skill types server supports/client will get sent to it.
void map_scrollCmd(char *data, int len)
Scrolls the map on the client by some amount.
void LOG(LogLevel level, const char *origin, const char *format,...)
Log messages of a certain importance to stderr.
GQuark client_error_quark()
int cs_print_string(GSocketConnection *fd, const char *str,...)
Send a printf-formatted packet to the socket.
void DrawInfoCmd(char *data, int len)
Draws a string in the info window.
gint16 want_config[CONFIG_NUMS]
void draw_ext_info(int orig_color, int type, int subtype, const char *message)
A message processor that accepts messages along with meta information color and type.
void Face2Cmd(guint8 *data, int len)
We only get here if the server believes we are caching images.
void StatsCmd(unsigned char *data, int len)
Updates the local copy of the stats and displays it.
void SendVersion(ClientSocket csock)
void UpdspellCmd(unsigned char *data, int len)
Basic support for socket communications, including the file descriptor, input buffer,...
char * printable(void *data, int len)
Replace the non-printable characters in 'data' with a dot ('.
@ LOG_ERROR
Warning that something definitely didn't work.
void Image2Cmd(guint8 *data, int len)
Client_Player cpl
Player object.
#define MSG_TYPE_CLIENT_CONFIG
Local configuration issues.
void Item2Cmd(unsigned char *data, int len)
Parses the data sent to us from the server.
void AddMeSuccess(char *data, int len)
This is really a throwaway command - there really isn't any reason to send addme_success commands.
void MagicMapCmd(unsigned char *data, int len)
void error_dialog(char *error, char *message)
Display an error message dialog.
void AddspellCmd(unsigned char *data, int len)
void AnimCmd(unsigned char *data, int len)
gint16 use_config[CONFIG_NUMS]
void AccountPlayersCmd(char *buf, int len)
This handles the accountplayers command.
void DeleteInventory(unsigned char *data, int len)
void Sound2Cmd(unsigned char *data, int len)
Parse the data contained by a sound2 command coming from the server and handle playing the specified ...
unsigned char buf[MAXSOCKBUF]
void SetupCmd(char *buf, int len)
Received a response to a setup from the server.
char * skill_names[MAX_SKILL]
Contains the base information we use to make up a packet we want to send.
@ LOG_DEBUG
Useful debugging information.
void VersionCmd(char *data, int len)
void client_mapsize(int width, int height)
Ask the server for the given map size.
void UpdateItemCmd(unsigned char *data, int len)
Updates some attributes of an item.
void CompleteCmd(unsigned char *data, int len)
void client_negotiate(int sound)
This function negotiates the characteriistics of a connection to the server.