⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netif.c

📁 在LINUX下运行的仿真机器人服务器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
			  send( "(error said_too_many_rule_messages)" );		      }		      break;		  default:		      std::cerr << __FILE__ << ": " << __LINE__ 				<< ": Coach msg has an unknown type: " 				<< msg << std::endl;	      }                            if( should_queue )                {		    message_queue.push_back( msg );		    send("(ok say)") ;                }               else 	      {                  delete msg;	      }            }           else 	  {              send("(error could_not_parse_say)");	  }        }       else         {          //pre v7.0          if( stadium->mode != PM_PlayOn )            {              if( freeform_messages_said < freeform_messages_allowed                   || freeform_messages_allowed < 0 )                {                  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().SayCoachMsgSize );                  say( msg );                  send( "(ok say)" );                }              else                {                  send( "(error said_too_many_messages)" );                  return;                }            }          else            {              send( "(warning cannot_say_while_playon)" );              return ;            }        }     }  else if( !strcmp( com, "bye" ) )     {      assignedp = FALSE;      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" ) ) {    if ( stadium->mode == PM_PlayOn)      {        send("(warning cannot_sub_while_playon)");        return ;      }     // when time elapsed, do not allow substitutions anymore (for penalties)     else if( stadium->time >= ServerParam::instance().halfTime() *                          ( ServerParam::instance().nr_normal_halfs +                            ServerParam::instance().nr_extra_halfs     ) )     {           send("(warning no_subs_left)");        return ;      }    Team* team = NULL;    if ( side == LEFT )      team = stadium->team_l;    if ( side == RIGHT )      team = stadium->team_r;    if ( team == NULL )      {        send("(warning no_team_found)");        return ;      }                    if ( team->subs == PlayerParam::instance().subsMax () )      {        send("(warning no_subs_left)");        return ;      }                                    int unum, player_type;    if ( sscanf ( command, "(%s %d %d)", com, &unum, &player_type ) < 3 )      {        send("(error illegal_command_form)");        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 ]->unum == unum )          {            player = team->player[ i ];            break;          }      }    if ( player == NULL )      {        send("(warning no_such_player)");        return ;      }    if ( player->goalie && player_type != 0 )      {        send("(warning cannot_change_goalie)");        return ;      }    if ( player_type != 0          && team->ptype_count[ player_type ] == PlayerParam::instance().ptMax()         && player_type != player->getPlayerType() )      {        send("(warning max_of_that_type_on_field)");        return ;      }                team->ptype_count [ player->player_type_id ]       = team->ptype_count [ player->player_type_id ] - 1;    player->substitute ( player_type );    if ( stadium->mode != PM_BeforeKickOff )      {        team->subs++;      }                team->ptype_count [ player_type ] = team->ptype_count [ player_type ] + 1;                stadium->broadcastSubstitution ( side, unum , player_type );    char buf[64];    sprintf ( buf, "(ok change_player_type %d %d)\n", unum, player_type );                send( buf );                return ;    //pfr:SYNCH  } else if (!strcmp(com, "done")) {    //std::cerr << "Recv olc done" << std::endl;    done_received = TRUE;    return ;  }  else if (!strcmp(com, "compression"))     {      int level ;      if ((n = sscanf(command,"(%s %d)",com,&level)) < 2)        {          send("(error illegal_command_form)") ;          return ;        }    #ifdef HAVE_LIBZ      if ( level > 9 )        {          send("(error illegal_command_form)") ;          return ;        }#ifdef HAVE_SSTREAM      std::ostringstream reply;       reply << "(ok compression " << level << ")";      send ( reply.str().c_str() );#else      std::ostrstream reply;       reply << "(ok compression " << level << ")" << std::ends;      send ( reply.str() );      reply.freeze( false );#endif      setCompressionLevel ( level );      #else      send ( "(warning compression_unsupported)" );#endif      return ;    }   else if( !strcmp( com, "team_graphic" ) )    {      if( stadium->mode != PM_BeforeKickOff )        {          send("warning only_before_kick_off");          return;        }      unsigned int x, y;      n = sscanf( command, "(%s (%u %u", com, &x, &y);      if( n < 3 )        {          send("(error illegal_command_form)") ;          return;        }            if( x >= 32 || y >= 8 )        // needs to be parameterised        {          send("(warning invalid_tile_location)");        }      std::auto_ptr< XPMHolder > holder( new XPMHolder( command ) );      if( !holder->valid() )        {          send("(error illegal_command_form)");          return;        }            if( holder->getWidth() != 8 || holder->getHeight() != 8 )        // needs to be parameterised        {          send("(warning invalid_tile_size)") ;          return;        }            stadium->sendGraphic( side, x, y, *holder );      Team* team = NULL;      if( side == LEFT )        team = stadium->team_l;      else        team = stadium->team_r;      team->addGraphic( x, y, holder );#ifdef HAVE_SSTREAM      std::ostringstream msg;      msg << "(ok team_graphic " << x << " " << y << ")";      send( msg.str().c_str() );#else      std::ostrstream msg;      msg << "(ok team_graphic " << x << " " << y << ")" << std::ends;      send( msg.str() );      msg.freeze( false );#endif    }  else {    send("(error unknown_command)") ;    return ;  }}void Stadium::broadcastSubstitution ( const int& side, const int& unum, const int& player_type, bool tell_ally_coach ){  char allies[64];  char enemies[64];  sprintf ( allies, "(change_player_type %d %d)\n", unum, player_type );  sprintf ( enemies, "(change_player_type %d)\n", unum );  // tell players  for (int i = 0 ; i < MAX_PLAYER * 2; i++)    {      if (player[i]->alive == DISABLE || player[i]->version < 7.0)        continue ;      if ( ( side == LEFT && player [ i ]->team == team_l ) || ( side == RIGHT && player [ i ]->team == team_r )  )        player[i]->send ( allies );      else        player[i]->send ( enemies );            }  // tell coaches  if ( team_r != NULL && team_r->olcoach != NULL &&        team_r->olcoach->version >= 7.0 ) {    if( side == RIGHT && tell_ally_coach ) {      team_r->olcoach->send ( allies );    }    if( side == LEFT ) {      team_r->olcoach->send ( enemies );    }  }  if ( team_l != NULL && team_l->olcoach != NULL &&       team_l->olcoach->version >= 7.0 ) {    if( side == LEFT && tell_ally_coach ) {      team_l->olcoach->send ( allies );    }    if( side == RIGHT ) {      team_l->olcoach->send ( enemies );    }  }  char buffer[64];  sprintf ( buffer ,            "(change_player_type %s %d %d)\n",            ( side == LEFT ? "l" : "r" ),            unum, player_type );  for ( MonitorCont::iterator i = M_monitors.begin ();        i != M_monitors.end (); ++i )    {      (*i)->send( buffer );    }  write_log( *this, buffer, SUBS );}/* *=================================================================== *  Misc *=================================================================== */void write_log ( Stadium& stad, const char *message, int flag) {  if ( flag == RECV )     if ( stad.text_log_open () )       {        stad.text_log_stream () << stad.time << "\t" << message;      }    if ( stad.game_log_open ()        && ( ( flag == RECV && ServerParam::instance().sendComms() ) || flag == SUBS ) )    {          stad.minfo.body.msg.board = htons(LOG_BOARD) ;     strncpy(stad.minfo.body.msg.message, message, 128) ;     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_TimeOver)         stad.WriteLog(&stad.minfo) ;   }	}void write_log(Stadium& stad, Player& p, const char *message, int flag) {  if ( stad.text_log_open ()       || ( stad.game_log_open () && flag == RECV )       || ( ServerParam::instance().sendComms () && flag == RECV ) )  {    char tmp[MaxStringSize] ;    sprintf(tmp, "%s %s_%d: %s\n", (flag == SEND) ? "Send" : "Recv", 	    p.team->name, p.unum, message) ;    write_log ( stad, tmp, flag );  }             }void write_log(Stadium& stad, Coach&, const char *message, int flag){  if ( stad.text_log_open ()       || ( stad.game_log_open () && flag == RECV )       || ( ServerParam::instance().sendComms () && flag == RECV ) )  {    char tmp[MaxStringSize] ;    sprintf ( tmp, "%s Coach: %s\n", (flag == SEND) ? "Send" : "Recv", 	      message) ;    write_log ( stad, tmp, flag );  }             }void write_log(Stadium& stad, OnlineCoach& p, const char *message, int flag){  if ( stad.text_log_open ()       || ( stad.game_log_open () && flag == RECV )       || ( ServerParam::instance().sendComms () && flag == RECV ) )  {    char tmp[MaxStringSize] ;    sprintf ( tmp, "%s %s_Coach: %s\n", (flag == SEND) ? "Send" : "Recv", 	      ( p.side == LEFT ) ? stad.team_l->name : stad.team_r->name,	      message );    write_log ( stad, tmp, flag );  }  }Value distance(PVector *pos1, PVector *pos2){  return sqrt(Pow(pos2->x - pos1->x) + Pow(pos2->y - pos1->y)) ;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -