Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* noby experimental identities system */
- void CGameClient::conidlist(IConsole::IResult *pResult, void *pUserData)
- {
- CGameClient *pSelf = (CGameClient *)pUserData;
- pSelf->num_identities = 0;
- int fd = open("identities.txt", O_RDONLY|O_CREAT);
- if (fd < 0) {
- pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "ids", "i/o error");
- return;
- }
- while (read(fd, &pSelf->identities[pSelf->num_identities], pSelf->id_size) == pSelf->id_size) {
- char bname[16] = { 0 }, bclan[12] = { 0 }, bskin[64] = { 0 }, aBuf[128] = { 0 };
- IntsToStr(&pSelf->identities[pSelf->num_identities].m_Name0, 4, bname);
- IntsToStr(&pSelf->identities[pSelf->num_identities].m_Clan0, 3, bclan);
- IntsToStr(&pSelf->identities[pSelf->num_identities].m_Skin0, 6, bskin);
- snprintf(aBuf, 128, "%3d: %16s %12s %16s", pSelf->num_identities, bname, bclan, bskin);
- pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "ids", aBuf);
- pSelf->num_identities++;
- }
- }
- void CGameClient::conidsave(IConsole::IResult *pResult, void *pUserData)
- {
- CGameClient *pSelf = (CGameClient *)pUserData;
- int id = pResult->GetInteger(0), fd = -1;
- if (id < 0 || id > 63 || !pSelf->m_aClients[id].m_Active) {
- pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "ids", "bad id");
- return;
- }
- struct CNetObj_ClientInfo tmp;
- struct CClientData *cptr = &pSelf->m_aClients[id];
- StrToInts(&tmp.m_Name0, 4, cptr->m_aName);
- StrToInts(&tmp.m_Clan0, 3, cptr->m_aClan);
- StrToInts(&tmp.m_Skin0, 6, cptr->m_aSkinName);
- tmp.m_Country = cptr->m_Country;
- tmp.m_ColorBody = cptr->m_ColorBody;
- tmp.m_ColorFeet = cptr->m_ColorFeet;
- tmp.m_UseCustomColor = cptr->m_UseCustomColor;
- for (int i = 0; i < pSelf->num_identities; i++) {
- if (!memcmp(&tmp, &pSelf->identities[i], pSelf->id_size)) {
- char aBuf[128] = { 0 };
- snprintf(aBuf, 128, "duplicate id %d", i);
- pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "ids", aBuf);
- return;
- }
- }
- if ((fd = open("identities.txt", O_RDWR|O_CREAT|O_APPEND, 0777)) < 0 ||
- write(fd, &tmp, pSelf->id_size) != pSelf->id_size)
- pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "ids", "i/o error");
- close(fd);
- memcpy(&pSelf->identities[pSelf->num_identities], &tmp, pSelf->id_size);
- pSelf->num_identities++;
- }
- void CGameClient::coniduse(IConsole::IResult *pResult, void *pUserData)
- {
- CGameClient *pSelf = (CGameClient *)pUserData;
- int id = pResult->GetInteger(0);
- if (id < 0 || id > pSelf->num_identities) {
- pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "ids", "bad id");
- return;
- }
- struct CNetObj_ClientInfo *ptr = &pSelf->identities[id];
- struct CClientData *cptr = &pSelf->m_aClients[pSelf->m_LocalIDs[0]];
- IntsToStr(&ptr->m_Name0, 4, g_Config.m_PlayerName);
- IntsToStr(&ptr->m_Clan0, 3, g_Config.m_PlayerClan);
- IntsToStr(&ptr->m_Skin0, 6, g_Config.m_ClPlayerSkin);
- strncpy(cptr->m_aName, g_Config.m_PlayerName, 16);
- strncpy(cptr->m_aClan, g_Config.m_PlayerClan, 12);
- strncpy(cptr->m_aSkinName, g_Config.m_ClPlayerSkin, 24);
- cptr->m_Country = g_Config.m_PlayerCountry = ptr->m_Country;
- cptr->m_UseCustomColor = g_Config.m_ClPlayerUseCustomColor = ptr->m_UseCustomColor;
- cptr->m_ColorBody = g_Config.m_ClPlayerColorBody = ptr->m_ColorBody;
- cptr->m_ColorFeet = g_Config.m_ClPlayerColorFeet = ptr->m_ColorFeet;
- pSelf->SendInfo(false);
- }
- #define MAX_IDENTITIES 1000
- CGameClient::CGameClient()
- {
- id_size = sizeof(struct CNetObj_ClientInfo);
- identities = (struct CNetObj_ClientInfo *)calloc(id_size, MAX_IDENTITIES);
- }
- CGameClient::~CGameClient()
- {
- free(identities);
- }
Advertisement
Add Comment
Please, Sign In to add comment