Example #1
0
extern int
proto_client_init(Proto_Client_Handle *ch)
{
    Proto_Msg_Types mt;
    Proto_Client *c;

    c = (Proto_Client *)malloc(sizeof(Proto_Client));
    if (c == NULL) return -1;
    bzero(c, sizeof(Proto_Client));

    proto_client_set_session_lost_handler(c,
                                          proto_client_session_lost_default_hdlr);

    // initialize local game state
    pthread_mutex_lock(&client_data_mutex);
    playerdata.id = -1;
    gamedata.game_state = -1;
    gamedata.game_version = 0;
    pthread_mutex_unlock(&client_data_mutex);

    for (mt = PROTO_MT_EVENT_BASE_RESERVED_FIRST + 1;
            mt < PROTO_MT_EVENT_BASE_RESERVED_LAST; mt++)
        proto_client_set_event_handler(c, mt, proto_client_event_null_handler);

    proto_client_set_event_handler(c, PROTO_MT_EVENT_BASE_UPDATE, proto_client_event_update_handler);

    *ch = c;
    return 1;
}
Example #2
0
int 
startConnection(Client *C, char *host, PortType port, Proto_MT_Handler h)
{
  if (globals.host[0]!=0 && globals.port!=0) {
    if (proto_client_connect(C->ph, host, port)!=0) {
      fprintf(stderr, "failed to connect\n");
      return -1;
    }

    //change to game board
    char board[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8'};
    //(void *) board;
    proto_session_set_data(proto_client_event_session(C->ph), board
);

    //proto_session_set_data(proto_client_event_session(C->ph), C);
#if 0
    if (h != NULL) {
      proto_client_set_event_handler(C->ph, PROTO_MT_EVENT_BASE_UPDATE, 
				     h);
    }
#endif
    return 1;
  }
  return 0;
}
Example #3
0
int 
startConnection(Client *C, char *host, PortType port, Proto_MT_Handler h)
{
  if (globals.host[0]!=0 && globals.port!=0) {
    if (proto_client_connect(C->ph, host, port)!=0) {
      fprintf(stderr, "failed to connect\n");
      return -1;
    }
    proto_session_set_data(proto_client_event_session(C->ph), C);
#if 0
    if (h != NULL) {
      proto_client_set_event_handler(C->ph, PROTO_MT_EVENT_BASE_UPDATE, 
             h);
    }
#endif
    return 1;
  }
  return 0;
}
Example #4
0
extern int
proto_client_init(Proto_Client_Handle *ch)
{
  Proto_Msg_Types mt;
  Proto_Client *c;
 
  c = (Proto_Client *)malloc(sizeof(Proto_Client));
  if (c==NULL) return -1;
  bzero(c, sizeof(Proto_Client));

  proto_client_set_session_lost_handler(c, 
			      	proto_client_session_lost_default_hdlr);

  for (mt=PROTO_MT_EVENT_BASE_RESERVED_FIRST+1;
       mt<PROTO_MT_EVENT_BASE_RESERVED_LAST; mt++)
    proto_client_set_event_handler(c, mt, proto_client_event_null_handler);

  *ch = c;
  return 1;
}
Example #5
0
/*  client_init
    Initialize the client data structure
   
    parameter: C            pointer client data structure
    return:    int          1 or -1 for success or failure respectively
*/
int client_init(Client *C,Proto_MT_Handler update_handler)
{
  // Zero global scope
  bzero(C, sizeof(Client));

  // Set connected state to zero
  C->connected = 0; 

  //Set UI size
  C->width = 700;
  C->height = 700;
  
  // initialize the client protocol subsystem
  if (proto_client_init(&(C->ph))<0) {
    fprintf(stderr, "client: main: ERROR initializing proto system\n");
    return -1;
  }
 
  // Specify the event channel handlers
  proto_client_set_event_handler(C->ph, PROTO_MT_EVENT_UPDATE, update_handler );
  return 1;
}