Main Page | Namespace List | Class Hierarchy | Compound List | File List | Compound Members | File Members

userData.cpp

Go to the documentation of this file.
00001 #include "userData.h"
00002 
00003 #include "ssgLocal.h"
00004 
00005 #define WRITE_CHAR(c, fd) { \
00006   fwrite((const void*)c, sizeof(char), 1, fd); \
00007 }
00008  
00009 #define READ_CHAR(c, fd) { \
00010   char temp; \
00011   fread((void*)&temp, sizeof(char), 1, fd); \
00012   if (temp != *c) \
00013     fprintf(stderr, "error: got a %c while expecting %c in config\n", c, temp); \
00014 }
00015 
00016 class userData;
00017 
00018 void userData::_reset_vals() {
00019   nick = NULL;
00020   first_name = NULL;
00021   last_name = NULL;
00022   male = true;
00023   nation = 0;
00024   for (int i=0; i< COUNT_NATIONS; i++) {
00025     fame[i] = 0;
00026   }
00027   money = 0;
00028   crew_members = 0;
00029   //ship = NULL;
00030   sector[0] = sector[1] = 0;
00031 }
00032 
00033 userData::userData() {
00034   _reset_vals();
00035 }
00036 
00037 userData::userData(char* fn) {
00038   _reset_vals();
00039   FILE* f;
00040   f = fopen(fn, "r");
00041   if (f == NULL) {
00042     fprintf(stderr, "could not open file %s for reading\n", fn);
00043     return;
00044   }
00045   load(f);
00046   fclose(f);
00047 }
00048 
00049 userData::userData(userData* other) {
00050   _reset_vals();
00051   copy_from(other, 1);
00052 }
00053 
00054 userData::userData(netMessage* msg) {
00055   _reset_vals();
00056   char tmp[50];
00057   int c;
00058   /*
00059   if (msg->getType() == MSG_USERDATA_RESPONSE) {
00060     if (nick != NULL)
00061       free(nick);
00062     c = msg->getch();
00063     msg->getc(&tmp, c);
00064     nick = strndup((const char*)&tmp, c);
00065     
00066     if (last_name != NULL)
00067     free(last_name);
00068     c = msg->getch();
00069     msg->getc(&tmp, c);
00070     last_name = strndup((const char*)&tmp, c);
00071     
00072     if (first_name != NULL)
00073     free(first_name);
00074     c = msg->getch();
00075     msg->getc(&tmp, c);
00076     first_name = strndup((const char*)&tmp, c);
00077 
00078     nation = (char)msg->getch();
00079     male = msg->getb();
00080     for (int i=0; i < COUNT_NATIONS; i++) {
00081       fame[i] = msg->geti(i);
00082     }
00083     money = (unsigned long)msg->getw();
00084     crew_members = (unsigned int)msg->getw();
00085     // TODO: ship && sector
00086   }
00087   */
00088 }
00089 
00090 userData::~userData() {
00091   free(nick);
00092   free(last_name);
00093   free(first_name);
00094 }
00095 
00096 int userData::get_player_fame(int nationid) {
00097   return 0;
00098 }
00099 
00100 void userData::copy_from(userData* other, int cf) {
00101   if (nick != NULL)
00102     free(nick);
00103   nick = other->get_nick();
00104   if (last_name != NULL)
00105     free(last_name);
00106   last_name = other->get_last_name();
00107   if (first_name != NULL)
00108     free(first_name);
00109   first_name = other->get_first_name();
00110   male = other->is_male();
00111   nation = other->get_player_nation();
00112   for (int i=0; i < COUNT_NATIONS; i++) {
00113     fame[i] = other->get_player_fame(i);
00114   }
00115   money = other->get_money();
00116   crew_members = other->get_crew_number();
00117   //if (ship != NULL)
00118     //delete ship;
00119   //ship = other->get_ship();
00120   // recalc the sector
00121 }
00122 
00123 userData* userData::clone(int cf) {
00124   userData* r;
00125   r = new userData(this);
00126   return r;
00127 }
00128 
00129 int userData::load(FILE* fd) {
00130 //TODO
00131 return 0;
00132 }
00133 
00134 int userData::save(FILE* fd) {
00135 //TODO
00136 return 0;
00137 }
00138 

Generated on Sat Jul 12 04:29:21 2003 for glPirates by doxygen 1.3.2