Guest User

tw identities

a guest
Apr 12th, 2019
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.55 KB | None | 0 0
  1.  
  2. /* noby experimental identities system */
  3. void CGameClient::conidlist(IConsole::IResult *pResult, void *pUserData)
  4. {
  5.     CGameClient *pSelf = (CGameClient *)pUserData;
  6.     pSelf->num_identities = 0;
  7.     int fd = open("identities.txt", O_RDONLY|O_CREAT);
  8.     if (fd < 0) {
  9.         pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "ids", "i/o error");
  10.         return;
  11.     }
  12.     while (read(fd, &pSelf->identities[pSelf->num_identities], pSelf->id_size) == pSelf->id_size) {
  13.         char bname[16] = { 0 }, bclan[12] = { 0 }, bskin[64] = { 0 }, aBuf[128] = { 0 };
  14.         IntsToStr(&pSelf->identities[pSelf->num_identities].m_Name0, 4, bname);
  15.         IntsToStr(&pSelf->identities[pSelf->num_identities].m_Clan0, 3, bclan);
  16.         IntsToStr(&pSelf->identities[pSelf->num_identities].m_Skin0, 6, bskin);
  17.         snprintf(aBuf, 128, "%3d: %16s %12s %16s", pSelf->num_identities, bname, bclan, bskin);
  18.         pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "ids", aBuf);
  19.         pSelf->num_identities++;
  20.     }
  21. }
  22. void CGameClient::conidsave(IConsole::IResult *pResult, void *pUserData)
  23. {
  24.     CGameClient *pSelf = (CGameClient *)pUserData;
  25.     int id = pResult->GetInteger(0), fd = -1;
  26.     if (id < 0 || id > 63 || !pSelf->m_aClients[id].m_Active) {
  27.         pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "ids", "bad id");
  28.         return;
  29.     }
  30.     struct CNetObj_ClientInfo tmp;
  31.     struct CClientData *cptr = &pSelf->m_aClients[id];
  32.     StrToInts(&tmp.m_Name0, 4, cptr->m_aName);
  33.     StrToInts(&tmp.m_Clan0, 3, cptr->m_aClan);
  34.     StrToInts(&tmp.m_Skin0, 6, cptr->m_aSkinName);
  35.     tmp.m_Country = cptr->m_Country;
  36.     tmp.m_ColorBody = cptr->m_ColorBody;
  37.     tmp.m_ColorFeet = cptr->m_ColorFeet;
  38.     tmp.m_UseCustomColor = cptr->m_UseCustomColor;
  39.     for (int i = 0; i < pSelf->num_identities; i++) {
  40.         if (!memcmp(&tmp, &pSelf->identities[i], pSelf->id_size)) {
  41.             char aBuf[128] = { 0 };
  42.             snprintf(aBuf, 128, "duplicate id %d", i);
  43.             pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "ids", aBuf);
  44.             return;
  45.         }
  46.     }
  47.     if ((fd = open("identities.txt", O_RDWR|O_CREAT|O_APPEND, 0777)) < 0 ||
  48.         write(fd, &tmp, pSelf->id_size) != pSelf->id_size)
  49.         pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "ids", "i/o error");
  50.     close(fd);
  51.     memcpy(&pSelf->identities[pSelf->num_identities], &tmp, pSelf->id_size);
  52.     pSelf->num_identities++;
  53. }
  54. void CGameClient::coniduse(IConsole::IResult *pResult, void *pUserData)
  55. {
  56.     CGameClient *pSelf = (CGameClient *)pUserData;
  57.     int id = pResult->GetInteger(0);
  58.     if (id < 0 || id > pSelf->num_identities) {
  59.         pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "ids", "bad id");
  60.         return;
  61.     }
  62.     struct CNetObj_ClientInfo *ptr = &pSelf->identities[id];
  63.     struct CClientData *cptr = &pSelf->m_aClients[pSelf->m_LocalIDs[0]];
  64.    
  65.     IntsToStr(&ptr->m_Name0, 4, g_Config.m_PlayerName);
  66.     IntsToStr(&ptr->m_Clan0, 3, g_Config.m_PlayerClan);
  67.     IntsToStr(&ptr->m_Skin0, 6, g_Config.m_ClPlayerSkin);
  68.    
  69.     strncpy(cptr->m_aName, g_Config.m_PlayerName, 16);
  70.     strncpy(cptr->m_aClan, g_Config.m_PlayerClan, 12);
  71.     strncpy(cptr->m_aSkinName, g_Config.m_ClPlayerSkin, 24);
  72.    
  73.     cptr->m_Country = g_Config.m_PlayerCountry = ptr->m_Country;
  74.     cptr->m_UseCustomColor = g_Config.m_ClPlayerUseCustomColor = ptr->m_UseCustomColor;
  75.     cptr->m_ColorBody = g_Config.m_ClPlayerColorBody = ptr->m_ColorBody;
  76.     cptr->m_ColorFeet = g_Config.m_ClPlayerColorFeet = ptr->m_ColorFeet;
  77.  
  78.     pSelf->SendInfo(false);
  79. }
  80. #define MAX_IDENTITIES 1000
  81. CGameClient::CGameClient()
  82. {
  83.     id_size = sizeof(struct CNetObj_ClientInfo);
  84.     identities = (struct CNetObj_ClientInfo *)calloc(id_size, MAX_IDENTITIES);
  85. }
  86. CGameClient::~CGameClient()
  87. {
  88.     free(identities);
  89. }
Advertisement
Add Comment
Please, Sign In to add comment