static int v2_attr_rply(int flags) { int auth_cnt, i; unsigned short errcode; if (flags & F_SUM) { GETSHORT(errcode); if (errcode != OK) { strcat(msgbuf, slpv2_error(errcode)); msglength = 0; /* skip rest of message */ return (0); } else { GETFIELD; /* attr list */ #ifdef VERIFYSLP GETBYTE(auth_cnt); for (i = 0; i < auth_cnt; i++) if (skip_v2authblock() < 0) return (0); #endif } } else if (flags & F_DTAIL) { V2_DOERRCODE; DOFIELD("Attribute list", FIELD_DEFAULT); /* auth */ GETBYTE(auth_cnt); for (i = 0; i < auth_cnt; i++) V2_DOAUTH(i); } return (1); }
static int v2_srv_reg(int flags) { int i, auth_cnt; if (flags & F_SUM) { SKIPBYTE; /* reserved */ SKIPSHORT; /* lifetime */ GETFIELD; /* URL */ #ifdef VERIFYSLP GETBYTE(auth_cnt); for (i = 0; i < auth_cnt; i++) if (skip_v2authblock() < 0) return (0); SKIPFIELD(FIELD_DEFAULT); /* type */ SKIPFIELD(FIELD_DEFAULT); /* scopes */ SKIPFIELD(FIELD_DEFAULT); /* attrs */ GETBYTE(auth_cnt); for (i = 0; i < auth_cnt; i++) if (skip_v2authblock() < 0) return (0); #endif } if (flags & F_DTAIL) { V2_DOURL(-1); DOFIELD("Service type", FIELD_DEFAULT); DOFIELD("Scopes", FIELD_DEFAULT); DOFIELD("Attribute list", FIELD_DEFAULT); /* auth */ GETBYTE(auth_cnt); for (i = 0; i < auth_cnt; i++) V2_DOAUTH(i); } return (1); }
static int v2_daadvert(int flags) { int auth_cnt, i; unsigned short errcode; unsigned int timestamp; if (flags & F_SUM) { SKIPSHORT; /* error code */ SKIPSHORT; SKIPSHORT; /* timestamp */ GETFIELD; /* URL */ #ifdef VERIFYSLP SKIPFIELD(FIELD_DEFAULT); /* scopes */ SKIPFIELD(FIELD_DEFAULT); /* attrs */ SKIPFIELD(FIELD_DEFAULT); /* SPIs */ GETBYTE(auth_cnt); for (i = 0; i < auth_cnt; i++) if (skip_v2authblock() < 0) return (0); #endif } else if (flags & F_DTAIL) { V2_DOERRCODE; V2_DOTIMESTAMP; DOFIELD("URL", FIELD_DEFAULT); DOFIELD("Scope list", FIELD_DEFAULT); DOFIELD("Attribute list", FIELD_DEFAULT); DOFIELD("Configured SPIs", FIELD_DEFAULT); /* auth */ GETBYTE(auth_cnt); for (i = 0; i < auth_cnt; i++) V2_DOAUTH(i); } return (1); }
static int v2_saadvert(int flags) { int auth_cnt, i; if (flags & F_SUM) { GETFIELD; /* URL */ #ifdef VERIFYSLP SKIPFIELD(FIELD_DEFAULT); /* scopes */ SKIPFIELD(FIELD_DEFAULT); /* attrs */ GETBYTE(auth_cnt); for (i = 0; i < auth_cnt; i++) if (skip_v2authblock() < 0) return (0); #endif } else if (flags & F_DTAIL) { DOFIELD("URL", FIELD_DEFAULT); DOFIELD("Scopes", FIELD_DEFAULT); DOFIELD("Attribute list", FIELD_DEFAULT); /* auth */ GETBYTE(auth_cnt); for (i = 0; i < auth_cnt; i++) V2_DOAUTH(i); } return (1); }
void Twofish::SetKey(const byte* userKey, word32 keylen, CipherDir /*dummy*/) { unsigned int len = (keylen <= 16 ? 2 : (keylen <= 24 ? 3 : 4)); word32 key[8]; GetUserKey(LittleEndianOrder, key, len*2, userKey, keylen); unsigned int i; for (i=0; i<40; i+=2) { word32 a = h(i, key, len); word32 b = rotlFixed(h(i+1, key+1, len), 8); k_[i] = a+b; k_[i+1] = rotlFixed(a+2*b, 9); } word32 svec[8]; for (i=0; i<len; i++) svec[2*(len-i-1)] = ReedSolomon(key[2*i+1], key[2*i]); for (i=0; i<256; i++) { word32 t = h0(i, svec, len); s_[0][i] = mds_[0][GETBYTE(t, 0)]; s_[1][i] = mds_[1][GETBYTE(t, 1)]; s_[2][i] = mds_[2][GETBYTE(t, 2)]; s_[3][i] = mds_[3][GETBYTE(t, 3)]; } }
int pgp_s2k_read(PullFilter *src, PGP_S2K *s2k) { int res = 0; GETBYTE(src, s2k->mode); GETBYTE(src, s2k->digest_algo); switch (s2k->mode) { case 0: break; case 1: res = pullf_read_fixed(src, 8, s2k->salt); break; case 3: res = pullf_read_fixed(src, 8, s2k->salt); if (res < 0) break; GETBYTE(src, s2k->iter); break; default: res = PXE_PGP_BAD_S2K_MODE; } return res; }
void DataOutputStream::writeUInt16(UINT16 data) { UINT8 buf[2]; buf[0] = GETBYTE(data, 1); buf[1] = GETBYTE(data, 0); writeFully((char *)buf, sizeof(buf)); }
void DataOutputStream::writeUInt32(UINT32 data) { UINT8 buf[4]; buf[0] = GETBYTE(data, 3); buf[1] = GETBYTE(data, 2); buf[2] = GETBYTE(data, 1); buf[3] = GETBYTE(data, 0); writeFully((char *)buf, sizeof(buf)); }
// this version is only used to make pbox and sbox void Blowfish::crypt_block(const word32 in[2], word32 out[2]) const { word32 left = in[0]; word32 right = in[1]; const word32 *const s=sbox; const word32 *p=pbox; left ^= p[0]; for (unsigned i=0; i<ROUNDS/2; i++) { right ^= (((s[GETBYTE(left,3)] + s[256+GETBYTE(left,2)]) ^ s[2*256+GETBYTE(left,1)]) + s[3*256+GETBYTE(left,0)]) ^ p[2*i+1]; left ^= (((s[GETBYTE(right,3)] + s[256+GETBYTE(right,2)]) ^ s[2*256+GETBYTE(right,1)]) + s[3*256+GETBYTE(right,0)]) ^ p[2*i+2]; } right ^= p[ROUNDS+1]; out[0] = right; out[1] = left; }
void Blowfish::ProcessAndXorBlock(const byte* in, const byte* xOr, byte* out) const { word32 left, right; const word32 *const s = sbox_; const word32* p = pbox_; gpBlock::Get(in)(left)(right); left ^= p[0]; // roll back up and use s and p index instead of just p for (unsigned i = 0; i < ROUNDS / 2; i++) { right ^= (((s[GETBYTE(left,3)] + s[256+GETBYTE(left,2)]) ^ s[2*256+GETBYTE(left,1)]) + s[3*256+GETBYTE(left,0)]) ^ p[2*i+1]; left ^= (((s[GETBYTE(right,3)] + s[256+GETBYTE(right,2)]) ^ s[2*256+GETBYTE(right,1)]) + s[3*256+GETBYTE(right,0)]) ^ p[2*i+2]; } right ^= p[ROUNDS + 1]; gpBlock::Put(xOr, out)(right)(left); }
void BlowfishEncryptLE (unsigned char *inBlock, unsigned char *outBlock, BF_KEY *key, int encrypt) { word32 left = LE32 (((word32 *) inBlock)[0]); word32 right = LE32 (((word32 *) inBlock)[1]); const word32 *const s = key->sbox; const word32 * p = encrypt ? key->pbox : key->pbox_dec; unsigned i; left ^= p[0]; for (i=0; i<ROUNDS/2; i++) { right ^= (((s[GETBYTE(left,3)] + s[256+GETBYTE(left,2)]) ^ s[2*256+GETBYTE(left,1)]) + s[3*256+GETBYTE(left,0)]) ^ p[2*i+1]; left ^= (((s[GETBYTE(right,3)] + s[256+GETBYTE(right,2)]) ^ s[2*256+GETBYTE(right,1)]) + s[3*256+GETBYTE(right,0)]) ^ p[2*i+2]; } right ^= p[ROUNDS+1]; ((word32 *) outBlock)[0] = LE32 (right); ((word32 *) outBlock)[1] = LE32 (left); }
// this version is only used to make pbox and sbox static void crypt_block(BF_KEY *key, const word32 in[2], word32 out[2]) { word32 left = in[0]; word32 right = in[1]; const word32 *const s=key->sbox; const word32 *p=key->pbox; unsigned i; left ^= p[0]; for (i=0; i<ROUNDS/2; i++) { right ^= (((s[GETBYTE(left,3)] + s[256+GETBYTE(left,2)]) ^ s[2*256+GETBYTE(left,1)]) + s[3*256+GETBYTE(left,0)]) ^ p[2*i+1]; left ^= (((s[GETBYTE(right,3)] + s[256+GETBYTE(right,2)]) ^ s[2*256+GETBYTE(right,1)]) + s[3*256+GETBYTE(right,0)]) ^ p[2*i+2]; } right ^= p[ROUNDS+1]; out[0] = right; out[1] = left; }
void Blowfish::ProcessBlock(const byte *in, byte *out) const { word32 left, right; GetBlockBigEndian(in, left, right); const word32 *const s=sbox; const word32 *p=pbox; left ^= p[0]; for (unsigned i=0; i<ROUNDS/2; i++) { right ^= (((s[GETBYTE(left,3)] + s[256+GETBYTE(left,2)]) ^ s[2*256+GETBYTE(left,1)]) + s[3*256+GETBYTE(left,0)]) ^ p[2*i+1]; left ^= (((s[GETBYTE(right,3)] + s[256+GETBYTE(right,2)]) ^ s[2*256+GETBYTE(right,1)]) + s[3*256+GETBYTE(right,0)]) ^ p[2*i+2]; } right ^= p[ROUNDS+1]; PutBlockBigEndian(out, right, left); }
byte LC_RNG::GenerateByte() { word32 hi = seed/q; word32 lo = seed%q; long test = a*lo - r*hi; if (test > 0) seed = test; else seed = test+ m; return (GETBYTE(seed, 0) ^ GETBYTE(seed, 1) ^ GETBYTE(seed, 2) ^ GETBYTE(seed, 3)); }
uint64_t archive_fetch_data(int fd, int size) { unsigned char data[8] = { 0 }; uint64_t val = 0; if (read(fd, data, size) != size) { DPRINTF("Invalid data block\n"); return (uint64_t)-1; } switch (size) { case 1: val = GETBYTE(data); break; case 2: val = GETWORD(data); break; case 4: val = GETUINT32(data); break; case 8: val = GETUINT64(data); break; default:val = (uint64_t)-1; DPRINTF("Cannot get %d bytes: Not implemented\n", size); break; } return val; }
// Disconnect client from char/world server bool CCharServer::pakLoginDSClient( CCharClient* thisclient, CPacket* P ) { unsigned int userid = GETDWORD((*P), 1 ); CCharClient* otherclient = GetClientByUserID( userid ); BYTE action = GETBYTE((*P),0); switch(action) { case 1: { if(otherclient==NULL) { Log( MSG_WARNING, "Userid '%u' is not online", userid ); return true; } otherclient->isLoggedIn = false; otherclient->isActive = false; BEGINPACKET( pak, 0x502 ); ADDBYTE ( pak, 1 ); ADDDWORD ( pak, userid ); //ADDBYTE ( pak, 0x00 ); //cryptPacket( (char*)&pak, NULL ); CChanels* thischannel = GetChannelByID( otherclient->channel ); if(thischannel!=NULL) send( thischannel->sock, (char*)&pak, pak.Size, 0 ); } break; } return true; }
unsigned short CJpegParse::GetComment(PTJpegIndex pinfo, unsigned char *ptr) { unsigned short len = GETWORD(ptr, 0); pinfo->frmcnt = GETWORD_INV(ptr, 2); pinfo->qf = GETBYTE(ptr, 25); return len; }
// delete/resurect character bool CCharServer::pakDeleteChar( CCharClient* thisclient, CPacket* P ) { if(!thisclient->isLoggedIn) return false; char* name = (char*)&P->Buffer[2]; MYSQL_RES *result; MYSQL_ROW row; result = DB->QStore("SELECT account_name FROM characters WHERE char_name='%s' LIMIT 1", name); if(result==NULL) return false; row = mysql_fetch_row(result); if (strcmp(row[0], thisclient->username)!=0) { Log(MSG_HACK, "User %s tried deleting another users (%s) character.", thisclient->username, name); DB->QFree( ); return false; } DB->QFree( ); short int action = GETBYTE((*P), 1 ); unsigned long int DeleteTime = 0; switch(action) { case 0x00://Resurect { DeleteTime = 0; if(!DB->QExecute(" UPDATE characters SET deletetime=0 WHERE char_name='%s'", (char*)&P->Buffer[2] )) return false; } break; case 0x01://Delete { DeleteTime = GetServerTime( ) + Config.DeleteTime; if(!DB->QExecute(" UPDATE characters SET deletetime=%i WHERE char_name='%s'", DeleteTime, (char*)&P->Buffer[2] )) return false; } break; } BEGINPACKET( pak, 0x714 ); if(DeleteTime > 0 ) { ADDDWORD ( pak, Config.DeleteTime ); } else { ADDDWORD ( pak, 0x00000000 ); } ADDSTRING ( pak, (char*)&P->Buffer[2] ); ADDBYTE ( pak, 0x00 ); thisclient->SendPacket( &pak ); return true; }
void DataOutputStream::writeUInt64(UINT64 data) { UINT8 buf[8]; buf[0] = GETBYTE(data, 7); buf[1] = GETBYTE(data, 6); buf[2] = GETBYTE(data, 5); buf[3] = GETBYTE(data, 4); buf[4] = GETBYTE(data, 3); buf[5] = GETBYTE(data, 2); buf[6] = GETBYTE(data, 1); buf[7] = GETBYTE(data, 0); writeFully((char *)buf, sizeof(buf)); }
// Change Party Options bool CWorldServer::pakPartyOption( CPlayer* thisclient, CPacket* P ) { if(!thisclient->Party->IsMaster) return true; CParty* party = thisclient->Party->party; if(party==NULL) return true; party->Option = GETBYTE((*P),0); BEGINPACKET( pak, 0x7d7 ); ADDBYTE ( pak, party->Option ); ADDBYTE ( pak, 0x00 ); party->SendToMembers( &pak ); return true; }
static int read_pubenc_keyid(PullFilter *pkt, uint8 *keyid_buf) { uint8 ver; int res; GETBYTE(pkt, ver); if (ver != 3) return -1; res = pullf_read_fixed(pkt, 8, keyid_buf); if (res < 0) return res; return pgp_skip_packet(pkt); }
// Send server IP bool CLoginServer::pakGetIP( CLoginClient* thisclient, CPacket* P ) { if (!thisclient->isLoggedIn) return false; ; MYSQL_ROW row; DWORD servernum = GETDWORD( (*P), 0 ); BYTE channelnum = GETBYTE( (*P), 4 ); BEGINPACKET( pak, 0x70a ); if(!DB->QExecute( "UPDATE accounts SET lastsvr=%i,lastip='%s',lasttime=UNIX_TIMESTAMP( NOW() ) WHERE id=%i", channelnum, inet_ntoa( thisclient->clientinfo.sin_addr ), thisclient->userid)) return false; MYSQL_RES *result = DB->QStore( "SELECT host,port,lanip,lansubmask,connected,maxconnections FROM channels WHERE id=%i and type=1", servernum ); if(result==NULL) return false; if(mysql_num_rows(result)!=1) { Log(MSG_WARNING, "Player selected a invalid channel or channel offline" ); DB->QFree( ); return true; } row = mysql_fetch_row(result); UINT connected = atoi(row[4]); UINT maxconnections = atoi(row[5]); ADDBYTE( pak, 0 ); ADDDWORD( pak, thisclient->userid ); ADDDWORD( pak, 0x87654321 ); if(strcmp(thisclient->ClientSubNet,row[3])==0)//from lan { ADDSTRING( pak, row[2] ); Log(MSG_INFO, "Lan: %s choice channel #%i", thisclient->username.c_str(), channelnum); } else if(strcmp( thisclient->ClientSubNet ,"127.0.0")==0)//same computer { ADDSTRING( pak, "127.0.0.1" ); Log(MSG_INFO, "Server: %s choice channel #%i", thisclient->username.c_str(), channelnum); } else { ADDSTRING( pak, row[0] ); Log(MSG_INFO, "Inet: %s choice channel #%i", thisclient->username.c_str(), channelnum); } ADDBYTE( pak, 0 ); ADDWORD( pak, atoi(row[1]) ); DB->QFree( ); thisclient->SendPacket ( &pak ); return true; }
// ??? bool CCharServer::pak7e5 ( CCharClient* thisclient, CPacket* P ) { if(!thisclient->isLoggedIn) return false; BYTE action = GETBYTE((*P),0); switch(action) { case 0x03: BEGINPACKET( pak, 0x7e5 ); ADDBYTE ( pak, 0x01 ); ADDWORD ( pak, 0x0000 ); thisclient->SendPacket( &pak ); break; default: Log( MSG_WARNING,"Unknown 7e5 action %i",action); } return true; }
// apply theta to a roundkey static void SquareTransform (word32 in[4], word32 out[4]) { static const byte G[4][4] = { 0x02U, 0x01U, 0x01U, 0x03U, 0x03U, 0x02U, 0x01U, 0x01U, 0x01U, 0x03U, 0x02U, 0x01U, 0x01U, 0x01U, 0x03U, 0x02U }; GF256 gf256(0xf5); for (int i = 0; i < 4; i++) { word32 temp = 0; for (int j = 0; j < 4; j++) for (int k = 0; k < 4; k++) temp ^= (word32)gf256.Multiply(GETBYTE(in[i], 3-k), G[k][j]) << ((3-j)*8); out[i] = temp; } }
void Blowfish::ProcessBlock(const byte *in, byte *out) const { #ifdef IS_LITTLE_ENDIAN word32 left = byteReverse(*(word32 *)in); word32 right = byteReverse(*(word32 *)(in+4)); #else word32 left = *(word32 *)in; word32 right = *(word32 *)(in+4); #endif const word32 *const s=sbox; const word32 *p=pbox; left ^= p[0]; for (unsigned i=0; i<ROUNDS/2; i++) { right ^= (((s[GETBYTE(left,3)] + s[256+GETBYTE(left,2)]) ^ s[2*256+GETBYTE(left,1)]) + s[3*256+GETBYTE(left,0)]) ^ p[2*i+1]; left ^= (((s[GETBYTE(right,3)] + s[256+GETBYTE(right,2)]) ^ s[2*256+GETBYTE(right,1)]) + s[3*256+GETBYTE(right,0)]) ^ p[2*i+2]; } right ^= p[ROUNDS+1]; #ifdef IS_LITTLE_ENDIAN *(word32 *)out = byteReverse(right); *(word32 *)(out+4) = byteReverse(left); #else *(word32 *)out = right; *(word32 *)(out+4) = left; #endif }
static int v2_srv_rply(int flags) { unsigned short itemcnt, errcode; int n; if (flags & F_SUM) { int i, auth_cnt; GETSHORT(errcode); if (errcode != OK) { strcat(msgbuf, slpv2_error(errcode)); msglength = 0; /* skip rest of message */ return (0); } else { GETSHORT(itemcnt); sprintf(msgend, "%d URL entries", itemcnt); #ifdef VERIFYSLP for (n = 0; n < itemcnt; n++) { SKIPBYTE; /* reserved */ SKIPSHORT; /* lifetime */ SKIPFIELD(FIELD_DEFAULT); /* URL */ GETBYTE(auth_cnt); for (i = 0; i < auth_cnt; auth_cnt++) if (skip_v2authblock() < 0) return (0); } #endif } } else if (flags & F_DTAIL) { V2_DOERRCODE; GETSHORT(itemcnt); sprintf(get_line(0, 0), "URL entry count = %d", itemcnt); for (n = 0; n < itemcnt; n++) { V2_DOURL(n); } } return (1); }
static int v2_srv_dereg(int flags) { if (flags & F_SUM) { int i, auth_cnt; SKIPFIELD(FIELD_DEFAULT); /* scopes */ SKIPBYTE; /* reserved */ SKIPSHORT; /* lifetime */ GETFIELD; /* URL */ #ifdef VERIFYSLP GETBYTE(auth_cnt); for (i = 0; i < auth_cnt; i++) if (skip_v2authblock() < 0) return (0); SKIPFIELD(FIELD_DEFAULT); /* attrs */ #endif } else if (flags & F_DTAIL) { DOFIELD("Scopes", FIELD_DEFAULT); V2_DOURL(-1); DOFIELD("Tag list", FIELD_DEFAULT); } return (1); }
static int process_secret_key(PullFilter *pkt, PGP_PubKey **pk_p, const uint8 *key, int key_len) { int res; int hide_type; int cipher_algo; int bs; uint8 iv[512]; PullFilter *pf_decrypt = NULL, *pf_key; PGP_CFB *cfb = NULL; PGP_S2K s2k; PGP_PubKey *pk; /* first read public key part */ res = _pgp_read_public_key(pkt, &pk); if (res < 0) return res; /* * is secret key encrypted? */ GETBYTE(pkt, hide_type); if (hide_type == HIDE_SHA1 || hide_type == HIDE_CKSUM) { if (key == NULL) return PXE_PGP_NEED_SECRET_PSW; GETBYTE(pkt, cipher_algo); res = pgp_s2k_read(pkt, &s2k); if (res < 0) return res; res = pgp_s2k_process(&s2k, cipher_algo, key, key_len); if (res < 0) return res; bs = pgp_get_cipher_block_size(cipher_algo); if (bs == 0) { px_debug("unknown cipher algo=%d", cipher_algo); return PXE_PGP_UNSUPPORTED_CIPHER; } res = pullf_read_fixed(pkt, bs, iv); if (res < 0) return res; /* * create decrypt filter */ res = pgp_cfb_create(&cfb, cipher_algo, s2k.key, s2k.key_len, 0, iv); if (res < 0) return res; res = pullf_create(&pf_decrypt, &pgp_decrypt_filter, cfb, pkt); if (res < 0) return res; pf_key = pf_decrypt; } else if (hide_type == HIDE_CLEAR) { pf_key = pkt; } else { px_debug("unknown hide type"); return PXE_PGP_KEYPKT_CORRUPT; } /* read secret key */ switch (pk->algo) { case PGP_PUB_RSA_SIGN: case PGP_PUB_RSA_ENCRYPT: case PGP_PUB_RSA_ENCRYPT_SIGN: res = pgp_mpi_read(pkt, &pk->sec.rsa.d); if (res < 0) break; res = pgp_mpi_read(pkt, &pk->sec.rsa.p); if (res < 0) break; res = pgp_mpi_read(pkt, &pk->sec.rsa.q); if (res < 0) break; res = pgp_mpi_read(pkt, &pk->sec.rsa.u); if (res < 0) break; break; case PGP_PUB_ELG_ENCRYPT: res = pgp_mpi_read(pf_key, &pk->sec.elg.x); break; case PGP_PUB_DSA_SIGN: res = pgp_mpi_read(pf_key, &pk->sec.dsa.x); break; default: px_debug("unknown public algo: %d", pk->algo); res = PXE_PGP_KEYPKT_CORRUPT; } /* read checksum / sha1 */ if (res >= 0) { if (hide_type == HIDE_SHA1) res = check_key_sha1(pf_key, pk); else res = check_key_cksum(pf_key, pk); } if (res >= 0) res = pgp_expect_packet_end(pf_key); if (pf_decrypt) pullf_free(pf_decrypt); if (cfb) pgp_cfb_free(cfb); if (res < 0) pgp_key_free(pk); else *pk_p = pk; return res; }
int _pgp_read_public_key(PullFilter *pkt, PGP_PubKey **pk_p) { int res; PGP_PubKey *pk; res = pgp_key_alloc(&pk); if (res < 0) return res; /* get version */ GETBYTE(pkt, pk->ver); if (pk->ver != 4) { res = PXE_PGP_NOT_V4_KEYPKT; goto out; } /* read time */ res = pullf_read_fixed(pkt, 4, pk->time); if (res < 0) goto out; /* pubkey algorithm */ GETBYTE(pkt, pk->algo); switch (pk->algo) { case PGP_PUB_DSA_SIGN: res = pgp_mpi_read(pkt, &pk->pub.dsa.p); if (res < 0) break; res = pgp_mpi_read(pkt, &pk->pub.dsa.q); if (res < 0) break; res = pgp_mpi_read(pkt, &pk->pub.dsa.g); if (res < 0) break; res = pgp_mpi_read(pkt, &pk->pub.dsa.y); if (res < 0) break; res = calc_key_id(pk); break; case PGP_PUB_RSA_SIGN: case PGP_PUB_RSA_ENCRYPT: case PGP_PUB_RSA_ENCRYPT_SIGN: res = pgp_mpi_read(pkt, &pk->pub.rsa.n); if (res < 0) break; res = pgp_mpi_read(pkt, &pk->pub.rsa.e); if (res < 0) break; res = calc_key_id(pk); if (pk->algo != PGP_PUB_RSA_SIGN) pk->can_encrypt = 1; break; case PGP_PUB_ELG_ENCRYPT: res = pgp_mpi_read(pkt, &pk->pub.elg.p); if (res < 0) break; res = pgp_mpi_read(pkt, &pk->pub.elg.g); if (res < 0) break; res = pgp_mpi_read(pkt, &pk->pub.elg.y); if (res < 0) break; res = calc_key_id(pk); pk->can_encrypt = 1; break; default: px_debug("unknown public algo: %d", pk->algo); res = PXE_PGP_UNKNOWN_PUBALGO; } out: if (res < 0) pgp_key_free(pk); else *pk_p = pk; return res; }
// Party Actions [invite/leave/kick] bool CWorldServer::pakPartyActions( CPlayer* thisclient, CPacket* P ) { unsigned int action = GETBYTE((*P),0); CMap* map = MapList.Index[thisclient->Position->Map]; switch(action) { case 0x00://Invita a new party case 0x01://invite a existent party { UINT clientid = GETWORD((*P),1); if(thisclient->Party->party!=NULL) { //LMA: Refreshing Capacity if needed thisclient->Party->party->RefreshMax(); if(thisclient->Party->party->Members.size()>=thisclient->Party->party->Capacity) { SendSysMsg( thisclient, "Party is full" ); return true; } } CPlayer* otherclient = map->GetPlayerInMap( clientid );// have to be in same map if(otherclient==NULL) { BEGINPACKET( pak, 0x7d1 ); ADDBYTE ( pak, 0x00 );//No encontro el ID ADDWORD ( pak, clientid ); ADDBYTE ( pak, 0x00 ); thisclient->client->SendPacket( &pak ); return true; } if(otherclient->Party->party!=NULL) { BEGINPACKET( pak, 0x7d1 ); ADDBYTE ( pak, 0x01 );//No puede ser solicitado (ya tiene party) ADDWORD ( pak, clientid ); ADDBYTE ( pak, 0x00 ); thisclient->client->SendPacket( &pak ); return true; } if(abs(otherclient->Stats->Level-thisclient->Stats->Level)>(Config.Partygap+1)) { BEGINPACKET( pak, 0x7d1 ); ADDBYTE ( pak, 0x07 );//Level inapropiado ADDWORD ( pak, clientid ); ADDBYTE ( pak, 0x00 ); thisclient->client->SendPacket( &pak ); return true; } BEGINPACKET( pak, 0x7d0 ); ADDBYTE ( pak, action ); ADDWORD ( pak, thisclient->clientid ); ADDBYTE ( pak, 0x00 ); otherclient->client->SendPacket( &pak ); } break; case 0x02://Leave Party { if(thisclient->Party->party==NULL) return true; CParty* party = thisclient->Party->party; BEGINPACKET( pak, 0x7d2 ); ADDWORD ( pak, 0xff00 ); ADDDWORD ( pak, thisclient->CharInfo->charid ); bool pflag = false; if(!party->RemovePlayer( thisclient )) //if this player is not in this party return true; if(party->Members.size()>1) { for(UINT i=0;i<party->Members.size();i++) { CPlayer* thismember = party->Members.at(i); if(!pflag) { ADDDWORD( pak, thismember->CharInfo->charid ); if(thisclient->Party->IsMaster) thismember->Party->IsMaster = true; pflag = true; } thismember->client->SendPacket( &pak ); } } else { for(UINT i=0;i<party->Members.size();i++) { CPlayer* thismember = party->Members.at(i); BEGINPACKET( pak, 0x7d1 ); ADDBYTE ( pak, 0x05 ); ADDWORD ( pak, 0x0000 ); ADDWORD ( pak, 0x0000 ); thismember->client->SendPacket( &pak ); thismember->Party->party = NULL; thismember->Party->IsMaster = true; } RemoveParty( party ); delete party; } } break; case 0x03: //Tomiz: Give leader New Way { if(thisclient->Party->party==NULL) return true; unsigned int clientid = GETWORD((*P),1); if ( !thisclient->Party->IsMaster || clientid == thisclient->clientid ) return true; CPlayer* otherclient = GetClientByID( clientid ); if(otherclient==NULL) return true; BEGINPACKET(pak, 0x7d1); ADDBYTE(pak, 8); ADDWORD(pak, otherclient->clientid); ADDWORD(pak, 0); otherclient->Party->IsMaster = true; thisclient->Party->IsMaster = false; thisclient->Party->party->SendToMembers( &pak ); } break; case 0x81: //Kick from party { unsigned int charid = GETDWORD((*P),1); if(thisclient->Party->party==NULL) return true; if(!thisclient->Party->IsMaster || thisclient->CharInfo->charid==charid) return true; CParty* party = thisclient->Party->party; CPlayer* thismember = party->GetMemberByCharID( charid ); if(thismember==NULL) return true; BEGINPACKET( pak, 0x7d1 ); // Kicked from party message ADDBYTE ( pak, 0x80 ); ADDDWORD ( pak, thismember->CharInfo->charid ); thismember->client->SendPacket( &pak ); RESETPACKET( pak, 0x7d2 ); ADDWORD ( pak, 0xff00 ); ADDDWORD ( pak, thismember->CharInfo->charid ); bool pflag = false; if(!party->RemovePlayer( thismember )) //if this player is not in this party return true; if(party->Members.size()>1) { for(UINT i=0;i<party->Members.size();i++) { CPlayer* othermember = party->Members.at(i); if(!pflag) { ADDDWORD( pak, othermember->CharInfo->charid ); if(thismember->Party->IsMaster) othermember->Party->IsMaster = true; pflag = true; } othermember->client->SendPacket( &pak ); } } else { for(UINT i=0;i<party->Members.size();i++) { CPlayer* othermember = party->Members.at(i); BEGINPACKET( pak, 0x7d1 ); ADDBYTE ( pak, 0x05 ); ADDWORD ( pak, 0x0000 ); ADDWORD ( pak, 0x0000 ); othermember->client->SendPacket( &pak ); othermember->Party->party = NULL; othermember->Party->IsMaster = true; } RemoveParty( party ); delete party; } } break; default: Log(MSG_WARNING,"Party unknown action: %i", action); } return true; }