📄 netif.c
字号:
// sprintf ( tmp,// "(change_player_type %d)\n",// team_r->player[i]->unum );// else// sprintf ( tmp,// "(change_player_type %s %d %d)\n",// team_r->name,// team_r->player[i]->unum,// team_r->player[i]->player_type_id );// coach->send ( tmp );// }// }// }// void Stadium::send_changed_players ( Player* player )// {// if ( player == NULL || !player->connected() ) // || player->version < 7.0// return;// player->sendChangedPlayers();// // char tmp[MaxStringSize] ;// // if ( team_l != NULL )// // for ( int i = 0; i < team_l->n; i++ )// // {// // if ( team_l->player[i]->player_type_id != 0 )// // {// // if ( player->team == team_l )// // sprintf ( tmp,// // "(change_player_type %d %d)\n",// // team_l->player[i]->unum,// // team_l->player[i]->player_type_id );// // else if ( player->team == team_r )// // sprintf ( tmp,// // "(change_player_type %d)\n",// // team_l->player[i]->unum );// // else// // return;// // player->send ( tmp );// // }// // }// // if ( team_r != NULL )// // for ( int i = 0; i < team_r->n; i++ )// // {// // if ( team_r->player[i]->player_type_id != 0 )// // {// // if ( player->team == team_r )// // sprintf ( tmp,// // "(change_player_type %d %d)\n",// // team_r->player[i]->unum,// // team_r->player[i]->player_type_id );// // else if ( player->team == team_l )// // sprintf ( tmp,// // "(change_player_type %d)\n",// // team_r->player[i]->unum );// // else// // return;// // player->send ( tmp );// // }// // }// }/* *=================================================================== * Coach *=================================================================== */int Coach::parse_init ( Stadium& stad, char *command, const rcss::net::Addr& addr ){ char com[MaxStringSize] ; int n ; n = sscanf(command, "(%[-0-9a-zA-Z.+*/?<>_]",com) ; if(n<1) { send("(error illegal_command_form)"); return 0; } if (!strcmp ( com, "init" ) ) { float ver = 0.0; n = sscanf ( command, "(init (version %f))", &ver ); if ( n < 1.0 ) { send("(error illegal_command_form)"); return 0; } if( !connect( addr ) ) { return 0; } version = ver; bool found = true; rcss::SerializerCoach::Creator ser_cre; if( rcss::SerializerCoach::factory().getCreator( ser_cre, (int)ver ) ) { const rcss::SerializerCoach* ser = ser_cre(); if( ser ) { rcss::AudioSenderCoach::Params audio_params( stad, getTransport(), *this, *ser ); rcss::AudioSenderCoach::Creator audio_cre; if( rcss::AudioSenderCoach::factory().getCreator( audio_cre, (int)ver ) ) { setAudioSender( audio_cre( audio_params ) ); rcss::InitSenderOfflineCoach::Params init_params( getTransport(), *this, stad, *ser ); rcss::InitSenderOfflineCoach::Creator init_cre; if( rcss::InitSenderOfflineCoach::factory().getCreator( init_cre, (int)version ) ) { rcss::InitSenderOfflineCoach::Ptr isoc = init_cre( init_params ); rcss::InitObserver<rcss::InitSenderOfflineCoach>::setInitSender( isoc ); } else found = false; } else found = false; } else found = false; } else found = false; if( !found ) { cerr << "Error: Could not find serializer or sender for version" << (int)version << endl; return 0; } setEnforceDedicatedPort ( ver >= 8.0 ); stad.addOfflineCoach( this ); stad.addListener( this ); sendInit(); //send("(init ok)") ; sendServerParams(); sendPlayerParams(); sendPlayerTypes(); sendChangedPlayers(); // stad.send_parameter_info ( this );// stad.send_changed_players ( this ); return 1; } else { // old type of coach that doesn;t send an init message return -1; }}void Coach::parse_command ( const char *command ) // unsigned long host, int port){// client.host = host ;// client.port = port ; char com[MaxStringSize] ; int n ; n = sscanf(command, "(%[-0-9a-zA-Z.+*/?<>_]",com) ; if(n<1) { send("(error illegal_command_form)"); return ; } if ( !strcmp ( com, "start" ) ) { _Start ( *stadium ); send("(ok start)"); } else if(!strcmp(com,"change_mode")) { char new_mode[MaxStringSize] ; PlayMode mode_id ; n = sscanf(command,"(change_mode %[-0-9a-zA-Z.+*/?<>_])", new_mode) ; if(n<1) { send("(error illegal_command_form)"); return ; } mode_id = PlayModeID(new_mode) ; if(mode_id == PM_Null) { send("(error illegal_mode)") ; return ; } stadium->change_play_mode(mode_id) ; send("(ok change_mode)") ; } else if (!strcmp(com,"move")) { char obj[MaxStringSize] ; double x = 0.0, y = 0.0, ang = 0.0, velx = 0.0, vely = 0.0 ; command++ ; while(*command != '(') { if (*command == NULLCHAR) { send("(error illegal_object_form)") ; return ; } command++ ; } int i = 0 ; while(*command != ')') { if (*command == NULLCHAR) { send("(error illegal_object_form)") ; return ; } *(obj+i) = *command ; i++ ; command++ ; } *(obj+i) = *command ; i++ ; command++ ; *(obj+i) = NULLCHAR ; if (!strcmp(obj, BALL_NAME)) stadium->M_caught_ball = NULL; n = sscanf(command," %lf %lf %lf %lf %lf)",&x,&y,&ang,&velx,&vely) ; if ( isnan ( x ) != 0 || isnan ( y ) != 0 || isnan ( ang ) != 0 || isnan ( velx ) != 0 || isnan ( vely ) != 0 ) { send("(error illegal_command_form)") ; return; } if (n==2) { if (!strcmp(obj, BALL_NAME)) stadium->set_ball(PVector(x,y), LEFT) ; else if( stadium->move_object(obj,PVector(x,y)) ) stadium->collisions (); else { send("(error illegal_object_form)") ; return; } } else if (n==3) { if (!strcmp(obj, BALL_NAME)) stadium->set_ball(PVector(x,y), LEFT, ang) ; else if( stadium->move_object(obj,PVector(x,y), Deg2Rad(std::max(std::min((ang), ServerParam::instance().maxm), ServerParam::instance().minm)))) stadium->collisions (); else { send("(error illegal_object_form)") ; return; } } else if (n==5) { if (!strcmp(obj, BALL_NAME)) stadium->set_ball(PVector(x,y), LEFT, ang, PVector(velx, vely)) ; else if( stadium->move_object(obj,PVector(x,y), Deg2Rad(std::max(std::min((ang), ServerParam::instance().maxm), ServerParam::instance().minm)), PVector(velx, vely)) ) stadium->collisions (); else { send("(error illegal_object_form)") ; return; } } else { send("(error illegal_command_form)"); return ; } send("(ok move)") ; } else if (!strcmp(com,"look")) { look ( *stadium ) ; } else if (!strcmp(com,"team_names")) { team_names ( *stadium ) ; } else if (!strcmp(com,"recover")) { recover ( *stadium ); } else if (!strcmp(com,"check_ball")) { check_ball ( *stadium ) ; } else if( !strcmp( com, "say" ) ) { static char msg[MaxStringSize] ; n = sscanf( command, SAY_MESSAGE_SCAN_FORMAT, com, msg ); if( n < 2 ) { send( "(error illegal_command_form)" ); return; } chop_last_parenthesis( msg, ServerParam::instance().sayMsgSize() ); stadium->say( msg, false ); send("(ok say)") ; } else if (!strcmp(com,"ear")) { char mode[16] ; n = sscanf(command,"(%s %s)", com, mode) ; if(n<2) {send("(error illegal_command_form)"); return ;} if (!strcmp(mode,"on)")) { hear = TRUE ; send("(ok ear on)") ; } else if (!strcmp(mode, "off)")) { hear = FALSE ; send("(ok ear off)") ; } else { send("(error illegal_command_form)"); return ; } } else if (!strcmp(com,"eye")) { char mode[16] ; n = sscanf(command,"(%s %s)", com, mode) ; if(n<2) {send("(error illegal_command_form)"); return ;} if (!strcmp(mode,"on)")) { eye = TRUE ; send("(ok eye on)") ; } else if (!strcmp(mode, "off)")) { eye = FALSE ; send("(ok eye off)") ; } else { send("(error illegal_command_form)"); return ; } } else if ( !strcmp ( com, "change_player_type" ) ) { char name[128]; int unum, player_type; if ( sscanf ( command, "(%s %s %d %d)", com, name, &unum, &player_type ) < 4 ) { send("(error illegal_command_form)"); return ; } Team* team = NULL; if ( stadium->team_l != NULL && stadium->team_l->name != NULL && !strcmp ( name, stadium->team_l->name ) ) team = stadium->team_l; if ( stadium->team_r != NULL && stadium->team_r->name != NULL && !strcmp ( name, stadium->team_r->name ) ) team = stadium->team_r; if ( team == NULL ) { send("(warning no_team_found)"); return ; } if ( player_type < 0 || player_type >= PlayerParam::instance().playerTypes() ) { send("(error out_of_range_player_type)"); return; } Player* player = NULL; for ( int i = 0; i < team->n; i++ ) { if ( team->player[ i ] != NULL && team->player[ i ]->unum == unum ) { player = team->player[ i ]; break; } } if ( player == NULL ) { send("(warning no_such_player)"); return ; } player->substitute ( player_type ); if ( team == stadium->team_l ) stadium->broadcastSubstitution ( LEFT, unum , player_type, true ); else stadium->broadcastSubstitution ( RIGHT, unum , player_type, true ); char buf[64]; sprintf ( buf, "(ok change_player_type %s %d %d)", name, unum, player_type ); send( buf ); return ; } //pfr:SYNCH else if (!strcmp(com, "done")) { //std::cerr << "Recv trainer done" << std::endl;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -