Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 23, 2005, 5:30:22 PM (18 years ago)
Author:
rennerc
Message:

converter: added functions for strings
network_protocol: length and id are now int
network_game_manager: fixed some more bugs :D
skybox: is loaded on client corectly now :)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/network/src/lib/network/converter.cc

    r6229 r6273  
    9292    return -1;
    9393  }
    94  
     94
    9595  const int mod = 256; // = 2^8
    9696
     
    405405  return FLOATSIZE;
    406406}
     407
     408/**
     409 * copies a strint to a byte array
     410 * @param s: string to copy
     411 * @param a: byte array
     412 * @param length: string length
     413 * @return: the used number of bytes in byte array
     414 */
     415int Converter::stringToByteArray( const char * s, byte * a, int length, int maxLength )
     416{
     417  if ( length+INTSIZE > maxLength )
     418  {
     419    PRINTF(1)("Byte array is too small (%d) to store %d bytes\n", maxLength, length+INTSIZE);
     420    return -1;
     421  }
     422
     423  int n = Converter::intToByteArray( length, a, maxLength );
     424
     425  memcpy( a+INTSIZE, s, length );
     426
     427  return length + INTSIZE;
     428}
     429
     430/**
     431 * reads a string out of a byte array
     432 * @param a: byte array
     433 * @param s: string
     434 * @param maxLength: max bytes to copy
     435 * @return: the number of read bytes in byte array
     436 */
     437int Converter::byteArrayToString( const byte * a, char * s, int maxLength )
     438{
     439  int length;
     440
     441  int n = Converter::byteArrayToInt( a, &length );
     442
     443  if ( length+1 > maxLength )
     444  {
     445    PRINTF(1)("There is not enough space in string (%d) to store %d bytes\n", maxLength, length+1 );
     446    return -1;
     447  }
     448
     449  memcpy( s, a+n, length );
     450  s[length] = '\0';
     451
     452  return n+length;
     453}
Note: See TracChangeset for help on using the changeset viewer.