本文整理汇总了C++中Proto_Client类的典型用法代码示例。如果您正苦于以下问题:C++ Proto_Client类的具体用法?C++ Proto_Client怎么用?C++ Proto_Client使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Proto_Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: proto_client_move
extern int
proto_client_move(Proto_Client_Handle ch, Player_Move direction)
{
int rc = 1, offset = 0;
Proto_Session *s;
Proto_Client *c = ch;
s = &(c->rpc_session);
//printf("Sending move command to server...\n\n");
marshall_mtonly(s, PROTO_MT_REQ_BASE_MOVE);
player_marshall(s, ClientGameState.me);
proto_session_body_marshall_int(s, direction);
rc = proto_session_rpc(s);
if (rc != 1)
{
c->session_lost_handler(s);
return rc;
}
else
{
offset = proto_session_body_unmarshall_int(s, 0, &rc);
player_unmarshall(s, offset, ClientGameState.me);
}
if (rc < 0) printf("player move Error!\n");
// else if (rc == 0) printf("player move rejected by server!\n");
// else printf("Player move successful.\n");
return rc;
}
示例2: proto_client_event_dispatcher
static void *
proto_client_event_dispatcher(void * arg)
{
Proto_Client *c;
Proto_Session *s;
Proto_Msg_Types mt;
Proto_MT_Handler hdlr;
pthread_detach(pthread_self());
/*NOT_IMPL;i*/
c = arg;
s = &(c->event_session);
for (;;) {
if (proto_session_rcv_msg(s)==1) {
mt = proto_session_hdr_unmarshall_type(s);
if (mt > PROTO_MT_EVENT_BASE_RESERVED_FIRST &&
mt < PROTO_MT_EVENT_BASE_RESERVED_LAST) {
hdlr = c->base_event_handlers[mt-PROTO_MT_EVENT_BASE_RESERVED_FIRST-1];
/*NOT_IMPL;//ADD CODE*/
if (hdlr(s)<0) goto leave;
}
} else {
c->session_lost_handler(s);
/*NOT_IMPL;//ADD CODE*/
goto leave;
}
}
leave:
close(s->fd);
return NULL;
}
示例3: do_dump_rpc
static int
do_dump_rpc(Proto_Client_Handle ch, Proto_Msg_Types mt)
{
int rc;
Proto_Session *s;
Proto_Client *c = ch;
if (proto_debug())
fprintf(stderr, "do_dump_rpc \n");
s = &(c->rpc_session);
marshall_mtonly(s, mt);
rc = proto_session_rpc(s);
if (rc == 1)
{
proto_session_body_unmarshall_int(s, 0, &rc);
}
else
{
c->session_lost_handler(s);
close(s->fd);
}
return rc;
}
示例4: proto_client_cell_info
extern int
proto_client_cell_info(Proto_Client_Handle ch, int x, int y, int * buf) {
int team, oc, rc;
char cell_type;
Proto_Session *s;
Proto_Client *c = ch;
s = &(c->rpc_session);
marshall_mtonly(s, PROTO_MT_REQ_BASE_GET_CELL_INFO);
proto_session_body_marshall_int(s, x);
proto_session_body_marshall_int(s, y);
rc = proto_session_rpc(s);
if (rc == 1) {
proto_session_body_unmarshall_char(s, 0, &cell_type);
if(cell_type == 'i')
return -1;
proto_session_body_unmarshall_int(s, sizeof(char), &team);
proto_session_body_unmarshall_int(s, sizeof(char) + sizeof(int), &oc);
buf[0] = (int)cell_type;
buf[1] = team;
buf[2] = oc;
}
else
c->session_lost_handler(s);
return rc;
}
示例5: do_numwall_rpc
static int
do_numwall_rpc(Proto_Client_Handle ch, Proto_Msg_Types mt)
{
int rc;
Proto_Session *s;
Proto_Client *c = ch;
Proto_Msg_Hdr h;
if (proto_debug())
fprintf(stderr, "do_numwall_rpc\n");
s = &(c->rpc_session);
bzero(&h, sizeof(h));
h.type = mt;
proto_session_hdr_marshall(s, &h);
rc = proto_session_rpc(s);
if (rc == 1) {
if(proto_session_body_unmarshall_int(s, 0, &rc) < 0)
fprintf(stderr, "get_numwall_rpc: proto_session_body_unmarshall_bytes failed\n");
if (proto_debug())
fprintf(stderr, "do_numwall_rpc: unmarshalled response rc = %d \n", rc);
}
else {
c->session_lost_handler(s);
close(s->fd);
}
return rc;
}
示例6: do_cinfo_rpc
static int
do_cinfo_rpc(Proto_Client_Handle ch, int x, int y, Proto_Msg_Types mt){
int rc=0;
Proto_Session *s;
Proto_Client *c = ch;
Proto_Msg_Hdr *hdr = malloc(sizeof(Proto_Msg_Hdr));
s = &(c->rpc_session);
bzero(hdr, sizeof(Proto_Msg_Hdr));
hdr->pstate.v0.raw=x;
hdr->pstate.v1.raw=y;
hdr->type = mt;
proto_session_hdr_marshall(s,hdr);
proto_dump_msghdr(&(s->shdr));
rc = proto_session_rpc(s);
if(rc==1){
proto_session_hdr_unmarshall(s,&s->rhdr);
proto_dump_msghdr(&(s->rhdr));
}
else
c->session_lost_handler(s);
return rc;
}
示例7: proto_client_pickup_shovel
extern int
proto_client_pickup_shovel(Proto_Client_Handle ch) {
int rc, offset;
Player *p = ClientGameState.me;
Proto_Session *s;
Proto_Client *c = ch;
s = &(c->rpc_session);
marshall_mtonly(s, PROTO_MT_REQ_BASE_PICKUP_SHOVEL);
player_marshall(s,p);
rc = proto_session_rpc(s);
if (rc != 1)
{
c->session_lost_handler(s);
return rc;
}
else
{
offset = proto_session_body_unmarshall_int(s, 0, &rc);
player_unmarshall(s, offset, ClientGameState.me);
}
return rc;
}
示例8: do_goodbye_rpc
static int
do_goodbye_rpc(Proto_Client_Handle ch, Player *p, Proto_Msg_Types mt){
int rc=0;
Proto_Session *s;
Proto_Client *c = ch;
Proto_Msg_Hdr hdr;
s = &(c->rpc_session);
bzero(&hdr, sizeof(Proto_Msg_Hdr));
hdr.type = mt;
proto_session_hdr_marshall(s,&hdr);
proto_session_body_marshall_player(s,p);
rc = proto_session_rpc(s);
if(rc==1){
proto_session_hdr_unmarshall(s,&s->rhdr);
// proto_dump_msghdr(&(s->rhdr));
}
else
c->session_lost_handler(s);
return rc;
}
示例9: proto_client_drop_flag
extern int
proto_client_drop_flag(Proto_Client_Handle ch) {
Player *p = ClientGameState.me;
int rc, offset;
Proto_Session *s;
Proto_Client *c = ch;
s = &(c->rpc_session);
marshall_mtonly(s, PROTO_MT_REQ_BASE_DROP_FLAG);
player_marshall(s,p);
rc = proto_session_rpc(s);
if (rc != 1)
{
c->session_lost_handler(s);
return rc;
}
else
{
offset = proto_session_body_unmarshall_int(s, 0, &rc);
player_unmarshall(s, offset, ClientGameState.me);
}
return rc;
}
示例10: do_numhome_rpc
// Assigment 3 rpc
static int
do_numhome_rpc(Proto_Client_Handle ch, Proto_Msg_Types mt, int data)
{
int rc;
Proto_Session *s;
Proto_Client *c = ch;
Proto_Msg_Hdr h;
if (proto_debug())
fprintf(stderr, "do_numhome_rpc (team = %d)\n", data);
s = &(c->rpc_session);
bzero(&h, sizeof(h));
h.type = mt;
proto_session_hdr_marshall(s, &h);
if (proto_session_body_marshall_int(s, data) < 0)
fprintf(stderr,
"get_numHome_rpc: proto_session_body_marshall_char failed. "
"Not enough available sbufer space\n");
rc = proto_session_rpc(s);
if (rc == 1) {
if(proto_session_body_unmarshall_int(s, 0, &rc) < 0)
fprintf(stderr, "do_numhome_rpc: proto_session_body_unmarshall_bytes failed\n");
if (proto_debug())
fprintf(stderr, "do_numhome_rpc: unmarshalled response rc = %d \n", rc);
}
else {
c->session_lost_handler(s);
close(s->fd);
}
return rc;
}
示例11: do_generic_dummy_rpc
// all rpc's are assume to only reply only with a return code in the body
// eg. like the null_mes
static int
do_generic_dummy_rpc(Proto_Client_Handle ch, Proto_Msg_Types mt)
{
int rc;
Proto_Session *s;
Proto_Client *c = ch;
s = &(c->rpc_session);
// marshall
marshall_mtonly(s, mt);
rc = proto_session_rpc(s);
if (rc == 1)
{
proto_session_body_unmarshall_int(s, 0, &rc);
}
else
{
c->session_lost_handler(s);
close(s->fd);
}
return rc;
}
示例12: do_cinfo_rpc
static int
do_cinfo_rpc(Proto_Client_Handle ch, Proto_Msg_Types mt, int x, int y)
{
int rc;
char cell, team, occupied;
Proto_Session *s;
Proto_Client *c = ch;
Proto_Msg_Hdr h;
s = &(c->rpc_session);
bzero(&h, sizeof(h));
h.type = mt;
proto_session_hdr_marshall(s, &h);
if (proto_debug())
fprintf(stderr, "do_cinfo_rpc: cinfo(%d, %d) \n", x, y);
if (proto_session_body_marshall_int(s, x) < 0)
fprintf(stderr,
"do_cinfo_rpc: proto_session_body_marshall_char failed. "
"Not enough available sbufer space\n");
if (proto_session_body_marshall_int(s, y) < 0)
fprintf(stderr,
"do_cinfo_rpc: proto_session_body_marshall_char failed. "
"Not enough available sbufer space\n");
rc = proto_session_rpc(s);
if (rc == 1) {
// unmarshall
if (proto_session_body_unmarshall_char(s, 0, &cell) < 0)
fprintf(stderr, "do_cinfo_rpc: proto_session_body_unmarshall_bytes failed\n");
if (proto_session_body_unmarshall_char(s, 1, &team) < 0)
fprintf(stderr, "do_cinfo_rpc: proto_session_body_unmarshall_bytes failed\n");
if (proto_session_body_unmarshall_char(s, 2, &occupied) < 0)
fprintf(stderr, "do_cinfo_rpc: proto_session_body_unmarshall_bytes failed\n");
if (proto_debug())
fprintf(stderr, "do_cinfo_rpc: unmarshalled response cell = %X, %c \n", cell & 0xFF, cell);
if (proto_debug())
fprintf(stderr, "do_cinfo_rpc: unmarshalled response team = %X, %c \n", team & 0xFF, team);
if (proto_debug())
fprintf(stderr, "do_cinfo_rpc: unmarshalled response occupied = %X, %c \n", occupied & 0xFF, occupied);
rc = 0;
rc =((cell & 0xFF)<<8) | ((team & 0xFF)<<16) | ((occupied & 0xFF)<<24);
if (proto_debug())
fprintf(stderr, "do_cinfo_rpc: return value = %X \n", rc);
}
else {
c->session_lost_handler(s);
close(s->fd);
}
return rc;
}
示例13: do_item_action_rpc
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;
}
示例14: proto_client_dump_maze
extern int
proto_client_dump_maze(Proto_Client_Handle ch) {
int rc;
Proto_Session *s;
Proto_Client *c = ch;
s = &(c->rpc_session);
marshall_mtonly(s, PROTO_MT_REQ_BASE_DUMP);
rc = proto_session_rpc(s);
if (rc == 1)
proto_session_body_unmarshall_int(s, 0, &rc);
else
c->session_lost_handler(s);
return rc;
}
示例15: do_move_rpc
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;
}