Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9406 in orxonox.OLD for trunk/src/lib/network/udp_socket.cc


Ignore:
Timestamp:
Jul 24, 2006, 11:09:47 AM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/network/udp_socket.cc

    r8802 r9406  
    7474{
    7575  this->init();
     76  this->ip = ip;
    7677  this->serverSocket = serverSocket;
    7778  this->userId = userId;
     
    105106  assert( serverSocket == NULL );
    106107
    107   IPaddress ip;
    108  
    109108  this->randomByte = generateNewRandomByte();
    110109
    111110  PRINTF(0)("connect to server %s on port %d\n", host.c_str(), port);
    112111
    113   if ( SDLNet_ResolveHost( &ip, host.c_str(), port ) != 0 )
     112  if ( SDLNet_ResolveHost( &this->ip, host.c_str(), port ) != 0 )
    114113  {
    115114    PRINTF(1)("SDLNet_ResolveHost: %s\n", SDLNet_GetError() );
     
    126125  }
    127126
    128   int channel = SDLNet_UDP_Bind(socket, 1, &ip);
     127  int channel = SDLNet_UDP_Bind(socket, 1, &this->ip);
    129128  if ( channel == -1 )
    130129  {
     
    147146  bOk = false;
    148147  socket = NULL;
    149 }
     148
     149  this->ip.host = 0;
     150  this->ip.port = 0;
     151}
     152
     153
     154/**
     155 * reconnects to
     156 * @param host new server address
     157 * @param port new port number
     158 *
     159 * this terminates the current connection and starts a new connection to the new server
     160 */
     161void UdpSocket::reconnectToServer( std::string host, int port)
     162{
     163  // first disconnect the old server
     164  this->disconnectServer();
     165
     166  // now connect to the new
     167  this->connectToServer( host, port);
     168}
     169
     170
     171/**
     172 * reconnects to
     173 * @param host new server address
     174 * @param port new port number
     175 *
     176 * this terminates the current connection and starts a new connection to the new server
     177 */
     178void UdpSocket::reconnectToServerSoft( std::string host, int port)
     179{}
     180
    150181
    151182/**
     
    179210
    180211    byte udpCmd = 0;
    181    
     212
    182213    if ( networkPacket.length > 0 )
    183214    {
     
    189220    else
    190221      return 0;
    191      
     222
    192223    if ( !checkRandomByte( networkPacket.data[0] ) )
    193224      return 0;
     
    198229      networkPacket.data = NULL;
    199230    }
    200    
     231
    201232    if ( !checkUdpCmd( udpCmd ) )
    202233      return 0;
     
    207238  {
    208239    int numrecv = SDLNet_UDP_Recv( socket, packet);
    209    
     240
    210241    byte udpCmd = 0;
    211242
     
    218249      else
    219250        return 0;
    220            
     251
    221252      if ( !checkRandomByte( packet->data[0] ) )
    222253        return 0;
    223              
     254
    224255      if ( !checkUdpCmd( udpCmd ) )
    225256        return 0;
     
    283314    return false;
    284315  }
    285  
     316
    286317  if ( !this->serverSocket && ( udpCmd & UDPCMD_INVALIDRNDBYTE ) )
    287318  {
     
    292323    return false;
    293324  }
    294  
     325
    295326  return true;
    296327}
     
    300331  srand( SDL_GetTicks() );
    301332  byte res = ( rand() & 0xFC );
    302  
     333
    303334  PRINTF(0)("generated random byte: %x\n", res);
    304  
     335
    305336  return res;
    306337}
Note: See TracChangeset for help on using the changeset viewer.