Client services

Client services — Communicating with game servers

Synopsis


#include <nhproxy/nhproxy.h>


struct      nhproxy_clnt_ext_procs;
void        nhproxy_clnt_set_ext_procs      (void (*ini_routine) (void),
                                             struct nhproxy_clnt_ext_procs *windowprocs);
nhproxy_bool_t nhproxy_clnt_connect         (char *scheme,
                                             char *address,
                                             int *argcp,
                                             char **argv);
nhproxy_bool_t nhproxy_clnt_accept          (nhproxy_io_func read_f,
                                             nhproxy_genericptr_t read_h,
                                             nhproxy_io_func write_f,
                                             nhproxy_genericptr_t write_h);
nhproxy_bool_t nhproxy_clnt_tryaccept       (nhproxy_io_func read_f,
                                             nhproxy_genericptr_t read_h,
                                             nhproxy_io_func write_f,
                                             nhproxy_genericptr_t write_h);
void        nhproxy_clnt_main               (void);
int         nhproxy_clnt_main_iteration     (void);
void        nhproxy_clnt_main_quit          (void);
char*       nhproxy_clnt_gettag             (const char *tag);
nhproxy_bool_t nhproxy_clnt_settag          (const char *tag,
                                             const char *value);
#define     NHPROXY_CLNT_SYNCHRONOUS
void        nhproxy_clnt_set_flags          (unsigned long mask,
                                             unsigned long value);
nhproxy_bool_t nhproxy_clnt_log_open        (nhproxy_io_func func,
                                             nhproxy_genericptr_t handle);
char*       nhproxy_clnt_get_failed_packet  (int *nb);
char*       nhproxy_clnt_get_extension      (const char *name,
                                             const char *min_ver,
                                             const char *next_ver,
                                             unsigned short *idp);
nhproxy_bool_t (*nhproxy_clnt_authhandler)  (unsigned long mask);
nhproxy_clnt_authhandler nhproxy_clnt_set_authhandler
                                            (nhproxy_clnt_authhandler new);

Description

External interfaces need to connect to game servers which may be implemented either as an executable on the local machine or as a TCP/IP server on a remote machine. These routines allow external interfaces to connect to game servers and serve incoming requests as required by the NhExt standard.

Example 1. Minimal implementation of an external interface

extern struct nhproxy_ext_procs ext_procs[];

void
init(void)
{
}

int
main(int argc, char **argv)
{
    nhproxy_clnt_set_ext_procs(init, &ext_procs);
    if (!nhproxy_connect(scheme, address, &argc, &argv))
	nhproxy_main();
}

Details

struct nhproxy_clnt_ext_procs

struct nhproxy_clnt_ext_procs {
    const char *name;
    int (*winext_init_nhwindows)(int *argc, char **argv,
      char ***capv);
    int (*winext_player_selection)(int *role, int *race,
      int *gend, int *align);
    char *(*winext_askname)(void);
    void (*winext_get_nh_event)(void) ;
    void (*winext_exit_nhwindows)(const char *str);
    void (*winext_suspend_nhwindows)(const char *str);
    void (*winext_resume_nhwindows)(void);
    int (*winext_create_nhwindow)(int type);
    void (*winext_clear_nhwindow)(int window, int rows,
      int cols, int layers);
    void (*winext_display_nhwindow)(int window,
      nhproxy_bool_t blocking);
    void (*winext_destroy_nhwindow)(int window);
    void (*winext_curs)(int window, int x, int y);
    void (*winext_putstr)(int window, int attr,
      const char *str);
    void (*winext_display_file)(int fh);
    void (*winext_start_menu)(int window);
    void (*winext_add_menu)(int window, int glyph,
      int identifier, char accelerator, char groupacc,
      int attr, const char *str, nhproxy_bool_t preselected);
    void (*winext_end_menu)(int window, const char *prompt);
    int (*winext_select_menu)(int window, int how,
      struct nhproxy_mi **selected);
    int (*winext_message_menu)(int let, int how,
      const char *mesg);
    void (*winext_update_inventory)(void);
    void (*winext_mark_synch)(void);
    void (*winext_wait_synch)(void);
    void (*winext_cliparound)(int x, int y);
    void (*winext_update_positionbar)(char *posbar);
    void (*winext_print_glyph)(int window, int x, int y,
      int glyph);
    void (*winext_raw_print)(const char *str);
    void (*winext_raw_print_bold)(const char *str);
    int (*winext_nhgetch)(void);
    int (*winext_nh_poskey)(int *x, int *y, int *mod);
    void (*winext_nhbell)(void);
    int (*winext_doprev_message)(void);
    char (*winext_yn_function)(const char *ques,
      const char *choices, char def, int *count);
    char *(*winext_getlin)(const char *ques);
    int (*winext_get_ext_cmd)(void);
    void (*winext_number_pad)(int state);
    void (*winext_delay_output)(void);
    void (*winext_change_color)(int color, long rgb,
      int reverse);
    void (*winext_change_background)(int white_or_black);
    int (*winext_set_font_name)(int window, char *font);
    char *(*winext_get_color_string)(void);
    void (*winext_start_screen)(void);
    void (*winext_end_screen)(void);
    int (*winext_outrip)(int window, char *killed_by);
    void (*winext_preference_update)(const char *optnam,
      const char *value);
    void (*winext_status)(int reconfig, int nv,
      const char **values);
    void (*winext_print_glyph_layered)(int window, int nl,
      struct nhproxy_glyph_layer *layers);
    void (*winext_send_config_file)(int fh);
};


nhproxy_clnt_set_ext_procs ()

void        nhproxy_clnt_set_ext_procs      (void (*ini_routine) (void),
                                             struct nhproxy_clnt_ext_procs *windowprocs);

ini_routine :
windowprocs :

nhproxy_clnt_connect ()

nhproxy_bool_t nhproxy_clnt_connect         (char *scheme,
                                             char *address,
                                             int *argcp,
                                             char **argv);

scheme :
address :
argcp :
argv :
Returns :

nhproxy_clnt_accept ()

nhproxy_bool_t nhproxy_clnt_accept          (nhproxy_io_func read_f,
                                             nhproxy_genericptr_t read_h,
                                             nhproxy_io_func write_f,
                                             nhproxy_genericptr_t write_h);

read_f :
read_h :
write_f :
write_h :
Returns :

nhproxy_clnt_tryaccept ()

nhproxy_bool_t nhproxy_clnt_tryaccept       (nhproxy_io_func read_f,
                                             nhproxy_genericptr_t read_h,
                                             nhproxy_io_func write_f,
                                             nhproxy_genericptr_t write_h);

read_f :
read_h :
write_f :
write_h :
Returns :

nhproxy_clnt_main ()

void        nhproxy_clnt_main               (void);


nhproxy_clnt_main_iteration ()

int         nhproxy_clnt_main_iteration     (void);

Returns :

nhproxy_clnt_main_quit ()

void        nhproxy_clnt_main_quit          (void);


nhproxy_clnt_gettag ()

char*       nhproxy_clnt_gettag             (const char *tag);

tag :
Returns :

nhproxy_clnt_settag ()

nhproxy_bool_t nhproxy_clnt_settag          (const char *tag,
                                             const char *value);

tag :
value :
Returns :

NHPROXY_CLNT_SYNCHRONOUS

#define NHPROXY_CLNT_SYNCHRONOUS	1


nhproxy_clnt_set_flags ()

void        nhproxy_clnt_set_flags          (unsigned long mask,
                                             unsigned long value);

Param1 :
Param2 :

nhproxy_clnt_log_open ()

nhproxy_bool_t nhproxy_clnt_log_open        (nhproxy_io_func func,
                                             nhproxy_genericptr_t handle);

func :
handle :
Returns :

nhproxy_clnt_get_failed_packet ()

char*       nhproxy_clnt_get_failed_packet  (int *nb);

nb :
Returns :

nhproxy_clnt_get_extension ()

char*       nhproxy_clnt_get_extension      (const char *name,
                                             const char *min_ver,
                                             const char *next_ver,
                                             unsigned short *idp);

name :
min_ver :
next_ver :
idp :
Returns :

nhproxy_clnt_authhandler ()

nhproxy_bool_t (*nhproxy_clnt_authhandler)  (unsigned long mask);

Authentication handlers are passed a bitmask of methods supported by the game server. If they are able to provide authentication using one of these methods they should set the authmethod tag to the relevant value and set any other tags needed by that method (eg., username and password for method 1). Handlers should set the mesg tag to an appropriate error message and return non-zero if they are not able to provide authentication.

Example 2. 

int
clnt_authhandler(unsigned long methods)
{
    /*
     * Always use method 1 if available (simple password).
     * Otherwise, use method 0 (no authentication).
     * If neither method is allowed, then fail.
     */
    if (!(methods & (1UL << 1))) {
	if (methods & (1UL << 0)) {
	    nhproxy_clnt_settag("authmethod", "0");
	    return 0;
	}
	s = g_strdup_printf("Game server requires authentication,\n"
	  "but doesn't allow any of my supported methods.\n\n"
	  "Supported methods: 0,1\n"
	  "Allowed methods: s", nhproxy_clnt_gettag("authmethods"));
	clnt_errhandler(s);
	g_free(s);
	nhproxy_clnt_settag("mesg", "No supported authentication methods");
	return 1;
    }
    nhproxy_clnt_settag("authmethod", "1");
    nhproxy_clnt_settag("username", user);
    nhproxy_clnt_settag("password", passwd);
    return 0;
}
Param1 :A bitmask of authentication methods supported by the game server.
Returns :Non-zero on error.

nhproxy_clnt_set_authhandler ()

nhproxy_clnt_authhandler nhproxy_clnt_set_authhandler
                                            (nhproxy_clnt_authhandler new);

Installs an authentication handler to be called if the game server requires authentication (ie., includes the authmethods tag in the NhProxy sub-protocol 0 greeting).

new : The new authentication handler to install.
Returns : The previous authentication handler, or NULL.