packMaker.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include"packMaker.h"
  2. #include"usermanager.h"
  3. #include"chaos.h"
  4. #include"definations.h"
  5. #include"cstring"
  6. static Chaos* chaos=0;
  7. static UserManager* users=0;
  8. static bool needupdate=true;
  9. static int bufusage[PACKRINGLEN]={0};
  10. static char buff[PACKRINGLEN][BUFFLEN]={0};
  11. static int buflength[PACKRINGLEN]={0};
  12. static int next=0;
  13. int mkHeartPack(char dst[],int magic){
  14. if(chaos==0){
  15. chaos=Chaos::getInstance();
  16. users=UserManager::getInstance();
  17. }
  18. int cur=next;
  19. int len=0;
  20. next++;
  21. next=next<PACKRINGLEN?next:0;
  22. len=mkHeader(buff[cur],magic);
  23. len+=sprintf(buff[cur]+len,"%s",users->myinfo.usrname)+1;
  24. len+=sprintf(buff[cur]+len,"%s",users->myinfo.grpname)+1;
  25. len+=sprintf(buff[cur]+len,"%s",users->myinfo.macaddr)+1;
  26. len+=sprintf(buff[cur]+len,"%s",users->myinfo.space01)+1;
  27. len+=sprintf(buff[cur]+len,"%s",users->myinfo.phone)+1;
  28. len+=sprintf(buff[cur]+len,"%s",users->myinfo.mail)+1;
  29. len+=sprintf(buff[cur]+len,"%s",users->myinfo.printer)+1;
  30. len+=sprintf(buff[cur]+len,"%s",users->myinfo.space02)+1;
  31. len+=sprintf(buff[cur]+len,"%s",users->myinfo.ipaddr)+1;
  32. len+=sprintf(buff[cur]+len,"%s",users->myinfo.space03)+1;
  33. len+=sprintf(buff[cur]+len,"%s",users->myinfo.icon)+1;
  34. len+=sprintf(buff[cur]+len,"%s",users->myinfo.netstatus)+1;
  35. len+=sprintf(buff[cur]+len,"%s",users->myinfo.sign)+1;
  36. len+=sprintf(buff[cur]+len,"%s",users->myinfo.computername);
  37. buflength[cur]=len;
  38. bufusage[cur]=magic;
  39. memcpy(dst,buff[cur],buflength[cur]);
  40. return buflength[cur];
  41. }
  42. int mkHeader(char dst[],int magic,unsigned* rtnPackNum){
  43. if(chaos==0){
  44. chaos=Chaos::getInstance();
  45. users=UserManager::getInstance();
  46. }
  47. unsigned packNum=(chaos->packNum)++;
  48. int len=sprintf(dst,"%s:%u:%s:%s:%u:",vermagic,
  49. packNum,users->myinfo.sysusrname,
  50. users->myinfo.computername,magic);
  51. if(rtnPackNum!=NULL){
  52. *rtnPackNum=packNum;
  53. }
  54. return len;
  55. }