📄 netif.c
字号:
<< strerror( errno ) << std::endl; } }}void Stadium::parseOnlineCoachInit ( const char* message, const rcss::net::Addr& addr ){ char tmp[MaxMesg]; sscanf(message,"(%s",tmp); if (!strcmp(tmp,"init")) { OnlineCoach* olc = newCoach ( addr, message ); if ( olc == NULL) { char errmsg[] = "(error no_such_team_or_already_have_coach)"; M_offline_coach_socket.send( errmsg, strlen ( errmsg ) + 1, addr ); } else write_log(*this, *olc, message, RECV) ; } else { char errmsg[] = "(error illegal_command_form)"; M_offline_coach_socket.send( errmsg, strlen ( errmsg ) + 1, addr ); }}void chop_last_parenthesis(char *str, int max_size){ int l = strlen(str) ; if(l > max_size) { str[max_size] = NULLCHAR ; } else { l-- ; if(str[l] == ')') str[l] = NULLCHAR ; }}void Stadium::say( const char *message, bool ref ){ if ( ref ) sendRefAudio( message ); else sendCoachAudio( *coach, message ); // send_audio_info(message, NULL, FALSE, standard) ; if ( text_log_open () || game_log_open () || ServerParam::instance().sendComms () ) { minfo.body.msg.board = htons(MSG_BOARD) ; sprintf(minfo.body.msg.message, "(%s %s)\n", REFEREE_NAME, message) ; // write to text log if ( text_log_open () ) { text_log_stream () << time << "\t" << minfo.body.msg.message; } // send to monitors if ( ServerParam::instance().sendComms () ) for ( MonitorCont::iterator i = M_monitors.begin (); i != M_monitors.end (); ++i ) { if ( (*i)->getVersion () == 1.0 ) (*i)->RemoteClient::send ( (char*)&minfo, sizeof ( dispinfo_t ) ); else { dispinfo_t2 minfo2; minfo2.mode = minfo.mode; minfo2.body.msg = minfo.body.msg; (*i)->RemoteClient::send ( (char*)&minfo2, sizeof ( dispinfo_t2 ) ); } } // write to game log if ( game_log_open () ) if (mode != PM_BeforeKickOff && mode != PM_TimeOver) WriteLog(&minfo) ; }}int OnlineCoach::check_message_queue(TheNumber time){ if( message_queue.size() <= 0 ) { return 0; } int messages_sent = 0; for( int i=ServerParam::instance().clang_mess_per_cycle; i > 0 && message_queue.size() > 0 ; i++ ) { rcss::clang::Msg* msg = *( message_queue.begin() ); if( stadium->mode != PM_PlayOn || time - msg->getTimeRecv() >= ServerParam::instance().clang_mess_delay) { msg->setTimeSend( stadium->time ); msg->setSide( side ); say( *msg ); message_queue.pop_front(); delete msg; ++messages_sent; } else { break; } } return messages_sent;}void OnlineCoach::say( const rcss::clang::Msg& message ){ stadium->sendCoachStdAudio( *this, message ); Stadium &stad = *(this->stadium) ; if ( stad.game_log_open () || ServerParam::instance().sendComms () ) {#ifdef HAVE_SSTREAM std::ostringstream coach_mess;#else std::ostrstream coach_mess;#endif coach_mess << message.getTimeRecv() << " "; message.print(coach_mess);#ifndef HAVE_SSTREAM coach_mess << std::ends; //null-terminate#endif stad.minfo.body.msg.board = htons(MSG_BOARD) ; char format[40]; sprintf(format, "(%%s %%.%ds)\n", max_message_length_for_display - (MaxMesg - MaxCoachMesg)); sprintf(stad.minfo.body.msg.message, format, (side == RIGHT) ? OLCOACH_NAME_R : OLCOACH_NAME_L,#ifdef HAVE_SSTREAM coach_mess.str().c_str()#else coach_mess.str()#endif ) ;#ifndef HAVE_SSTREAM coach_mess.freeze( false );#endif if ( ServerParam::instance().sendComms () ) for ( Stadium::MonitorCont::iterator i = stad.monitors().begin (); i != stad.monitors().end (); ++i ) { if ( (*i)->getVersion () == 1.0 ) (*i)->RemoteClient::send ( (char*)&(stad.minfo), sizeof ( dispinfo_t ) ); else { dispinfo_t2 minfo2; minfo2.mode = stad.minfo.mode; minfo2.body.msg = stad.minfo.body.msg; (*i)->RemoteClient::send ( (char*)&(minfo2), sizeof ( dispinfo_t2 ) ); } } if ( stad.game_log_open () ) if (stad.mode != PM_BeforeKickOff && stad.mode != PM_TimeOver) stad.WriteLog(&stad.minfo) ; }}void OnlineCoach::say(char *message, bool ){ stadium->sendCoachAudio( *this, message ); Stadium &stad = *(this->stadium) ; // stad.send_audio_info(message, NULL, this->side, standard) ; if ( stad.game_log_open () || ServerParam::instance().sendComms () ) { stad.minfo.body.msg.board = htons(MSG_BOARD) ; char format[40]; sprintf(format, "(%%s %%.%ds)\n", max_message_length_for_display - (MaxMesg - MaxCoachMesg)); sprintf(stad.minfo.body.msg.message, format, (side == RIGHT) ? OLCOACH_NAME_R : OLCOACH_NAME_L, message) ; if ( ServerParam::instance().sendComms () ) for ( Stadium::MonitorCont::iterator i = stad.monitors().begin (); i != stad.monitors().end (); ++i ) { if ( (*i)->getVersion () == 1.0 ) (*i)->RemoteClient::send ( (char*)&(stad.minfo), sizeof ( dispinfo_t ) ); else { dispinfo_t2 minfo2; minfo2.mode = stad.minfo.mode; minfo2.body.msg = stad.minfo.body.msg; (*i)->RemoteClient::send ( (char*)&(minfo2), sizeof ( dispinfo_t2 ) ); } } if ( stad.game_log_open () ) if (stad.mode != PM_BeforeKickOff && stad.mode != PM_TimeOver) stad.WriteLog(&stad.minfo) ; }}/* *=================================================================== * Visual Information Loop *=================================================================== */void Stadium::udp_send_message() { int i, sw, tmp ; /* send to clients */ for(i = 0 ; i < MAX_PLAYER * 2; i++) { sw = irand(MAX_PLAYER * 2) ; tmp = dest[i] ; dest[i] = dest[sw] ; dest[sw] = tmp ; } for(i = 0 ; i < MAX_PLAYER * 2; i++ ) { if ( player[dest[i]]->alive == DISABLE || !player[dest[i]]->connected () ) continue ; player[dest[i]]->send_visual_info() ; }}/* *=================================================================== * UDP Send *=================================================================== */void Stadium::udp_send(const char *msg, Player &player,const Logical){ if ( player.alive != DISABLE && player.connected () ) { player.send ( msg ); }}void Stadium::udp_send(const char *msg, const rcss::net::Addr& addr ){ if( M_player_socket.send( msg, strlen( msg ) + 1, addr ) == -1 ) { std::cerr << __FILE__ ": " << __LINE__ << ": Error sending to socket: " << strerror( errno ) << std::endl; }}void Stadium::udp_send( const char *msg, const rcss::net::Addr& addr, int){ if( M_online_coach_socket.send( msg, strlen( msg ) + 1, addr ) == -1 ) { std::cerr << __FILE__ ": " << __LINE__ << ": Error sending to socket: " << strerror( errno ) << std::endl; }}PlayMode PlayModeID(char *mode){ int n ; for(n = 0 ; n < PM_MAX ; n++) { if(!strcmp(PlayModeString[n],mode)) return (PlayMode)n ; } return PM_Null ;}// void Stadium::send_init_info(Player& player) // {// player.sendInit();// // std::ostrstream ost;// // ost << "(init " << SideStr(player.team->side) << " " // // << player.unum << " "// // << PlayModeString[mode]// // << ")" << std::endl << std::ends ; // // player.send ( ost.str () ); // send_parameter_info ( &player );// send_changed_players ( &player ); // // ost.freeze ( false );// }// void Stadium::send_reconnect_info(Player& player) // {// player.sendReconnect();// // std::ostrstream ost; // // ost << "(reconnect " << SideStr ( player.team->side ) << " " // // << PlayModeString[mode]// // << ")" << std::endl << std::ends ;// // player.send( ost.str () );// send_parameter_info( &player );// send_changed_players( &player );// // ost.freeze ( false );// }// void Stadium::send_parameter_info ( Player* player )// {// if ( player == NULL || !player->connected() ) // || player->version < 7.0// return;// player->sendServerParams();// player->sendPlayerParams();// player->sendPlayerTypes();// // if ( player->version >= 8.0 )// // {// // // player->send( ServerParamSensor_v8::data_t( ServerParam::instance() ) );// // // player->send( PlayerParamSensor_v8::data_t( PlayerParam::instance() ) );// // for ( int i = 0; i < PlayerParam::instance().playerTypes (); i++ )// // {// // if ( player_types [ i ] != NULL )// // {// // player->send( PlayerTypeSensor_v8::data_t( i, *player_types [ i ] ) );// // }// // }// // }// // else// // {// // // player->send( ServerParamSensor_v7::data_t( ServerParam::instance() ) );// // // player->send( PlayerParamSensor_v7::data_t( PlayerParam::instance() ) );// // for ( int i = 0; i < PlayerParam::instance().playerTypes (); i++ )// // {// // if ( player_types [ i ] != NULL )// // {// // player->send ( PlayerTypeSensor_v7::data_t ( i, *player_types [ i ] ) );// // }// // }// // }// }// void Stadium::send_parameter_info ( Coach* coach )// {// if ( coach == NULL || coach->version < 7.0 || !coach->connected() )// return;// if ( coach->version >= 8.0 )// {// coach->send( ServerParamSensor_v8::data_t( ServerParam::instance() ) );// coach->send( PlayerParamSensor_v8::data_t( PlayerParam::instance() ) );// for ( int i = 0; i < PlayerParam::instance().playerTypes (); i++ )// {// if ( player_types [ i ] != NULL )// {// coach->send ( PlayerTypeSensor_v8::data_t ( i, *player_types [ i ] ) );// }// }// }// else// {// coach->send( ServerParamSensor_v7::data_t( ServerParam::instance() ) );// coach->send( PlayerParamSensor_v7::data_t( PlayerParam::instance() ) );// for( int i = 0; i < PlayerParam::instance().playerTypes (); i++ )// {// if ( player_types [ i ] != NULL )// {// coach->send ( PlayerTypeSensor_v7::data_t ( i, *player_types [ i ] ) );// }// }// }// }// void Stadium::send_changed_players ( Coach* coach )// {// if ( coach == NULL || coach->version < 7.0 || !coach->connected() )// return;// 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 ( coach->side == LEFT )// sprintf ( tmp,// "(change_player_type %d %d)\n",// team_l->player[i]->unum,// team_l->player[i]->player_type_id );// else if ( coach->side == RIGHT )// sprintf ( tmp,// "(change_player_type %d)\n",// team_l->player[i]->unum );// else// sprintf ( tmp,// "(change_player_type %s %d %d)\n",// team_l->name,// team_l->player[i]->unum,// team_l->player[i]->player_type_id );// coach->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 ( coach->side == RIGHT )// sprintf ( tmp,// "(change_player_type %d %d)\n",// team_r->player[i]->unum,// team_r->player[i]->player_type_id );// else if ( coach->side == LEFT )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -