static int proto_server_mt_cinfo_handler(Proto_Session *s) { int in_x, in_y, rc; char cell, team, occupied; Proto_Msg_Hdr h; if (proto_debug()) { fprintf(stderr, "proto_server_mt_cinfo_handler: invoked for session:\n"); //proto_session_dump(s); } // read msg here proto_session_body_unmarshall_int(s, 0, &in_x); proto_session_body_unmarshall_int(s, sizeof(int), &in_y); if (proto_debug()) fprintf(stderr, "proto_server_mt_numjail_handler: requested cellinfo( %d, %d )\n", in_x, in_y); //cell = '#';//cell = (char)0xCC; // call mze.c numjail(teamNo) func //team = '1';//team = (char)0xDD; //occupied = 'Y';//occupied = (char)0xEE; cell = get_cell_type( in_x, in_y ); team = get_cell_team( in_x, in_y ); occupied = is_cell_occupied( in_x, in_y ); //findCInfo(in_x, in_y); if (proto_debug()) fprintf(stderr, "proto_server_mt_numjail_handler: maze.c::func returned\n" " cell='%c', team='%c', occupied='%c'\n", cell, team, occupied); // create replay message bzero(&h, sizeof(h)); h.type = proto_session_hdr_unmarshall_type(s); h.type += PROTO_MT_REP_BASE_RESERVED_FIRST; proto_session_hdr_marshall(s, &h); if (proto_session_body_marshall_char(s, cell) < 0 ) fprintf(stderr, "proto_server_mt_cinfo_handler: " "proto_session_body_marshall_bytes failed\n"); if (proto_session_body_marshall_char(s, team) < 0 ) fprintf(stderr, "proto_server_mt_cinfo_handler: " "proto_session_body_marshall_bytes failed\n"); if (proto_session_body_marshall_char(s, occupied) < 0 ) fprintf(stderr, "proto_server_mt_cinfo_handler: " "proto_session_body_marshall_bytes failed\n"); rc = proto_session_send_msg(s, 1); // TODO: return failed if an error occours return rc; }
static int do_item_action_rpc(Proto_Client_Handle ch, Proto_Msg_Types mt, char item, char action) { int rc; Proto_Session *s; Proto_Client *c = ch; Proto_Msg_Hdr h; // prepare message s = &(c->rpc_session); bzero(&h, sizeof(h)); h.type = mt; proto_session_hdr_marshall(s, &h); if (proto_debug()) fprintf(stderr, "do_item_action: pId: %d, item: #%c#, action = #%c#\n", playerdata.id, item, action); if (proto_session_body_marshall_int(s, playerdata.id) < 0) fprintf(stderr, "do_item_action_rpc: proto_session_body_marshall_int failed. " "Not enough available sbufer space\n"); if (proto_session_body_marshall_char(s, item) < 0) fprintf(stderr, "do_item_action: proto_session_body_marshall_char failed. " "Not enough available sbufer space\n"); if (proto_session_body_marshall_char(s, action) < 0) fprintf(stderr, "do_item_action: proto_session_body_marshall_char failed. " "Not enough available sbufer space\n"); rc = proto_session_rpc(s); // process response if (rc == 1) { proto_session_hdr_unmarshall(s, &h); wait_for_event(h.sver.raw); if (proto_session_body_unmarshall_int(s, 0, &rc) < 0) fprintf(stderr, "do_item_action: proto_session_body_unmarshall_int failed\n"); if (proto_debug()) fprintf(stderr, "do_item_action: unmarshalled response rc = %d, game version = %llu, game state = %d \n", rc, h.sver.raw, h.gstate.v0.raw); } else { c->session_lost_handler(s); close(s->fd); } return rc; }
extern void proto_session_hdr_marshall_mapBody(Proto_Session *s, char *map){ int i; for (i=0; i<strlen(map); i++) { char currentChar = map[i]; proto_session_body_marshall_char(s, currentChar); } }
extern int maze_marshall_cell(Proto_Session *s, Cell *cell) { int rc = proto_session_body_marshall_int(s, cell->x); if (rc != 1) return rc; rc = proto_session_body_marshall_int(s, cell->y); if (rc != 1) return rc; rc = proto_session_body_marshall_char(s, cell->type); if (rc != 1) return rc; rc = proto_session_body_marshall_int(s, cell->team); return rc; }
static int do_move_rpc(Proto_Client_Handle ch, Proto_Msg_Types mt, char data) { int rc, temp_version; Proto_Session *s; Proto_Client *c = ch; Proto_Msg_Hdr h; // prepare message: pID, move_command s = &(c->rpc_session); bzero(&h, sizeof(h)); h.type = mt; proto_session_hdr_marshall(s, &h); if (proto_debug()) fprintf(stderr, "do_move_rpc:\n pId: %d\n move: #%c#\n", playerdata.id, data); if (proto_session_body_marshall_int(s, playerdata.id) < 0) fprintf(stderr, "do_move_rpc: proto_session_body_marshall_int failed. " "Not enough available sbufer space\n"); if (proto_session_body_marshall_char(s, data) < 0) fprintf(stderr, "do_move_rpc: proto_session_body_marshall_char failed. " "Not enough available sbufer space\n"); rc = proto_session_rpc(s); // process reply if (rc == 1) { proto_session_hdr_unmarshall(s, &h); // wait until we have recieved the envent update wait_for_event(h.sver.raw); if (proto_session_body_unmarshall_int(s, 0, &rc) < 0) fprintf(stderr, "do_move_rpc: proto_session_body_unmarshall_int failed\n"); if (proto_debug()) fprintf(stderr, "do_move_rpc: unmarshalled response rc = %d, game version = %llu, game state = %d \n", rc, h.sver.raw, h.gstate.v0.raw); } else { c->session_lost_handler(s); close(s->fd); } return rc; }
extern int proto_client_maze_info(Proto_Client_Handle ch, char type) { int rc; Proto_Session *s; Proto_Client *c = ch; s = &(c->rpc_session); marshall_mtonly(s, PROTO_MT_REQ_BASE_GET_MAZE_INFO); proto_session_body_marshall_char(s, type); rc = proto_session_rpc(s); if (rc == 1) proto_session_body_unmarshall_int(s, 0, &rc); else c->session_lost_handler(s); return rc; }