示例#1
1
        /* ===================================================== */   
        void handle_message( const connection_ptr& con, const message& m )
        { 
          try {
           chan_data& cdat = get_channel_data(con);
 
           ilog( "${msg_type}", ("msg_type", (bitname::message_type)m.msg_type ) );
           
           switch( (bitname::message_type)m.msg_type )
           {
               case name_inv_msg:
                 handle_name_inv( con, cdat, m.as<name_inv_message>() );
                 break;
               case block_inv_msg:
                 handle_block_inv( con, cdat, m.as<block_inv_message>() );
                 break;
               case get_name_inv_msg:
                 handle_get_name_inv( con, cdat, m.as<get_name_inv_message>() );
                 break;
               case get_headers_msg:
                 handle_get_headers( con, cdat, m.as<get_headers_message>() );
                 break;
               case get_block_msg:
                 handle_get_block( con, cdat, m.as<get_block_message>() );
                 break;
               case get_block_index_msg:
                 handle_get_block_index( con, cdat, m.as<get_block_index_message>() );
                 break;
               case get_name_header_msg:
                 handle_get_name( con, cdat, m.as<get_name_header_message>() );
                 break;
               case name_header_msg:
                 handle_name( con, cdat, m.as<name_header_message>() );
                 break;
               case block_index_msg:
                 handle_block_index( con, cdat, m.as<block_index_message>() );
                 break;
               case block_msg:
                 handle_block( con, cdat, m.as<block_message>() );
                 break;
               case headers_msg:
                 handle_headers( con, cdat, m.as<headers_message>() );
                 break;
               default:
                 FC_THROW_EXCEPTION( exception, "unknown bitname message type ${msg_type}", ("msg_type", m.msg_type ) );
           }
          } 
          catch ( fc::exception& e )
          {
            wlog( "${e}  ${from}", ("e",e.to_detail_string())("from",con->remote_endpoint()) );
          }
        }  // handle_message
示例#2
0
static int main_loop(int sock) {
    char buf[1000];
    for (;;) {
        //printf("Rx: \"%s\"\n", buf);

        int result = client_rx_line(sock, buf, 999);
        if (result) break;

        char* args;

        //  printf("CMD: \"%s\"\n", buf);

        isolate_verb(buf, &args);

        //printf("ISO: \"%s\"(\"%s\")\n\n", buf, args);

        pingSock = sock;
        if (0 == strcasecmp(buf, "NAME")) {
            handle_name(sock, args);
            continue;
        }

        if (0 == strcasecmp(buf, "NEWGAME")) {
            handle_newgame(sock, args);
            continue;
        }

        if (0 == strcasecmp(buf, "PLAYER")) {
            handle_player(sock, args);
            continue;
        }

        if (0 == strcasecmp(buf, "YOURMOVE")) {
            handle_yourmove(sock, args);
            continue;
        }

        if (0 == strcasecmp(buf, "GAMEOVER")) {
            handle_gameover(sock, args);
            continue;
        }

        if (0 == strcasecmp(buf, "ERROR") || 0 == strcasecmp(buf, "BADPROT")) {
            handle_error(sock, args);
            continue;
        }

        printf("Server error: unknown verb \"%s\"\n", buf);
        return 1;

    }
    return 1;
}