Beispiel #1
0
//This function is used for RPC's that do not contain anything in the body
//Parameter: Proto_Msg_Hdr *h - that contains all necessary information for the RPC
//           Proto_Client_Handle ch - Handle to the Proto_Client 
//           Pos current - current position of the player
//           Pos next - next position that the players wants to move to
//Returns:   Return Code - as specified in Game_Error_Types in types.h
extern int 
do_action_request_rpc(Proto_Client_Handle ch, Proto_Msg_Hdr * hdr,Pos current, Pos next)
{
  int rc;
  Proto_Session *s;
  Proto_Client *c = ch;
  
  s = &(c->rpc_session);
  proto_session_hdr_marshall(s,hdr);
  if( hdr->gstate.v1.raw >= ACTION_MOVE && 
      hdr->gstate.v1.raw <= ACTION_PICKUP_SHOVEL)
  {
      proto_session_body_marshall_bytes(s,sizeof(Pos),(char*)&current);
      proto_session_body_marshall_bytes(s,sizeof(Pos),(char*)&next);
  }
  
  rc = proto_session_send_msg(s,1);
  rc = proto_session_rcv_msg(s);
  
  if(rc<=0) rc =-1;
  return rc;
}
Beispiel #2
0
static int
proto_server_mt_join_game_handler(Proto_Session *s)
{
    int rc, player, dimy, dimx;
    Proto_Msg_Hdr h;

    player = 1;
    char dummy_maze[] = {'1','2','3','4','5','6','7','8','9'};

    if (proto_debug())
       fprintf(stderr, "proto_server_mt_join_game_handler: invoked for session:\n");
    //proto_session_dump(s);

    // prepare reply message
    bzero(&h, sizeof(s));
    h.type = proto_session_hdr_unmarshall_type(s);
    h.type += PROTO_MT_REP_BASE_RESERVED_FIRST;
    // send to client the current state and version
    h.sver.raw = server_gameData.version; 
    h.gstate.v0.raw = server_gameData.state; 
    proto_session_hdr_marshall(s, &h);

    // TODO: call game logic 
    dimx = 3;//dimx = get_maze_dimx();
    dimy = 3;//dimy = get_maze_dimy();

    // TODO: update game version and state if necesary
    // pthread_mutex_lock(&server_data_mutex);
    // pthread_mutex_unlock(&server_data_mutex);

    // relpy: pID, xdim, ydim, maze
    if (proto_session_body_marshall_int(s, player) < 0)
        fprintf(stderr, "proto_server_mt_join_game_handler: "
                "proto_session_body_marshall_int failed\n");
    if (proto_session_body_marshall_int(s, dimx) < 0 )
        fprintf(stderr, "proto_server_mt_join_game_handler: "
                "proto_session_body_marshall_int failed\n");
    if (proto_session_body_marshall_int(s, dimy) < 0 )
        fprintf(stderr, "proto_server_mt_join_game_handler: "
                "proto_session_body_marshall_int failed\n");
    if (proto_session_body_marshall_bytes(s, dimx*dimy, &dummy_maze[0]) < 0)
        fprintf(stderr, "proto_server_mt_join_game_handler: "
                "proto_session_body_marshall_bytes failed\n");

    rc = proto_session_send_msg(s,1);
    // TODO: update subscribers
    doUpdateClientsGame(0);
    return rc;
}