9
3

client.cpp 447 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "../common/debug.h"
  17. #include "../common/Log.h"
  18. #include <iostream>
  19. #include <iomanip>
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <math.h>
  24. #include <zlib.h>
  25. #include <assert.h>
  26. #include <algorithm>
  27. #include "Player.h"
  28. #include "Commands/Commands.h"
  29. #include "ClientPacketFunctions.h"
  30. #include "../common/ConfigReader.h"
  31. #include "Guilds/Guild.h"
  32. #include "Variables.h"
  33. #include "Rules/Rules.h"
  34. #include "Titles.h"
  35. #include "Chat/Chat.h"
  36. #include "SpellProcess.h"
  37. #include "Zone/ChestTrap.h"
  38. #include "../../common/GlobalHeaders.h"
  39. //#include "Quests.h"
  40. #ifdef WIN32
  41. #include <WinSock2.h>
  42. #include <windows.h>
  43. #define snprintf _snprintf
  44. #define vsnprintf _vsnprintf
  45. #define strncasecmp _strnicmp
  46. #define strcasecmp _stricmp
  47. #else
  48. #include <sys/socket.h>
  49. #ifdef FREEBSD
  50. #include <sys/types.h>
  51. #endif
  52. #include <netinet/in.h>
  53. #include <arpa/inet.h>
  54. #include <unistd.h>
  55. #endif
  56. #if defined(__GNUC__)
  57. #define _snprintf snprintf
  58. #endif
  59. #include "client.h"
  60. #include "../common/emu_opcodes.h"
  61. #include "../common/packet_dump.h"
  62. #include "WorldDatabase.h"
  63. #include "races.h"
  64. #include "classes.h"
  65. #include "LoginServer.h"
  66. #include "World.h"
  67. #include "../common/EQ2_Common_Structs.h"
  68. #include "net.h"
  69. #include "../common/MiscFunctions.h"
  70. #include "Skills.h"
  71. #include "LuaInterface.h"
  72. #include "Quests.h"
  73. #include "Collections/Collections.h"
  74. #include "Achievements/Achievements.h"
  75. #include "Traits/Traits.h"
  76. #include "Recipes/Recipe.h"
  77. #include "Tradeskills/Tradeskills.h"
  78. #include "AltAdvancement/AltAdvancement.h"
  79. #include "Bots/Bot.h"
  80. #include "VisualStates.h"
  81. extern WorldDatabase database;
  82. extern const char* ZONE_NAME;
  83. extern LoginServer loginserver;
  84. extern sint32 numclients;
  85. extern NetConnection net;
  86. extern Commands commands;
  87. extern ClientList client_list;
  88. extern ZoneList zone_list;
  89. extern ZoneAuth zone_auth;
  90. extern MasterItemList master_item_list;
  91. extern MasterSkillList master_skill_list;
  92. extern MasterSpellList master_spell_list;
  93. extern MasterTraitList master_trait_list;
  94. extern MasterQuestList master_quest_list;
  95. extern MasterFactionList master_faction_list;
  96. extern MasterRecipeList master_recipe_list;
  97. extern volatile bool RunLoops;
  98. extern ConfigReader configReader;
  99. extern LuaInterface* lua_interface;
  100. extern World world;
  101. extern Variables variables;
  102. extern Classes classes;
  103. extern Races races;
  104. extern GuildList guild_list;
  105. extern MasterCollectionList master_collection_list;
  106. extern MasterAchievementList master_achievement_list;
  107. extern RuleManager rule_manager;
  108. extern Chat chat;
  109. extern MasterAAList master_aa_list;
  110. extern MasterAAList master_tree_nodes;
  111. extern ChestTrapList chest_trap_list;
  112. extern MasterRecipeBookList master_recipebook_list;
  113. extern VisualStates visual_states;
  114. using namespace std;
  115. Client::Client(EQStream* ieqs) : underworld_cooldown_timer(5000), pos_update(125), quest_pos_timer(2000), lua_debug_timer(30000), delayTimer(500), transmuteID(0), temp_placement_timer(10), spawn_removal_timer(250) {
  116. eqs = ieqs;
  117. ip = eqs->GetrIP();
  118. port = ntohs(eqs->GetrPort());
  119. merchant_transaction = nullptr;
  120. mail_window.item = nullptr; // don't want this to be set(loose ptr) when using ResetSendMail to provide rest of the defaults
  121. ResetSendMail(false);
  122. timestamp_flag = 0;
  123. current_quest_id = 0;
  124. last_update_time = 0;
  125. quest_updates = false;
  126. //autobootup_timeout = new Timer(10000);
  127. //autobootup_timeout->Disable();
  128. CLE_keepalive_timer = new Timer(15000);
  129. connect = new Timer(1000);
  130. connect->Disable();
  131. zoneID = 0;
  132. account_name[0] = 0;
  133. character_id = 0;
  134. account_id = 0;
  135. pwaitingforbootup = 0;
  136. current_zone = 0;
  137. connected_to_zone = false;
  138. connected = false;
  139. camp_timer = 0;
  140. linkdead_timer = 0;
  141. client_zoning = false;
  142. zoning_id = 0;
  143. zoning_x = 0;
  144. zoning_y = 0;
  145. zoning_z = 0;
  146. zoning_instance_id = 0;
  147. player_pos_changed = false;
  148. ++numclients;
  149. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  150. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  151. remove_from_list = false;
  152. new_client_login = NewLoginState::LOGIN_NONE;
  153. UpdateWindowTitle(0);
  154. num_active_failures = 0;
  155. player = new Player();
  156. player->SetClient(this);
  157. combine_spawn = 0;
  158. lua_debug = false;
  159. ready_for_spawns = false;
  160. ready_for_updates = false;
  161. lua_debug_timer.Disable();
  162. transport_spawn = 0;
  163. MBuyBack.SetName("Client::MBuyBack");
  164. MDeletePlayer.SetName("Client::MDeletePlayer");
  165. MQuestPendingUpdates.SetName("Client::MQuestPendingUpdates");
  166. search_items = 0;
  167. version = 0;
  168. next_conversation_id = 0;
  169. pending_guild_invite.guild = 0;
  170. pending_guild_invite.invited_by = 0;
  171. m_recipeListSent = false;
  172. m_resurrect.SetName("Client::m_resurrect");
  173. current_rez.expire_timer = 0;
  174. current_rez.should_delete = true;
  175. pending_last_name = 0;
  176. should_target = false;
  177. initial_spawns_sent = false;
  178. MQuestTimers.SetName("Client::quest_timers");
  179. memset(&incoming_paperdoll, 0, sizeof(incoming_paperdoll));
  180. on_auto_mount = false;
  181. should_load_spells = true;
  182. spawnPlacementMode = ServerSpawnPlacementMode::DEFAULT;
  183. delayedLogin = false;
  184. delayedAccountID = 0;
  185. delayedAccessKey = 0;
  186. delayTimer.Disable();
  187. tempPlacementSpawn = nullptr;
  188. placement_unique_item_id = 0;
  189. SetHasOwnerOrEditAccess(false);
  190. temporary_transport_id = 0;
  191. rejoin_group_id = 0;
  192. lastRegionRemapTime = 0;
  193. regionDebugMessaging = false;
  194. client_reloading_zone = false;
  195. last_saved_timestamp = 0;
  196. MQueueStateCmds.SetName("Client::MQueueStateCmds");
  197. save_spell_state_timer.Disable();
  198. save_spell_state_time_bucket = 0;
  199. player_loading_complete = false;
  200. MItemDetails.SetName("Client::MItemDetails");
  201. MSpellDetails.SetName("Client::MSpellDetails");
  202. hasSentTempPlacementSpawn = false;
  203. spawn_removal_timer.Start();
  204. disable_save = false;
  205. SetZoningDestination(nullptr);
  206. underworld_cooldown_timer.Disable();
  207. player_pos_change_count = 0;
  208. pov_ghost_spawn_id = 0;
  209. recipe_orig_packet = nullptr;
  210. recipe_xor_packet = nullptr;
  211. recipe_packet_count = 0;
  212. recipe_orig_packet_size = 0;
  213. }
  214. Client::~Client() {
  215. RemoveClientFromZone();
  216. //let the stream factory know were done with this stream
  217. if (eqs) {
  218. eqs->Close();
  219. try {
  220. eqs->ReleaseFromUse();
  221. }
  222. catch (...) {}
  223. }
  224. eqs = NULL;
  225. //safe_delete(autobootup_timeout);
  226. safe_delete(linkdead_timer);
  227. vector<QueuedQuest*>::iterator itr;
  228. QueuedQuest* queued_quest = 0;
  229. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  230. queued_quest = *itr;
  231. safe_delete(queued_quest);
  232. }
  233. quest_queue.clear();
  234. vector<QuestRewardData*>::iterator rwd_itr;
  235. QuestRewardData* quest_rwd_data = 0;
  236. for (rwd_itr = quest_pending_reward.begin(); rwd_itr != quest_pending_reward.end(); rwd_itr++) {
  237. quest_rwd_data = *rwd_itr;
  238. safe_delete(quest_rwd_data);
  239. }
  240. quest_pending_reward.clear();
  241. safe_delete(CLE_keepalive_timer);
  242. safe_delete(connect);
  243. --numclients;
  244. UpdateWindowTitle(0);
  245. }
  246. void Client::RemoveClientFromZone() {
  247. if(player && player->GetZone())
  248. player->GetZone()->GetSpellProcess()->RemoveSpellTimersFromSpawn(player, true, false, true, true);
  249. if (GetTempPlacementSpawn() && GetCurrentZone()) {
  250. Spawn* tmp = GetTempPlacementSpawn();
  251. SetTempPlacementSpawn(nullptr);
  252. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  253. }
  254. if (current_zone && player) {
  255. if (player->GetGroupMemberInfo()) {
  256. TempRemoveGroup();
  257. }
  258. world.GetGroupManager()->ClearPendingInvite(player);
  259. }
  260. if (lua_interface)
  261. lua_interface->RemoveDebugClients(this);
  262. if (player)
  263. zone_list.RemoveClientFromMap(player->GetName(), this);
  264. safe_delete(camp_timer);
  265. safe_delete(search_items);
  266. safe_delete(current_rez.expire_timer);
  267. safe_delete(pending_last_name);
  268. safe_delete_array(incoming_paperdoll.image_bytes);
  269. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  270. player = nullptr;
  271. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  272. deque<BuyBackItem*>::iterator itr;
  273. MBuyBack.writelock(__FUNCTION__, __LINE__);
  274. for (itr = buy_back_items.begin(); itr != buy_back_items.end();) {
  275. safe_delete(*itr);
  276. itr = buy_back_items.erase(itr);
  277. }
  278. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  279. }
  280. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  281. if (eqs) {
  282. if (!eqs->CheckActive()) {
  283. client_list.Remove(this);
  284. eqs = 0;
  285. }
  286. }
  287. if (app && eqs && version > 0)
  288. eqs->EQ2QueuePacket(app, attemptedCombine);
  289. else {
  290. safe_delete(app);
  291. }
  292. }
  293. void Client::PopulateSkillMap() {
  294. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  295. if (app)
  296. QueuePacket(app);
  297. else {
  298. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  299. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  300. }
  301. }
  302. void Client::SendLoginInfo() {
  303. if(GetPlayer()->IsReturningFromLD())
  304. firstlogin = true;
  305. if (firstlogin) {
  306. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  307. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  308. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  309. PopulateSkillMap();
  310. // JA: Check client version and move player to valid zone if current client does not support last saved zone (loading SF client on DoV saved zone) IT CAN HAPPEN!
  311. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  312. }
  313. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  314. database.ToggleCharacterOnline(this, 1);
  315. int32 count = 0;
  316. if(!GetPlayer()->IsReturningFromLD())
  317. {
  318. count = database.LoadCharacterTitles(GetCharacterID(), player);
  319. if (count == 0) {
  320. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  321. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  322. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  323. }
  324. }
  325. if(!GetPlayer()->IsReturningFromLD())
  326. {
  327. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  328. if (count == 0)
  329. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  330. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  331. if (count == 0)
  332. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  333. }
  334. ClientPacketFunctions::SendLoginAccepted(this);
  335. ClientPacketFunctions::SendAbilities ( this );
  336. ClientPacketFunctions::SendCommandNamePacket(this);
  337. ClientPacketFunctions::SendQuickBarInit(this);
  338. // we only need to send the MOTD if it is the first time the person is logging in.
  339. if (firstlogin) {
  340. ClientPacketFunctions::SendMOTD(this);
  341. ClientPacketFunctions::SendCharacterMacros(this);
  342. zone_list.CheckFriendList(this);
  343. }
  344. if(!GetPlayer()->IsReturningFromLD())
  345. {
  346. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  347. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  348. {
  349. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  350. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  351. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  352. }
  353. GetPlayer()->item_list.SetMaxItemIndex();
  354. database.LoadPlayerFactions(this);
  355. database.LoadCharacterQuests(this);
  356. database.LoadCharacterQuestRewards(this);
  357. database.LoadPlayerMail(this);
  358. }
  359. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  360. SendQuestJournal(true, 0, false);
  361. if (version > 546) // right version? possibly not!
  362. master_aa_list.DisplayAA(this, 0, 3);
  363. if (version > 283)
  364. SendCollectionList();
  365. SendBiography();
  366. map<int32, Quest*>::iterator itr;
  367. Quest* quest = 0;
  368. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  369. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  370. quest = itr->second;
  371. if (quest->IsTracked()) {
  372. quest->SetTracked(false);
  373. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  374. quest->SetTracked(true);
  375. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  376. }
  377. }
  378. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  379. // SendAchievementsList();
  380. /*Guild* guild = player->GetGuild();
  381. if (guild) {
  382. guild->UpdateGuildMemberInfo(GetPlayer());
  383. if (firstlogin)
  384. guild->SendGuildMOTD(this);
  385. guild->SendGuildUpdate(this);
  386. guild->SendGuildMember(GetPlayer(), firstlogin);
  387. guild->SendGuildEventList(this);
  388. guild->SendGuildBankEventList(this);
  389. guild->SendAllGuildEvents(this);
  390. guild->SendGuildMemberList(this);
  391. }*/
  392. if (version > 283) {
  393. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  394. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  395. if (outapp) {
  396. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  397. //DumpPacket(outapp);
  398. QueuePacket(outapp);
  399. }
  400. }
  401. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  402. ClientPacketFunctions::SendCommandList(this);
  403. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  404. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  405. ClientPacketFunctions::SendInstanceList(this);
  406. SendZoneInfo();
  407. /*Spell* spell = 0;
  408. vector<QuickBarItem*>::iterator itr;
  409. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  410. if((*itr)->type == 1){
  411. spell = master_spell_list.GetSpell((*itr)->id);
  412. if(spell)
  413. QueuePacket(spell->serialize(this, false, 0x20));
  414. }
  415. }*/
  416. }
  417. void Client::SendPlayerDeathWindow()
  418. {
  419. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  420. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  421. vector<RevivePoint*>::iterator itr;
  422. if (results && results->size() > 0)
  423. {
  424. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  425. if (packet)
  426. {
  427. packet->setArrayLengthByName("location_count", results->size());
  428. RevivePoint* point = 0;
  429. int32 i = 0;
  430. for (itr = results->begin(); itr != results->end(); itr++, i++)
  431. {
  432. point = *itr;
  433. if (point)
  434. {
  435. packet->setArrayDataByName("location_id", point->id, i);
  436. //zone_name = database.GetZoneName(point->zone_id);
  437. string zone_name = database.GetZoneDescription(point->zone_id);
  438. if (zone_name.length() > 0)
  439. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  440. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  441. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  442. }
  443. if (point->id == 0xFFFFFFFF)//tmp location
  444. safe_delete(point);
  445. }
  446. #if EQDEBUG >= 3
  447. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  448. packet->PrintPacket();
  449. #endif
  450. EQ2Packet* outapp = packet->serialize();
  451. QueuePacket(outapp);
  452. safe_delete(packet);
  453. }
  454. // done with the revive points so lets free up the pointer
  455. safe_delete(results);
  456. }
  457. }
  458. void Client::DisplayDeadWindow()
  459. {
  460. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  461. player->SetHP(0);
  462. player->SetPower(0);
  463. GetCurrentZone()->TriggerCharSheetTimer();
  464. if(GetVersion() <= 546) {
  465. ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 1);
  466. ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 1);
  467. }
  468. else {
  469. ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 1);
  470. ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 1);
  471. }
  472. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  473. if (packet)
  474. {
  475. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  476. QueuePacket(packet->serialize());
  477. safe_delete(packet);
  478. }
  479. SendPlayerDeathWindow();
  480. }
  481. void Client::HandlePlayerRevive(int32 point_id)
  482. {
  483. if(GetVersion() <= 546) {
  484. ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 0);
  485. ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 0);
  486. }
  487. else {
  488. ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 0);
  489. ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 0);
  490. }
  491. SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
  492. PacketStruct* packet = configReader.getStruct("WS_Resurrected", GetVersion());
  493. if (packet)
  494. {
  495. QueuePacket(packet->serialize());
  496. safe_delete(packet);
  497. }
  498. float origX, origY, origZ, origHeading = 0.0f;
  499. origX = player->GetX();
  500. origY = player->GetY();
  501. origZ = player->GetZ();
  502. origHeading = player->GetHeading();
  503. ZoneServer* originalZone = GetCurrentZone();
  504. int32 origGridID = GetPlayer()->GetLocation();
  505. float x, y, z, heading;
  506. RevivePoint* revive_point = 0;
  507. if (point_id != 0xFFFFFFFF)
  508. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  509. string zone_desc;
  510. const char* location_name = "Unknown";
  511. player->SetAlive(true);
  512. player->SetResurrecting(true);
  513. player->SetHP(player->GetTotalHP());
  514. player->SetPower(player->GetTotalPower());
  515. //revive at zone safe coords
  516. if (!revive_point)
  517. {
  518. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  519. x = GetCurrentZone()->GetSafeX();
  520. y = GetCurrentZone()->GetSafeY();
  521. z = GetCurrentZone()->GetSafeZ();
  522. heading = GetCurrentZone()->GetSafeHeading();
  523. zone_desc = GetCurrentZone()->GetZoneDescription();
  524. location_name = "Zone Safe Point";
  525. Zone(GetCurrentZone()->GetZoneName(), false);
  526. }
  527. else
  528. {
  529. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  530. x = revive_point->x;
  531. y = revive_point->y;
  532. z = revive_point->z;
  533. heading = revive_point->heading;
  534. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  535. location_name = revive_point->location_name.c_str();
  536. Zone(GetCurrentZone()->GetZoneName(), false);
  537. }
  538. player->SetX(x);
  539. player->SetY(y);
  540. player->SetZ(z);
  541. player->SetHeading(heading);
  542. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  543. zone_desc.c_str(),
  544. player->GetX(),
  545. player->GetY(),
  546. player->GetZ(),
  547. player->GetHeading(),
  548. player->GetHP(),
  549. player->GetPower(),
  550. location_name);
  551. //player->ClearEverything();
  552. Save();
  553. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  554. {
  555. string zone_name = database.GetZoneName(revive_point->zone_id);
  556. if (zone_name.length() == 0)
  557. {
  558. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  559. x = GetCurrentZone()->GetSafeX();
  560. y = GetCurrentZone()->GetSafeY();
  561. z = GetCurrentZone()->GetSafeZ();
  562. heading = GetCurrentZone()->GetSafeHeading();
  563. location_name = "Zone Safe Point";
  564. }
  565. else
  566. {
  567. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  568. location_name = revive_point->location_name.c_str();
  569. //player->ClearEverything();
  570. Save();
  571. Zone(zone_name.c_str(), false);
  572. }
  573. }
  574. zone_desc = GetCurrentZone()->GetZoneDescription();
  575. Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  576. player->SetSpawnType(4);
  577. if (version > 283) {
  578. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  579. if (packet)
  580. {
  581. QueuePacket(packet->serialize());
  582. safe_delete(packet);
  583. }
  584. }
  585. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  586. if (packet)
  587. {
  588. packet->setDataByName("x", x);
  589. packet->setDataByName("y", y);
  590. packet->setDataByName("z", z);
  591. QueuePacket(packet->serialize());
  592. safe_delete(packet);
  593. }
  594. SendControlGhost();
  595. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  596. if (packet)
  597. {
  598. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  599. QueuePacket(packet->serialize());
  600. safe_delete(packet);
  601. }
  602. if(rule_manager.GetGlobalRule(R_Combat, EnableSpiritShards)->GetBool())
  603. {
  604. NPC* shard = player->InstantiateSpiritShard(origX, origY, origZ, origHeading, origGridID, originalZone);
  605. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  606. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_PRESPAWN);
  607. originalZone->RemoveSpawn(player, false, true, true, true, true);
  608. originalZone->AddSpawn(shard);
  609. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  610. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_SPAWN);
  611. }
  612. m_resurrect.writelock(__FUNCTION__, __LINE__);
  613. if (current_rez.active)
  614. current_rez.should_delete = true;
  615. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  616. }
  617. void Client::SendControlGhost(int32 send_id, int8 unknown2) {
  618. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  619. if (packet) {
  620. packet->setDataByName("spawn_id", send_id);
  621. packet->setDataByName("speed", GetPlayer()->GetSpeed());
  622. packet->setDataByName("size", 0.51);
  623. packet->setDataByName("unknown2", unknown2);
  624. packet->setDataByName("air_speed", player->GetAirSpeed());
  625. EQ2Packet* app = packet->serialize();
  626. QueuePacket(app);
  627. safe_delete(packet);
  628. }
  629. }
  630. void Client::SendCharInfo() {
  631. EQ2Packet* app;
  632. player->SetEquippedItemAppearances();
  633. ClientPacketFunctions::SendCharacterData(this);
  634. SendCharPOVGhost();
  635. SendControlGhost(player->GetIDWithPlayerSpawn(player), 255);
  636. //sending bad spawn packet?
  637. //SendAchievementsList();
  638. //if (version > 546)
  639. //ClientPacketFunctions::SendHousingList(this);
  640. ClientPacketFunctions::SendCharacterSheet(this);
  641. ClientPacketFunctions::SendTraitList(this);// moved from below
  642. ClientPacketFunctions::SendAbilities(this);
  643. ClientPacketFunctions::SendSkillBook(this);
  644. if (!IsReloadingZone() && !player->IsResurrecting() && GetVersion() >= 546) {
  645. ClientPacketFunctions::SendUpdateSpellBook(this);
  646. }
  647. else {
  648. player->SetResurrecting(false);
  649. }
  650. GetCurrentZone()->AddSpawn(player);
  651. if(IsReloadingZone() && (zoning_x || zoning_y || zoning_z)) {
  652. GetPlayer()->SetX(zoning_x);
  653. GetPlayer()->SetY(zoning_y);
  654. GetPlayer()->SetZ(zoning_z);
  655. GetPlayer()->SetHeading(zoning_h);
  656. EQ2Packet* packet = GetPlayer()->Move(zoning_x, zoning_y, zoning_z, GetVersion(), zoning_h);
  657. QueuePacket(packet);
  658. }
  659. //SendCollectionList();
  660. Guild* guild = player->GetGuild();
  661. if (guild)
  662. guild->GuildMemberLogin(this, firstlogin);
  663. app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  664. if (app) {
  665. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  666. //DumpPacket(app);
  667. QueuePacket(app);
  668. }
  669. app = player->GetEquipmentList()->serialize(GetVersion(), player);
  670. if (app) {
  671. QueuePacket(app);
  672. }
  673. app = player->GetAppearanceEquipmentList()->serialize(GetVersion(), player);
  674. if (app) {
  675. QueuePacket(app);
  676. }
  677. vector<Item*>* items = player->GetPlayerItemList()->GetItemsFromBagID(-3); // bank items
  678. if (items && items->size() > 0) {
  679. for (int32 i = 0; i < items->size(); i++) {
  680. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  681. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  682. //DumpPacket(outapp);
  683. QueuePacket(outapp);
  684. }
  685. }
  686. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  687. QueuePacket(app);
  688. safe_delete(items);
  689. items = player->GetPlayerItemList()->GetItemsFromBagID(-4); //shared bank items
  690. if (items && items->size() > 0) {
  691. for (int32 i = 0; i < items->size(); i++)
  692. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  693. }
  694. safe_delete(items);
  695. if (version > 283) {
  696. SendTitleUpdate();
  697. }
  698. GetPlayer()->UpdateWeapons();
  699. if(!GetPlayer()->IsReturningFromLD()) {
  700. database.LoadBuyBacks(this);
  701. }
  702. if (version > 546)
  703. master_aa_list.DisplayAA(this, 0, 0);
  704. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  705. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  706. string zone_motd_send = "Zone MOTD: " + zone_motd;
  707. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  708. }
  709. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  710. if (zone_script && lua_interface)
  711. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  712. this->client_zoning = false;
  713. this->zoning_id = 0;
  714. this->zoning_instance_id = 0;
  715. SetZoningDestination(nullptr);
  716. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  717. GetCurrentZone()->AddDamagedSpawn(player);
  718. if (firstlogin)
  719. firstlogin = false;
  720. player->ClearProcs();
  721. items = player->GetEquippedItemList();
  722. if (items && items->size() > 0) {
  723. for (int32 i = 0; i < items->size(); i++) {
  724. Item* item = items->at(i);
  725. if (item && item->GetItemScript() && lua_interface)
  726. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  727. }
  728. }
  729. //Allow this player to change their last name if they meet the level requirement
  730. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  731. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  732. safe_delete(items);
  733. if (!player->Alive())
  734. DisplayDeadWindow();
  735. ClientPacketFunctions::SendLocalizedTextMessage(this);
  736. if (GetCurrentZone()->GetInstanceID())
  737. {
  738. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  739. if (ph) {
  740. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  741. string name = string(GetPlayer()->GetName());
  742. if (name.compare(ph->player_name) == 0)
  743. SetHasOwnerOrEditAccess(true);
  744. }
  745. }
  746. bool groupMentor = false;
  747. GetPlayer()->group_id = rejoin_group_id;
  748. if(!world.RejoinGroup(this, rejoin_group_id))
  749. GetPlayer()->group_id = 0;
  750. else
  751. {
  752. Entity* ent = world.GetGroupManager()->IsPlayerInGroup(rejoin_group_id, GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id);
  753. if(ent && ent->IsPlayer())
  754. {
  755. GetPlayer()->SetMentorStats(ent->GetLevel(), ent->GetID(), false);
  756. groupMentor = true;
  757. }
  758. }
  759. if(!groupMentor)
  760. GetPlayer()->SetMentorStats(GetPlayer()->GetLevel(), 0, false);
  761. if(!GetPlayer()->IsReturningFromLD()) {
  762. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_MAINTAINEDEFFECTS);
  763. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_SPELLEFFECTS);
  764. }
  765. else {
  766. Spawn* pet_spawn = nullptr;
  767. if(GetPlayer()->GetPet())
  768. pet_spawn = GetPlayer()->GetPet();
  769. else if(GetPlayer()->GetCharmedPet())
  770. pet_spawn = GetPlayer()->GetCharmedPet();
  771. else if(GetPlayer()->GetCosmeticPet())
  772. pet_spawn = GetPlayer()->GetCosmeticPet();
  773. else if(GetPlayer()->GetDeityPet())
  774. pet_spawn = GetPlayer()->GetDeityPet();
  775. if(pet_spawn) {
  776. GetPlayer()->GetInfoStruct()->set_pet_id(GetPlayer()->GetIDWithPlayerSpawn(pet_spawn));
  777. }
  778. }
  779. GetPlayer()->SetSaveSpellEffects(false);
  780. GetPlayer()->SetCharSheetChanged(true);
  781. GetPlayer()->SetReturningFromLD(false);
  782. }
  783. void Client::SendZoneSpawns() {
  784. //Allows us to place spawns almost anywhere
  785. if (version > 283) {
  786. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  787. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  788. QueuePacket(app);
  789. }
  790. ClientPacketFunctions::SendSkillSlotMappings(this);
  791. ClientPacketFunctions::SendGameWorldTime(this);
  792. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  793. }
  794. void Client::SendCharPOVGhost() {
  795. bool use_ghost_pov = false;
  796. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  797. int32 ghost_id = 0;
  798. if (set_pov) {
  799. if(pov_ghost_spawn_id) {
  800. Spawn* spawn = GetCurrentZone()->GetSpawnByID(pov_ghost_spawn_id);
  801. ghost_id = player->GetIDWithPlayerSpawn(spawn);
  802. if(spawn) {
  803. use_ghost_pov = true;
  804. }
  805. }
  806. if(use_ghost_pov) {
  807. set_pov->setDataByName("spawn_id", ghost_id);
  808. }
  809. else {
  810. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  811. }
  812. EQ2Packet* app_pov = set_pov->serialize();
  813. QueuePacket(app_pov);
  814. safe_delete(set_pov);
  815. }
  816. }
  817. void Client::SendZoneInfo() {
  818. ZoneServer* zone = GetCurrentZone();
  819. if (zone) {
  820. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  821. QueuePacket(packet);
  822. if (version > 283) {
  823. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  824. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  825. #if EQDEBUG >= 9
  826. fog_packet->PrintPacket();
  827. #endif
  828. if (fog_packet) {
  829. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  830. QueuePacket(fog_packet->serialize());
  831. safe_delete(fog_packet);
  832. }
  833. zone->SendFlightPathsPackets(this);
  834. }
  835. }
  836. /*
  837. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  838. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  839. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  840. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  841. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  842. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  843. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  844. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  845. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  846. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  847. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  848. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  849. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  850. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  851. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  852. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  853. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  854. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  855. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  856. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  857. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  858. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  859. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  860. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  861. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  862. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  863. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  864. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  865. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  866. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  867. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  868. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  869. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  870. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  871. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  872. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
  873. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  874. QueuePacket(appA);
  875. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  876. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  877. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  878. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  879. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  880. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  881. QueuePacket(appB);
  882. */
  883. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  884. SendFriendList();
  885. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  886. SendIgnoreList();
  887. }
  888. void Client::SendDefaultGroupOptions() {
  889. /*
  890. 0 - loot method
  891. 1 - loot items rarity
  892. 2 - Auto split coin
  893. 4 - default yell method
  894. 6 - group autolock
  895. 7 - solo autolock
  896. */
  897. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  898. if (default_options) {
  899. default_options->setDataByName("loot_method", GetPlayer()->GetInfoStruct()->get_group_loot_method());
  900. default_options->setDataByName("loot_items_rarity", GetPlayer()->GetInfoStruct()->get_group_loot_items_rarity());
  901. default_options->setDataByName("auto_split_coin", GetPlayer()->GetInfoStruct()->get_group_auto_split());
  902. default_options->setDataByName("default_yell_method", GetPlayer()->GetInfoStruct()->get_group_default_yell());
  903. default_options->setDataByName("group_autolock", GetPlayer()->GetInfoStruct()->get_group_autolock());
  904. default_options->setDataByName("default_group_lock_method", GetPlayer()->GetInfoStruct()->get_group_lock_method());
  905. if(GetVersion() > 561) {
  906. default_options->setDataByName("solo_autolock", GetPlayer()->GetInfoStruct()->get_group_solo_autolock());
  907. default_options->setDataByName("auto_loot_method", GetPlayer()->GetInfoStruct()->get_group_auto_loot_method());
  908. }
  909. EQ2Packet* app7 = default_options->serialize();
  910. QueuePacket(app7);
  911. safe_delete(default_options);
  912. }
  913. }
  914. bool Client::HandlePacket(EQApplicationPacket* app) {
  915. bool ret = true;
  916. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  917. //DumpPacket(app);
  918. #if EQDEBUG >= 9
  919. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  920. DumpPacket(app, true);
  921. #endif
  922. EmuOpcode opcode = app->GetOpcode();
  923. #if EQDEBUG >= 9
  924. const char* name = app->GetOpcodeName();
  925. if (name)
  926. cout << name;
  927. else
  928. cout << "Unknown";
  929. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  930. DumpPacket(app);
  931. #endif
  932. //if (opcode != OP_UpdatePositionMsg) {
  933. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  934. //}
  935. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  936. {
  937. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  938. }
  939. switch (opcode) {
  940. case _maxEmuOpcode:
  941. break;
  942. case OP_LoginByNumRequestMsg: {
  943. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  944. PacketStruct* request;
  945. request = configReader.getStruct("LoginByNumRequest", 1);
  946. if (request) {
  947. if(request->LoadPacketData(app->pBuffer, app->size)) {
  948. // test the original location of Version for clients older than 1212
  949. version = request->getType_int16_ByName("version");
  950. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  951. // must be new client data version method, re-fetch the packet
  952. safe_delete(request);
  953. request = configReader.getStruct("LoginByNumRequest", 1208);
  954. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  955. // Xinux suggests using an INT16 here. Our first new version = 57000
  956. version = request->getType_int16_ByName("version");
  957. }
  958. else {
  959. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  960. break;
  961. }
  962. }
  963. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  964. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  965. ClientPacketFunctions::SendLoginDenied(this);
  966. /* reset version and protect server from trying to send packets out to a bad client
  967. ** cause of Dec 6th/Dec 7th 2023 crash
  968. ** Client::MakeSpawnChangePacket
  969. ** int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd); <-- crashes pulling opcode with bad version
  970. */
  971. version = 546;
  972. ready_for_updates = false;
  973. ready_for_spawns = false;
  974. return false;
  975. }
  976. int32 account_id = request->getType_int32_ByName("account_id");
  977. int32 access_code = request->getType_int32_ByName("access_code");
  978. if (!HandleNewLogin(account_id, access_code))
  979. return false;
  980. }
  981. }
  982. safe_delete(request);
  983. break;
  984. }
  985. case OP_DefaultGroupOptionsMsg: {
  986. PacketStruct* packet = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  987. if (packet) {
  988. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  989. packet->PrintPacket();
  990. int8 loot_method = packet->getType_int8_ByName("loot_method");
  991. int8 loot_items_rarity = packet->getType_int8_ByName("loot_items_rarity");
  992. int8 auto_split_coin = packet->getType_int8_ByName("auto_split_coin");
  993. int8 default_yell_method = packet->getType_int8_ByName("default_yell_method");
  994. int8 autolock = packet->getType_int8_ByName("group_autolock");
  995. int8 group_lock_method = packet->getType_int8_ByName("default_group_lock_method");
  996. int8 solo_autolock = packet->getType_int8_ByName("solo_autolock");
  997. int8 auto_loot_method = 0;
  998. if (GetVersion() > 561) {
  999. auto_loot_method = packet->getType_int8_ByName("auto_loot_method");
  1000. if (auto_loot_method > AutoLootMode::METHOD_DECLINE)
  1001. auto_loot_method = AutoLootMode::METHOD_DECLINE;
  1002. }
  1003. GetPlayer()->GetInfoStruct()->set_group_loot_method(loot_method);
  1004. GetPlayer()->GetInfoStruct()->set_group_loot_items_rarity(loot_items_rarity);
  1005. GetPlayer()->GetInfoStruct()->set_group_auto_split(auto_split_coin);
  1006. GetPlayer()->GetInfoStruct()->set_group_default_yell(default_yell_method);
  1007. GetPlayer()->GetInfoStruct()->set_group_autolock(autolock);
  1008. GetPlayer()->GetInfoStruct()->set_group_lock_method(group_lock_method);
  1009. GetPlayer()->GetInfoStruct()->set_group_solo_autolock(solo_autolock);
  1010. GetPlayer()->GetInfoStruct()->set_group_auto_loot_method(auto_loot_method);
  1011. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTMETHOD, (char*)std::to_string(loot_method).c_str());
  1012. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTITEMRARITY, (char*)std::to_string(loot_items_rarity).c_str());
  1013. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOSPLIT, (char*)std::to_string(auto_split_coin).c_str());
  1014. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPDEFAULTYELL, (char*)std::to_string(default_yell_method).c_str());
  1015. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOLOCK, (char*)std::to_string(autolock).c_str());
  1016. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOCKMETHOD, (char*)std::to_string(group_lock_method).c_str());
  1017. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPSOLOAUTOLOCK, (char*)std::to_string(solo_autolock).c_str());
  1018. database.insertCharacterProperty(this, CHAR_PROPERTY_AUTOLOOTMETHOD, (char*)std::to_string(auto_loot_method).c_str());
  1019. if (this->GetPlayer()->GetGroupMemberInfo() && this->GetPlayer()->GetGroupMemberInfo()->leader)
  1020. {
  1021. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  1022. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  1023. if (group)
  1024. {
  1025. GroupOptions goptions;
  1026. goptions.loot_method = loot_method;
  1027. goptions.loot_items_rarity = loot_items_rarity;
  1028. goptions.auto_split = auto_split_coin;
  1029. goptions.default_yell = default_yell_method;
  1030. goptions.group_autolock = autolock;
  1031. goptions.solo_autolock = solo_autolock;
  1032. goptions.auto_loot_method = auto_loot_method;
  1033. group->SetDefaultGroupOptions(&goptions);
  1034. }
  1035. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  1036. }
  1037. }
  1038. safe_delete(packet);
  1039. }
  1040. break;
  1041. }
  1042. case OP_MapRequest: {
  1043. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  1044. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  1045. if (packet && app->size > 2 && GetCurrentZone()) {
  1046. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1047. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  1048. if (fog_packet) {
  1049. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  1050. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  1051. fog_packet->setDataByName("unknown1", 1);
  1052. fog_packet->setDataByName("unknown3", 1);
  1053. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1054. //fog_packet->PrintPacket();
  1055. QueuePacket(fog_packet->serialize());
  1056. safe_delete(fog_packet);
  1057. }
  1058. }
  1059. safe_delete(packet);
  1060. }
  1061. break;
  1062. }
  1063. case OP_RequestCampMsg: {
  1064. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  1065. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  1066. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1067. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1068. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1069. request->getType_int8_ByName("quit"),
  1070. request->getType_int8_ByName("camp_desktop"),
  1071. request->getType_int16_ByName("camp_char_select"),
  1072. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1073. //DumpPacket(app->pBuffer, app->size);
  1074. //request->PrintPacket();
  1075. if (!camp_timer) {
  1076. int16 camp_time = 20; // default if rule cannot be found
  1077. if (GetAdminStatus() >= 100)
  1078. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  1079. else
  1080. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  1081. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  1082. if (response) {
  1083. bool disconnect = false;
  1084. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  1085. // Command: /camp desktop
  1086. // Command: /quit
  1087. response->setDataByName("camp_desktop", 1);
  1088. disconnect = true;
  1089. }
  1090. else {
  1091. // Command: /camp
  1092. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  1093. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  1094. response->setDataByName("seconds", camp_time);
  1095. }
  1096. camp_timer = new Timer(camp_time * 1000);
  1097. camp_timer->Enable();
  1098. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  1099. // /camp {char_name}
  1100. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  1101. }
  1102. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  1103. // /camp (go back to char selection screen)
  1104. response->setDataByName("char_name", " ");
  1105. response->setDataByName("camp_char_select", 1);
  1106. }
  1107. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1108. response->getType_int8_ByName("seconds"),
  1109. response->getType_int8_ByName("camp_desktop"),
  1110. response->getType_int8_ByName("camp_char_select"),
  1111. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1112. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  1113. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  1114. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  1115. //response->PrintPacket();
  1116. QueuePacket(response->serialize());
  1117. safe_delete(response);
  1118. if (disconnect)
  1119. Disconnect();
  1120. }
  1121. }
  1122. }
  1123. safe_delete(request);
  1124. break;
  1125. }
  1126. case OP_StoodMsg: {
  1127. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  1128. if (camp_timer)
  1129. {
  1130. // JA: clear camping flag
  1131. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1132. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1133. safe_delete(camp_timer);
  1134. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1135. QueuePacket(outapp);
  1136. }
  1137. player->SetTempVisualState(0);
  1138. break;
  1139. }
  1140. case OP_StandMsg: {
  1141. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  1142. if (camp_timer)
  1143. {
  1144. // JA: clear camping flag
  1145. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1146. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1147. safe_delete(camp_timer);
  1148. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1149. QueuePacket(outapp);
  1150. }
  1151. player->SetTempVisualState(539);
  1152. break;
  1153. }
  1154. case OP_SitMsg: {
  1155. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  1156. player->SetTempVisualState(538);
  1157. break;
  1158. }
  1159. case OP_SatMsg: {
  1160. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  1161. player->SetTempVisualState(540);
  1162. break;
  1163. }
  1164. case OP_QuestJournalOpenMsg:
  1165. case OP_QuestJournalInspectMsg: {
  1166. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  1167. if (app->size < sizeof(int32))
  1168. break;
  1169. int32 quest_id = 0;
  1170. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  1171. GetPlayer()->SendQuest(quest_id);
  1172. break;
  1173. }
  1174. case OP_QuestJournalSetVisibleMsg: {
  1175. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  1176. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  1177. if (packet) {
  1178. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1179. int32 quest_id = packet->getType_int32_ByName("quest_id");
  1180. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  1181. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  1182. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  1183. if (player_quests) {
  1184. if (player_quests->count(quest_id) > 0)
  1185. player_quests->at(quest_id)->SetHidden(hidden);
  1186. else
  1187. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1188. }
  1189. else
  1190. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1191. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  1192. }
  1193. safe_delete(packet);
  1194. }
  1195. break;
  1196. }
  1197. case OP_MacroUpdateMsg: {
  1198. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1199. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1200. if (macro_update) {
  1201. if(macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1202. vector<string>* update = new vector<string>;
  1203. int8 number = macro_update->getType_int8_ByName("number");
  1204. int16 icon = macro_update->getType_int16_ByName("icon");
  1205. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1206. int8 count = macro_update->getType_int8_ByName("macro_count");
  1207. if (GetVersion() <= 283) {
  1208. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1209. }
  1210. else {
  1211. for (int8 i = 0; i < count; i++) {
  1212. char tmp_command[15] = { 0 };
  1213. sprintf(tmp_command, "command_%i", i);
  1214. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1215. }
  1216. }
  1217. if (name.length() == 0)
  1218. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1219. else
  1220. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1221. safe_delete(update);
  1222. }
  1223. safe_delete(macro_update);
  1224. }
  1225. break;
  1226. }
  1227. case OP_DialogSelectMsg: {
  1228. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1229. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1230. if (packet) {
  1231. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1232. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1233. int32 response_index = packet->getType_int32_ByName("response");
  1234. HandleDialogSelectMsg(conversation_id, response_index);
  1235. }
  1236. }
  1237. safe_delete(packet);
  1238. break;
  1239. }
  1240. case OP_CancelMoveObjectModeMsg: {
  1241. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1242. if (GetTempPlacementSpawn())
  1243. {
  1244. Spawn* tmp = GetTempPlacementSpawn();
  1245. SetTempPlacementSpawn(nullptr);
  1246. SetPlacementUniqueItemID(0);
  1247. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  1248. break; // break out early if we are tied to a temp spawn
  1249. }
  1250. // if we are moving some other object? other use-cases not covered
  1251. break;
  1252. }
  1253. case OP_PositionMoveableObject: {
  1254. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1255. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1256. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1257. Spawn* spawn = 0;
  1258. if (GetTempPlacementSpawn())
  1259. spawn = GetTempPlacementSpawn();
  1260. else
  1261. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1262. if (!spawn) {
  1263. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1264. break;
  1265. }
  1266. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1267. {
  1268. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1269. break;
  1270. }
  1271. int32 uniqueID = spawn->GetPickupUniqueItemID();
  1272. if(uniqueID) {
  1273. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  1274. if(uniqueItem && uniqueItem->CheckFlag2(HOUSE_LORE) && GetCurrentZone()->HouseItemSpawnExists(uniqueItem->details.item_id)) {
  1275. Message(CHANNEL_COLOR_RED, "Item %s is house lore and you cannot place another.", uniqueItem->name.c_str());
  1276. break;
  1277. }
  1278. }
  1279. // handles instantiation logic + adding to zone of a new house object
  1280. PopulateHouseSpawn(place_object);
  1281. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1282. char query[256];
  1283. switch (GetSpawnPlacementMode())
  1284. {
  1285. case ServerSpawnPlacementMode::OPEN_HEADING:
  1286. {
  1287. if (spawn && spawn->IsWidget())
  1288. {
  1289. Widget* widget = (Widget*)spawn;
  1290. widget->SetOpenHeading(newHeading);
  1291. widget->SetIncludeHeading(true);
  1292. spawn->position_changed = true;
  1293. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1294. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1295. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1296. }
  1297. else
  1298. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1299. break;
  1300. }
  1301. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1302. {
  1303. if (spawn && spawn->IsWidget())
  1304. {
  1305. Widget* widget = (Widget*)spawn;
  1306. widget->SetClosedHeading(newHeading);
  1307. widget->SetIncludeHeading(true);
  1308. spawn->position_changed = true;
  1309. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1310. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1311. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1312. if (spawn->GetSpawnLocationID())
  1313. {
  1314. Query query;
  1315. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1316. }
  1317. }
  1318. else
  1319. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1320. break;
  1321. }
  1322. default:
  1323. {
  1324. spawn->SetX(place_object->getType_float_ByName("x"));
  1325. spawn->SetY(place_object->getType_float_ByName("y"));
  1326. spawn->SetZ(place_object->getType_float_ByName("z"));
  1327. spawn->SetHeading(newHeading);
  1328. spawn->SetSpawnOrigX(spawn->GetX());
  1329. spawn->SetSpawnOrigY(spawn->GetY());
  1330. spawn->SetSpawnOrigZ(spawn->GetZ());
  1331. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1332. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1333. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1334. else if (spawn->GetSpawnLocationID() > 0)
  1335. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1336. }
  1337. }
  1338. PopulateHouseSpawnFinalize();
  1339. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1340. }
  1341. safe_delete(place_object);
  1342. break;
  1343. }
  1344. case OP_CampAbortedMsg: {
  1345. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1346. if (camp_timer)
  1347. {
  1348. // JA: clear camping flag
  1349. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1350. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1351. safe_delete(camp_timer);
  1352. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1353. QueuePacket(outapp);
  1354. }
  1355. break;
  1356. }
  1357. case OP_DoneLoadingUIResourcesMsg: {
  1358. if(GetVersion() < 546) {
  1359. ClientPacketFunctions::SendUpdateSpellBook(this);
  1360. }
  1361. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1362. QueuePacket(app);
  1363. if(!player_loading_complete)
  1364. {
  1365. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  1366. if (zone_script && lua_interface)
  1367. lua_interface->RunZoneScript(zone_script, "player_loadcomplete", GetCurrentZone(), GetPlayer());
  1368. player_loading_complete = true;
  1369. }
  1370. break;
  1371. }
  1372. case OP_DoneLoadingZoneResourcesMsg: {
  1373. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1374. SendZoneSpawns();
  1375. break;
  1376. }
  1377. case OP_DefaultGroupOptionsRequestMsg: {
  1378. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1379. SendDefaultGroupOptions();
  1380. break;
  1381. }
  1382. case OP_DoneLoadingEntityResourcesMsg: {
  1383. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1384. if (!IsReadyForSpawns())
  1385. SetReadyForSpawns(true);
  1386. player->CalculateApplyWeight();
  1387. SendCharInfo();
  1388. pos_update.Start();
  1389. quest_pos_timer.Start();
  1390. break;
  1391. }
  1392. case OP_LootItemsRequestMsg: {
  1393. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1394. HandleLootItemRequestPacket(app);
  1395. break;
  1396. }
  1397. case OP_StoppedLootingMsg: {
  1398. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoppedLootingMsg", opcode, opcode);
  1399. if (app->size < sizeof(int32))
  1400. break;
  1401. int32 loot_id = 0;
  1402. memcpy(&loot_id, app->pBuffer, sizeof(int32));
  1403. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  1404. if(spawn) {
  1405. spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  1406. spawn->SetLooterSpawnID(0);
  1407. }
  1408. break;
  1409. }
  1410. case OP_WaypointSelectMsg: {
  1411. PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
  1412. if (packet) {
  1413. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1414. int32 selection = packet->getType_int32_ByName("selection");
  1415. if (selection > 0) {
  1416. SelectWaypoint(selection);
  1417. }
  1418. }
  1419. }
  1420. safe_delete(packet);
  1421. break;
  1422. }
  1423. case OP_KnowledgeWindowSlotMappingMsg: {
  1424. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1425. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1426. if (packet) {
  1427. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1428. int num_updates = packet->getType_int16_ByName("spell_count");
  1429. int32 spell_id = 0;
  1430. int16 slot_id = 0;
  1431. char tmp_spell_id[15];
  1432. char tmp_slot[15];
  1433. for (int i = 0; i < num_updates; i++) {
  1434. memset(tmp_spell_id, 0, 15);
  1435. memset(tmp_slot, 0, 15);
  1436. sprintf(tmp_spell_id, "spell_id_%i", i);
  1437. sprintf(tmp_slot, "slot_id_%i", i);
  1438. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1439. if (spell_id > 0) {
  1440. slot_id = packet->getType_int16_ByName(tmp_slot);
  1441. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1442. if (spell && spell->slot != slot_id) {
  1443. spell->slot = slot_id;
  1444. spell->save_needed = true;
  1445. }
  1446. }
  1447. }
  1448. }
  1449. safe_delete(packet);
  1450. }
  1451. //SendKnowledgeWindowSlot();
  1452. break;
  1453. }
  1454. case OP_ReadyToZoneMsg: {
  1455. if (!IsReadyForSpawns())
  1456. {
  1457. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1458. }
  1459. else
  1460. {
  1461. if(zoning_destination) {
  1462. SetCurrentZone(zoning_destination);
  1463. }
  1464. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1465. bool succeed_override_zone = true;
  1466. if(!GetCurrentZone()) {
  1467. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone and zone is not there! Emergency boot!", player->GetName());
  1468. if(zoning_instance_id) {
  1469. ZoneServer* zone = zone_list.GetByInstanceID(zoning_instance_id, zoning_id, true);
  1470. if(!zone) {
  1471. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver instance id %u zone id %u.", player->GetName(), zoning_instance_id, zoning_id);
  1472. succeed_override_zone = false;
  1473. }
  1474. else {
  1475. SetCurrentZone(zone);
  1476. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique instance has been created for %s through emergency boot!", player->GetName());
  1477. }
  1478. }
  1479. else if(zoning_id) {
  1480. ZoneServer* zone = zone_list.Get(zoning_id, true, true);
  1481. if(!zone) {
  1482. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver zone id %u.", player->GetName(), zoning_id);
  1483. succeed_override_zone = false;
  1484. }
  1485. else {
  1486. SetCurrentZone(zone);
  1487. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique zone has been created for %s through emergency boot!", player->GetName());
  1488. }
  1489. }
  1490. }
  1491. if (client_zoning)
  1492. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1493. else
  1494. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1495. Disconnect();
  1496. }
  1497. break;
  1498. }
  1499. case OP_ClientFellMsg: {
  1500. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1501. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1502. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1503. float height = request->getType_float_ByName("height");
  1504. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1505. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1506. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1507. break;
  1508. }*/
  1509. float safe_height = 13.0f;
  1510. float safe_skill_with_bonus = GetPlayer()->CalculateSkillWithBonus("Safe Fall", ITEM_STAT_SAFE_FALL, true);
  1511. if (safe_skill_with_bonus > 0.0f)
  1512. safe_height += (1 + safe_skill_with_bonus) / 5;
  1513. if (height > safe_height) {
  1514. int16 damage = (int16)ceil((height - safe_height) * 125);
  1515. if (height >= 80)
  1516. damage = 30000;
  1517. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1518. if (damage > 0) {
  1519. GetPlayer()->TakeDamage(damage);
  1520. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1521. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1522. if (!GetPlayer()->GetInvulnerable())
  1523. GetPlayer()->SetCharSheetChanged(true);
  1524. GetCurrentZone()->SendDamagePacket(0, GetPlayer(), DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE, GetPlayer()->GetInvulnerable() ? DAMAGE_PACKET_RESULT_INVULNERABLE : DAMAGE_PACKET_RESULT_SUCCESSFUL, DAMAGE_PACKET_DAMAGE_TYPE_FALLING, damage, 0);
  1525. if (GetPlayer()->GetHP() == 0) {
  1526. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1527. }
  1528. }
  1529. }
  1530. }
  1531. safe_delete(request);
  1532. break;
  1533. }
  1534. case OP_MapFogDataUpdateMsg: {
  1535. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1536. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1537. break;
  1538. }
  1539. case OP_SelectZoneTeleporterDestinatio: {
  1540. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1541. ProcessTeleportLocation(app);
  1542. break;
  1543. }
  1544. case OP_SendLatestRequestMsg: {
  1545. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1546. if(GetVersion() < 60085) {
  1547. // this does not exist in newer clients like AoM, confirmed to exist in DoF, other clients will need review at a later time
  1548. uchar blah25[] = { 0x01 };
  1549. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1550. QueuePacket(app25);
  1551. }
  1552. break;
  1553. }
  1554. case OP_RequestRecipeDetailsMsg: {
  1555. PacketStruct* packet = configReader.getStruct("WS_RequestRecipeDetail", GetVersion());
  1556. if (packet) {
  1557. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1558. vector<int32> recipes;
  1559. int32 recipe_id = 0;
  1560. char recipe_prop_name[30];
  1561. int32 num_recipes = packet->getType_int32_ByName("num_recipes");
  1562. // WS_RecipeDetails
  1563. for (int32 i = 0; i < num_recipes; i++) {
  1564. memset(recipe_prop_name, 0, 30);
  1565. snprintf(recipe_prop_name, 30, "recipe_id_%i", i);
  1566. recipe_id = packet->getType_int32_ByName(recipe_prop_name);
  1567. if(recipe_id > 0) {
  1568. recipes.push_back(recipe_id);
  1569. }
  1570. }
  1571. SendRecipeDetails(&recipes);
  1572. }
  1573. safe_delete(packet);
  1574. }
  1575. break;
  1576. }
  1577. case OP_ShowCreateFromRecipeUIMsg: {
  1578. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1579. break;
  1580. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1581. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1582. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1583. QueuePacket(app);
  1584. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1585. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1586. QueuePacket(app);
  1587. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1588. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1589. ,0xff,0xff,0xff};
  1590. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1591. QueuePacket(app);
  1592. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1593. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1594. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1595. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1596. QueuePacket(app);
  1597. uchar blah5[] ={0x00,0x00};
  1598. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1599. QueuePacket(app);
  1600. break;*/
  1601. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1602. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1603. //QueuePacket(app);
  1604. }
  1605. case OP_BeginItemCreationMsg: {
  1606. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1607. //DumpPacket(app->pBuffer, app->size);
  1608. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1609. if (packet) {
  1610. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1611. int32 item = 0;
  1612. int8 qty = 0;
  1613. vector<pair<int32, int16>> items;
  1614. char tmp_item_id[30];
  1615. int8 num_primary_selected_items = packet->getType_int8_ByName("num_primary_selected_items");
  1616. for (int8 i = 0; i < num_primary_selected_items; i++) {
  1617. memset(tmp_item_id, 0, 30);
  1618. sprintf(tmp_item_id, "primary_selected_item_id_%i", i);
  1619. item = packet->getType_int32_ByName(tmp_item_id);
  1620. sprintf(tmp_item_id, "primary_selected_item_qty_%i", i);
  1621. qty = packet->getType_int16_ByName(tmp_item_id);
  1622. if (item > 0)
  1623. items.push_back(make_pair(item,qty));
  1624. item = 0;
  1625. }
  1626. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1627. for (int8 i = 0; i < build_components; i++) {
  1628. memset(tmp_item_id, 0, 30);
  1629. sprintf(tmp_item_id, "num_selected_items_%i", i);
  1630. int8 num_selected_items = packet->getType_int8_ByName(tmp_item_id);
  1631. for (int8 j = 0; j < num_selected_items; j++) {
  1632. memset(tmp_item_id, 0, 30);
  1633. sprintf(tmp_item_id, "selected_id%i_%i", i,j);
  1634. item = packet->getType_int32_ByName(tmp_item_id);
  1635. sprintf(tmp_item_id, "selected_qty%i_%i", i, j);
  1636. qty = packet->getType_int16_ByName(tmp_item_id);
  1637. if (item > 0)
  1638. items.push_back(make_pair(item, qty));
  1639. item = 0;
  1640. }
  1641. }
  1642. int8 num_fuel_items = packet->getType_int8_ByName("num_fuel_items");
  1643. for (int8 i = 0; i < num_fuel_items; i++) {
  1644. memset(tmp_item_id, 0, 30);
  1645. sprintf(tmp_item_id, "fuel_id_%i", i);
  1646. item = packet->getType_int32_ByName(tmp_item_id);
  1647. sprintf(tmp_item_id, "fuel_qty_%i", i);
  1648. qty = packet->getType_int16_ByName(tmp_item_id);
  1649. if (item > 0)
  1650. items.push_back(make_pair(item, qty));
  1651. item = 0;
  1652. }
  1653. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1654. }
  1655. safe_delete(packet);
  1656. }
  1657. break;
  1658. }
  1659. case OP_StopItemCreationMsg: {
  1660. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1661. //DumpPacket(app->pBuffer, app->size);
  1662. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1663. break;
  1664. }
  1665. case OP_SysClient:
  1666. case OP_SignalMsg: {
  1667. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient/OP_SignalMsg", opcode, opcode);
  1668. PacketStruct* packet = configReader.getStruct("WS_Signal", 1);
  1669. if (packet) {
  1670. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1671. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1672. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1673. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1674. SetReloadingZone(false);
  1675. if(GetPlayer()->IsDeletedSpawn()) {
  1676. GetPlayer()->SetDeletedSpawn(false);
  1677. }
  1678. ResetZoningCoords();
  1679. SetReadyForUpdates();
  1680. GetPlayer()->SendSpawnChanges(true);
  1681. ProcessStateCommands();
  1682. GetPlayer()->changed = true;
  1683. GetPlayer()->info_changed = true;
  1684. GetPlayer()->vis_changed = true;
  1685. player_pos_changed = true;
  1686. GetPlayer()->AddChangedZoneSpawn();
  1687. ProcessZoneIgnoreWidgets();
  1688. }
  1689. else {
  1690. LogWrite(CCLIENT__WARNING, 0, "Client", "Player %s reported SysClient/SignalMsg state %s.", GetPlayer()->GetName(), str.data.c_str());
  1691. }
  1692. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1693. if (zone_script && lua_interface)
  1694. {
  1695. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1696. }
  1697. }
  1698. safe_delete(packet);
  1699. }
  1700. break;
  1701. }
  1702. case OP_EntityVerbsRequestMsg: {
  1703. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1704. HandleVerbRequest(app);
  1705. break;
  1706. }
  1707. case OP_EntityVerbsVerbMsg: {
  1708. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1709. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1710. if (packet) {
  1711. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1712. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1713. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1714. Spawn* spawn = player->GetTarget();
  1715. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1716. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1717. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1718. {
  1719. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1720. if (spawn->IsGroundSpawn())
  1721. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1722. else if (spawn->IsObject())
  1723. ((Object*)spawn)->HandleUse(this, command);
  1724. else if (spawn->IsWidget())
  1725. ((Widget*)spawn)->HandleUse(this, command);
  1726. else if (spawn->IsSign())
  1727. ((Sign*)spawn)->HandleUse(this, command);
  1728. }
  1729. }
  1730. }
  1731. else {
  1732. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1733. if (command.size > 0) {
  1734. string command_name = command.data;
  1735. if (command_name.find(" ") < 0xFFFFFFFF) {
  1736. if (GetVersion() <= 546) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
  1737. string::size_type pos = command_name.find(" ");
  1738. while(pos != string::npos){
  1739. command_name.replace(pos, 1, "_");
  1740. pos = command_name.find(" ");
  1741. }
  1742. }
  1743. else
  1744. command_name = command_name.substr(0, command_name.find(" "));
  1745. }
  1746. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1747. if (handler != 0xFFFFFFFF) {
  1748. if (command.data == command_name) {
  1749. command.data = "";
  1750. command.size = 0;
  1751. }
  1752. else {
  1753. command.data = command.data.substr(command.data.find(" ") + 1);
  1754. command.size = command.data.length();
  1755. }
  1756. commands.Process(handler, &command, this);
  1757. }
  1758. else {
  1759. if (spawn && spawn->IsNPC()) {
  1760. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1761. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1762. command_name = command.data;
  1763. string::size_type pos = command_name.find(" ");
  1764. while (pos != string::npos) {
  1765. command_name.replace(pos, 1, "_");
  1766. pos = command_name.find(" ");
  1767. }
  1768. if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
  1769. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1770. }
  1771. }
  1772. }
  1773. }
  1774. else
  1775. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1776. }
  1777. }
  1778. }
  1779. }
  1780. safe_delete(packet);
  1781. }
  1782. break;
  1783. }
  1784. case OP_SkillInfoRequest: {
  1785. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1786. HandleSkillInfoRequest(app);
  1787. break;
  1788. }
  1789. case OP_UpdateTargetMsg: {
  1790. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1791. int16 index = 0;
  1792. memcpy(&index, app->pBuffer, sizeof(int16));
  1793. if (index == 0xFFFF)
  1794. GetPlayer()->SetTarget(0);
  1795. else {
  1796. Spawn* spawn = GetPlayer()->GetSpawnByIndex(index);
  1797. if(spawn)
  1798. GetPlayer()->SetTarget(spawn);
  1799. else {
  1800. LogWrite(PLAYER__ERROR, 1, "Player", "Player %s tried to target %u index, but that index was not valid.", GetPlayer()->GetName(), index);
  1801. }
  1802. }
  1803. if (GetPlayer()->GetTarget())
  1804. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1805. //player->SetTarget((int16*)app->pBuffer);
  1806. break;
  1807. }
  1808. case OP_ExamineInfoRequestMsg: {
  1809. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1810. HandleExamineInfoRequest(app);
  1811. break;
  1812. }
  1813. case OP_QuickbarUpdateMsg:
  1814. //case OP_QuickbarAddMsg:
  1815. {
  1816. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1817. HandleQuickbarUpdateRequest(app);
  1818. break;
  1819. }
  1820. case OP_PredictionUpdateMsg: {
  1821. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
  1822. if (version <= 546) {
  1823. int8 offset = 9;
  1824. if (app->pBuffer[0] == 0xFF)
  1825. offset += 2;
  1826. if (app->size > offset) {
  1827. if (player->IsCasting()) {
  1828. float distance = 0;
  1829. float x = player->GetX();
  1830. float y = player->GetY();
  1831. float z = player->GetZ();
  1832. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1833. distance = player->GetDistance(x, y, z, false);
  1834. if (distance > .5)
  1835. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1836. }
  1837. else
  1838. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1839. player_pos_changed = true;
  1840. //DumpPacket(app);
  1841. }
  1842. }
  1843. else {
  1844. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1845. QueuePacket(app);
  1846. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1847. }
  1848. break;
  1849. }
  1850. case OP_RemoteCmdMsg: {
  1851. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1852. if (app->size > 0) {
  1853. EQ2_CommandString remote(app->pBuffer, app->size);
  1854. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1855. #if EQDEBUG >= 9
  1856. DumpPacket(app);
  1857. #endif
  1858. commands.Process(remote.handler, &remote.command, this);
  1859. }
  1860. else //bad client, disconnect
  1861. Disconnect();
  1862. break;
  1863. }
  1864. case OP_CancelSpellCast: {
  1865. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1866. current_zone->Interrupted(player, 0, 0, true);
  1867. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1868. break;
  1869. }
  1870. case OP_UpdatePositionMsg: {
  1871. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
  1872. int8 offset = 13;
  1873. if (app->pBuffer[0] == 0xFF)
  1874. offset += 2;
  1875. if (app->size > offset) {
  1876. if (player->IsCasting()) {
  1877. float distance = 0;
  1878. float x = player->GetX();
  1879. float y = player->GetY();
  1880. float z = player->GetZ();
  1881. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1882. distance = player->GetDistance(x, y, z, false);
  1883. if (distance > .5)
  1884. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1885. }
  1886. else
  1887. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1888. player_pos_changed = true;
  1889. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1890. //DumpPacket(app);
  1891. }
  1892. break;
  1893. }
  1894. case OP_MailSendMessageMsg: {
  1895. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1896. HandleSentMail(app);
  1897. break;
  1898. }
  1899. case OP_StopTrackingMsg: {
  1900. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1901. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1902. break;
  1903. }
  1904. case OP_BeginTrackingMsg: {
  1905. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1906. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1907. if (packet) {
  1908. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1909. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1910. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1911. if (spawn) {
  1912. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1913. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1914. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1915. }
  1916. }
  1917. safe_delete(packet);
  1918. }
  1919. break;
  1920. }
  1921. case OP_BioUpdateMsg: {
  1922. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1923. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1924. if (packet) {
  1925. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1926. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1927. }
  1928. safe_delete(packet);
  1929. }
  1930. break;
  1931. }
  1932. case OP_RewardPackMsg: {
  1933. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1934. /* This logging is still here because I remember another system using this packet and just want to make sure we can figure out that it's being sent
  1935. when we come across it (scatman) */
  1936. const char* name = app->GetOpcodeName();
  1937. if (name)
  1938. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1939. else
  1940. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1941. //DumpPacket(app);
  1942. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1943. if (packet) {
  1944. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1945. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1946. /* Player has contacted a guild recruiter */
  1947. if (recruiter_name.length() > 0) {
  1948. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1949. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1950. if (recruiter && guild) {
  1951. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1952. recruiter->Message(CHANNEL_GUILD_EVENT, "%s [%u %s], [0 Unskilled] (%s) is requesting to speak to YOU about joining the guild.", player->GetName(), player->GetLevel(), classes.GetClassNameCase(player->GetAdventureClass()).c_str(), races.GetRaceNameCase(player->GetRace()));
  1953. recruiter->PlaySound("ui_guild_page");
  1954. }
  1955. }
  1956. /* New picture taken for guild recruiting */
  1957. else {
  1958. //DumpPacket(app->pBuffer, app->size);
  1959. int32 guild_id = 0;
  1960. int16 picture_data_size = 0;
  1961. unsigned char* recruiter_picture_data = 0;
  1962. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1963. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1964. Guild* guild = guild_list.GetGuild(guild_id);
  1965. if (guild) {
  1966. GuildMember* gm = guild->GetGuildMember(player);
  1967. if (gm) {
  1968. safe_delete_array(gm->recruiter_picture_data);
  1969. recruiter_picture_data = new unsigned char[picture_data_size];
  1970. for (int16 i = 0; i < picture_data_size; i++)
  1971. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1972. gm->recruiter_picture_data = recruiter_picture_data;
  1973. gm->recruiter_picture_data_size = picture_data_size;
  1974. guild->SetMemberSaveNeeded(true);
  1975. }
  1976. }
  1977. }
  1978. }
  1979. safe_delete(packet);
  1980. }
  1981. break;
  1982. }
  1983. case OP_PetOptions: {
  1984. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  1985. Spawn* target = player->GetTarget();
  1986. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  1987. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  1988. bool change = false;
  1989. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1990. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  1991. if (strlen(name.c_str()) != 0 && SetPetName(name.c_str())) {
  1992. target->SetName(name.c_str());
  1993. GetCurrentZone()->SendUpdateTitles(target);
  1994. change = true;
  1995. }
  1996. int8 pet_behavior = player->GetInfoStruct()->get_pet_behavior();
  1997. // Check protect self setting and update if needed
  1998. if (packet->getType_int8_ByName("protect_self") == 1) {
  1999. if ((pet_behavior & 2) == 0) {
  2000. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 2);
  2001. change = true;
  2002. }
  2003. }
  2004. else {
  2005. if ((pet_behavior & 2) != 0) {
  2006. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 2);
  2007. change = true;
  2008. }
  2009. }
  2010. // Check protect master setting and update if needed
  2011. if (packet->getType_int8_ByName("protect_master") == 1) {
  2012. if ((pet_behavior & 1) == 0) {
  2013. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 1);
  2014. change = true;
  2015. }
  2016. }
  2017. else {
  2018. if ((pet_behavior & 1) != 0) {
  2019. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 1);
  2020. change = true;
  2021. }
  2022. }
  2023. int8 pet_movement = player->GetInfoStruct()->get_pet_movement();
  2024. // Check stay/follow setting and update if needed
  2025. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  2026. if (pet_movement != 2) {
  2027. player->GetInfoStruct()->set_pet_movement(2);
  2028. change = true;
  2029. }
  2030. }
  2031. else {
  2032. if (pet_movement != 1) {
  2033. player->GetInfoStruct()->set_pet_movement(1);
  2034. change = true;
  2035. }
  2036. }
  2037. // Ranged/Melee settings are not implemented yet
  2038. if (change)
  2039. player->SetCharSheetChanged(true);
  2040. }
  2041. safe_delete(packet);
  2042. }
  2043. break;
  2044. }
  2045. case OP_RecipeBook: {
  2046. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  2047. SendRecipeList();
  2048. break;
  2049. }
  2050. case OP_BuyPlayerHouseMsg: {
  2051. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  2052. //DumpPacket(app);
  2053. int64 bank_money = GetPlayer()->GetBankCoinsPlat();
  2054. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  2055. if (packet) {
  2056. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2057. int64 house_id = 0;
  2058. if(GetVersion() <= 546) {
  2059. house_id = packet->getType_int32_ByName("house_id");
  2060. }
  2061. else {
  2062. house_id = packet->getType_int64_ByName("house_id");
  2063. }
  2064. HouseZone* hz = world.GetHouseZone(house_id);
  2065. if (hz) {
  2066. bool got_bank_money = BankHasCoin(hz->cost_coin);
  2067. int8 disable_alignment_req = rule_manager.GetGlobalRule(R_Player, DisableHouseAlignmentRequirement)->GetInt8();
  2068. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  2069. if (houses.size() > 24)
  2070. {
  2071. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  2072. safe_delete(packet);
  2073. break;
  2074. }
  2075. if(disable_alignment_req && hz->alignment > 0 && hz->alignment != GetPlayer()->GetAlignment())
  2076. {
  2077. std::string req = "You must be of ";
  2078. if (hz->alignment == 1)
  2079. req.append("Good");
  2080. else
  2081. req.append("Evil");
  2082. req.append(" alignment to purchase this house");
  2083. SimpleMessage(CHANNEL_COLOR_YELLOW, req.c_str());
  2084. safe_delete(packet);
  2085. break;
  2086. }
  2087. int32 status_req = hz->cost_status;
  2088. int32 available_status = player->GetInfoStruct()->get_status_points();
  2089. if (status_req <= available_status && (!hz->cost_coin || (hz->cost_coin && player->RemoveCoins(hz->cost_coin))))
  2090. {
  2091. player->GetInfoStruct()->subtract_status_points(status_req);
  2092. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id, false, false);
  2093. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  2094. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  2095. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  2096. //ClientPacketFunctions::SendHousingList(this);
  2097. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  2098. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
  2099. PlaySound("coin_cha_ching");
  2100. }
  2101. else if (status_req <= available_status && got_bank_money == 1) {
  2102. player->GetInfoStruct()->subtract_status_points(status_req);
  2103. bool bankwithdrawl = BankWithdrawalNoBanker(hz->cost_coin);
  2104. //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
  2105. if (bankwithdrawl == 0) {
  2106. PlaySound("buy_failed");
  2107. SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
  2108. safe_delete(packet);
  2109. break;
  2110. }
  2111. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id, false, false);
  2112. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  2113. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  2114. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  2115. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  2116. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
  2117. PlaySound("coin_cha_ching");
  2118. }
  2119. else
  2120. {
  2121. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  2122. PlaySound("buy_failed");
  2123. }
  2124. }
  2125. }
  2126. }
  2127. safe_delete(packet);
  2128. break;
  2129. }
  2130. case OP_EnterHouseMsg: {
  2131. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  2132. //DumpPacket(app);
  2133. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  2134. if (packet) {
  2135. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2136. PlayerHouse* ph = nullptr;
  2137. HouseZone* hz = nullptr;
  2138. int64 house_id = 0;
  2139. int32 spawn_index = 0;
  2140. if(GetVersion() <= 546) {
  2141. spawn_index = packet->getType_int32_ByName("house_id");
  2142. }
  2143. else {
  2144. house_id = packet->getType_int64_ByName("house_id");
  2145. }
  2146. ZoneServer* house = GetHouseZoneServer(spawn_index, house_id);
  2147. if (house) {
  2148. Zone(house, true);
  2149. }
  2150. }
  2151. }
  2152. safe_delete(packet);
  2153. break;
  2154. }
  2155. case OP_PayHouseUpkeepMsg: {
  2156. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  2157. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  2158. if (packet) {
  2159. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2160. int64 house_id = 0;
  2161. if(GetVersion() <= 546) {
  2162. house_id = packet->getType_int32_ByName("house_id");
  2163. }
  2164. else {
  2165. house_id = packet->getType_int64_ByName("house_id");
  2166. }
  2167. HouseZone* hz = nullptr;
  2168. PlayerHouse* ph = world.GetPlayerHouse(this, GetVersion() <= 546 ? house_id : 0, GetVersion() > 546 ? house_id : 0, &hz);
  2169. if (ph)
  2170. {
  2171. if (!hz)
  2172. {
  2173. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  2174. safe_delete(packet);
  2175. break;
  2176. }
  2177. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  2178. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  2179. {
  2180. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  2181. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  2182. {
  2183. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  2184. PlaySound("buy_failed");
  2185. safe_delete(packet);
  2186. break;
  2187. }
  2188. }
  2189. bool escrowChange = false;
  2190. int64 statusReq = hz->upkeep_status;
  2191. int64 tmpRecoverStatus = 0;
  2192. if(ph->escrow_status && statusReq >= ph->escrow_status )
  2193. {
  2194. escrowChange = true;
  2195. tmpRecoverStatus = ph->escrow_status;
  2196. statusReq -= ph->escrow_status;
  2197. ph->escrow_status = 0;
  2198. }
  2199. else if (ph->escrow_status && statusReq && statusReq <= ph->escrow_status)
  2200. {
  2201. escrowChange = true;
  2202. ph->escrow_status -= statusReq;
  2203. tmpRecoverStatus = statusReq;
  2204. statusReq = 0;
  2205. }
  2206. int64 coinReq = hz->upkeep_coin;
  2207. int64 tmpRecoverCoins = 0;
  2208. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  2209. {
  2210. escrowChange = true;
  2211. tmpRecoverCoins = ph->escrow_coins;
  2212. coinReq -= ph->escrow_coins;
  2213. ph->escrow_coins = 0;
  2214. }
  2215. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  2216. {
  2217. escrowChange = true;
  2218. // more than enough in escrow, subtract and make our cost 0!
  2219. ph->escrow_coins -= coinReq;
  2220. tmpRecoverCoins = coinReq;
  2221. coinReq = 0;
  2222. }
  2223. int32 available_status_points = player->GetInfoStruct()->get_status_points();
  2224. if(!statusReq || (statusReq && statusReq <= available_status_points))
  2225. {
  2226. if(coinReq && player->RemoveCoins(coinReq))
  2227. coinReq = 0;
  2228. if(!coinReq && statusReq && player->GetInfoStruct()->subtract_status_points(statusReq))
  2229. statusReq = 0;
  2230. }
  2231. bool got_bank_money = BankHasCoin(hz->upkeep_coin);
  2232. if (!coinReq && !statusReq) // TODO: Need option to take from bank if player does not have enough coin on them
  2233. {
  2234. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2235. if (escrowChange)
  2236. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2237. ph->upkeep_due = upkeep_due;
  2238. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2239. //ClientPacketFunctions::SendHousingList(this);
  2240. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
  2241. PlaySound("coin_cha_ching");
  2242. }
  2243. else if (!statusReq && got_bank_money == 1) {
  2244. bool bankwithdrawl = BankWithdrawalNoBanker(hz->upkeep_coin);
  2245. //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
  2246. if (bankwithdrawl == 0) {
  2247. PlaySound("buy_failed");
  2248. SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
  2249. safe_delete(packet);
  2250. break;
  2251. }
  2252. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2253. if (escrowChange)
  2254. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2255. ph->upkeep_due = upkeep_due;
  2256. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2257. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
  2258. PlaySound("coin_cha_ching");
  2259. }
  2260. else
  2261. {
  2262. // recover the escrow we were going to use but could not spend due to lack of funds
  2263. if (tmpRecoverCoins)
  2264. ph->escrow_coins += tmpRecoverCoins;
  2265. if(tmpRecoverStatus)
  2266. ph->escrow_status += tmpRecoverStatus;
  2267. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money or status to pay for upkeep.");
  2268. PlaySound("buy_failed");
  2269. }
  2270. }
  2271. else
  2272. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", house_id);
  2273. }
  2274. }
  2275. safe_delete(packet);
  2276. break;
  2277. }
  2278. case OP_ExitHouseMsg: {
  2279. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  2280. int32 instance_id = GetCurrentZone()->GetInstanceID();
  2281. if (instance_id > 0) {
  2282. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  2283. if (ph) {
  2284. HouseZone* hz = world.GetHouseZone(ph->house_id);
  2285. if (hz) {
  2286. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  2287. // determine if this is an instanced zone that already exists
  2288. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  2289. if (instance_zone || new_zone) {
  2290. GetPlayer()->SetX(hz->exit_x);
  2291. GetPlayer()->SetY(hz->exit_y);
  2292. GetPlayer()->SetZ(hz->exit_z);
  2293. GetPlayer()->SetHeading(hz->exit_heading);
  2294. if (instance_zone)
  2295. Zone(instance_zone->GetInstanceID(), false, true);
  2296. else
  2297. Zone(new_zone, false);
  2298. }
  2299. }
  2300. }
  2301. }
  2302. break;
  2303. }
  2304. case OP_QuestJournalWaypointMsg: {
  2305. //DumpPacket(app);
  2306. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  2307. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  2308. if (packet) {
  2309. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2310. int32 quests = packet->getType_int32_ByName("num_quests");
  2311. if (quests > 100) // just picking a number higher than max allowed
  2312. {
  2313. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  2314. break;
  2315. }
  2316. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  2317. for (int32 i = 0; i < quests; i++) {
  2318. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  2319. if (id == 0)
  2320. continue;
  2321. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  2322. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  2323. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2324. if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
  2325. player->player_quests[id]->SetTracked(tracked);
  2326. player->player_quests[id]->SetSaveNeeded(true);
  2327. }
  2328. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2329. }
  2330. }
  2331. safe_delete(packet);
  2332. }
  2333. break;
  2334. }
  2335. case OP_PaperdollImage: {
  2336. /* PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  2337. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2338. //First check if this is a new image... delete an existing partial image if one exists
  2339. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  2340. if (packet_index == 0) {
  2341. safe_delete_array(incoming_paperdoll.image_bytes);
  2342. incoming_paperdoll.last_received_packet_index = 0;
  2343. incoming_paperdoll.current_size_bytes = 0;
  2344. }
  2345. //return if this packet is not the one we are expecting...
  2346. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  2347. safe_delete(packet);
  2348. break;
  2349. }
  2350. //Check how many packets we're supposed to be receiving for this/these images
  2351. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  2352. //Check the image type, if this is a new type in the same series of packets we have a new image
  2353. int8 img_type = packet->getType_int8_ByName("image_type");
  2354. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  2355. //We have a new image. Save the old data and clear before continuing
  2356. SavePlayerImages();
  2357. }
  2358. incoming_paperdoll.image_type = img_type;
  2359. //Get the size of the image data in this packet
  2360. sint64 image_size = packet->getType_int32_ByName("imageSize");
  2361. if (image_size <= 0 || image_size > 1048576) {
  2362. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  2363. safe_delete(packet);
  2364. break;
  2365. }
  2366. //Create a new array
  2367. int32 new_image_size = image_size;
  2368. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  2369. if (incoming_paperdoll.image_bytes) {
  2370. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  2371. safe_delete_array(incoming_paperdoll.image_bytes);
  2372. }
  2373. //variable i should be the index in the packet of the first PNG file byte
  2374. vector<DataStruct*>* d_structs = packet->getStructs();
  2375. vector<DataStruct*>::iterator itr;
  2376. int32 i = 0;
  2377. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  2378. DataStruct* ds = (*itr);
  2379. if (strcmp(ds->GetName(), "pngData_0") != 0)
  2380. i += ds->GetDataSizeInBytes();
  2381. else
  2382. break;
  2383. }
  2384. //Return if this packet is bad and we would read out of bounds
  2385. if (app->size - i < new_image_size) {
  2386. safe_delete(packet);
  2387. safe_delete_array(new_image);
  2388. break;
  2389. }
  2390. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  2391. memcpy(tmp, app->pBuffer + i, new_image_size);
  2392. incoming_paperdoll.current_size_bytes += new_image_size;
  2393. incoming_paperdoll.image_bytes = new_image;
  2394. //Check if this is the last packet we're expecting for this image. Create a final image if so
  2395. if (incoming_paperdoll.image_num_packets == 1 ||
  2396. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  2397. SavePlayerImages();
  2398. }
  2399. incoming_paperdoll.last_received_packet_index = packet_index;
  2400. }
  2401. safe_delete(packet);
  2402. */
  2403. break;
  2404. }
  2405. case OP_ReadyForTakeOffMsg:
  2406. {
  2407. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  2408. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  2409. if (GetPendingFlightPath() > 0) {
  2410. if (index != -1) {
  2411. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  2412. if (packet) {
  2413. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  2414. packet->setDataByName("path_id", index);
  2415. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  2416. QueuePacket(packet->serialize());
  2417. safe_delete(packet);
  2418. on_auto_mount = true;
  2419. }
  2420. }
  2421. else {
  2422. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2423. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2424. EndAutoMount();
  2425. }
  2426. SetPendingFlightPath(0);
  2427. }
  2428. else
  2429. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  2430. break;
  2431. }
  2432. case OP_EarlyLandingRequestMsg:
  2433. {
  2434. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  2435. EndAutoMount();
  2436. break;
  2437. }
  2438. case OP_SubmitCharCust:
  2439. {
  2440. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  2441. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  2442. if (packet && packet->LoadPacketData(app->pBuffer, app->size, GetVersion() <= 546 ? false : true)) {
  2443. int8 type = packet->getType_int8_ByName("type");
  2444. if (type == 0) {
  2445. /*if (player->custNPC) {
  2446. player->custNPCTarget->CustomizeAppearance(packet);
  2447. current_zone->SendSpawnChanges(player->custNPCTarget);
  2448. }
  2449. else {*/
  2450. player->CustomizeAppearance(packet);
  2451. current_zone->SendSpawnChanges(player);
  2452. //}
  2453. }
  2454. }
  2455. safe_delete(packet);
  2456. /*
  2457. if (player->custNPC) {
  2458. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2459. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2460. if (player->custNPCTarget->IsBot())
  2461. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2462. player->custNPC = false;
  2463. player->custNPCTarget = 0;
  2464. player->changed = true;
  2465. player->info_changed = true;
  2466. current_zone->SendSpawnChanges(player, this);
  2467. }*/
  2468. break;
  2469. }
  2470. default: {
  2471. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2472. const char* name = app->GetOpcodeName();
  2473. if (name)
  2474. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2475. else
  2476. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2477. // keeping this around for debugging purposes
  2478. DumpPacket(app);
  2479. }
  2480. }
  2481. if (!eqs || !eqs->CheckActive()) {
  2482. return false;
  2483. }
  2484. return ret;
  2485. }
  2486. bool Client::HandleLootItem(Spawn* entity, Item* item, Spawn* target, bool overrideLootRestrictions) {
  2487. if (!item) {
  2488. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2489. return false;
  2490. }
  2491. int32 conflictItemList = 0, conflictequipmentList = 0, conflictAppearanceEquipmentList = 0;
  2492. int16 lore_stack_count = 0;
  2493. Player* lootingPlayer = player;
  2494. Client* lootingClient = this;
  2495. if (target != nullptr && target != lootingPlayer && target->IsPlayer()) {
  2496. lootingPlayer = (Player*)target;
  2497. lootingClient = lootingPlayer->GetClient();
  2498. }
  2499. // needs to only be checked before expiration of loot restrictions
  2500. if (entity && !overrideLootRestrictions) {
  2501. if (entity->GetLootGroupID() > 0 && (!lootingPlayer->GetGroupMemberInfo() || lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID())) {
  2502. LogWrite(LOOT__ERROR, 0, "Loot", "%s: Loot Group ID from %s did not match Item: %s (%u), expected group id %u.", entity->GetName(), lootingPlayer->GetName(), item->name.c_str(), item->details.item_id, entity->GetLootGroupID());
  2503. return false;
  2504. }
  2505. if (entity->GetLootMethod() != GroupLootMethod::METHOD_FFA) {
  2506. switch (entity->GetLootMethod()) {
  2507. case GroupLootMethod::METHOD_LEADER: {
  2508. if (entity->GetLootGroupID() > 0 && (!lootingPlayer->GetGroupMemberInfo() || (lootingPlayer->GetGroupMemberInfo() && (lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID() || !lootingPlayer->GetGroupMemberInfo()->leader)))) {
  2509. LogWrite(LOOT__ERROR, 0, "Loot", "%s: Loot Attempt from %s was not allowed with Item: %s (%u), must be group leader.", entity->GetName(), lootingPlayer->GetName(), item->name.c_str(), item->details.item_id);
  2510. return false;
  2511. }
  2512. break;
  2513. }
  2514. case GroupLootMethod::METHOD_LOTTO:
  2515. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2516. if (entity->IsLootTimerRunning()) {
  2517. LogWrite(LOOT__INFO, 0, "Loot", "%s: Loot Timer is still running, flag player %s to lotto Item: %s (%u).", entity->GetName(), lootingPlayer->GetName(), item->name.c_str(), item->details.item_id);
  2518. return false;
  2519. }
  2520. break;
  2521. }
  2522. }
  2523. }
  2524. }
  2525. if (((conflictItemList = lootingPlayer->item_list.CheckSlotConflict(item, true, true, &lore_stack_count)) == LORE ||
  2526. (conflictequipmentList = lootingPlayer->equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE ||
  2527. (conflictAppearanceEquipmentList = lootingPlayer->appearance_equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE) && !item->CheckFlag(STACK_LORE)) {
  2528. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to lore conflict.", item->name.c_str());
  2529. return false;
  2530. }
  2531. else if (conflictItemList == STACK_LORE || conflictequipmentList == STACK_LORE || conflictAppearanceEquipmentList == STACK_LORE) {
  2532. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to stack lore conflict.", item->name.c_str());
  2533. return false;
  2534. }
  2535. if (lootingPlayer->item_list.HasFreeSlot() || lootingPlayer->item_list.CanStack(item)) {
  2536. if (lootingPlayer->item_list.AssignItemToFreeSlot(item)) {
  2537. if (item->CheckFlag2(HEIRLOOM)) { // TODO: RAID Support
  2538. GroupMemberInfo* gmi = lootingClient->GetPlayer()->GetGroupMemberInfo();
  2539. if (gmi && gmi->group_id)
  2540. {
  2541. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  2542. if (group)
  2543. {
  2544. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  2545. deque<GroupMemberInfo*>* members = group->GetMembers();
  2546. if (members) {
  2547. for (int8 i = 0; i < members->size(); i++) {
  2548. Entity* member = members->at(i)->member;
  2549. if (!member)
  2550. continue;
  2551. if ((member->GetZone() != lootingClient->GetPlayer()->GetZone()))
  2552. continue;
  2553. if (member->IsPlayer()) {
  2554. item->grouped_char_ids.insert(std::make_pair(((Player*)member)->GetCharacterID(), true));
  2555. item->save_needed = true;
  2556. }
  2557. }
  2558. }
  2559. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  2560. }
  2561. }
  2562. }
  2563. int8 type = CHANNEL_LOOT;
  2564. if (entity) {
  2565. lootingClient->Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2566. }
  2567. else {
  2568. lootingClient->Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2569. }
  2570. Guild* guild = lootingPlayer->GetGuild();
  2571. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2572. char adjective[32];
  2573. int8 type;
  2574. memset(adjective, 0, sizeof(adjective));
  2575. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2576. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2577. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2578. }
  2579. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2580. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2581. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2582. }
  2583. else {
  2584. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2585. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2586. }
  2587. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2588. guild->SendMessageToGuild(type, "%s has looted the %s %s", lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2589. }
  2590. if (item->GetItemScript() && lua_interface)
  2591. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, lootingPlayer);
  2592. lootingClient->CheckPlayerQuestsItemUpdate(item);
  2593. if (GetVersion() <= 546) {
  2594. EQ2Packet* outapp = lootingPlayer->SendInventoryUpdate(GetVersion());
  2595. if (outapp)
  2596. lootingClient->QueuePacket(outapp);
  2597. }
  2598. return true;
  2599. }
  2600. else
  2601. lootingClient->SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2602. }
  2603. else
  2604. lootingClient->SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2605. return false;
  2606. }
  2607. bool Client::HandleLootItemByID(Spawn* entity, int32 item_id, Spawn* target) {
  2608. if (!entity) {
  2609. return false;
  2610. }
  2611. Item* item = entity->LootItem(item_id);
  2612. bool success = false;
  2613. success = HandleLootItem(entity, item, target);
  2614. if (!success)
  2615. entity->AddLootItem(item);
  2616. return success;
  2617. }
  2618. void Client::HandleLootItemRequestPacket(EQApplicationPacket* app) {
  2619. PacketStruct* packet = configReader.getStruct("WS_LootItem", GetVersion());
  2620. if (packet) {
  2621. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  2622. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2623. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2624. int32 target_id = packet->getType_int32_ByName("target_id");
  2625. int8 button_clicked = packet->getType_int8_ByName("button_clicked");
  2626. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2627. if(!spawn) {
  2628. safe_delete(packet);
  2629. return;
  2630. }
  2631. Item* item = nullptr;
  2632. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2633. if (items) {
  2634. int32 item_id = packet->getType_int32_ByName("item_id_0");
  2635. for (int32 i = 0; i < items->size(); i++) {
  2636. Item* master_item = items->at(i);
  2637. if (master_item && (loot_all || master_item->details.item_id == item_id)) {
  2638. item = new Item(master_item);
  2639. if (item) {
  2640. loot_all = HandleLootItem(0, item);
  2641. if (loot_all) {
  2642. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2643. if (GetVersion() <= 546) {
  2644. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2645. if (outapp)
  2646. QueuePacket(outapp);
  2647. }
  2648. }
  2649. }
  2650. if (!loot_all)
  2651. break;
  2652. }
  2653. }
  2654. safe_delete(items);
  2655. safe_delete(packet);
  2656. return;
  2657. }
  2658. spawn->LockLoot();
  2659. bool unlockedLoot = false;
  2660. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2661. if (loot_all) {
  2662. switch (spawn->GetLootMethod()) {
  2663. case GroupLootMethod::METHOD_LOTTO: {
  2664. spawn->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
  2665. break;
  2666. }
  2667. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2668. spawn->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
  2669. }
  2670. default: {
  2671. if (!unlockedLoot) {
  2672. spawn->UnlockLoot();
  2673. unlockedLoot = true;
  2674. }
  2675. int32 item_id = 0;
  2676. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2677. loot_all = HandleLootItemByID(spawn, item_id, GetPlayer());
  2678. }
  2679. break;
  2680. }
  2681. }
  2682. spawn->UnlockLoot();
  2683. if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
  2684. CloseLoot(loot_id);
  2685. }
  2686. }
  2687. else {
  2688. int8 item_count = packet->getType_int8_ByName("item_count");
  2689. for (int8 cur = 0; cur < item_count; cur++) {
  2690. char item_field_name[64];
  2691. snprintf(item_field_name, 64, "item_id_%u", cur);
  2692. int32 item_id = packet->getType_int32_ByName(item_field_name);
  2693. Spawn* target = this->GetPlayer();
  2694. if (target_id != 0xFFFFFFFF && GetPlayer()->GetGroupMemberInfo()) {
  2695. Spawn* destTarget = GetPlayer()->GetSpawnWithPlayerID(target_id);
  2696. if (destTarget && (!destTarget->IsPlayer() || !world.GetGroupManager()->IsInGroup(GetPlayer()->GetGroupMemberInfo()->group_id, ((Player*)destTarget)))) {
  2697. SimpleMessage(CHANNEL_COMMAND_TEXT, "HACKS!!");
  2698. safe_delete(packet);
  2699. spawn->UnlockLoot();
  2700. return;
  2701. }
  2702. target = destTarget;
  2703. }
  2704. bool breakLoopAllLooted = false;
  2705. switch (spawn->GetLootMethod()) {
  2706. case GroupLootMethod::METHOD_LOTTO: {
  2707. spawn->AddLottoItemRequest(item_id, GetPlayer()->GetID());
  2708. break;
  2709. }
  2710. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2711. if (button_clicked == 3) { // decline
  2712. break;
  2713. }
  2714. if (GetVersion() <= 546) {
  2715. button_clicked = 1; // selecting is need
  2716. }
  2717. spawn->AddNeedGreedItemRequest(item_id, GetPlayer()->GetID(), (button_clicked == 1));
  2718. break;
  2719. }
  2720. default: {
  2721. if (!unlockedLoot) {
  2722. spawn->UnlockLoot();
  2723. unlockedLoot = true;
  2724. }
  2725. if (!loot_all) {
  2726. HandleLootItemByID(spawn, item_id, target);
  2727. }
  2728. else {
  2729. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2730. loot_all = HandleLootItemByID(spawn, item_id, target);
  2731. }
  2732. breakLoopAllLooted = true;
  2733. }
  2734. break;
  2735. }
  2736. }
  2737. if (breakLoopAllLooted) {
  2738. break;
  2739. }
  2740. }
  2741. if (!unlockedLoot) {
  2742. spawn->UnlockLoot();
  2743. }
  2744. if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO ||
  2745. (spawn->GetLootMethod() == GroupLootMethod::METHOD_NEED_BEFORE_GREED && item_count >= spawn->GetLootCount())) {
  2746. CloseLoot(loot_id);
  2747. }
  2748. }
  2749. if (GetVersion() > 546) {
  2750. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2751. if (outapp)
  2752. QueuePacket(outapp);
  2753. }
  2754. if (spawn->GetLootMethod() != GroupLootMethod::METHOD_LOTTO && spawn->GetLootMethod() != GroupLootMethod::METHOD_NEED_BEFORE_GREED) {
  2755. LootSpawnRequest(spawn);
  2756. }
  2757. else {
  2758. spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  2759. }
  2760. if (!spawn->HasLoot()) {
  2761. CloseLoot(loot_id);
  2762. if (spawn->IsNPC())
  2763. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2764. }
  2765. }
  2766. else {
  2767. spawn->UnlockLoot();
  2768. if (!spawn) {
  2769. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2770. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2771. }
  2772. else
  2773. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2774. }
  2775. }
  2776. safe_delete(packet);
  2777. }
  2778. }
  2779. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2780. PacketStruct* request = 0;
  2781. // cout << "Request: \n";
  2782. // DumpPacket(app);
  2783. switch (app->pBuffer[0]) {
  2784. case 0: { //items
  2785. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2786. if (request) {
  2787. if(request->LoadPacketData(app->pBuffer, app->size)) {
  2788. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2789. if (!item)
  2790. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2791. if (item) {
  2792. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2793. if (response) {
  2794. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2795. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2796. response->setSmallStringByName("name", item->name.c_str());
  2797. EQ2Packet* app2 = response->serialize();
  2798. //DumpPacket(app2);
  2799. QueuePacket(app2);
  2800. safe_delete(response);
  2801. }
  2802. }
  2803. }
  2804. safe_delete(request);
  2805. }
  2806. break;
  2807. }
  2808. case 2: {//spells
  2809. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2810. if (request) {
  2811. if(request->LoadPacketData(app->pBuffer, app->size)) {
  2812. int32 id = request->getType_int32_ByName("id");
  2813. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2814. Spell* spell = master_spell_list.GetSpell(id, tier);
  2815. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2816. if (response) {
  2817. response->setDataByName("request_type", 2);
  2818. response->setDataByName("unique_id", tier);
  2819. response->setDataByName("id", id);
  2820. if (spell)
  2821. response->setSmallStringByName("name", spell->GetName());
  2822. else
  2823. response->setSmallStringByName("name", "Unknown Spell");
  2824. EQ2Packet* app2 = response->serialize();
  2825. // DumpPacket(app2);
  2826. QueuePacket(app2);
  2827. safe_delete(response);
  2828. }
  2829. }
  2830. safe_delete(request);
  2831. }
  2832. break;
  2833. }
  2834. default: {
  2835. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2836. }
  2837. }
  2838. safe_delete(request);
  2839. }
  2840. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2841. PacketStruct* request = 0;
  2842. if (!app || app->size == 0)
  2843. return;
  2844. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2845. //DumpPacket(app);
  2846. int8 type = app->pBuffer[0];
  2847. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2848. if (version <= 283) {
  2849. if (type == 1)
  2850. type = 4;
  2851. else if (type == 2)
  2852. type = 5;
  2853. }
  2854. if (type == 3) {
  2855. Spell* spell = 0;
  2856. bool trait_display;
  2857. request = configReader.getStruct((GetVersion() <= 283) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  2858. if (!request) {
  2859. return;
  2860. }
  2861. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2862. safe_delete(request);
  2863. return;
  2864. }
  2865. int32 id = request->getType_int32_ByName("id");
  2866. int32 tier = request->getType_int32_ByName("tier");
  2867. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2868. bool display = true;
  2869. if (version <= 283 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2870. display = false;
  2871. else if (version <= 546)
  2872. display = request->getType_int8_ByName("display");
  2873. else if (version > 546)
  2874. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  2875. //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
  2876. if (trait_tier != 0xFFFFFFFF) {
  2877. spell = master_spell_list.GetSpell(id, trait_tier);
  2878. if (!spell) {
  2879. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2880. }
  2881. trait_display = true;
  2882. }
  2883. else {
  2884. spell = master_spell_list.GetSpell(id, tier);
  2885. trait_display = false;
  2886. }
  2887. // if we can't find it on the master spell list, see if it is a custom spell
  2888. if (!spell)
  2889. {
  2890. lua_interface->FindCustomSpellLock();
  2891. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2892. if (tmpSpell)
  2893. spell = tmpSpell->spell;
  2894. lua_interface->FindCustomSpellUnlock();
  2895. }
  2896. if (spell && !CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
  2897. if (!spell->IsCopiedSpell())
  2898. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2899. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  2900. //DumpPacket(app);
  2901. QueuePacket(app);
  2902. }
  2903. else if(spell && GetVersion() <=546 && CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
  2904. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display, GetVersion() <= 546 ? true : false);
  2905. //DumpPacket(app);
  2906. QueuePacket(app);
  2907. }
  2908. }
  2909. else if (type == 0) {
  2910. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2911. if (!request) {
  2912. return;
  2913. }
  2914. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2915. safe_delete(request);
  2916. return;
  2917. }
  2918. int32 id = request->getType_int32_ByName("id");
  2919. Item* item = 0;
  2920. // translate from unique id to spawn id for houses
  2921. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2922. bool wasSpawn = false;
  2923. if (spawn)
  2924. {
  2925. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2926. if (item)
  2927. {
  2928. wasSpawn = true;
  2929. item = new Item(item);
  2930. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2931. }
  2932. }
  2933. if (!item)
  2934. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2935. if (!item)
  2936. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2937. if (!item)
  2938. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(id);
  2939. if (!item)
  2940. item = master_item_list.GetItem(id);
  2941. if (item) {// && sent_item_details.count(id) == 0){
  2942. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2943. sent_item_details[id] = true;
  2944. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2945. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2946. QueuePacket(app);
  2947. if (wasSpawn)
  2948. delete item;
  2949. }
  2950. else {
  2951. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2952. DumpPacket(app);
  2953. }
  2954. }
  2955. else if (type == 1) {
  2956. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2957. if (!request) {
  2958. return;
  2959. }
  2960. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2961. safe_delete(request);
  2962. return;
  2963. }
  2964. int32 id = request->getType_int32_ByName("id");
  2965. int32 unique_id = request->getType_int32_ByName("unique_id");
  2966. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  2967. if (!item)
  2968. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  2969. if (!item)
  2970. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(unique_id);
  2971. if (!item)
  2972. item = master_item_list.GetItem(id);
  2973. if (item) {
  2974. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2975. sent_item_details[id] = true;
  2976. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2977. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2978. QueuePacket(app);
  2979. }
  2980. else {
  2981. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2982. DumpPacket(app);
  2983. }
  2984. }
  2985. else if (type == 2) {
  2986. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  2987. if (!request) {
  2988. return;
  2989. }
  2990. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2991. safe_delete(request);
  2992. return;
  2993. }
  2994. int32 id = request->getType_int32_ByName("item_id");
  2995. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  2996. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  2997. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  2998. //int32 unique_id = request->getType_int32_ByName("unique_id");
  2999. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  3000. //printf("Type: (%i) Unknown_0: (%u) Unknown_1: (%u) Unknown2: (%i) Unique ID: (%u) Unknown5: (%i) Item ID: (%u)\n",type,unknown_0,unknown_1,unknown2,unique_id,unknown5,id);
  3001. Item* item = master_item_list.GetItem(id);
  3002. if (item) {
  3003. //only display popup for non merchant links
  3004. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, GetVersion() > 546 ? true : false);
  3005. QueuePacket(app);
  3006. }
  3007. else {
  3008. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  3009. DumpPacket(app);
  3010. }
  3011. }
  3012. else if (type == 4) { //spell effect
  3013. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  3014. if (!request) {
  3015. return;
  3016. }
  3017. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3018. safe_delete(request);
  3019. return;
  3020. }
  3021. int32 id = request->getType_int32_ByName("id");
  3022. int16 display = request->getType_int8_ByName("partial_info");
  3023. SpellEffects* effect = player->GetSpellEffect(id);
  3024. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  3025. if (effect) {
  3026. int8 tier = effect->tier;
  3027. Spell* spell = master_spell_list.GetSpell(id, tier);
  3028. // if we can't find it on the master spell list, see if it is a custom spell
  3029. if (!spell)
  3030. {
  3031. lua_interface->FindCustomSpellLock();
  3032. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  3033. EQ2Packet* pack = 0;
  3034. if (tmpSpell)
  3035. spell = tmpSpell->spell;
  3036. lua_interface->FindCustomSpellUnlock();
  3037. }
  3038. if (spell && !CountSentSpell(id, tier)) {
  3039. if (!spell->IsCopiedSpell())
  3040. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3041. int8 type = 0;
  3042. if (version <= 283)
  3043. type = 1;
  3044. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  3045. //DumpPacket(app);
  3046. QueuePacket(app);
  3047. }
  3048. }
  3049. }
  3050. else if (type == 5) { // recipe info
  3051. request = configReader.getStruct((GetVersion() <= 283) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  3052. if (!request)
  3053. return;
  3054. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3055. safe_delete(request);
  3056. return;
  3057. }
  3058. int32 id = 0;
  3059. if(GetVersion() < 546) {
  3060. id = request->getType_int32_ByName("id");
  3061. }
  3062. else if(GetVersion() == 546) {
  3063. id = request->getType_int32_ByName("unique_id");
  3064. }
  3065. else {
  3066. id = request->getType_int32_ByName("unknown_id");
  3067. }
  3068. Recipe* recipe = master_recipe_list.GetRecipe(id);
  3069. if (recipe) {
  3070. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  3071. //DumpPacket(app);
  3072. QueuePacket(app);
  3073. }
  3074. }
  3075. else if (type == 6) { // AA spell info
  3076. Spell* spell = 0;
  3077. //Spell* spell2 = 0;
  3078. //AltAdvanceData* data = 0;
  3079. request = configReader.getStruct((GetVersion() <= 283) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  3080. if (!request)
  3081. return;
  3082. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3083. safe_delete(request);
  3084. return;
  3085. }
  3086. int32 id = request->getType_int32_ByName("id");
  3087. int32 tier = GetPlayer()->GetSpellTier(id);
  3088. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  3089. //data = master_aa_list.GetAltAdvancement(id);
  3090. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  3091. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  3092. spell = master_spell_list.GetSpell(id, tier);
  3093. if (!spell)
  3094. spell = master_spell_list.GetSpell(id, 1);
  3095. if (!spell)
  3096. {
  3097. lua_interface->FindCustomSpellLock();
  3098. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  3099. if (tmpSpell)
  3100. spell = tmpSpell->spell;
  3101. lua_interface->FindCustomSpellUnlock();
  3102. }
  3103. if (!spell)
  3104. {
  3105. LogWrite(WORLD__ERROR, 0, "WORLD", "FAILED Examine Info Request-> Spell ID: %u, tier: %i", id, tier);
  3106. return;
  3107. }
  3108. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  3109. if (!spell->IsCopiedSpell())
  3110. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3111. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  3112. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  3113. if(GetVersion() > 546) {
  3114. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  3115. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  3116. //DumpPacket(app);
  3117. QueuePacket(app);
  3118. }
  3119. //}
  3120. }
  3121. else {
  3122. LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
  3123. DumpPacket(app);
  3124. }
  3125. safe_delete(request);
  3126. }
  3127. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  3128. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  3129. if (request) {
  3130. if(request->LoadPacketData(app->pBuffer, app->size)) {
  3131. int32 id = request->getType_int32_ByName("id");
  3132. int32 bar = request->getType_int32_ByName("hotbar_number");
  3133. int32 slot = request->getType_int32_ByName("hotkey_slot");
  3134. int32 type = request->getType_int32_ByName("type");
  3135. int8 tier = request->getType_int32_ByName("unique_id");
  3136. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  3137. Spell* spell = 0;
  3138. if (type == 0xFFFFFFFF)
  3139. GetPlayer()->RemoveQuickbarItem(bar, slot);
  3140. else {
  3141. if (type == QUICKBAR_NORMAL)
  3142. spell = master_spell_list.GetSpell(id, tier);
  3143. if (spell)
  3144. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  3145. else
  3146. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  3147. }
  3148. }
  3149. safe_delete(request);
  3150. }
  3151. }
  3152. bool Client::Process(bool zone_process) {
  3153. bool ret = true;
  3154. // EQS can become null if player is linkdead, we want to always be able to process the camp/linkdead timers when active
  3155. if ((camp_timer && camp_timer->Check()) || (linkdead_timer && linkdead_timer->Check())) {
  3156. ResetSendMail();
  3157. if(getConnection())
  3158. getConnection()->SendDisconnect(false);
  3159. safe_delete(camp_timer);
  3160. if(linkdead_timer) {
  3161. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player %s triggered linkdead timer, disconnecting", GetPlayer()->GetName());
  3162. // we remove the linkdead status and force a camp out immediately
  3163. if((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0) {
  3164. GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() - ACTIVITY_STATUS_LINKDEAD);
  3165. }
  3166. if ((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0) {
  3167. GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  3168. }
  3169. }
  3170. safe_delete(linkdead_timer);
  3171. ret = false;
  3172. }
  3173. if (!eqs) {
  3174. return false;
  3175. }
  3176. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  3177. return true;
  3178. }
  3179. switch(new_client_login) {
  3180. case NewLoginState::LOGIN_SEND: {
  3181. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  3182. SendLoginInfo();
  3183. new_client_login = NewLoginState::LOGIN_NONE;
  3184. break;
  3185. }
  3186. case NewLoginState::LOGIN_INITIAL_LOAD: {
  3187. bool isDBActive = database.IsActiveQuery(GetCharacterID());
  3188. // wait for starting skills/spells to load and reload from DB.
  3189. if(!isDBActive) {
  3190. if (GetPlayer()->GetInfoStruct()->get_reload_player_spells()) {
  3191. database.LoadCharacterSpells(GetCharacterID(), GetPlayer());
  3192. GetPlayer()->GetInfoStruct()->set_reload_player_spells(0);
  3193. }
  3194. new_client_login = NewLoginState::LOGIN_SEND;
  3195. }
  3196. break;
  3197. }
  3198. case NewLoginState::LOGIN_ALLOWED: {
  3199. int32 count = 0;
  3200. if(!GetPlayer()->IsReturningFromLD())
  3201. {
  3202. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  3203. count = database.LoadCharacterSkills(GetCharacterID(), player);
  3204. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
  3205. count = database.LoadCharacterSpells(GetCharacterID(), player);
  3206. }
  3207. else
  3208. {
  3209. LogWrite(CCLIENT__INFO, 0, "Client", "Player is returning from linkdead status (Player does not need reload) thus skipping database loading for '%s'...", player->GetName());
  3210. }
  3211. // get the latest character starting skills / spells, may have been updated after character creation
  3212. if(GetPlayer()->GetInfoStruct()->get_first_world_login()) {
  3213. world.SyncCharacterAbilities(this);
  3214. Query query;
  3215. query.AddQueryAsync(GetCharacterID(), &database, Q_UPDATE, "UPDATE characters set first_world_login = 0 where id=%u", GetCharacterID());
  3216. GetPlayer()->GetInfoStruct()->set_first_world_login(0);
  3217. }
  3218. new_client_login = NewLoginState::LOGIN_INITIAL_LOAD;
  3219. break;
  3220. }
  3221. case NewLoginState::LOGIN_DELAYED: {
  3222. if(!delay_msg_timer.Enabled() || delay_msg_timer.Check()) {
  3223. LogWrite(CCLIENT__INFO, 0, "Client", "Wait for zone %s to load for new client %s...", GetCurrentZone()->GetZoneName(), GetPlayer()->GetName());
  3224. delay_msg_timer.Start(1000, true);
  3225. }
  3226. if(!GetCurrentZone()->IsLoading()) {
  3227. new_client_login = NewLoginState::LOGIN_ALLOWED;
  3228. }
  3229. return true;
  3230. break;
  3231. }
  3232. }
  3233. delay_msg_timer.Disable();
  3234. sockaddr_in to;
  3235. memset((char*)&to, 0, sizeof(to));
  3236. to.sin_family = AF_INET;
  3237. to.sin_port = port;
  3238. to.sin_addr.s_addr = ip;
  3239. /************ Get all packets from packet manager out queue and process them ************/
  3240. EQApplicationPacket* app = 0;
  3241. if (eqs && !eqs->CheckActive()) {
  3242. num_active_failures++;
  3243. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  3244. if (num_active_failures > 100) {
  3245. return false;
  3246. }
  3247. return true;
  3248. }
  3249. while (ret && eqs && (app = eqs->PopPacket())) {
  3250. ret = HandlePacket(app);
  3251. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  3252. delete app;
  3253. }
  3254. if (GetCurrentZone() && !GetCurrentZone()->IsLoading() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  3255. //database.LoadCharacterActiveSpells(player);
  3256. player->UnlockAllSpells(true);
  3257. should_load_spells = false;
  3258. }
  3259. if(spawn_removal_timer.Check() && GetPlayer()) {
  3260. GetPlayer()->ProcessSpawnRangeUpdates();
  3261. GetPlayer()->CheckSpawnStateQueue();
  3262. }
  3263. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  3264. {
  3265. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  3266. return false;
  3267. }
  3268. if (quest_updates) {
  3269. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  3270. ProcessQuestUpdates();
  3271. }
  3272. int32 queue_timer_delay = rule_manager.GetGlobalRule(R_Client, QuestQueueTimer)->GetInt32();
  3273. if(queue_timer_delay < 10) {
  3274. queue_timer_delay = 10;
  3275. }
  3276. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - queue_timer_delay)) {
  3277. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  3278. CheckQuestQueue();
  3279. }
  3280. MSaveSpellStateMutex.lock();
  3281. if(save_spell_state_timer.Check())
  3282. {
  3283. save_spell_state_timer.Disable();
  3284. GetPlayer()->SaveSpellEffects();
  3285. }
  3286. MSaveSpellStateMutex.unlock();
  3287. if (temp_placement_timer.Check()) {
  3288. if(GetTempPlacementSpawn() && GetPlayer()->WasSentSpawn(GetTempPlacementSpawn()->GetID()) && !hasSentTempPlacementSpawn) {
  3289. SendMoveObjectMode(GetTempPlacementSpawn(), 0);
  3290. hasSentTempPlacementSpawn = true;
  3291. temp_placement_timer.Disable();
  3292. }
  3293. }
  3294. if (pos_update.Check())
  3295. {
  3296. ProcessStateCommands();
  3297. GetPlayer()->ResetMentorship(); // check if we need to asynchronously reset mentorship
  3298. if(GetPlayer()->GetRegionMap())
  3299. GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3300. if(player_pos_changed && IsReadyForUpdates()) {
  3301. if(!underworld_cooldown_timer.Enabled() || (underworld_cooldown_timer.Enabled() && underworld_cooldown_timer.Check())) {
  3302. bool underworld = false;
  3303. if(rule_manager.GetGlobalRule(R_Zone, UseMapUnderworldCoords)->GetBool()) {
  3304. if(GetCurrentZone()->GetUnderWorld() != -1000000.0f) {
  3305. if(GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld())
  3306. underworld = true;
  3307. }
  3308. else if(GetPlayer()->GetMap() && GetPlayer()->GetMap()->GetMinY() != 9999999.0f && GetPlayer()->GetY() < (GetPlayer()->GetMap()->GetMinY() + rule_manager.GetGlobalRule(R_Zone, MapUnderworldCoordOffset)->GetFloat())) {
  3309. underworld = true;
  3310. }
  3311. }
  3312. else if(GetPlayer()->GetMap() && GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld()) {
  3313. underworld = true;
  3314. }
  3315. if(underworld) {
  3316. player->SetX(GetCurrentZone()->GetSafeX());
  3317. player->SetY(GetCurrentZone()->GetSafeY());
  3318. player->SetZ(GetCurrentZone()->GetSafeZ());
  3319. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3320. EQ2Packet* app = GetPlayer()->Move(player->GetX(), player->GetY(), player->GetZ(), GetVersion(), player->GetHeading());
  3321. if(app){
  3322. QueuePacket(app);
  3323. }
  3324. SimpleMessage(CHANNEL_COLOR_RED, "You have been teleported to a safe location in the zone, because you appeared to have fallen through the world.");
  3325. }
  3326. underworld_cooldown_timer.Start();
  3327. }
  3328. //GetPlayer()->CalculateLocation();
  3329. client_list.CheckPlayersInvisStatus(this);
  3330. GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
  3331. player_pos_changed = false;
  3332. GetCurrentZone()->CheckTransporters(this);
  3333. if(GetPlayer()->GetRegionMap())
  3334. {
  3335. GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3336. }
  3337. }
  3338. else if (IsReadyForUpdates() && GetPlayer()->GetRegionMap()) {
  3339. GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3340. }
  3341. }
  3342. if (lua_interface && lua_debug && lua_debug_timer.Check())
  3343. lua_interface->UpdateDebugClients(this);
  3344. if (quest_pos_timer.Check())
  3345. CheckPlayerQuestsLocationUpdate();
  3346. if (player->GetSkills()->HasSkillUpdates()) {
  3347. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  3348. if (skills) {
  3349. Skill* skill = 0;
  3350. vector<Skill*>::iterator itr;
  3351. for (itr = skills->begin(); itr != skills->end(); itr++) {
  3352. skill = *itr;
  3353. SkillChanged(skill, skill->previous_val, skill->current_val);
  3354. }
  3355. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  3356. if (app) QueuePacket(app);
  3357. safe_delete(skills);
  3358. }
  3359. }
  3360. m_resurrect.writelock(__FUNCTION__, __LINE__);
  3361. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  3362. safe_delete(current_rez.expire_timer);
  3363. current_rez.expire_timer = 0;
  3364. current_rez.active = false;
  3365. current_rez.caster = 0;
  3366. current_rez.crit = false;
  3367. current_rez.crit_mod = 0;
  3368. current_rez.expire_timer = 0;
  3369. current_rez.heal_name = "";
  3370. current_rez.hp_perc = 0;
  3371. current_rez.mp_perc = 0;
  3372. current_rez.no_calcs = false;
  3373. current_rez.range = 0;
  3374. current_rez.should_delete = false;
  3375. current_rez.spell_name = "";
  3376. current_rez.spell_visual = 0;
  3377. current_rez.subspell = 0;
  3378. }
  3379. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  3380. // Quest timers
  3381. Quest* failed_step = 0;
  3382. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  3383. if (quest_timers.size() > 0) {
  3384. vector<int32>::iterator itr;
  3385. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  3386. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  3387. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  3388. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  3389. Quest* quest = player_quests->at(*itr);
  3390. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  3391. failed_step = quest;
  3392. break;
  3393. }
  3394. }
  3395. else {
  3396. itr = quest_timers.erase(itr);
  3397. break;
  3398. }
  3399. }
  3400. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  3401. }
  3402. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  3403. if (failed_step)
  3404. failed_step->StepFailed(failed_step->GetTimerStep());
  3405. if (player->ControlFlagsChanged())
  3406. player->SendControlFlagUpdates(this);
  3407. if (!eqs || (eqs && !eqs->CheckActive()))
  3408. ret = false;
  3409. // redundant to client disconnect
  3410. // if(!ret)
  3411. // Save();
  3412. return ret;
  3413. }
  3414. ClientList::ClientList() {
  3415. MClients.SetName("ClientList::MClients");
  3416. }
  3417. ClientList::~ClientList() {
  3418. }
  3419. void ClientList::ReloadQuests() {
  3420. list<Client*>::iterator client_iter;
  3421. Client* client = 0;
  3422. MClients.readlock(__FUNCTION__, __LINE__);
  3423. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3424. client = *client_iter;
  3425. if (client)
  3426. client->ReloadQuests();
  3427. }
  3428. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3429. }
  3430. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  3431. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  3432. return;
  3433. list<Client*>::iterator client_iter;
  3434. Client* client = 0;
  3435. MClients.readlock(__FUNCTION__, __LINE__);
  3436. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3437. client = *client_iter;
  3438. if (client == owner || client->GetPlayer() == NULL)
  3439. continue;
  3440. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  3441. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  3442. }
  3443. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3444. }
  3445. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  3446. list<Client*>::iterator client_iter;
  3447. Client* client = 0;
  3448. MClients.readlock(__FUNCTION__, __LINE__);
  3449. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3450. client = *client_iter;
  3451. if (!client->GetPlayer())
  3452. continue;
  3453. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  3454. }
  3455. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3456. }
  3457. int32 ClientList::Count() {
  3458. return client_list.size();
  3459. }
  3460. void ClientList::Add(Client* client) {
  3461. MClients.writelock(__FUNCTION__, __LINE__);
  3462. client_list.push_back(client);
  3463. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3464. }
  3465. Client* ClientList::FindByAccountID(int32 account_id) {
  3466. list<Client*>::iterator client_iter;
  3467. Client* client = 0;
  3468. Client* ret = 0;
  3469. MClients.readlock(__FUNCTION__, __LINE__);
  3470. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3471. client = *client_iter;
  3472. if (client->GetAccountID() == account_id) {
  3473. ret = client;
  3474. break;
  3475. }
  3476. }
  3477. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3478. return ret;
  3479. }
  3480. Client* ClientList::FindByName(char* charName) {
  3481. list<Client*>::iterator client_iter;
  3482. Client* client = 0;
  3483. Client* ret = 0;
  3484. MClients.readlock(__FUNCTION__, __LINE__);
  3485. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3486. client = *client_iter;
  3487. if (!client || !client->GetPlayer())
  3488. continue;
  3489. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  3490. ret = client;
  3491. break;
  3492. }
  3493. }
  3494. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3495. return ret;
  3496. }
  3497. Client* ClientList::Get(int32 ip, int16 port) {
  3498. list<Client*>::iterator client_iter;
  3499. Client* client = 0;
  3500. Client* ret = 0;
  3501. MClients.readlock(__FUNCTION__, __LINE__);
  3502. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3503. client = *client_iter;
  3504. if (client->GetIP() == ip && client->GetPort() == port) {
  3505. ret = client;
  3506. break;
  3507. }
  3508. }
  3509. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3510. return ret;
  3511. }
  3512. void ClientList::Process() {
  3513. list<Client*>::iterator client_iter;
  3514. list<Client*>::iterator erase_iter;
  3515. Client* client = 0;
  3516. MClients.readlock(__FUNCTION__, __LINE__);
  3517. erase_iter = client_list.end();
  3518. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3519. client = *client_iter;
  3520. // have a sanity check because the client list can sometimes obtain null client pointers
  3521. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  3522. erase_iter = client_iter;
  3523. break;
  3524. }
  3525. }
  3526. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3527. if (erase_iter != client_list.end()) {
  3528. client = *erase_iter;
  3529. MClients.writelock(__FUNCTION__, __LINE__);
  3530. client_list.erase(erase_iter);
  3531. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3532. if (client && !client->remove_from_list) {
  3533. struct in_addr in;
  3534. in.s_addr = client->GetIP();
  3535. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  3536. safe_delete(client);
  3537. }
  3538. }
  3539. }
  3540. void ClientList::RemoveConnection(EQStream* eqs) {
  3541. Client* client;
  3542. if (eqs) {
  3543. list<Client*>::iterator client_iter;
  3544. MClients.readlock(__FUNCTION__, __LINE__);
  3545. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3546. client = *client_iter;
  3547. if (client->getConnection() == eqs)
  3548. client->Disconnect(true);
  3549. }
  3550. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3551. }
  3552. }
  3553. bool ClientList::ContainsStream(EQStream* eqs) {
  3554. if (!eqs) {
  3555. return false;
  3556. }
  3557. list<Client*>::iterator client_iter;
  3558. bool ret = false;
  3559. MClients.readlock(__FUNCTION__, __LINE__);
  3560. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3561. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  3562. ret = true;
  3563. break;
  3564. }
  3565. }
  3566. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3567. return ret;
  3568. }
  3569. void ClientList::Remove(Client* client, bool remove_data) {
  3570. client->remove_from_list = true;
  3571. if (remove_data) {
  3572. safe_delete(client);
  3573. }
  3574. }
  3575. void Client::SetCurrentZone(ZoneServer* zone) {
  3576. current_zone = zone;
  3577. if(player) {
  3578. player->SetZone(zone, GetVersion());
  3579. }
  3580. }
  3581. void Client::SetCurrentZone(int32 id) {
  3582. if (current_zone) {
  3583. //current_zone->GetCombat()->RemoveHate(player);
  3584. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3585. }
  3586. SetCurrentZone(zone_list.Get(id));
  3587. }
  3588. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  3589. if (current_zone) {
  3590. //current_zone->GetCombat()->RemoveHate(player);
  3591. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3592. }
  3593. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  3594. }
  3595. ZoneServer* Client::GetCurrentZone() {
  3596. return current_zone;
  3597. }
  3598. int8 Client::GetMessageChannelColor(int8 channel_type) {
  3599. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  3600. if (channel_type == CHANNEL_LOOT)
  3601. return CHANNEL_COLOR_NEW_LOOT;
  3602. }
  3603. else if (GetVersion() >= 973) {
  3604. if (channel_type == CHANNEL_LOOT)
  3605. return CHANNEL_COLOR_NEWEST_LOOT;
  3606. }
  3607. if (GetVersion() <= 283) {
  3608. if (channel_type <=12)
  3609. return channel_type;
  3610. switch (channel_type) {
  3611. case CHANNEL_GROUP_CHAT:
  3612. case CHANNEL_GROUP_SAY:
  3613. case CHANNEL_RAID_SAY:
  3614. case CHANNEL_GUILD_CHAT:
  3615. case CHANNEL_GUILD_SAY:
  3616. case CHANNEL_OFFICER_SAY:
  3617. case CHANNEL_GUILD_MOTD:
  3618. return channel_type - 1;
  3619. case CHANNEL_PRIVATE_CHAT:
  3620. case CHANNEL_NONPLAYER_TELL:
  3621. return channel_type - 5;
  3622. case CHANNEL_PRIVATE_TELL:
  3623. case CHANNEL_TELL_FROM_CS:
  3624. return channel_type - 6;
  3625. case CHANNEL_CHAT_CHANNEL_TEXT:
  3626. case CHANNEL_OUT_OF_CHARACTER:
  3627. case CHANNEL_AUCTION:
  3628. case CHANNEL_CUSTOM_CHANNEL:
  3629. case CHANNEL_CHARACTER_TEXT:
  3630. case CHANNEL_REWARD:
  3631. case CHANNEL_DEATH:
  3632. case CHANNEL_PET_CHAT:
  3633. case CHANNEL_SKILL:
  3634. return channel_type - 7;
  3635. case CHANNEL_SPELLS:
  3636. case CHANNEL_YOU_CAST:
  3637. case CHANNEL_YOU_FAIL:
  3638. return channel_type - 8;
  3639. case CHANNEL_FRIENDLY_CAST:
  3640. case CHANNEL_FRIENDLY_FAIL:
  3641. case CHANNEL_OTHER_CAST:
  3642. case CHANNEL_OTHER_FAIL:
  3643. case CHANNEL_HOSTILE_CAST:
  3644. case CHANNEL_HOSTILE_FAIL:
  3645. case CHANNEL_WORN_OFF:
  3646. case CHANNEL_SPELLS_OTHER:
  3647. return channel_type - 9;
  3648. case CHANNEL_COMBAT:
  3649. return channel_type - 15;
  3650. case CHANNEL_HEROIC_OPPORTUNITY:
  3651. case CHANNEL_NON_MELEE_DAMAGE:
  3652. case CHANNEL_DAMAGE_SHIELD:
  3653. return channel_type - 16;
  3654. case CHANNEL_MELEE_COMBAT:
  3655. case CHANNEL_WARNINGS:
  3656. case CHANNEL_YOU_HIT:
  3657. case CHANNEL_YOU_MISS:
  3658. case CHANNEL_ATTACKER_HITS:
  3659. case CHANNEL_ATTACKER_MISSES:
  3660. return channel_type - 18;
  3661. case CHANNEL_OTHER_HIT:
  3662. case CHANNEL_OTHER_MISSES:
  3663. case CHANNEL_CRITICAL_HIT:
  3664. return channel_type - 22;
  3665. case CHANNEL_OTHER:
  3666. case CHANNEL_MONEY_SPLIT:
  3667. case CHANNEL_LOOT:
  3668. return channel_type - 30;
  3669. case CHANNEL_COMMAND_TEXT:
  3670. case CHANNEL_BROADCAST:
  3671. case CHANNEL_WHO:
  3672. case CHANNEL_COMMANDS:
  3673. case CHANNEL_MERCHANT:
  3674. case CHANNEL_MERCHANT_BUY_SELL:
  3675. case CHANNEL_CONSIDER_MESSAGE:
  3676. case CHANNEL_CON_MINUS_2:
  3677. case CHANNEL_CON_MINUS_1:
  3678. case CHANNEL_CON_0:
  3679. case CHANNEL_CON_1:
  3680. case CHANNEL_CON_2:
  3681. return channel_type - 31;
  3682. default: {
  3683. return CHANNEL_DEFAULT;
  3684. }
  3685. }
  3686. }
  3687. else if (GetVersion() <= 546) {
  3688. if (channel_type < 20)
  3689. return channel_type;
  3690. switch (channel_type) {
  3691. case CHANNEL_GUILD_MOTD:
  3692. case CHANNEL_GUILD_MEMBER_ONLINE:
  3693. case CHANNEL_GUILD_EVENT:
  3694. return channel_type + 1;
  3695. case CHANNEL_PRIVATE_CHAT:
  3696. case CHANNEL_NONPLAYER_TELL:
  3697. return channel_type - 1;
  3698. case CHANNEL_PRIVATE_TELL:
  3699. case CHANNEL_TELL_FROM_CS:
  3700. case CHANNEL_ARENA:
  3701. case CHANNEL_CHAT_CHANNEL_TEXT:
  3702. case CHANNEL_OUT_OF_CHARACTER:
  3703. case CHANNEL_AUCTION:
  3704. case CHANNEL_CUSTOM_CHANNEL:
  3705. case CHANNEL_CHARACTER_TEXT:
  3706. case CHANNEL_REWARD:
  3707. case CHANNEL_DEATH:
  3708. case CHANNEL_PET_CHAT:
  3709. case CHANNEL_SKILL:
  3710. case CHANNEL_FACTION:
  3711. case CHANNEL_SPELLS:
  3712. case CHANNEL_YOU_CAST:
  3713. case CHANNEL_YOU_FAIL:
  3714. return channel_type - 2;
  3715. case CHANNEL_FRIENDLY_CAST:
  3716. case CHANNEL_FRIENDLY_FAIL:
  3717. case CHANNEL_OTHER_CAST:
  3718. case CHANNEL_OTHER_FAIL:
  3719. case CHANNEL_HOSTILE_CAST:
  3720. case CHANNEL_HOSTILE_FAIL:
  3721. case CHANNEL_WORN_OFF:
  3722. case CHANNEL_SPELLS_OTHER:
  3723. case CHANNEL_HEAL_SPELLS:
  3724. case CHANNEL_HEALS:
  3725. case CHANNEL_FRIENDLY_HEALS:
  3726. case CHANNEL_OTHER_HEALS:
  3727. case CHANNEL_HOSTILE_HEALS:
  3728. return channel_type - 3;
  3729. case CHANNEL_COMBAT:
  3730. case CHANNEL_GENERAL_COMBAT:
  3731. case CHANNEL_HEROIC_OPPORTUNITY:
  3732. case CHANNEL_NON_MELEE_DAMAGE:
  3733. case CHANNEL_DAMAGE_SHIELD:
  3734. case CHANNEL_WARD:
  3735. return channel_type - 4;
  3736. case CHANNEL_MELEE_COMBAT:
  3737. case CHANNEL_WARNINGS:
  3738. case CHANNEL_YOU_HIT:
  3739. case CHANNEL_YOU_MISS:
  3740. case CHANNEL_ATTACKER_HITS:
  3741. case CHANNEL_ATTACKER_MISSES:
  3742. case CHANNEL_YOUR_PET_HITS:
  3743. case CHANNEL_YOUR_PET_MISSES:
  3744. case CHANNEL_ATTACKER_HITS_PET:
  3745. case CHANNEL_ATTACKER_MISSES_PET:
  3746. case CHANNEL_OTHER_HIT:
  3747. case CHANNEL_OTHER_MISSES:
  3748. return channel_type - 5;
  3749. case CHANNEL_OTHER:
  3750. case CHANNEL_MONEY_SPLIT:
  3751. case CHANNEL_LOOT:
  3752. return channel_type - 14;
  3753. case CHANNEL_COMMAND_TEXT:
  3754. case CHANNEL_BROADCAST:
  3755. case CHANNEL_WHO:
  3756. case CHANNEL_COMMANDS:
  3757. case CHANNEL_MERCHANT:
  3758. case CHANNEL_MERCHANT_BUY_SELL:
  3759. case CHANNEL_CONSIDER_MESSAGE:
  3760. case CHANNEL_CON_MINUS_2:
  3761. case CHANNEL_CON_MINUS_1:
  3762. case CHANNEL_CON_0:
  3763. case CHANNEL_CON_1:
  3764. case CHANNEL_CON_2:
  3765. case CHANNEL_TRADESKILLS:
  3766. case CHANNEL_HARVESTING:
  3767. case CHANNEL_HARVESTING_WARNINGS:
  3768. return channel_type - 15;
  3769. default: {
  3770. return CHANNEL_DEFAULT;
  3771. }
  3772. }
  3773. }
  3774. else {
  3775. switch (channel_type) {
  3776. default: {
  3777. return channel_type;
  3778. }
  3779. }
  3780. }
  3781. return channel_type;
  3782. }
  3783. void Client::HandleTellMessage(Client* from, const char* message, const char* to, int32 current_language_id) {
  3784. if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  3785. return;
  3786. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  3787. if (packet) {
  3788. packet->setDataByName("from", from->GetPlayer()->GetName());
  3789. packet->setDataByName("to", to);
  3790. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  3791. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  3792. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  3793. packet->setDataByName("unknown2", 1, 1);
  3794. packet->setDataByName("show_bubble", 1);
  3795. if (current_language_id == 0 || GetPlayer()->HasLanguage(current_language_id)) {
  3796. packet->setDataByName("understood", 1);
  3797. }
  3798. packet->setDataByName("time", 2);
  3799. packet->setDataByName("language", current_language_id);
  3800. packet->setMediumStringByName("message", message);
  3801. EQ2Packet* outpacket = packet->serialize();
  3802. QueuePacket(outpacket);
  3803. safe_delete(packet);
  3804. }
  3805. }
  3806. void Client::SimpleMessage(int8 color, const char* message) {
  3807. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  3808. if (command_packet) {
  3809. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  3810. command_packet->setMediumStringByName("text", message);
  3811. command_packet->setDataByName("unknown02", 0x00ff);
  3812. EQ2Packet* outapp = command_packet->serialize();
  3813. QueuePacket(outapp);
  3814. safe_delete(command_packet);
  3815. }
  3816. }
  3817. void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
  3818. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  3819. if (packet) {
  3820. int8 xxx = spell->GetSpellData()->is_aa;
  3821. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  3822. packet->setDataByName("spell_id", spell->GetSpellID());
  3823. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  3824. packet->setDataByName("spell_name", spell->GetName());
  3825. if(add_silently)
  3826. packet->setDataByName("add_silently", 1);
  3827. if(add_to_hotbar)
  3828. packet->setDataByName("add_to_hotbar", 1);
  3829. packet->setDataByName("unknown", xxx);
  3830. packet->setDataByName("display_spell_tier", 1);
  3831. packet->setDataByName("unknown3", 1);
  3832. packet->setDataByName("tier", spell->GetSpellTier());
  3833. packet->setDataByName("icon", spell->GetSpellIcon());
  3834. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  3835. packet->setDataByName("unknown5", 0xFFFFFFFF);
  3836. //packet->PrintPacket();
  3837. EQ2Packet* outapp = packet->serialize();
  3838. //DumpPacket(outapp);
  3839. QueuePacket(outapp);
  3840. safe_delete(packet);
  3841. }
  3842. }
  3843. void Client::Message(int8 type, const char* message, ...) {
  3844. va_list argptr;
  3845. char buffer[4096];
  3846. va_start(argptr, message);
  3847. vsnprintf(buffer, sizeof(buffer), message, argptr);
  3848. va_end(argptr);
  3849. SimpleMessage(type, buffer);
  3850. }
  3851. void Client::Disconnect(bool send_disconnect)
  3852. {
  3853. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  3854. this->Save();
  3855. this->GetPlayer()->WritePlayerStatistics();
  3856. SetConnected(false);
  3857. if (send_disconnect && getConnection())
  3858. getConnection()->SendDisconnect(true);
  3859. eqs = 0;
  3860. }
  3861. bool Client::Summon(const char* search_name) {
  3862. Spawn* target = 0;
  3863. if (search_name || GetPlayer()->GetTarget()) {
  3864. Client* search_client = 0;
  3865. if (search_name) {
  3866. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3867. if (target && target->IsPlayer())
  3868. search_client = target->GetClient();
  3869. if (!target) {
  3870. search_client = zone_list.GetClientByCharName(string(search_name));
  3871. if (search_client)
  3872. target = search_client->GetPlayer();
  3873. }
  3874. }
  3875. else
  3876. target = GetPlayer()->GetTarget();
  3877. if (target && target != GetPlayer()) {
  3878. target->SetX(GetPlayer()->GetX());
  3879. target->SetY(GetPlayer()->GetY());
  3880. target->SetZ(GetPlayer()->GetZ());
  3881. target->SetHeading(GetPlayer()->GetHeading());
  3882. if (!target->IsPlayer()) {
  3883. target->SetSpawnOrigX(target->GetX());
  3884. target->SetSpawnOrigY(target->GetY());
  3885. target->SetSpawnOrigZ(target->GetZ());
  3886. target->SetSpawnOrigHeading(target->GetHeading());
  3887. }
  3888. target->SetLocation(GetPlayer()->GetLocation());
  3889. if(target->IsNPC()) {
  3890. ((NPC*)target)->HaltMovement();
  3891. }
  3892. }
  3893. else if (target)
  3894. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  3895. if (search_client && search_client != this) {
  3896. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  3897. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  3898. if (search_client->GetCurrentZone() != GetCurrentZone())
  3899. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  3900. else {
  3901. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  3902. if (app)
  3903. search_client->QueuePacket(app);
  3904. }
  3905. }
  3906. }
  3907. if (!target)
  3908. return false;
  3909. else
  3910. return true;
  3911. }
  3912. std::string Client::IdentifyInstanceLockout(int32 zoneID, bool displayClient) {
  3913. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3914. if(instanceType < 1)
  3915. return std::string("");
  3916. ZoneServer* instance_zone = nullptr;
  3917. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3918. if (data) {
  3919. // If lockout instances check to see if we are locked out
  3920. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  3921. int32 time = 0;
  3922. // Check success timer
  3923. if (data->last_success_timestamp > 0) {
  3924. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  3925. // Timer has not expired yet can't re enter
  3926. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3927. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  3928. }
  3929. }
  3930. // Check failure timer
  3931. if (data->last_failure_timestamp > 0) {
  3932. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  3933. // Timer has not expired yet
  3934. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3935. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  3936. }
  3937. }
  3938. // Time > 0 then we are locked out, make the message and send it and return true
  3939. if (time > 0) {
  3940. string time_msg = "";
  3941. int16 hour;
  3942. int8 min;
  3943. int8 sec;
  3944. hour = time / 3600;
  3945. time = time % 3600;
  3946. min = time / 60;
  3947. time = time % 60;
  3948. sec = time;
  3949. if (hour > 0) {
  3950. char temp[10];
  3951. snprintf(temp, 9," %i", hour);
  3952. time_msg.append(temp);
  3953. time_msg.append(" hour");
  3954. time_msg.append((hour > 1) ? "s" : "");
  3955. }
  3956. if (min > 0) {
  3957. char temp[5];
  3958. snprintf(temp, 4," %i", min);
  3959. time_msg.append(temp);
  3960. time_msg.append(" minute");
  3961. time_msg.append((min > 1) ? "s" : "");
  3962. }
  3963. // Only add seconds if minutes and hours are 0
  3964. if (hour == 0 && min == 0 && sec > 0) {
  3965. char temp[5];
  3966. snprintf(temp, 4," %i", sec);
  3967. time_msg.append(temp);
  3968. time_msg.append(" second");
  3969. time_msg.append((sec > 1) ? "s" : "");
  3970. }
  3971. if(displayClient)
  3972. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  3973. return time_msg;
  3974. }
  3975. }
  3976. }
  3977. return std::string("");
  3978. }
  3979. ZoneServer* Client::IdentifyInstance(int32 zoneID) {
  3980. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3981. if(instanceType < 1)
  3982. return nullptr;
  3983. ZoneServer* instance_zone = nullptr;
  3984. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3985. if (data) {
  3986. std::string lockoutTime = IdentifyInstanceLockout(zoneID);
  3987. // If lockout instances check to see if we are locked out
  3988. if (lockoutTime.length() > 0) {
  3989. return nullptr;
  3990. }
  3991. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  3992. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID, false, false);
  3993. // if we got an instance_zone and the instance_id from the data is 0 or data instance id is not the same as the zone instance id then update values
  3994. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  3995. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  3996. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  3997. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  3998. }
  3999. else
  4000. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  4001. data->instance_id = instance_zone->GetInstanceID();
  4002. }
  4003. }
  4004. return instance_zone;
  4005. }
  4006. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  4007. ZoneServer* instance_zone = NULL;
  4008. int8 instanceType = 0;
  4009. // determine if this is a group instanced zone that already exists
  4010. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  4011. if (instance_zone != NULL)
  4012. Zone(instance_zone->GetInstanceID(), zone_coords_valid);
  4013. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  4014. {
  4015. // best to check if we already have our own instance!
  4016. if((instance_zone = IdentifyInstance(zoneID)) == nullptr)
  4017. {
  4018. switch (instanceType)
  4019. {
  4020. case SOLO_LOCKOUT_INSTANCE:
  4021. case GROUP_LOCKOUT_INSTANCE:
  4022. case RAID_LOCKOUT_INSTANCE:
  4023. {
  4024. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4025. if (instance_zone) {
  4026. // once lockout instance zone shuts down you can't renenter if you have a lockout or if you don't you get a new zone
  4027. // so delete `instances` entry for the zone when it shuts down.
  4028. int32 db_id = database.AddCharacterInstance(GetPlayer()->GetCharacterID(), instance_zone->GetInstanceID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceType(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime());
  4029. if (db_id > 0)
  4030. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  4031. }
  4032. break;
  4033. }
  4034. case SOLO_PERSIST_INSTANCE:
  4035. case GROUP_PERSIST_INSTANCE:
  4036. case RAID_PERSIST_INSTANCE:
  4037. {
  4038. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4039. if (instance_zone) {
  4040. int32 db_id = database.AddCharacterInstance(GetPlayer()->GetCharacterID(), instance_zone->GetInstanceID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceType(), Timer::GetUnixTimeStamp(), 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime());
  4041. if (db_id > 0)
  4042. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), Timer::GetUnixTimeStamp(), 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  4043. }
  4044. break;
  4045. }
  4046. case PUBLIC_INSTANCE:
  4047. case TRADESKILL_INSTANCE:
  4048. {
  4049. // if its public/tradeskill, look for a public already setup
  4050. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  4051. if (instance_zone) {
  4052. // Check the current population against the max population, if greater or equal start a new version
  4053. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  4054. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4055. }
  4056. else
  4057. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4058. break;
  4059. }
  4060. case PERSONAL_HOUSE_INSTANCE:
  4061. case GUILD_HOUSE_INSTANCE:
  4062. {
  4063. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  4064. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  4065. // with the OP_EnterHouseMsg opcode
  4066. break;
  4067. }
  4068. case QUEST_INSTANCE:
  4069. {
  4070. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4071. break;
  4072. /*
  4073. ALTER TABLE `zones` CHANGE COLUMN `instance_type` `instance_type` ENUM('NONE','GROUP_LOCKOUT_INSTANCE','GROUP_PERSIST_INSTANCE','RAID_LOCKOUT_INSTANCE','RAID_PERSIST_INSTANCE','SOLO_LOCKOUT_INSTANCE','SOLO_PERSIST_INSTANCE','TRADESKILL_INSTANCE','PUBLIC_INSTANCE','PERSONAL_HOUSE_INSTANCE','GUILD_HOUSE_INSTANCE','QUEST_INSTANCE') NOT NULL DEFAULT 'NONE' COLLATE 'latin1_general_ci' AFTER `start_zone`;
  4074. */
  4075. }
  4076. default:
  4077. {
  4078. // NONE
  4079. }
  4080. }
  4081. }
  4082. if (instance_zone != NULL)
  4083. Zone(instance_zone, zone_coords_valid);
  4084. }
  4085. if (instance_zone != NULL)
  4086. return true;
  4087. else
  4088. return false;
  4089. }
  4090. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  4091. Spawn* target = 0;
  4092. if (search_name || GetPlayer()->GetTarget()) {
  4093. Client* search_client = 0;
  4094. if (search_name) {
  4095. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  4096. if (!target) {
  4097. search_client = zone_list.GetClientByCharName(search_name);
  4098. if (search_client)
  4099. target = search_client->GetPlayer();
  4100. }
  4101. if (target)
  4102. GetPlayer()->SetTarget(target);
  4103. }
  4104. else
  4105. target = GetPlayer()->GetTarget();
  4106. if (target && target != GetPlayer()) {
  4107. GetPlayer()->SetX(target->GetX());
  4108. GetPlayer()->SetY(target->GetY());
  4109. GetPlayer()->SetZ(target->GetZ());
  4110. GetPlayer()->SetHeading(target->GetHeading());
  4111. GetPlayer()->SetLocation(target->GetLocation());
  4112. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  4113. }
  4114. else if (target)
  4115. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  4116. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  4117. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  4118. else if (target) {
  4119. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion(), (target->GetHeading() + 180.0f));
  4120. if (app)
  4121. QueuePacket(app);
  4122. }
  4123. }
  4124. if (!target)
  4125. return false;
  4126. else
  4127. return true;
  4128. }
  4129. bool Client::CheckZoneAccess(const char* zoneName) {
  4130. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  4131. ZoneServer* zone = zone_list.Get(zoneName, false, false, false);
  4132. // JA: implemented /zone lock|unlock commands (2012.07.28)
  4133. if (zone && zone->GetZoneLockState())
  4134. {
  4135. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  4136. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  4137. return false;
  4138. }
  4139. sint16 zoneMinStatus = 0;
  4140. int16 zoneMinLevel = 0;
  4141. int16 zoneMaxLevel = 0;
  4142. int16 zoneMinVersion = 0;
  4143. if (!zone)
  4144. {
  4145. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  4146. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  4147. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  4148. return true;
  4149. }
  4150. }
  4151. else
  4152. {
  4153. zoneMinStatus = zone->GetMinimumStatus();
  4154. zoneMinLevel = zone->GetMinimumLevel();
  4155. zoneMaxLevel = zone->GetMaximumLevel();
  4156. zoneMinVersion = zone->GetMinimumVersion();
  4157. }
  4158. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  4159. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  4160. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  4161. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  4162. {
  4163. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  4164. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  4165. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  4166. return false;
  4167. }
  4168. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  4169. {
  4170. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  4171. {
  4172. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  4173. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  4174. return false;
  4175. }
  4176. }
  4177. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  4178. {
  4179. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  4180. {
  4181. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  4182. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  4183. return false;
  4184. }
  4185. }
  4186. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  4187. {
  4188. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  4189. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  4190. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  4191. {
  4192. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  4193. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  4194. return false;
  4195. }
  4196. }
  4197. return true;
  4198. }
  4199. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID, bool is_spell) {
  4200. Zone(zone_list.GetByInstanceID(instanceid, 0, false, true), set_coords, is_spell);
  4201. }
  4202. void Client::Zone(ZoneServer* new_zone, bool set_coords, bool is_spell) {
  4203. if (!new_zone) {
  4204. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  4205. return;
  4206. }
  4207. client_zoning = true;
  4208. zoning_id = new_zone->GetZoneID();
  4209. zoning_instance_id = new_zone->GetInstanceID();
  4210. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  4211. player->SetResurrecting(true);
  4212. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  4213. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  4214. SaveSpells();
  4215. ResetSendMail();
  4216. // Remove players pet from zone if there is one
  4217. ((Entity*)player)->DismissAllPets();
  4218. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  4219. GetCurrentZone()->RemoveSpawn(player, false, true, true, true, !is_spell);
  4220. GetPlayer()->DeleteSpellEffects(true);
  4221. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  4222. SetZoningDestination(new_zone);
  4223. SetCurrentZone(new_zone);
  4224. if (player->GetGroupMemberInfo())
  4225. {
  4226. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  4227. player->UpdateGroupMemberInfo();
  4228. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  4229. }
  4230. // block out the member info for the group
  4231. TempRemoveGroup();
  4232. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  4233. if (set_coords)
  4234. {
  4235. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  4236. __FUNCTION__,
  4237. GetCurrentZone()->GetSafeX(),
  4238. GetCurrentZone()->GetSafeY(),
  4239. GetCurrentZone()->GetSafeZ(),
  4240. GetCurrentZone()->GetSafeHeading(),
  4241. new_zone->GetZoneName()
  4242. );
  4243. player->SetX(GetCurrentZone()->GetSafeX());
  4244. player->SetY(GetCurrentZone()->GetSafeY());
  4245. player->SetZ(GetCurrentZone()->GetSafeZ());
  4246. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  4247. SetZoningCoords(GetCurrentZone()->GetSafeX(), GetCurrentZone()->GetSafeY(),
  4248. GetCurrentZone()->GetSafeZ(), GetCurrentZone()->GetSafeHeading());
  4249. }
  4250. else {
  4251. ResetZoningCoords();
  4252. }
  4253. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  4254. Save();
  4255. char* new_zone_ip = 0;
  4256. if (IsPrivateAddress(this->GetIP()) && strlen(net.GetInternalWorldAddress()) > 0)
  4257. new_zone_ip = net.GetInternalWorldAddress();
  4258. else
  4259. new_zone_ip = net.GetWorldAddress();
  4260. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  4261. int32 key = Timer::GetUnixTimeStamp();
  4262. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  4263. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  4264. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  4265. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  4266. if (version > 283) {
  4267. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  4268. if (packet)
  4269. {
  4270. QueuePacket(packet->serialize());
  4271. safe_delete(packet);
  4272. }
  4273. }
  4274. }
  4275. void Client::Zone(const char* new_zone, bool set_coords, bool is_spell)
  4276. {
  4277. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  4278. Zone(zone_list.Get(new_zone), set_coords, is_spell);
  4279. }
  4280. float Client::DistanceFrom(Client* client) {
  4281. float ret = 0;
  4282. if (client && client != this) {
  4283. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  4284. ret = sqrt(ret);
  4285. }
  4286. return ret;
  4287. }
  4288. void Client::DetermineCharacterUpdates() {
  4289. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  4290. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  4291. cdu->account_id = GetAccountID();
  4292. cdu->char_id = GetCharacterID();
  4293. int32 timestamp = Timer::GetUnixTimeStamp();
  4294. int8 flag = GetTimeStampFlag();
  4295. if (flag & LEVEL_UPDATE_FLAG)
  4296. {
  4297. cdu->update_field = LEVEL_UPDATE_FLAG;
  4298. cdu->update_data = player->GetLevel();
  4299. loginserver.SendPacket(outpack);
  4300. }
  4301. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  4302. if (flag & CLASS_UPDATE_FLAG)
  4303. {
  4304. cdu->update_field = CLASS_UPDATE_FLAG;
  4305. cdu->update_data = player->GetAdventureClass();
  4306. loginserver.SendPacket(outpack);
  4307. }
  4308. if (flag & GENDER_UPDATE_FLAG)
  4309. {
  4310. cdu->update_field = GENDER_UPDATE_FLAG;
  4311. cdu->update_data = player->GetGender();
  4312. loginserver.SendPacket(outpack);
  4313. }
  4314. if (flag & DELETE_UPDATE_FLAG) {
  4315. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4316. }
  4317. safe_delete(outpack); // Zone, armor and name use a different structure
  4318. if (flag & RACE_UPDATE_FLAG)
  4319. {
  4320. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  4321. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  4322. ru->account_id = GetAccountID();
  4323. ru->char_id = GetCharacterID();
  4324. ru->race = player->GetRace();
  4325. ru->model_type = player->GetModelType();
  4326. loginserver.SendPacket(outpack);
  4327. safe_delete(outpack);
  4328. }
  4329. if (flag & ZONE_UPDATE_FLAG) {
  4330. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  4331. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  4332. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  4333. czu->account_id = GetAccountID();
  4334. czu->char_id = GetCharacterID();
  4335. czu->zone_id = GetCurrentZone()->GetZoneID();
  4336. const char* zone_file = GetCurrentZone()->GetZoneFile();
  4337. czu->zone_length = strlen(zone_file);
  4338. if (czu->zone_length > 64)
  4339. czu->zone_length = 64;
  4340. strncpy(czu->new_zone, zone_file, czu->zone_length);
  4341. loginserver.SendPacket(outpack);
  4342. safe_delete(outpack);
  4343. }
  4344. if (flag & ARMOR_UPDATE_FLAG) {
  4345. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4346. }
  4347. if (flag & NAME_UPDATE_FLAG) {
  4348. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4349. }
  4350. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  4351. }
  4352. void Client::Save() {
  4353. if (GetCharacterID() == 0 || IsSaveDisabled())
  4354. return;
  4355. if (current_zone) {
  4356. DetermineCharacterUpdates();
  4357. UpdateCharacterInstances();
  4358. this->SetLastSavedTimeStamp(Timer::GetCurrentTime2());
  4359. database.Save(this);
  4360. if (GetPlayer()->UpdateQuickbarNeeded()) {
  4361. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  4362. GetPlayer()->ResetQuickbarNeeded();
  4363. }
  4364. database.SaveItems(this);
  4365. database.SaveBuyBacks(this);
  4366. GetPlayer()->SaveHistory();
  4367. GetPlayer()->SaveLUAHistory();
  4368. MSaveSpellStateMutex.lock();
  4369. GetPlayer()->SaveSpellEffects();
  4370. MSaveSpellStateMutex.unlock();
  4371. }
  4372. }
  4373. void Client::UpdateCharacterInstances() {
  4374. if (GetPlayer() != NULL)
  4375. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  4376. /*if ( GetPlayer() != NULL )
  4377. {
  4378. // determine the last timestamp then get a new one, determine the difference in the timestamp
  4379. // to use for applying the update to each instances timer
  4380. int32 lastSaveTS = GetLastSavedTimeStamp();
  4381. int32 newSaveTS = Timer::GetUnixTimeStamp();
  4382. int32 diffTS = newSaveTS - lastSaveTS;
  4383. // update instance timers
  4384. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  4385. // update with the new timestamp and save the db
  4386. this->SetLastSavedTimeStamp(newSaveTS);
  4387. }*/
  4388. }
  4389. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  4390. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  4391. if (packet) {
  4392. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  4393. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  4394. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  4395. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  4396. vector<EntityCommand*> commands;
  4397. vector<EntityCommand*> delete_commands;
  4398. if (out && spawn) {
  4399. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  4400. {
  4401. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  4402. if (!spawn->primary_command_list[i]->default_allow_list)
  4403. {
  4404. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4405. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  4406. continue;
  4407. }
  4408. else
  4409. {
  4410. // default is allow list, only deny if added to the list as deny (false itr second)
  4411. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4412. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  4413. continue;
  4414. }
  4415. commands.push_back(spawn->primary_command_list[i]);
  4416. }
  4417. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  4418. commands.push_back(spawn->secondary_command_list[i]);
  4419. if (spawn->IsPlayer()) {
  4420. if (player->IsFriend(spawn->GetName()))
  4421. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  4422. else
  4423. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  4424. if (player->IsIgnored(spawn->GetName()))
  4425. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  4426. else
  4427. {
  4428. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  4429. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  4430. }
  4431. if (((Player*)spawn)->GetGroupMemberInfo()) {
  4432. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  4433. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  4434. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  4435. }
  4436. if(spawn->IsPlayer() && player->GetGroupMemberInfo() && !player->GetGroupMemberInfo()->mentor_target_char_id)
  4437. delete_commands.push_back(player->CreateEntityCommand("Mentor", 10000, "mentor", "", 0, 0));
  4438. else if(spawn->IsPlayer() && player->GetGroupMemberInfo() && player->GetGroupMemberInfo()->mentor_target_char_id == ((Player*)spawn)->GetCharacterID())
  4439. delete_commands.push_back(player->CreateEntityCommand("Stop Mentoring", 10000, "unmentor", "", 0, 0));
  4440. }
  4441. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  4442. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  4443. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  4444. }
  4445. out->setDataByName("spawn_id", spawn_id);
  4446. out->setArrayLengthByName("num_verbs", commands.size());
  4447. for (int32 i = 0; i < commands.size(); i++) {
  4448. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  4449. out->setArrayDataByName("distance", commands[i]->distance, i);
  4450. if (commands[i]->error_text.length() == 0)
  4451. out->setArrayAddToPacketByName("error", false, i);
  4452. else {
  4453. out->setArrayDataByName("display_error", 1, i);
  4454. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  4455. }
  4456. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  4457. }
  4458. EQ2Packet* outapp = out->serialize();
  4459. //DumpPacket(outapp);
  4460. QueuePacket(outapp);
  4461. safe_delete(out);
  4462. for (int32 i = 0; i < delete_commands.size(); i++) {
  4463. safe_delete(delete_commands[i]);
  4464. }
  4465. }
  4466. }
  4467. safe_delete(packet);
  4468. }
  4469. }
  4470. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  4471. if (previous_value != new_value) {
  4472. Message(CHANNEL_SKILL, "You get %s at %s (%i/%i).", new_value > previous_value ? "better" : "worse", skill->name.data.c_str(), new_value, skill->max_val);
  4473. char tmp[200] = { 0 };
  4474. sprintf(tmp, "\\#6EFF6EYou get %s at \12\\#C8FFC8%s\\#6EFF6E! (%i/%i)", new_value > previous_value ? "better" : "worse", skill->name.data.c_str(), new_value, skill->max_val);
  4475. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  4476. }
  4477. }
  4478. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  4479. {
  4480. /* JA notes on the unknown:
  4481. 2 = ding glimmer
  4482. 16 = Achievement Unlocked
  4483. 6 no longer does anything
  4484. */
  4485. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  4486. if (packet) {
  4487. packet->setDataByName("unknown", unknown);
  4488. packet->setMediumStringByName("text", text);
  4489. if (type && strlen(type) > 0)
  4490. packet->setMediumStringByName("message_type", type);
  4491. packet->setDataByName("size", size);
  4492. packet->setDataByName("red", red);
  4493. packet->setDataByName("green", green);
  4494. packet->setDataByName("blue", blue);
  4495. QueuePacket(packet->serialize());
  4496. safe_delete(packet);
  4497. }
  4498. }
  4499. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  4500. if (new_level < 1) {
  4501. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4502. return;
  4503. }
  4504. if (player->GetLevel() != new_level) {
  4505. player->SetLevel(new_level);
  4506. if (player->GetGroupMemberInfo()) {
  4507. player->UpdateGroupMemberInfo();
  4508. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4509. }
  4510. }
  4511. if (new_level > old_level) {
  4512. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  4513. }
  4514. if (player->GetPet()) {
  4515. NPC* pet = (NPC*)player->GetPet();
  4516. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  4517. pet->SetLevel(new_level);
  4518. pet->UpdateWeapons();
  4519. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4520. if (command_packet) {
  4521. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  4522. command_packet->setDataByName("anim_type", 1753);
  4523. QueuePacket(command_packet->serialize());
  4524. safe_delete(command_packet);
  4525. }
  4526. }
  4527. }
  4528. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4529. if (level_update) {
  4530. level_update->setDataByName("old_level", old_level);
  4531. level_update->setDataByName("new_level", new_level);
  4532. QueuePacket(level_update->serialize());
  4533. safe_delete(level_update);
  4534. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  4535. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  4536. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  4537. }
  4538. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4539. if (command_packet) {
  4540. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  4541. command_packet->setDataByName("anim_type", 1753);
  4542. QueuePacket(command_packet->serialize());
  4543. safe_delete(command_packet);
  4544. }
  4545. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  4546. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  4547. SendNewAdventureSpells();
  4548. GetPlayer()->GetInfoStruct()->set_level(new_level);
  4549. GetPlayer()->UpdateWeapons();
  4550. // GetPlayer()->SetLevel(new_level);
  4551. LogWrite(MISC__TODO, 1, "TODO", "Get new HP/POWER/stat based on default values from DB\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  4552. GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
  4553. GetPlayer()->SetTotalHPBaseInstance(GetPlayer()->GetTotalHPBaseInstance());
  4554. GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
  4555. GetPlayer()->SetTotalPowerBaseInstance(GetPlayer()->GetTotalPowerBaseInstance());
  4556. GetPlayer()->CalculateBonuses();
  4557. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  4558. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  4559. /*InfoStruct* info = player->GetInfoStruct();
  4560. info->set_agi_base(new_level * 2 + 15);
  4561. info->set_intel_base(new_level * 2 + 15);
  4562. info->set_wis_base(new_level * 2 + 15);
  4563. info->set_str_base(new_level * 2 + 15);
  4564. info->set_sta_base(new_level * 2 + 15);
  4565. info->set_cold_base((int16)(new_level * 1.5 + 10));
  4566. info->set_heat_base((int16)(new_level * 1.5 + 10));
  4567. info->set_disease_base((int16)(new_level * 1.5 + 10));
  4568. info->set_mental_base((int16)(new_level * 1.5 + 10));
  4569. info->set_magic_base((int16)(new_level * 1.5 + 10));
  4570. info->set_divine_base((int16)(new_level * 1.5 + 10));
  4571. info->set_poison_base((int16)(new_level * 1.5 + 10));
  4572. GetPlayer()->GetInfoStruct()->set_poison_base((int16)(new_level * 1.5 + 10));*/
  4573. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4574. GetPlayer()->SetCharSheetChanged(true);
  4575. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  4576. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4577. int16 new_skill_cap = 5 * new_level;
  4578. PlayerSkillList* player_skills = player->GetSkills();
  4579. player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
  4580. player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
  4581. if(rule_manager.GetGlobalRule(R_Player, AutoSkillUpBaseSkills)->GetBool()) {
  4582. //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
  4583. player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
  4584. player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
  4585. }
  4586. player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
  4587. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
  4588. if(rule_manager.GetGlobalRule(R_Player, AutoSkillUpBaseSkills)->GetBool()) {
  4589. //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
  4590. player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
  4591. player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
  4592. }
  4593. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  4594. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  4595. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  4596. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  4597. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPONRY, new_skill_cap);
  4598. if (new_level > player->GetTSLevel())
  4599. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  4600. //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
  4601. if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
  4602. player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
  4603. if (player_skills->HasSkill(SKILL_ID_FISTS))
  4604. player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
  4605. if (player_skills->HasSkill(SKILL_ID_DESTROYING))
  4606. player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
  4607. if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
  4608. player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
  4609. Guild* guild = GetPlayer()->GetGuild();
  4610. if (guild) {
  4611. int8 event_type = 0;
  4612. if (new_level < 10)
  4613. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  4614. else if (new_level == 10)
  4615. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  4616. else if (new_level >= 11 && new_level < 20)
  4617. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  4618. else if (new_level == 20)
  4619. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  4620. else if (new_level >= 21 && new_level < 30)
  4621. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  4622. else if (new_level == 30)
  4623. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  4624. else if (new_level >= 31 && new_level < 40)
  4625. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  4626. else if (new_level == 40)
  4627. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  4628. else if (new_level >= 41 && new_level < 50)
  4629. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  4630. else if (new_level == 50)
  4631. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  4632. else if (new_level >= 51 && new_level < 60)
  4633. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  4634. else if (new_level == 60)
  4635. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  4636. else if (new_level >= 61 && new_level < 70)
  4637. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  4638. else if (new_level == 70)
  4639. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  4640. else if (new_level >= 71 && new_level < 80)
  4641. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  4642. else if (new_level == 80)
  4643. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  4644. guild->AddNewGuildEvent(event_type, "%s has gained an adventure level and is now a level %u %s.", Timer::GetUnixTimeStamp(), true, GetPlayer()->GetName(), new_level, classes.GetClassNameCase(GetPlayer()->GetAdventureClass()).c_str());
  4645. guild->SendMessageToGuild(event_type, "%s has gained an adventure level and is now a level %u %s.", GetPlayer()->GetName(), new_level, classes.GetClassNameCase(GetPlayer()->GetAdventureClass()).c_str());
  4646. guild->UpdateGuildMemberInfo(GetPlayer());
  4647. guild->SendGuildMember(GetPlayer());
  4648. guild->SendGuildMemberList();
  4649. }
  4650. // Need to send the trait list every time the players level changes
  4651. // Also need to force the char sheet update or else there can be a large delay from when you level
  4652. // to when you are actually able to select traits.
  4653. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4654. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4655. if (version > 546)
  4656. master_aa_list.DisplayAA(this, 0, 0);
  4657. if (GetPlayer()->SpawnedBots.size() > 0) {
  4658. map<int32, int32>::iterator itr;
  4659. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  4660. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  4661. if (bot && bot->IsBot())
  4662. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  4663. }
  4664. }
  4665. }
  4666. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  4667. if (new_level < 1) {
  4668. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4669. return;
  4670. }
  4671. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  4672. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  4673. return;
  4674. }
  4675. if (new_level > old_level)
  4676. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  4677. if (player->GetTSLevel() != new_level) {
  4678. player->SetTSLevel(new_level);
  4679. if (player->GetGroupMemberInfo()) {
  4680. player->UpdateGroupMemberInfo();
  4681. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4682. }
  4683. }
  4684. // Only tradeskill skills should increace, and then only those related to your class
  4685. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4686. if (level_update) {
  4687. level_update->setDataByName("old_level", old_level);
  4688. level_update->setDataByName("new_level", new_level);
  4689. level_update->setDataByName("type", 1);
  4690. QueuePacket(level_update->serialize());
  4691. safe_delete(level_update);
  4692. }
  4693. // provide new spells upon levelling
  4694. SendNewTradeskillSpells();
  4695. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4696. if (command_packet) {
  4697. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  4698. command_packet->setDataByName("anim_type", 1753);
  4699. QueuePacket(command_packet->serialize());
  4700. safe_delete(command_packet);
  4701. }
  4702. GetPlayer()->GetInfoStruct()->set_tradeskill_level(new_level);
  4703. GetPlayer()->SetTSLevel(new_level);
  4704. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4705. GetPlayer()->SetCharSheetChanged(true);
  4706. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  4707. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4708. PlayerSkillList* player_skills = player->GetSkills();
  4709. int16 specialize_skill_cap = new_level * 5;
  4710. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  4711. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  4712. int8 ts_class = player->GetTradeskillClass();
  4713. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  4714. int32 skill_id_1, skill_id_2, skill_id_3;
  4715. switch (base_ts_class) {
  4716. case ARTISAN:
  4717. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4718. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4719. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4720. break;
  4721. case OUTFITTER:
  4722. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4723. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4724. skill_id_1 = SKILL_ID_TAILORING;
  4725. skill_id_2 = SKILL_ID_METALSHAPING;
  4726. skill_id_3 = SKILL_ID_METALWORKING;
  4727. if (ts_class == TAILOR) {
  4728. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4729. skill_id_1 = 0;
  4730. }
  4731. else if (ts_class == ARMORER) {
  4732. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4733. skill_id_2 = 0;
  4734. }
  4735. else if (ts_class == WEAPONSMITH) {
  4736. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4737. skill_id_3 = 0;
  4738. }
  4739. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4740. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4741. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4742. break;
  4743. case SCHOLAR:
  4744. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4745. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4746. skill_id_1 = SKILL_ID_SCRIBING;
  4747. skill_id_2 = SKILL_ID_CHEMISTRY;
  4748. skill_id_3 = SKILL_ID_ARTIFICING;
  4749. if (ts_class == SAGE) {
  4750. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4751. skill_id_1 = 0;
  4752. }
  4753. else if (ts_class == ALCHEMIST) {
  4754. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4755. skill_id_2 = 0;
  4756. }
  4757. else if (ts_class == JEWELER) {
  4758. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4759. skill_id_3 = 0;
  4760. }
  4761. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4762. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4763. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4764. break;
  4765. case CRAFTSMAN:
  4766. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4767. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4768. skill_id_1 = SKILL_ID_ARTISTRY;
  4769. skill_id_2 = SKILL_ID_FLETCHING;
  4770. skill_id_3 = SKILL_ID_SCULPTING;
  4771. if (ts_class == PROVISIONER) {
  4772. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4773. skill_id_1 = 0;
  4774. }
  4775. else if (ts_class == WOODWORKER) {
  4776. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4777. skill_id_2 = 0;
  4778. }
  4779. else if (ts_class == CARPENTER) {
  4780. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4781. skill_id_3 = 0;
  4782. }
  4783. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4784. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4785. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4786. break;
  4787. default:
  4788. break;
  4789. }
  4790. if (new_level > player->GetAdventureClass())
  4791. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  4792. Guild* guild = GetPlayer()->GetGuild();
  4793. if (guild) {
  4794. int8 event_type = 0;
  4795. if (new_level < 10)
  4796. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  4797. else if (new_level == 10)
  4798. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  4799. else if (new_level >= 11 && new_level < 20)
  4800. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  4801. else if (new_level == 20)
  4802. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  4803. else if (new_level >= 21 && new_level < 30)
  4804. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  4805. else if (new_level == 30)
  4806. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  4807. else if (new_level >= 31 && new_level < 40)
  4808. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  4809. else if (new_level == 40)
  4810. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  4811. else if (new_level >= 41 && new_level < 50)
  4812. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  4813. else if (new_level == 50)
  4814. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  4815. else if (new_level >= 51 && new_level < 60)
  4816. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  4817. else if (new_level == 60)
  4818. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  4819. else if (new_level >= 61 && new_level < 70)
  4820. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  4821. else if (new_level == 70)
  4822. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  4823. else if (new_level >= 71 && new_level < 80)
  4824. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  4825. else if (new_level == 80)
  4826. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  4827. guild->AddNewGuildEvent(event_type, "%s has gained a tradeskill level and is now a level %u %s.", Timer::GetUnixTimeStamp(), true, GetPlayer()->GetName(), new_level, classes.GetClassNameCase(GetPlayer()->GetTradeskillClass() + 42).c_str());
  4828. guild->SendMessageToGuild(event_type, "%s has gained a tradeskill level and is now a level %u %s.", GetPlayer()->GetName(), new_level, classes.GetClassNameCase(GetPlayer()->GetTradeskillClass() + 42).c_str());
  4829. guild->UpdateGuildMemberInfo(GetPlayer());
  4830. guild->SendGuildMember(GetPlayer());
  4831. guild->SendGuildMemberList();
  4832. }
  4833. // Need to send the trait list every time the players level changes
  4834. // Also need to force the char sheet update or else there can be a large delay from when you level
  4835. // to when you are actually able to select traits.
  4836. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4837. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4838. }
  4839. void Client::CloseLoot(int32 spawn_id) {
  4840. if (GetVersion() > 546) {
  4841. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  4842. if (packet) {
  4843. packet->setDataByName("window_id", 4);
  4844. EQ2Packet* outapp = packet->serialize();
  4845. if (outapp) {
  4846. //DumpPacket(outapp);
  4847. QueuePacket(outapp);
  4848. }
  4849. safe_delete(packet);
  4850. }
  4851. }
  4852. if(spawn_id > 0){
  4853. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  4854. if (packet) {
  4855. packet->setDataByName("spawn_id", spawn_id);
  4856. EQ2Packet* outapp = packet->serialize();
  4857. if (outapp)
  4858. QueuePacket(outapp);
  4859. safe_delete(packet);
  4860. }
  4861. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  4862. if(spawn) {
  4863. spawn->CloseLoot(GetPlayer());
  4864. }
  4865. }
  4866. }
  4867. string Client::GetCoinMessage(int32 total_coins) {
  4868. if (total_coins == 0) {
  4869. return " 0 Copper";
  4870. }
  4871. char tmp[64] = { 0 };
  4872. string message = "";
  4873. int32 val = 0;
  4874. if (total_coins >= 1000000) {
  4875. val = total_coins / 1000000;
  4876. total_coins -= 1000000 * val;
  4877. sprintf(tmp, " %u Platinum", val);
  4878. message.append(tmp);
  4879. memset(tmp, 0, 64);
  4880. }
  4881. if (total_coins >= 10000) {
  4882. val = total_coins / 10000;
  4883. total_coins -= 10000 * val;
  4884. sprintf(tmp, " %u Gold", val);
  4885. message.append(tmp);
  4886. memset(tmp, 0, 64);
  4887. }
  4888. if (total_coins >= 100) {
  4889. val = total_coins / 100;
  4890. total_coins -= 100 * val;
  4891. sprintf(tmp, " %u Silver", val);
  4892. message.append(tmp);
  4893. memset(tmp, 0, 64);
  4894. }
  4895. if (total_coins > 0) {
  4896. sprintf(tmp, " %u Copper", (int32)total_coins);
  4897. message.append(tmp);
  4898. }
  4899. return message;
  4900. }
  4901. void Client::SendLootResponsePacket(int32 total_coins, vector<Item*>* items, Spawn* entity, bool ignore_loot_tier) {
  4902. if (!entity) {
  4903. CloseLoot(0);
  4904. return;
  4905. }
  4906. if (total_coins > 0) {
  4907. player->AddCoins(total_coins);
  4908. //PlaySound("coin_cha_ching");
  4909. string message = "";
  4910. if (entity->GetHP() == 0) {
  4911. message = "You loot ";
  4912. entity->SetLootCoins(0, false);
  4913. }
  4914. else
  4915. message = "You receive ";
  4916. message.append(GetCoinMessage(total_coins));
  4917. if (entity->GetHP() == 0)
  4918. message.append(" from the corpse of ").append(entity->GetName());
  4919. int8 type = CHANNEL_LOOT;
  4920. SimpleMessage(type, message.c_str());
  4921. }
  4922. if (!items || items->size() == 0)
  4923. CloseLoot(entity->GetID());
  4924. entity->StartLootTimer(GetPlayer());
  4925. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  4926. if (packet) {
  4927. entity->AddSpawnLootWindowCompleted(GetPlayer()->GetID(), false);
  4928. vector<Item*>::iterator itr;
  4929. int32 packet_size = 0;
  4930. EQ2Packet* outapp = 0;
  4931. uchar* data = 0;
  4932. vector<Item*> send_items;
  4933. if (items && items->size() > 0) {
  4934. for (int i = 0; i < items->size(); i++) {
  4935. Item* item = (*items)[i];
  4936. if (entity->GetLootMethod() > GroupLootMethod::METHOD_FFA && !ignore_loot_tier) {
  4937. bool skipItem = entity->IsItemInLootTier(item);
  4938. if (!skipItem) {
  4939. send_items.push_back(item);
  4940. }
  4941. }
  4942. else {
  4943. send_items.push_back(item);
  4944. }
  4945. }
  4946. }
  4947. if (GetVersion() >= 284) {
  4948. if (GetVersion() > 561) {
  4949. if (send_items.size() > 0) {
  4950. packet->setDataByName("loot_count", send_items.size());
  4951. packet->setDataByName("display", 1);
  4952. }
  4953. packet->setDataByName("loot_type", entity->GetLootMethod());
  4954. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000);
  4955. packet->setDataByName("loot_id", entity->GetID());
  4956. EQ2Packet* tmpPacket = packet->serialize();
  4957. packet_size += tmpPacket->size;
  4958. if (send_items.size() > 0) {
  4959. data = new uchar[send_items.size() * 1000 + packet_size];
  4960. memset(data, 0, send_items.size() * 1000 + packet_size);
  4961. }
  4962. else {
  4963. data = new uchar[packet_size];
  4964. memset(data, 0, packet_size);
  4965. }
  4966. uchar* ptr = data;
  4967. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  4968. ptr += tmpPacket->size;
  4969. safe_delete(tmpPacket);
  4970. Item* item = 0;
  4971. if (send_items.size() > 0) {
  4972. for (itr = send_items.begin(); itr != send_items.end(); itr++) {
  4973. item = *itr;
  4974. memcpy(ptr, &item->details.item_id, sizeof(int32));
  4975. ptr += sizeof(int32);
  4976. packet_size += sizeof(int32);
  4977. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  4978. int8 offset = 0;
  4979. if (GetVersion() >= 1188) {
  4980. offset = 13;
  4981. }
  4982. else if (GetVersion() >= 860) {
  4983. offset = 11;
  4984. }
  4985. else if (GetVersion() <= 561) {
  4986. offset = 19;
  4987. }
  4988. else {
  4989. offset = 10;
  4990. }
  4991. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  4992. ptr += tmpPacket->size - offset;
  4993. packet_size += tmpPacket->size - offset;
  4994. safe_delete(tmpPacket);
  4995. }
  4996. }
  4997. packet_size -= sizeof(int32);
  4998. memcpy(data, &packet_size, sizeof(int32));
  4999. packet_size += sizeof(int32);
  5000. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  5001. }
  5002. else {
  5003. if (send_items.size() > 0) {
  5004. packet->setArrayLengthByName("loot_count", send_items.size());
  5005. Item* item = 0;
  5006. if (send_items.size() > 0) {
  5007. int i = 0;
  5008. for (itr = send_items.begin(); itr != send_items.end(); itr++) {
  5009. item = *itr;
  5010. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  5011. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  5012. i++;
  5013. }
  5014. }
  5015. packet->setDataByName("display", 1);
  5016. }
  5017. packet->setDataByName("loot_type", entity->GetLootMethod()); // normal
  5018. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000); // 60 seconds
  5019. packet->setDataByName("spawn_id", entity->GetID());
  5020. outapp = packet->serialize();
  5021. }
  5022. }
  5023. else {
  5024. if (send_items.size() > 0) {
  5025. packet->setArrayLengthByName("loot_count", send_items.size());
  5026. for (int i = 0; i < send_items.size(); i++) {
  5027. Item* item = (send_items)[i];
  5028. packet->setArrayDataByName("name", item->name.c_str(), i);
  5029. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5030. packet->setArrayDataByName("count", item->details.count, i);
  5031. packet->setArrayDataByName("icon", item->details.icon, i);
  5032. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  5033. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  5034. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  5035. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  5036. else
  5037. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  5038. }
  5039. }
  5040. packet->setDataByName("object_id", entity->GetID());
  5041. packet->setDataByName("unknown3", 1);
  5042. packet->setDataByName("unknown4", 1);
  5043. packet->setDataByName("unknown5", 60);
  5044. outapp = packet->serialize();
  5045. }
  5046. if (outapp) {
  5047. QueuePacket(outapp);
  5048. }
  5049. safe_delete_array(data);
  5050. safe_delete(packet);
  5051. }
  5052. }
  5053. bool Client::LootSpawnByMethod(Spawn* entity) {
  5054. bool sentLoot = false;
  5055. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  5056. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  5057. if (gmi && gmi->group_id)
  5058. {
  5059. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  5060. if (group)
  5061. {
  5062. int8 auto_split_coin = group->GetGroupOptions()->auto_split;
  5063. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  5064. deque<GroupMemberInfo*>* members = group->GetMembers();
  5065. int32 split_coin_per_player = 0;
  5066. int32 coins_remain_after_split = entity->GetLootCoins();
  5067. int32 total_coins = entity->GetLootCoins();
  5068. if (auto_split_coin) {
  5069. int8 members_in_zone = 0;
  5070. for (int8 i = 0; i < members->size(); i++) {
  5071. Entity* member = members->at(i)->member;
  5072. if (!member || !member->IsPlayer())
  5073. continue;
  5074. if (member->GetZone() != GetPlayer()->GetZone())
  5075. continue;
  5076. members_in_zone++;
  5077. }
  5078. if (members_in_zone < 1) // this should not happen, but divide by zero checked
  5079. members_in_zone = 0;
  5080. split_coin_per_player = entity->GetLootCoins() / members_in_zone;
  5081. coins_remain_after_split = entity->GetLootCoins() - (split_coin_per_player * members_in_zone);
  5082. entity->SetLootCoins(0, false);
  5083. }
  5084. LogWrite(LOOT__INFO, 0, "Loot", "%s: Group LootSpawnByMethod %u, auto coin split %u, split coin per player %u, remaining coin after split %u", entity->GetName(), entity->GetLootMethod(), auto_split_coin, split_coin_per_player, coins_remain_after_split);
  5085. bool startWithLooter = true;
  5086. for (int8 i = 0; i < members->size(); i++) {
  5087. Entity* member = members->at(i)->member;
  5088. if (!member || !member->IsPlayer())
  5089. continue;
  5090. if (member->GetZone() != GetPlayer()->GetZone())
  5091. continue;
  5092. // this will make sure we properly send the loot window to the initial requester if there is no item rarity matches
  5093. if (startWithLooter && member != GetPlayer())
  5094. continue;
  5095. else if (!startWithLooter && member == GetPlayer())
  5096. continue;
  5097. else if (startWithLooter) {
  5098. i = 0;
  5099. startWithLooter = false;
  5100. }
  5101. if (auto_split_coin && (split_coin_per_player + coins_remain_after_split) > 0) {
  5102. player->AddCoins(split_coin_per_player + coins_remain_after_split);
  5103. if (((Player*)member)->GetClient()) {
  5104. ((Player*)member)->GetClient()->Message(CHANNEL_MONEY_SPLIT, "Your share of %s from the corpse of %s is %s.", GetCoinMessage(total_coins).c_str(), entity->GetLootName(), GetCoinMessage(split_coin_per_player + coins_remain_after_split).c_str());
  5105. }
  5106. if (coins_remain_after_split > 0) // overflow of coin division went to the first player
  5107. coins_remain_after_split = 0;
  5108. }
  5109. switch (entity->GetLootMethod()) {
  5110. case GroupLootMethod::METHOD_LOTTO:
  5111. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  5112. if (((Player*)member)->GetClient()) {
  5113. switch (member->GetInfoStruct()->get_group_auto_loot_method()) {
  5114. case 1: { // lotto, need
  5115. if (entity->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
  5116. entity->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
  5117. }
  5118. else { // *need* before greed
  5119. entity->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
  5120. }
  5121. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5122. // if it already exists we have to override the setting
  5123. entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  5124. break;
  5125. }
  5126. case 2: { // decline
  5127. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5128. // if it already exists we have to override the setting
  5129. entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  5130. break;
  5131. }
  5132. default: { // presume 0 or higher than 2
  5133. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity, true);
  5134. break;
  5135. }
  5136. }
  5137. sentLoot = true;
  5138. }
  5139. break;
  5140. }
  5141. case GroupLootMethod::METHOD_ROUND_ROBIN: {
  5142. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5143. sentLoot = true;
  5144. break;
  5145. }
  5146. case GroupLootMethod::METHOD_LEADER: {
  5147. if (member->GetGroupMemberInfo()->leader)
  5148. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
  5149. break;
  5150. }
  5151. case GroupLootMethod::METHOD_FFA: {
  5152. if(member == GetPlayer()) {
  5153. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
  5154. }
  5155. break;
  5156. }
  5157. }
  5158. }
  5159. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5160. }
  5161. }
  5162. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  5163. return sentLoot;
  5164. }
  5165. void Client::LootSpawnRequest(Spawn* entity, bool attemptDisarm) {
  5166. bool lootAllowed = false;
  5167. bool sentLoot = false;
  5168. std::vector<int32> item_list;
  5169. if (entity->IsNPC()) {
  5170. entity->LockLoot();
  5171. lootAllowed = ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer());
  5172. entity->UnlockLoot();
  5173. if (lootAllowed) {
  5174. OpenChest(entity, attemptDisarm);
  5175. }
  5176. else {
  5177. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  5178. return;
  5179. }
  5180. entity->LockLoot();
  5181. if (((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  5182. lootAllowed = true;
  5183. if ((sentLoot = LootSpawnByMethod(entity))) {
  5184. entity->GetLootItemsList(&item_list);
  5185. }
  5186. else {
  5187. SendLootResponsePacket(entity->GetLootCoins(), entity->GetLootItems(), entity);
  5188. }
  5189. }
  5190. entity->UnlockLoot();
  5191. if (lootAllowed) {
  5192. entity->DistributeGroupLoot_RoundRobin(&item_list, true);
  5193. }
  5194. }
  5195. }
  5196. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  5197. {
  5198. if (!entity)
  5199. return;
  5200. int8 chest_difficulty = 0;
  5201. int32 state = 0;
  5202. // Check for the chest and set the action state
  5203. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  5204. string modelName;
  5205. if (entity->GetModelType() == 4034) {
  5206. // small chest, open with copper coins
  5207. // does not include traps, however can be disarmed
  5208. chest_difficulty = 1;
  5209. state = 11899;
  5210. modelName.append("Small Chest");
  5211. }
  5212. else if (entity->GetModelType() == 5864) {
  5213. // treasure chest, open with silver coins
  5214. chest_difficulty = 2;
  5215. state = 11901;
  5216. modelName.append("Treasure Chest");
  5217. }
  5218. else if (entity->GetModelType() == 5865) {
  5219. // ornate chest, open with gold coins
  5220. chest_difficulty = 3;
  5221. state = 11900;
  5222. modelName.append("Ornate Chest");
  5223. }
  5224. else if (entity->GetModelType() == 4015) {
  5225. // exquisite chest, open with gold coins and jewels as well as a glow effect
  5226. chest_difficulty = 5;
  5227. state = 11898;
  5228. modelName.append("Exquisite Chest");
  5229. }
  5230. bool firstChestOpen = false;
  5231. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  5232. {
  5233. ChestTrap::ChestTrapInfo nextTrap;
  5234. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  5235. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  5236. firstChestOpen = true;
  5237. entity->SetTrapTriggered(true, state);
  5238. if (ret)
  5239. {
  5240. if (disarmSkill && attemptDisarm)
  5241. {
  5242. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  5243. {
  5244. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  5245. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  5246. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  5247. }
  5248. else
  5249. {
  5250. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  5251. }
  5252. // despite fail/succeed we should always try to increase skill if disarm is available
  5253. GetPlayer()->GetSkillByName("Disarm Trap", true);
  5254. }
  5255. else // no disarm skill, always fail
  5256. {
  5257. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  5258. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  5259. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  5260. }
  5261. }
  5262. }
  5263. else if (!entity->HasTrapTriggered())
  5264. {
  5265. firstChestOpen = true;
  5266. entity->SetTrapTriggered(true, state);
  5267. }
  5268. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  5269. // for those in range the SendStateCommand will cause it to animate open.
  5270. // players not currently in radius will have it queued with client->QueueStateCommand when SendSpawn takes place
  5271. if (firstChestOpen)
  5272. GetCurrentZone()->SendStateCommand(entity, state);
  5273. }
  5274. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  5275. {
  5276. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  5277. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  5278. if (source == NULL)
  5279. source = (Entity*)GetPlayer();
  5280. if (spell)
  5281. {
  5282. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  5283. if (gmi && gmi->group_id)
  5284. {
  5285. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  5286. if (group)
  5287. {
  5288. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  5289. deque<GroupMemberInfo*>* members = group->GetMembers();
  5290. for (int8 i = 0; i < members->size(); i++) {
  5291. Entity* member = members->at(i)->member;
  5292. if(!member)
  5293. continue;
  5294. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  5295. continue;
  5296. // if we have a radius provided then check if the group member is outside the radius or not
  5297. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  5298. continue;
  5299. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  5300. }
  5301. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5302. }
  5303. }
  5304. else
  5305. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  5306. }
  5307. }
  5308. Spawn* Client::GetBanker() {
  5309. return banker;
  5310. }
  5311. void Client::SetBanker(Spawn* in_banker) {
  5312. banker = in_banker;
  5313. }
  5314. void Client::Bank(Spawn* banker, bool cancel) {
  5315. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  5316. if (!cancel)
  5317. SetBanker(banker);
  5318. else
  5319. SetBanker(0);
  5320. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  5321. if (packet) {
  5322. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  5323. int64 coins = GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + GetPlayer()->GetInfoStruct()->get_bank_coin_silver() * 100 +
  5324. GetPlayer()->GetInfoStruct()->get_bank_coin_gold() * 10000 + (int64)GetPlayer()->GetInfoStruct()->get_bank_coin_plat() * 1000000;
  5325. int32 coins1, coins2;
  5326. coins1 = ((int32*)&coins)[0];
  5327. coins2 = ((int32*)&coins)[1];
  5328. packet->setDataByName("bank_coins", coins1);
  5329. packet->setDataByName("bank_coins2", coins2);
  5330. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->get_coin_copper());
  5331. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->get_coin_silver());
  5332. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->get_coin_gold());
  5333. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->get_coin_plat());
  5334. if (!cancel)
  5335. packet->setDataByName("display", 1);
  5336. QueuePacket(packet->serialize());
  5337. safe_delete(packet);
  5338. }
  5339. }
  5340. }
  5341. bool Client::BankHasCoin(int64 amount){
  5342. int32 tmp = 0;
  5343. if(amount <= 0)
  5344. return 0;
  5345. //plat
  5346. if (amount >= 1000000) {
  5347. tmp = amount / 1000000;
  5348. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5349. if(bank_coins_plat >= tmp)
  5350. return 1;
  5351. }
  5352. //gold
  5353. if (amount >= 10000) {
  5354. tmp = amount / 10000;
  5355. int32 bank_coins_gold = GetPlayer()->GetBankCoinsGold();
  5356. if(bank_coins_gold >= tmp)
  5357. return 1;
  5358. }
  5359. //silver
  5360. if (amount >= 100) {
  5361. tmp = amount / 100;
  5362. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5363. if(bank_coins_silver >= tmp)
  5364. return 1;
  5365. }
  5366. //copper
  5367. if (amount > 0) {
  5368. int32 bank_coins_copper = GetPlayer()->GetBankCoinsCopper();
  5369. if(bank_coins_copper >= amount)
  5370. return 1;
  5371. }
  5372. return 0;
  5373. }
  5374. bool Client::BankWithdrawalNoBanker(int64 amount) {
  5375. bool cheater = false;
  5376. if (amount > 0) {
  5377. string withdrawal = "";
  5378. char withdrawal_data[512] = { 0 };
  5379. int32 tmp = 0;
  5380. if (amount >= 1000000) {
  5381. tmp = amount / 1000000;
  5382. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5383. if (tmp > bank_coins_plat)
  5384. cheater = true;
  5385. else {
  5386. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  5387. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  5388. amount -= (int64)tmp * 1000000;
  5389. sprintf(withdrawal_data, "%u Platinum ", tmp);
  5390. withdrawal.append(withdrawal_data);
  5391. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5392. }
  5393. }
  5394. if (!cheater && amount >= 10000) {
  5395. tmp = amount / 10000;
  5396. if (tmp > GetPlayer()->GetBankCoinsGold())
  5397. cheater = true;
  5398. else {
  5399. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  5400. bank_coins_gold -= tmp;
  5401. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  5402. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  5403. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  5404. }
  5405. else
  5406. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  5407. amount -= tmp * 10000;
  5408. sprintf(withdrawal_data, "%u Gold ", tmp);
  5409. withdrawal.append(withdrawal_data);
  5410. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5411. }
  5412. }
  5413. if (!cheater && amount >= 100) {
  5414. tmp = amount / 100;
  5415. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5416. if (tmp > bank_coins_silver)
  5417. cheater = true;
  5418. else {
  5419. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  5420. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  5421. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  5422. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  5423. }
  5424. else
  5425. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  5426. amount -= tmp * 100;
  5427. sprintf(withdrawal_data, "%u Silver ", tmp);
  5428. withdrawal.append(withdrawal_data);
  5429. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5430. }
  5431. }
  5432. if (!cheater) {
  5433. if (amount > 0) {
  5434. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  5435. withdrawal.append(withdrawal_data);
  5436. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  5437. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  5438. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  5439. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  5440. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  5441. }
  5442. else
  5443. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  5444. }
  5445. if (withdrawal.length() > 0) {
  5446. withdrawal.append("withdrawn ");
  5447. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5448. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5449. withdrawal.append(withdrawal_data);
  5450. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  5451. return 1;
  5452. }
  5453. }
  5454. else
  5455. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5456. return 0;
  5457. }
  5458. return 0;
  5459. }
  5460. void Client::BankWithdrawal(int64 amount) {
  5461. bool cheater = false;
  5462. if (GetBanker() && amount > 0) {
  5463. string withdrawal = "";
  5464. char withdrawal_data[512] = { 0 };
  5465. int32 tmp = 0;
  5466. if (amount >= 1000000) {
  5467. tmp = amount / 1000000;
  5468. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5469. if (tmp > bank_coins_plat)
  5470. cheater = true;
  5471. else {
  5472. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  5473. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  5474. amount -= (int64)tmp * 1000000;
  5475. sprintf(withdrawal_data, "%u Platinum ", tmp);
  5476. withdrawal.append(withdrawal_data);
  5477. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5478. }
  5479. }
  5480. if (!cheater && amount >= 10000) {
  5481. tmp = amount / 10000;
  5482. if (tmp > GetPlayer()->GetBankCoinsGold())
  5483. cheater = true;
  5484. else {
  5485. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  5486. bank_coins_gold -= tmp;
  5487. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  5488. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  5489. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  5490. }
  5491. else
  5492. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  5493. amount -= tmp * 10000;
  5494. sprintf(withdrawal_data, "%u Gold ", tmp);
  5495. withdrawal.append(withdrawal_data);
  5496. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5497. }
  5498. }
  5499. if (!cheater && amount >= 100) {
  5500. tmp = amount / 100;
  5501. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5502. if (tmp > bank_coins_silver)
  5503. cheater = true;
  5504. else {
  5505. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  5506. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  5507. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  5508. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  5509. }
  5510. else
  5511. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  5512. amount -= tmp * 100;
  5513. sprintf(withdrawal_data, "%u Silver ", tmp);
  5514. withdrawal.append(withdrawal_data);
  5515. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5516. }
  5517. }
  5518. if (!cheater) {
  5519. if (amount > 0) {
  5520. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  5521. withdrawal.append(withdrawal_data);
  5522. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  5523. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  5524. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  5525. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  5526. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  5527. }
  5528. else
  5529. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  5530. }
  5531. if (withdrawal.length() > 0) {
  5532. withdrawal.append("withdrawn ");
  5533. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5534. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5535. withdrawal.append(withdrawal_data);
  5536. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  5537. }
  5538. }
  5539. else
  5540. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5541. player->SetCharSheetChanged(true);
  5542. Bank(banker);
  5543. }
  5544. }
  5545. void Client::BankDeposit(int64 amount) {
  5546. bool cheater = false;
  5547. if (GetBanker() && amount > 0) {
  5548. int32 tmp = 0;
  5549. char deposit_data[512] = { 0 };
  5550. string deposit = "";
  5551. if (amount >= 1000000) {
  5552. tmp = amount / 1000000;
  5553. if (tmp > GetPlayer()->GetCoinsPlat())
  5554. cheater = true;
  5555. else {
  5556. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(tmp);
  5557. GetPlayer()->GetInfoStruct()->set_coin_plat(GetPlayer()->GetInfoStruct()->get_coin_plat() - tmp);
  5558. amount -= (int64)tmp * 1000000;
  5559. sprintf(deposit_data, "%u Platinum ", tmp);
  5560. deposit.append(deposit_data);
  5561. memset(deposit_data, 0, sizeof(deposit_data));
  5562. }
  5563. }
  5564. if (!cheater && amount >= 10000) {
  5565. tmp = amount / 10000;
  5566. if (tmp > GetPlayer()->GetCoinsGold())
  5567. cheater = true;
  5568. else {
  5569. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) > 100) {
  5570. GetPlayer()->GetInfoStruct()->set_bank_coin_gold((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) - 100);
  5571. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(1);
  5572. }
  5573. else
  5574. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(tmp);
  5575. GetPlayer()->GetInfoStruct()->set_coin_gold(GetPlayer()->GetInfoStruct()->get_coin_gold() - tmp);
  5576. amount -= tmp * 10000;
  5577. sprintf(deposit_data, "%u Gold ", tmp);
  5578. deposit.append(deposit_data);
  5579. memset(deposit_data, 0, sizeof(deposit_data));
  5580. }
  5581. }
  5582. if (!cheater && amount >= 100) {
  5583. tmp = amount / 100;
  5584. if (tmp > GetPlayer()->GetCoinsSilver())
  5585. cheater = true;
  5586. else {
  5587. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) > 100) {
  5588. GetPlayer()->GetInfoStruct()->set_bank_coin_silver((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) - 100);
  5589. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(1);
  5590. }
  5591. else
  5592. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(tmp);
  5593. GetPlayer()->GetInfoStruct()->set_coin_silver(GetPlayer()->GetInfoStruct()->get_coin_silver() - tmp);
  5594. amount -= tmp * 100;
  5595. sprintf(deposit_data, "%u Silver ", tmp);
  5596. deposit.append(deposit_data);
  5597. memset(deposit_data, 0, sizeof(deposit_data));
  5598. }
  5599. }
  5600. if (!cheater) {
  5601. if (amount > 0) {
  5602. sprintf(deposit_data, "%u Copper ", (int32)amount);
  5603. deposit.append(deposit_data);
  5604. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) > 100) {
  5605. GetPlayer()->GetInfoStruct()->set_bank_coin_copper((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) - 100);
  5606. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(1);
  5607. }
  5608. else
  5609. GetPlayer()->GetInfoStruct()->add_bank_coin_copper(amount);
  5610. GetPlayer()->GetInfoStruct()->set_coin_copper(GetPlayer()->GetInfoStruct()->get_coin_copper() - amount);
  5611. }
  5612. if (deposit.length() > 0) {
  5613. deposit.append("deposited ");
  5614. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5615. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5616. deposit.append(deposit_data);
  5617. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  5618. }
  5619. }
  5620. else
  5621. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5622. player->SetCharSheetChanged(true);
  5623. Bank(banker);
  5624. }
  5625. }
  5626. void Client::AddPendingQuestAcceptReward(Quest* quest)
  5627. {
  5628. std::unique_lock lock(MPendingQuestAccept);
  5629. pending_quest_accept.push_back(quest->GetQuestID());
  5630. }
  5631. void Client::AddPendingQuestReward(Quest* quest, bool update, bool is_temporary, std::string description) {
  5632. QueueQuestReward(quest->GetQuestID(), is_temporary, false, false, (is_temporary ? quest->GetCoinTmpReward() : 0),
  5633. (is_temporary ? quest->GetStatusTmpReward() : 0), description, false, 0);
  5634. quest_updates = update;
  5635. if(quest_updates) {
  5636. SaveQuestRewardData(true);
  5637. }
  5638. }
  5639. void Client::QueueQuestReward(int32 quest_id, bool is_temporary, bool is_collection, bool has_displayed, int64 tmp_coin, int32 tmp_status, std::string description, bool db_saved, int32 index) {
  5640. if(HasQuestRewardQueued(quest_id, is_temporary, is_collection))
  5641. return;
  5642. QuestRewardData* data = new QuestRewardData;
  5643. data->quest_id = quest_id;
  5644. data->is_temporary = is_temporary;
  5645. data->is_collection = is_collection;
  5646. data->has_displayed = has_displayed;
  5647. data->tmp_coin = tmp_coin;
  5648. data->tmp_status = tmp_status;
  5649. data->description = std::string(description);
  5650. data->db_saved = db_saved;
  5651. data->db_index = index;
  5652. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5653. quest_pending_reward.push_back(data);
  5654. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5655. }
  5656. bool Client::HasQuestRewardQueued(int32 quest_id, bool is_temporary, bool is_collection) {
  5657. bool success = false;
  5658. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5659. if (quest_pending_reward.size() > 0) {
  5660. vector<QuestRewardData*>::iterator itr;
  5661. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  5662. int32 questID = (*itr)->quest_id;
  5663. bool temporary = (*itr)->is_temporary;
  5664. bool collection = (*itr)->is_collection;
  5665. if( questID == quest_id && is_temporary == temporary && is_collection == collection ) {
  5666. success = true;
  5667. break;
  5668. }
  5669. }
  5670. }
  5671. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5672. return success;
  5673. }
  5674. void Client::RemoveQueuedQuestReward() {
  5675. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5676. if(quest_pending_reward.size() > 0) {
  5677. QuestRewardData* data = quest_pending_reward.at(0);
  5678. if(data->db_saved) {
  5679. Query query;
  5680. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_rewards where char_id = %u and indexed = %u", GetCharacterID(), data->db_index);
  5681. if(data->is_temporary && data->quest_id) {
  5682. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_temporary_rewards where char_id = %u and quest_id = %u", GetCharacterID(), data->quest_id);
  5683. }
  5684. }
  5685. quest_pending_reward.erase(quest_pending_reward.begin());
  5686. }
  5687. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5688. SaveQuestRewardData(true);
  5689. }
  5690. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  5691. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5692. quest_pending_updates[quest_id][step_id] = progress;
  5693. quest_updates = true;
  5694. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5695. }
  5696. void Client::ProcessQuestUpdates() {
  5697. if(!IsReadyForUpdates())
  5698. return;
  5699. if (quest_pending_updates.size() > 0) {
  5700. map<int32, map<int32, int32> > tmp_quest_updates;
  5701. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5702. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  5703. quest_pending_updates.clear();
  5704. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5705. map<int32, map<int32, int32> >::iterator quest_itr;
  5706. map<int32, int32>::iterator step_itr;
  5707. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  5708. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  5709. if (step_itr->second == 0xFFFFFFFF) {
  5710. SetStepComplete(quest_itr->first, step_itr->first);
  5711. player->SendQuestRequiredSpawns(quest_itr->first);
  5712. }
  5713. else
  5714. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  5715. }
  5716. }
  5717. }
  5718. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5719. if (quest_pending_reward.size() > 0) {
  5720. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5721. // only able to display one reward at a time
  5722. if(GetPlayer()->IsActiveReward())
  5723. return;
  5724. Query query;
  5725. vector<QuestRewardData*>::iterator itr;
  5726. vector<QuestRewardData*> tmp_quest_rewards;
  5727. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5728. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.begin()+1);
  5729. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5730. bool delete_first = false;
  5731. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end();) {
  5732. int32 questID = (*itr)->quest_id;
  5733. if((*itr)->is_collection && GetPlayer()->GetPendingCollectionReward()) {
  5734. DisplayCollectionComplete(GetPlayer()->GetPendingCollectionReward());
  5735. GetPlayer()->SetActiveReward(true);
  5736. (*itr)->has_displayed = true;
  5737. UpdateCharacterRewardData((*itr));
  5738. break;
  5739. }
  5740. else if(questID > 0 && GetPlayer()->UpdateQuestReward(questID, (*itr))) {
  5741. (*itr)->has_displayed = true;
  5742. UpdateCharacterRewardData((*itr));
  5743. // only able to display one reward at a time
  5744. break;
  5745. } else {
  5746. delete_first = true;
  5747. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, deleting quest id from tmp_quest_rewards.", questID, GetPlayer()->GetName());
  5748. break;
  5749. }
  5750. }
  5751. if(delete_first) {
  5752. RemoveQueuedQuestReward();
  5753. }
  5754. } else {
  5755. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5756. }
  5757. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5758. if (quest_pending_reward.size() > 0) {
  5759. quest_updates = true;
  5760. }
  5761. else {
  5762. quest_updates = false;
  5763. }
  5764. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5765. }
  5766. void Client::CheckQuestQueue() {
  5767. MQuestQueue.writelock();
  5768. last_update_time = 0;
  5769. vector<QueuedQuest*>::iterator itr;
  5770. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  5771. if(!GetPlayer()->SendQuestStepUpdate((*itr)->quest_id, (*itr)->step, (*itr)->display_quest_helper)) {
  5772. LogWrite(CCLIENT__ERROR, 0, "Client", "Queued Quest ID %u missing for Player %s, cannot send quest step update.", (*itr)->quest_id, GetPlayer()->GetName());
  5773. }
  5774. safe_delete((*itr));
  5775. }
  5776. quest_queue.clear();
  5777. MQuestQueue.releasewritelock();
  5778. }
  5779. void Client::SetStepComplete(int32 quest_id, int32 step) {
  5780. Quest* quest = player->SetStepComplete(quest_id, step);
  5781. if (quest) {
  5782. SendQuestUpdate(quest);
  5783. GetCurrentZone()->SendQuestUpdates(this);
  5784. }
  5785. }
  5786. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  5787. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  5788. if (quest) {
  5789. SendQuestUpdate(quest);
  5790. GetCurrentZone()->SendQuestUpdates(this);
  5791. }
  5792. }
  5793. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  5794. bool hadUpdates = false;
  5795. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  5796. if (quest_updates) {
  5797. for (int32 i = 0; i < quest_updates->size(); i++)
  5798. {
  5799. SendQuestUpdate(quest_updates->at(i));
  5800. hadUpdates = true;
  5801. }
  5802. }
  5803. safe_delete(quest_updates);
  5804. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5805. if (quest_failures) {
  5806. for (int32 i = 0; i < quest_failures->size(); i++)
  5807. {
  5808. SendQuestFailure(quest_failures->at(i));
  5809. hadUpdates = true;
  5810. }
  5811. }
  5812. safe_delete(quest_failures);
  5813. if (hadUpdates)
  5814. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5815. }
  5816. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  5817. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  5818. if (quest_updates) {
  5819. for (int32 i = 0; i < quest_updates->size(); i++)
  5820. SendQuestUpdate(quest_updates->at(i));
  5821. GetCurrentZone()->SendQuestUpdates(this);
  5822. }
  5823. safe_delete(quest_updates);
  5824. }
  5825. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  5826. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  5827. if (quest_updates) {
  5828. for (int32 i = 0; i < quest_updates->size(); i++)
  5829. SendQuestUpdate(quest_updates->at(i));
  5830. }
  5831. safe_delete(quest_updates);
  5832. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5833. if (quest_failures) {
  5834. for (int32 i = 0; i < quest_failures->size(); i++)
  5835. SendQuestFailure(quest_failures->at(i));
  5836. }
  5837. safe_delete(quest_failures);
  5838. }
  5839. void Client::CheckPlayerQuestsLocationUpdate() {
  5840. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  5841. if (quest_updates) {
  5842. for (int32 i = 0; i < quest_updates->size(); i++)
  5843. SendQuestUpdate(quest_updates->at(i));
  5844. }
  5845. safe_delete(quest_updates);
  5846. }
  5847. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  5848. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  5849. if (quest_updates) {
  5850. for (int32 i = 0; i < quest_updates->size(); i++)
  5851. SendQuestUpdate(quest_updates->at(i));
  5852. }
  5853. safe_delete(quest_updates);
  5854. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5855. if (quest_failures) {
  5856. for (int32 i = 0; i < quest_failures->size(); i++)
  5857. SendQuestFailure(quest_failures->at(i));
  5858. }
  5859. safe_delete(quest_failures);
  5860. }
  5861. void Client::AddPendingQuest(Quest* quest, bool forced) {
  5862. if (version <= 283 || forced) { //this client doesn't ask if you want the quest, so auto accept
  5863. MPendingQuestAccept.lock();
  5864. player->pending_quests[quest->GetQuestID()] = quest;
  5865. MPendingQuestAccept.unlock();
  5866. AcceptQuest(quest->GetQuestID());
  5867. }
  5868. else {
  5869. MPendingQuestAccept.lock();
  5870. player->pending_quests[quest->GetQuestID()] = quest;
  5871. MPendingQuestAccept.unlock();
  5872. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  5873. //DumpPacket(outapp);
  5874. QueuePacket(outapp);
  5875. }
  5876. }
  5877. void Client::AcceptQuest(int32 quest_id) {
  5878. MPendingQuestAccept.lock_shared();
  5879. if (player->pending_quests.count(quest_id) > 0) {
  5880. Quest* quest = player->pending_quests[quest_id];
  5881. if(quest) {
  5882. MPendingQuestAccept.unlock_shared();
  5883. MPendingQuestAccept.lock();
  5884. player->pending_quests.erase(quest->GetQuestID());
  5885. MPendingQuestAccept.unlock();
  5886. AddPlayerQuest(quest);
  5887. GetCurrentZone()->SendQuestUpdates(this);
  5888. GetPlayer()->UpdateQuestCompleteCount(quest_id);
  5889. return; // already unlocked mutex
  5890. }
  5891. }
  5892. MPendingQuestAccept.unlock_shared();
  5893. }
  5894. void Client::RemovePendingQuest(int32 quest_id) {
  5895. bool send_updates = false;
  5896. MPendingQuestAccept.lock_shared();
  5897. if (player->pending_quests.count(quest_id) > 0) {
  5898. Quest* quest = player->pending_quests[quest_id];
  5899. MPendingQuestAccept.unlock_shared();
  5900. MPendingQuestAccept.lock();
  5901. player->pending_quests.erase(quest_id);
  5902. MPendingQuestAccept.unlock();
  5903. if(lua_interface) {
  5904. lua_interface->CallQuestFunction(quest, "Declined", GetPlayer());
  5905. lua_interface->SetLuaUserDataStale(quest);
  5906. }
  5907. safe_delete(quest);
  5908. send_updates = true;
  5909. }
  5910. else {
  5911. MPendingQuestAccept.unlock_shared();
  5912. }
  5913. if(send_updates) {
  5914. GetCurrentZone()->SendQuestUpdates(this);
  5915. }
  5916. }
  5917. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  5918. if (!quest || !progress) {
  5919. return;
  5920. }
  5921. map<int32, int32>::iterator itr;
  5922. QuestStep* step = 0;
  5923. for (itr = progress->begin(); itr != progress->end(); itr++) {
  5924. step = quest->GetQuestStep(itr->first);
  5925. if (step && itr->second > 0) {
  5926. step->SetStepProgress(itr->second);
  5927. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  5928. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  5929. }
  5930. }
  5931. if (lua_interface && step)
  5932. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  5933. else if(!step) {
  5934. LogWrite(QUEST__ERROR, 0, "Client", "Missing step for quest %s (ID %u), cannot CallQuestFunction for CurrentStep", quest->GetName(), quest->GetQuestID());
  5935. }
  5936. }
  5937. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  5938. bool lockCleared = false;
  5939. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5940. if (player->player_quests.count(quest->GetQuestID()) > 0 && player->player_quests[quest->GetQuestID()]) {
  5941. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  5942. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  5943. int32 questID = quest->GetQuestID();
  5944. lockCleared = true;
  5945. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5946. RemovePlayerQuest(questID, false, false);
  5947. }
  5948. player->player_quests[quest->GetQuestID()] = quest;
  5949. if(!lockCleared)
  5950. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5951. quest->SetPlayer(player);
  5952. quest->SetSaveNeeded(true);
  5953. current_quest_id = quest->GetQuestID();
  5954. if (send_packets && quest->GetQuestGiver() > 0)
  5955. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5956. if (lua_interface && call_accepted)
  5957. lua_interface->CallQuestFunction(quest, "Accepted", player);
  5958. if (send_packets) {
  5959. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5960. //SendQuestJournal();
  5961. SendQuestJournalUpdate(quest);
  5962. // sent twice to match live
  5963. quest->SetTracked(false);
  5964. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5965. quest->SetTracked(true);
  5966. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5967. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5968. }
  5969. //This isn't during a load screen, so update spawns with required quests
  5970. if (call_accepted)
  5971. player->SendQuestRequiredSpawns(quest->GetQuestID());
  5972. }
  5973. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  5974. if (current_quest_id == id)
  5975. current_quest_id = 0;
  5976. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5977. if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
  5978. if (delete_quest) {
  5979. player->player_quests[id]->SetDeleted(true);
  5980. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  5981. }
  5982. int32 quest_giver = player->player_quests[id]->GetQuestGiver();
  5983. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5984. if (send_update && quest_giver > 0)
  5985. GetCurrentZone()->SendSpawnChangesByDBID(quest_giver, this, false, true);
  5986. if (send_update) {
  5987. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5988. SendQuestJournal(false, 0, true);
  5989. }
  5990. player->RemoveQuest(id, delete_quest);
  5991. if (send_update) {
  5992. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5993. SendQuestJournal(false, 0, true);
  5994. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5995. }
  5996. }
  5997. else {
  5998. // if we don't have any quests to count then release the write lock
  5999. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6000. }
  6001. }
  6002. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  6003. if (quest) {
  6004. QuestStep* quest_step = quest->GetQuestStep(step);
  6005. if (quest_step) {
  6006. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  6007. quest_step->WasUpdated(false);
  6008. }
  6009. }
  6010. }
  6011. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  6012. QueuedQuest* item = new QueuedQuest;
  6013. item->quest_id = quest->GetQuestID();
  6014. item->step = step;
  6015. item->display_quest_helper = display_quest_helper;
  6016. MQuestQueue.writelock();
  6017. quest_queue.push_back(item);
  6018. last_update_time = Timer::GetCurrentTime2();
  6019. MQuestQueue.releasewritelock();
  6020. }
  6021. void Client::SendQuestFailure(Quest* quest) {
  6022. vector<QuestStep*>* failures = quest->GetQuestFailures();
  6023. if (failures) {
  6024. QuestStep* step = 0;
  6025. for (int32 i = 0; i < failures->size(); i++) {
  6026. step = failures->at(i);
  6027. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  6028. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6029. SendQuestJournal(false, 0, true);
  6030. }
  6031. failures->clear();
  6032. }
  6033. }
  6034. void Client::SendQuestUpdate(Quest* quest) {
  6035. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  6036. if (updates) {
  6037. QuestStep* step = 0;
  6038. bool updated = false;
  6039. for (int32 i = 0; i < updates->size(); i++) {
  6040. step = updates->at(i);
  6041. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  6042. {
  6043. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  6044. SendQuestUpdateStep(quest, step->GetStepID());
  6045. updated = true;
  6046. }
  6047. if (step->WasUpdated()) {
  6048. // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
  6049. SendQuestJournal(false, 0, true);
  6050. if(!updated)
  6051. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  6052. updated = true;
  6053. }
  6054. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6055. }
  6056. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  6057. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  6058. SendQuestJournalUpdate(quest, true);
  6059. }
  6060. if (quest->GetCompleted()) {
  6061. if (quest->GetQuestReturnNPC() > 0)
  6062. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  6063. if (quest->GetCompletedFlag())
  6064. quest->SetCompletedFlag(false);
  6065. }
  6066. updates->clear();
  6067. }
  6068. }
  6069. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  6070. if (!client)
  6071. client = this;
  6072. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  6073. if (packet) {
  6074. EQ2Packet* outapp = packet->serialize();
  6075. //DumpPacket(outapp);
  6076. client->QueuePacket(outapp);
  6077. safe_delete(packet);
  6078. }
  6079. }
  6080. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  6081. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  6082. if (packet) {
  6083. QueuePacket(packet->serialize());
  6084. safe_delete(packet);
  6085. }
  6086. }
  6087. void Client::ReloadQuests() {
  6088. vector<int32> ids = player->GetQuestIDs();
  6089. Quest* quest = 0;
  6090. for (int32 i = 0; i < ids.size(); i++) {
  6091. quest = master_quest_list.GetQuest(ids[i]);
  6092. if (quest)
  6093. AddPlayerQuest(quest, false);
  6094. else
  6095. RemovePlayerQuest(ids[i]);
  6096. }
  6097. }
  6098. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  6099. std::unique_lock lock(MPendingQuestAccept);
  6100. bool found_quest = false;
  6101. vector<int32>::iterator itr;
  6102. int32 questID = 0;
  6103. Quest* quest = nullptr;
  6104. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end();) {
  6105. questID = *itr;
  6106. bool quest_exists = false;
  6107. quest = GetPlayer()->PendingQuestAcceptance(questID, item_id, &quest_exists);
  6108. if(!quest_exists) {
  6109. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, removing quest id from pending_quest_accept.", questID, GetPlayer()->GetName());
  6110. itr = pending_quest_accept.erase(itr);
  6111. quest = nullptr;
  6112. continue;
  6113. }
  6114. else if (quest) {
  6115. pending_quest_accept.erase(itr);
  6116. break;
  6117. }
  6118. itr++;
  6119. }
  6120. return quest;
  6121. }
  6122. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  6123. int8 num_slots_needed = 0;
  6124. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  6125. Item* master_item = 0;
  6126. if (item_id > 0) {
  6127. num_slots_needed++;
  6128. master_item = master_item_list.GetItem(item_id);
  6129. }
  6130. int32 totalItems = 0;
  6131. vector<Item*>* items = 0;
  6132. vector<Item*>* tmpItems = 0;
  6133. bool isTempState = quest->GetQuestTemporaryState();
  6134. if(isTempState)
  6135. {
  6136. tmpItems = quest->GetTmpRewardItems();
  6137. if (tmpItems && tmpItems->size() > 0)
  6138. {
  6139. num_slots_needed += tmpItems->size();
  6140. totalItems += tmpItems->size();
  6141. }
  6142. }
  6143. else
  6144. {
  6145. items = quest->GetRewardItems();
  6146. if (items && items->size() > 0)
  6147. {
  6148. num_slots_needed += items->size();
  6149. totalItems += items->size();
  6150. }
  6151. }
  6152. RemoveQueuedQuestReward();
  6153. GetPlayer()->SetActiveReward(false);
  6154. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= totalItems)) {
  6155. if (master_item)
  6156. AddItem(item_id);
  6157. if (tmpItems && tmpItems->size() > 0) {
  6158. for (int32 i = 0; i < tmpItems->size(); i++)
  6159. AddItem(new Item(tmpItems->at(i)));
  6160. }
  6161. if (items && items->size() > 0) {
  6162. for (int32 i = 0; i < items->size(); i++)
  6163. AddItem(new Item(items->at(i)));
  6164. }
  6165. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6166. if (outapp)
  6167. QueuePacket(outapp);
  6168. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  6169. map<int32, sint32>::iterator itr;
  6170. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  6171. int32 faction_id = itr->first;
  6172. sint32 amount = itr->second;
  6173. if (amount > 0)
  6174. player->GetFactions()->IncreaseFaction(faction_id, amount);
  6175. else
  6176. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  6177. }
  6178. if(quest->GetQuestTemporaryState())
  6179. {
  6180. int64 total_coins = quest->GetCoinTmpReward();
  6181. if (total_coins > 0)
  6182. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  6183. player->GetInfoStruct()->add_status_points(quest->GetStatusTmpReward());
  6184. }
  6185. else {
  6186. player->GetInfoStruct()->add_status_points(quest->GetStatusPoints());
  6187. }
  6188. quest->SetQuestTemporaryState(false);
  6189. player->SetCharSheetChanged(true);
  6190. }
  6191. else {
  6192. GetPlayer()->SetActiveReward(true);
  6193. AddPendingQuestAcceptReward(quest);
  6194. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  6195. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  6196. }
  6197. }
  6198. void Client::DisplayQuestRewards(Quest* quest, int64 coin, vector<Item*>* rewards, vector<Item*>* selectable_rewards, map<int32, sint32>* factions, const char* header, int32 status_points, const char* text, bool was_displayed) {
  6199. if (coin == 0 && (!rewards || rewards->size() == 0) && (!selectable_rewards || selectable_rewards->size() == 0) && (!factions || factions->size() == 0) && status_points == 0 && text == 0 && (!quest || (quest->GetCoinsReward() == 0 && quest->GetCoinsRewardMax() == 0))) {
  6200. /*if (quest)
  6201. text = quest->GetName();
  6202. else*/
  6203. return;//nothing to give
  6204. }
  6205. GetPlayer()->ClearPendingSelectableItemRewards(0, true);
  6206. GetPlayer()->ClearPendingItemRewards();
  6207. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  6208. if (packet2) {
  6209. int32 source_id = 0;
  6210. if (quest)
  6211. source_id = quest->GetQuestID();
  6212. int64 rewarded_coin = 0;
  6213. if (quest) {
  6214. if (quest->GetCoinsReward() > 0) {
  6215. if (quest->GetCoinsRewardMax() > 0)
  6216. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  6217. else
  6218. rewarded_coin = quest->GetCoinsReward();
  6219. }
  6220. quest->SetGeneratedCoin(rewarded_coin);
  6221. }
  6222. if (rewarded_coin > coin)
  6223. coin = rewarded_coin;
  6224. if (!quest && !was_displayed) { //this entire function is either for version <=561 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6225. if (coin > 0) {
  6226. player->AddCoins(coin);
  6227. PlaySound("coin_cha_ching");
  6228. }
  6229. }
  6230. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  6231. packet2->setSubstructDataByName("reward_data", "reward", header);
  6232. packet2->setSubstructDataByName("reward_data", "max_coin", coin);
  6233. if (player->GetGuild() && !was_displayed) {
  6234. if (!quest) { //this entire function is either for version <=561 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6235. player->GetInfoStruct()->add_status_points(status_points);
  6236. player->SetCharSheetChanged(true);
  6237. }
  6238. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  6239. }
  6240. if(text)
  6241. packet2->setSubstructDataByName("reward_data", "text", text);
  6242. std::vector<Item*> items;
  6243. quest->GetTmpRewardItemsByID(&items);
  6244. if(rewards || items.size() > 0){
  6245. int32 item_count = items.size();
  6246. item_count += rewards ? rewards->size() : 0;
  6247. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
  6248. int i = 0;
  6249. if(rewards) {
  6250. for (i = 0; i < rewards->size(); i++) {
  6251. Item* item = rewards->at(i);
  6252. if (item) {
  6253. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  6254. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  6255. }
  6256. if(!quest) //this entire function is either for version <=561 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6257. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  6258. }
  6259. }
  6260. for (int j = 0; j < items.size(); j++) {
  6261. Item* item = items.at(j);
  6262. if (item) {
  6263. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  6264. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  6265. }
  6266. if(!quest) //this entire function is either for version <=561 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6267. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  6268. i++;
  6269. }
  6270. }
  6271. if (selectable_rewards) {
  6272. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  6273. for (int i = 0; i < selectable_rewards->size(); i++) {
  6274. Item* item = selectable_rewards->at(i);
  6275. if (item) {
  6276. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  6277. packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  6278. if (!quest) //this entire function is either for version <=561 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6279. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  6280. }
  6281. }
  6282. }
  6283. if (factions) {
  6284. map<int32, sint32>::iterator itr;
  6285. map<Faction*, signed int> factions_map;
  6286. for (itr = factions->begin(); itr != factions->end(); itr++) {
  6287. Faction* faction = master_faction_list.GetFaction(itr->first);
  6288. if (faction)
  6289. factions_map[faction] = itr->second;
  6290. }
  6291. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  6292. map<Faction*, signed int>::iterator faction_itr;
  6293. int8 i = 0;
  6294. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  6295. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  6296. sint32 amount = faction_itr->second;
  6297. packet2->setArrayDataByName("amount", amount, i);
  6298. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6299. if (amount > 0)
  6300. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  6301. else
  6302. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  6303. }
  6304. i++;
  6305. }
  6306. }
  6307. QueuePacket(packet2->serialize());
  6308. safe_delete(packet2);
  6309. }
  6310. }
  6311. void Client::PopulateQuestRewardItems(vector <Item*>* items, PacketStruct* packet,
  6312. std::string num_rewards_str, std::string reward_id_str, std::string item_str) {
  6313. if(!items || !packet)
  6314. return;
  6315. if (items) {
  6316. int32 total_item_count = 0;
  6317. for(int s=0;s<items->size();s++) {
  6318. Item* tmpItem = items->at(s);
  6319. if(tmpItem) {
  6320. if(tmpItem->details.count > 1) {
  6321. total_item_count += tmpItem->details.count;
  6322. }
  6323. else {
  6324. total_item_count += 1;
  6325. }
  6326. }
  6327. }
  6328. packet->setArrayLengthByName(num_rewards_str.c_str(), total_item_count);
  6329. int16 count = 0;
  6330. int16 pos = 0;
  6331. for (int32 i = 0; i < items->size();) {
  6332. packet->setArrayDataByName(reward_id_str.c_str(), items->at(i)->details.item_id, pos);
  6333. if (version < 860)
  6334. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, -1);
  6335. else if (version < 1193)
  6336. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos);
  6337. else
  6338. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, 2);
  6339. pos++;
  6340. if(count >= items->at(i)->details.count-1) {
  6341. count = 0;
  6342. }
  6343. else if(items->at(i)->details.count > 1) {
  6344. count++;
  6345. continue;
  6346. }
  6347. i++;
  6348. }
  6349. }
  6350. }
  6351. void Client::DisplayQuestComplete(Quest* quest, bool tempReward, std::string customDescription, bool was_displayed) {
  6352. if (!quest)
  6353. return;
  6354. if (GetVersion() <= 561) {
  6355. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints(), tempReward ? customDescription.c_str() : quest->GetCompletedDescription(), was_displayed);
  6356. return;
  6357. }
  6358. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  6359. if (packet) {
  6360. packet->setDataByName("title", "Quest Reward!");
  6361. packet->setDataByName("name", quest->GetName());
  6362. if(tempReward)
  6363. {
  6364. packet->setDataByName("description", customDescription.c_str());
  6365. }
  6366. else
  6367. packet->setDataByName("description", quest->GetCompletedDescription());
  6368. packet->setDataByName("level", quest->GetLevel());
  6369. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  6370. int8 difficulty = 0;
  6371. if ((string)quest->GetType() == "Tradeskill")
  6372. difficulty = player->GetTSArrowColor(quest->GetLevel());
  6373. else
  6374. difficulty = player->GetArrowColor(quest->GetLevel());
  6375. packet->setDataByName("difficulty", difficulty);
  6376. if(tempReward)
  6377. {
  6378. packet->setDataByName("max_coin", quest->GetCoinTmpReward());
  6379. packet->setDataByName("min_coin", quest->GetCoinTmpReward());
  6380. packet->setDataByName("status_points", quest->GetStatusPoints());
  6381. }
  6382. else
  6383. {
  6384. int64 rewarded_coin = 0;
  6385. if (quest->GetCoinsReward() > 0) {
  6386. if (quest->GetCoinsRewardMax() > 0)
  6387. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  6388. else
  6389. rewarded_coin = quest->GetCoinsReward();
  6390. }
  6391. quest->SetGeneratedCoin(rewarded_coin);
  6392. packet->setDataByName("max_coin", rewarded_coin);
  6393. packet->setDataByName("min_coin", rewarded_coin);
  6394. packet->setDataByName("status_points", quest->GetStatusPoints());
  6395. }
  6396. if(tempReward) {
  6397. PopulateQuestRewardItems(quest->GetTmpRewardItems(), packet);
  6398. }
  6399. else
  6400. {
  6401. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  6402. PopulateQuestRewardItems(quest->GetRewardItems(), packet);
  6403. PopulateQuestRewardItems(quest->GetSelectableRewardItems(), packet, std::string("num_select_rewards"),
  6404. std::string("select_reward_id"), std::string("select_item"));
  6405. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  6406. if (reward_factions && reward_factions->size() > 0) {
  6407. packet->setArrayLengthByName("num_factions", reward_factions->size());
  6408. map<int32, sint32>::iterator itr;
  6409. int16 index = 0;
  6410. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  6411. int32 faction_id = itr->first;
  6412. sint32 amount = itr->second;
  6413. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  6414. if (faction_name) {
  6415. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  6416. packet->setArrayDataByName("amount", amount, index);
  6417. }
  6418. index++;
  6419. }
  6420. }
  6421. }
  6422. EQ2Packet* outapp = packet->serialize();
  6423. // DumpPacket(outapp);
  6424. QueuePacket(outapp);
  6425. safe_delete(packet);
  6426. }
  6427. }
  6428. void Client::DisplayRandomizeFeatures(int32 flags) {
  6429. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  6430. if (flags > 0) {
  6431. if (flags & RANDOMIZE_GENDER)
  6432. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  6433. if (flags & RANDOMIZE_RACE)
  6434. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  6435. if (flags & RANDOMIZE_MODEL_TYPE)
  6436. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  6437. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  6438. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  6439. if (flags & RANDOMIZE_HAIR_TYPE)
  6440. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  6441. if (flags & RANDOMIZE_WING_TYPE)
  6442. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  6443. if (flags & RANDOMIZE_CHEEK_TYPE)
  6444. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  6445. if (flags & RANDOMIZE_CHIN_TYPE)
  6446. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  6447. if (flags & RANDOMIZE_EAR_TYPE)
  6448. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  6449. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  6450. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  6451. if (flags & RANDOMIZE_EYE_TYPE)
  6452. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  6453. if (flags & RANDOMIZE_LIP_TYPE)
  6454. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  6455. if (flags & RANDOMIZE_NOSE_TYPE)
  6456. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  6457. if (flags & RANDOMIZE_EYE_COLOR)
  6458. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  6459. if (flags & RANDOMIZE_HAIR_COLOR1)
  6460. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  6461. if (flags & RANDOMIZE_HAIR_COLOR2)
  6462. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  6463. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  6464. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  6465. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  6466. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  6467. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  6468. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  6469. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  6470. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  6471. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  6472. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  6473. if (flags & RANDOMIZE_SKIN_COLOR)
  6474. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  6475. if (flags & RANDOMIZE_WING_COLOR1)
  6476. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  6477. if (flags & RANDOMIZE_WING_COLOR2)
  6478. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  6479. }
  6480. else
  6481. {
  6482. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  6483. }
  6484. }
  6485. void Client::GiveQuestReward(Quest* quest, bool has_displayed) {
  6486. current_quest_id = 0;
  6487. if(!quest->GetQuestTemporaryState() && !has_displayed)
  6488. {
  6489. quest->IncrementCompleteCount();
  6490. player->AddCompletedQuest(quest);
  6491. }
  6492. AddPendingQuestAcceptReward(quest);
  6493. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  6494. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6495. SendQuestJournal();
  6496. if(quest->GetQuestTemporaryState()) {
  6497. return;
  6498. }
  6499. if(!has_displayed) {
  6500. if (quest->GetExpReward() > 0) {
  6501. int32 xp = quest->GetExpReward();
  6502. player->AddXP(xp);
  6503. }
  6504. if (quest->GetTSExpReward() > 0) {
  6505. int8 ts_level = player->GetTSLevel();
  6506. int32 xp = quest->GetTSExpReward();
  6507. if (player->AddTSXP(xp)) {
  6508. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  6509. if (player->GetTSLevel() != ts_level)
  6510. ChangeTSLevel(ts_level, player->GetTSLevel());
  6511. player->SetCharSheetChanged(true);
  6512. }
  6513. }
  6514. int64 total_coins = quest->GetGeneratedCoin();
  6515. if (total_coins > 0)
  6516. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  6517. player->RemoveQuest(quest->GetQuestID(), false);
  6518. }
  6519. if (quest->GetQuestGiver() > 0)
  6520. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  6521. if(!has_displayed) {
  6522. RemovePlayerQuest(quest->GetQuestID(), true, false);
  6523. }
  6524. }
  6525. void Client::DisplayConversation(int32 conversation_id, int32 spawn_id, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2, int8 language, int8 can_close) {
  6526. std::unique_lock lock(MConversation);
  6527. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  6528. if (packet) {
  6529. packet->setDataByName("conversation_id", conversation_id);
  6530. packet->setDataByName("text", text);
  6531. packet->setDataByName("language", language); // default 0
  6532. packet->setDataByName("enable_blue_ui", 0); // default 0
  6533. packet->setDataByName("can_close", can_close); // default 1
  6534. conversation_map[conversation_id].clear();
  6535. if (conversations) {
  6536. packet->setArrayLengthByName("num_responses", conversations->size());
  6537. for (int32 i = 0; i < conversations->size(); i++) {
  6538. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  6539. if (conversations->at(i).function.length() > 0)
  6540. conversation_map[conversation_id][i] = conversations->at(i).function;
  6541. }
  6542. }
  6543. packet->setDataByName("spawn_id", spawn_id);
  6544. if (mp3) {
  6545. packet->setDataByName("voice", mp3);
  6546. packet->setDataByName("key1", key1);
  6547. packet->setDataByName("key2", key2);
  6548. }
  6549. QueuePacket(packet->serialize());
  6550. safe_delete(packet);
  6551. }
  6552. }
  6553. void Client::DisplayConversation(Item* item, vector<ConversationOption>* conversations, const char* text, int8 type, const char* mp3, int32 key1, int32 key2, int8 language, int8 can_close) {
  6554. if (!item || !text || !conversations || conversations->size() == 0) {
  6555. return;
  6556. }
  6557. int32 conversation_id = GetConversationID(0, item);
  6558. if (conversation_id == 0) {
  6559. next_conversation_id++;
  6560. conversation_id = next_conversation_id;
  6561. }
  6562. MConversation.lock();
  6563. conversation_items[conversation_id] = item;
  6564. MConversation.unlock();
  6565. if (type == 4)
  6566. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  6567. else
  6568. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  6569. }
  6570. void Client::DisplayConversation(Spawn* src, int8 type, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2, int8 language, int8 can_close) {
  6571. if (!src || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  6572. return;
  6573. }
  6574. int32 conversation_id = GetConversationID(src, 0);
  6575. if (conversation_id == 0) {
  6576. next_conversation_id++;
  6577. conversation_id = next_conversation_id;
  6578. }
  6579. MConversation.lock();
  6580. conversation_spawns[conversation_id] = src->GetID();
  6581. MConversation.unlock();
  6582. /* Spawns can start two different types of conversations.
  6583. * Type 1: The chat type with bubbles.
  6584. * Type 2: The dialog type with the blue box. */
  6585. if (type == 1)
  6586. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(src), conversations, text, mp3, key1, key2, language, can_close);
  6587. else if (type == 2)
  6588. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  6589. else //if (type == 3)
  6590. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  6591. }
  6592. void Client::CloseDialog(int32 conversation_id) {
  6593. std::unique_lock lock(MConversation);
  6594. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  6595. if (packet) {
  6596. packet->setDataByName("conversation_id", conversation_id);
  6597. QueuePacket(packet->serialize());
  6598. safe_delete(packet);
  6599. }
  6600. std::map<int32, Item*>::iterator itr;
  6601. while((itr = conversation_items.find(conversation_id)) != conversation_items.end())
  6602. {
  6603. conversation_items.erase(itr);
  6604. }
  6605. std::map<int32, int32>::iterator itr2 = conversation_spawns.find(conversation_id);
  6606. while((itr2 = conversation_spawns.find(conversation_id)) != conversation_spawns.end())
  6607. {
  6608. conversation_spawns.erase(itr2);
  6609. }
  6610. }
  6611. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  6612. std::shared_lock lock(MConversation);
  6613. int32 conversation_id = 0;
  6614. if (spawn) {
  6615. map<int32, int32>::iterator itr;
  6616. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  6617. if (itr->second == spawn->GetID()) {
  6618. conversation_id = itr->first;
  6619. break;
  6620. }
  6621. }
  6622. }
  6623. else if (item) {
  6624. map<int32, Item*>::iterator itr;
  6625. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  6626. if (itr->second == item) {
  6627. conversation_id = itr->first;
  6628. break;
  6629. }
  6630. }
  6631. }
  6632. return conversation_id;
  6633. }
  6634. Spawn* Client::GetCombineSpawn() {
  6635. return combine_spawn;
  6636. }
  6637. bool Client::ShouldTarget() {
  6638. return should_target;
  6639. }
  6640. void Client::TargetSpawn(Spawn* spawn) {
  6641. should_target = false;
  6642. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  6643. if (packet) {
  6644. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  6645. QueuePacket(packet->serialize());
  6646. safe_delete(packet);
  6647. }
  6648. }
  6649. void Client::CombineSpawns(float radius, Spawn* spawn) {
  6650. combine_spawn = spawn;
  6651. spawn->RemoveSpawnFromGroup(true);
  6652. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  6653. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  6654. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6655. should_target = true;
  6656. }
  6657. void Client::AddCombineSpawn(Spawn* spawn) {
  6658. if (combine_spawn && combine_spawn != spawn && spawn) {
  6659. combine_spawn->AddSpawnToGroup(spawn);
  6660. spawn->AddSpawnToGroup(combine_spawn);
  6661. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6662. }
  6663. else if (spawn)
  6664. combine_spawn = spawn;
  6665. should_target = true;
  6666. }
  6667. void Client::RemoveCombineSpawn(Spawn* spawn) {
  6668. if (combine_spawn && spawn)
  6669. spawn->RemoveSpawnFromGroup();
  6670. if (combine_spawn == spawn)
  6671. combine_spawn->RemoveSpawnFromGroup(true);
  6672. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6673. if (combine_spawn == spawn)
  6674. combine_spawn = 0;
  6675. }
  6676. void Client::SaveCombineSpawns(const char* name) {
  6677. if (!combine_spawn) {
  6678. return;
  6679. }
  6680. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  6681. if (!spawns) {
  6682. return;
  6683. }
  6684. int32 count = spawns->size();
  6685. int32 spawnLocationID = 0;
  6686. if (count == 1)
  6687. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  6688. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  6689. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  6690. // we remove the spawn inside SaveCombinedSpawnLocation
  6691. //GetCurrentZone()->RemoveSpawn(combine_spawn);
  6692. }
  6693. else
  6694. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  6695. safe_delete(spawns);
  6696. combine_spawn = 0;
  6697. }
  6698. bool Client::AddItem(int32 item_id, int16 quantity, AddItemType type) {
  6699. Item* master_item = master_item_list.GetItem(item_id);
  6700. Item* item = 0;
  6701. if (master_item)
  6702. item = new Item(master_item);
  6703. if (item) {
  6704. if (quantity > 0)
  6705. item->details.count = quantity;
  6706. return AddItem(item, nullptr, type);
  6707. }
  6708. else
  6709. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6710. return false;
  6711. }
  6712. bool Client::AddItem(Item* item, bool* item_deleted, AddItemType type) {
  6713. if (!item) {
  6714. return false;
  6715. }
  6716. if (player->AddItem(item, type)) {
  6717. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6718. if (outapp) {
  6719. //DumpPacket(outapp);
  6720. QueuePacket(outapp);
  6721. //resend bag desc with new item name added
  6722. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  6723. if (outapp) {
  6724. //DumpPacket(outapp);
  6725. QueuePacket(outapp);
  6726. }
  6727. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6728. DumpPacket(app);
  6729. client->QueuePacket(app);
  6730. */
  6731. }
  6732. CheckPlayerQuestsItemUpdate(item);
  6733. if (item->GetItemScript() && lua_interface)
  6734. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6735. }
  6736. else {
  6737. lua_interface->SetLuaUserDataStale(item);
  6738. // likely lore conflict
  6739. if(item_deleted)
  6740. *item_deleted = true;
  6741. return false;
  6742. }
  6743. return true;
  6744. }
  6745. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  6746. Item* master_item = master_item_list.GetItem(item_id);
  6747. Item* item = 0;
  6748. if (master_item)
  6749. item = new Item(master_item);
  6750. if (item) {
  6751. if (quantity > 0)
  6752. item->details.count = quantity;
  6753. return AddItemToBank(item);
  6754. }
  6755. else
  6756. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6757. return false;
  6758. }
  6759. bool Client::AddItemToBank(Item* item) {
  6760. if (!item) {
  6761. return false;
  6762. }
  6763. if (player->AddItemToBank(item)) {
  6764. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6765. if (outapp) {
  6766. QueuePacket(outapp);
  6767. //resend bag desc with new item name added
  6768. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  6769. if (outapp)
  6770. QueuePacket(outapp);
  6771. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6772. DumpPacket(app);
  6773. client->QueuePacket(app);
  6774. */
  6775. }
  6776. CheckPlayerQuestsItemUpdate(item);
  6777. if (item->GetItemScript() && lua_interface)
  6778. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6779. }
  6780. else {
  6781. lua_interface->SetLuaUserDataStale(item);
  6782. // likely lore conflict
  6783. safe_delete(item);
  6784. return false;
  6785. }
  6786. return true;
  6787. }
  6788. void Client::UnequipItem(int16 index, sint32 bag_id, int8 to_slot, int8 appearance_equip) {
  6789. vector<EQ2Packet*> packets = GetPlayer()->UnequipItem(index, bag_id, to_slot, GetVersion(), appearance_equip);
  6790. EQ2Packet* outapp = 0;
  6791. for(int32 i=0;i<packets.size();i++)
  6792. {
  6793. outapp = packets[i];
  6794. if(outapp)
  6795. QueuePacket(outapp);
  6796. }
  6797. GetPlayer()->UpdateWeapons();
  6798. EQ2Packet* characterSheetPackets = GetPlayer()->GetPlayerInfo()->serialize(GetVersion());
  6799. QueuePacket(characterSheetPackets);
  6800. }
  6801. bool Client::RemoveItem(Item* item, int16 quantity, bool force_override_no_delete) {
  6802. EQ2Packet* outapp;
  6803. bool delete_item = false;
  6804. assert(item);
  6805. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  6806. item->details.count -= quantity;
  6807. item->save_needed = true;
  6808. }
  6809. else {
  6810. database.DeleteItem(character_id, item, 0);
  6811. player->GetPlayerItemList()->RemoveItem(item, false);
  6812. delete_item = true;
  6813. }
  6814. if(force_override_no_delete)
  6815. delete_item = false;
  6816. if ((outapp = player->SendInventoryUpdate(version))) {
  6817. QueuePacket(outapp);
  6818. if (item->GetItemScript() && lua_interface)
  6819. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  6820. if (delete_item)
  6821. {
  6822. PurgeItem(item);
  6823. lua_interface->SetLuaUserDataStale(item);
  6824. safe_delete(item);
  6825. }
  6826. GetPlayer()->CalculateApplyWeight();
  6827. return true;
  6828. }
  6829. return false;
  6830. }
  6831. void Client::SetLuaDebugClient(bool val) {
  6832. if (val)
  6833. lua_debug_timer.Start();
  6834. lua_debug = val;
  6835. if (lua_interface && !val) {
  6836. lua_interface->RemoveDebugClients(this);
  6837. lua_debug_timer.Disable();
  6838. }
  6839. }
  6840. void Client::SetMerchantTransaction(Spawn* spawn) {
  6841. merchant_transaction = spawn;
  6842. }
  6843. Spawn* Client::GetMerchantTransaction() {
  6844. return merchant_transaction;
  6845. }
  6846. void Client::SetMailTransaction(Spawn* spawn) {
  6847. ResetSendMail(spawn ? false : true);
  6848. MMailWindowMutex.lock();
  6849. mail_transaction = spawn;
  6850. MMailWindowMutex.unlock();
  6851. }
  6852. Spawn* Client::GetMailTransaction() {
  6853. return mail_transaction;
  6854. }
  6855. void Client::PlaySound(const char* name) {
  6856. if (name) {
  6857. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  6858. if (packet) {
  6859. packet->setMediumStringByName("name", name);
  6860. QueuePacket(packet->serialize());
  6861. safe_delete(packet);
  6862. }
  6863. }
  6864. }
  6865. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  6866. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  6867. if(multiplier){
  6868. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  6869. float diff_low = faction_val - multiplier->faction_min;
  6870. if(diff_low < 0)
  6871. diff_low*=-1;
  6872. float total_diff = multiplier->faction_max - multiplier->faction_min;
  6873. if(total_diff < 0)
  6874. total_diff*=-1;
  6875. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  6876. float total1 = (diff_low/total_diff);
  6877. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  6878. return final_buy_multiplier;
  6879. }*/
  6880. return 1;
  6881. }
  6882. float Client::CalculateSellMultiplier(int32 merchant_id) {
  6883. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  6884. if(multiplier){
  6885. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  6886. float diff_low = faction_val - multiplier->faction_min;
  6887. if(diff_low < 0)
  6888. diff_low*=-1;
  6889. float total_diff = multiplier->faction_max - multiplier->faction_min;
  6890. if(total_diff < 0)
  6891. total_diff*=-1;
  6892. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  6893. float total1 = (diff_low/total_diff);
  6894. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  6895. return final_sell_multiplier;
  6896. }*/
  6897. return 1;
  6898. }
  6899. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  6900. Spawn* spawn = GetMerchantTransaction();
  6901. Guild* guild = GetPlayer()->GetGuild();
  6902. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY)) &&
  6903. spawn->IsClientInMerchantLevelRange(this)) {
  6904. int32 total_sell_price = 0;
  6905. int32 total_status_sell_price = 0; //for status
  6906. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6907. int32 sell_price = 0;
  6908. int32 status_sell_price = 0; //for status
  6909. Item* master_item = master_item_list.GetItem(item_id);
  6910. Item* item = 0;
  6911. if (unique_id == 0)
  6912. item = player->item_list.GetItemFromID(item_id, quantity);
  6913. else
  6914. item = player->item_list.GetItemFromUniqueID(unique_id);
  6915. if (!item)
  6916. item = player->item_list.GetItemFromID(item_id);
  6917. if (item && master_item) {
  6918. if(item->details.item_locked)
  6919. {
  6920. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell the item in use.");
  6921. return;
  6922. }
  6923. else if(item->CheckFlag(NO_VALUE))
  6924. {
  6925. SimpleMessage(CHANNEL_COLOR_RED, "This item has no value.");
  6926. return;
  6927. }
  6928. else if (item->IsBag())
  6929. {
  6930. int32 bagitemcount = player->GetPlayerItemList()->GetItemCountInBag(item);
  6931. if (bagitemcount > 0) {
  6932. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell a bag with items inside it.");
  6933. return;
  6934. }
  6935. }
  6936. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  6937. if (sell_price > item->sell_price)
  6938. sell_price = item->sell_price;
  6939. if (quantity > item->details.count)
  6940. quantity = item->details.count;
  6941. total_sell_price = sell_price * quantity;
  6942. //------------------------------For Selling Status Items
  6943. status_sell_price = (int32)(master_item->sell_status * multiplier);
  6944. if (status_sell_price > item->sell_status)
  6945. status_sell_price = item->sell_status;
  6946. if (quantity > item->details.count)
  6947. quantity = item->details.count;
  6948. total_status_sell_price = status_sell_price * quantity;
  6949. if(total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  6950. total_status_sell_price = 0;
  6951. player->GetInfoStruct()->add_status_points(total_status_sell_price);
  6952. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  6953. if (player->GetGuild() && guild->GetLevel() < guildMaxLevel) {
  6954. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  6955. guild->SendGuildMemberList();
  6956. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  6957. }
  6958. if (quantity > 1)
  6959. {
  6960. if(total_status_sell_price)
  6961. Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %i %s to %s for %s and %u Status Points.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str(), status_sell_price);
  6962. else
  6963. Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %i %s to %s for %s.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
  6964. }
  6965. else
  6966. {
  6967. if(total_status_sell_price)
  6968. Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %s to %s for %s and %u Status Points.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str(), status_sell_price);
  6969. else
  6970. Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %s to %s for %s.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
  6971. }
  6972. player->AddCoins(total_sell_price);
  6973. if(!item->no_buy_back && (total_status_sell_price == 0 || (total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))))
  6974. AddBuyBack(unique_id, item_id, quantity, sell_price);
  6975. if (quantity >= item->details.count) {
  6976. database.DeleteItem(GetCharacterID(), item, 0);
  6977. player->item_list.DestroyItem(item->details.index);
  6978. }
  6979. else {
  6980. item->details.count -= quantity;
  6981. item->save_needed = true;
  6982. }
  6983. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6984. if (outapp)
  6985. QueuePacket(outapp);
  6986. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  6987. SendBuyBackList();
  6988. }
  6989. }
  6990. }
  6991. void Client::BuyBack(int32 item_id, int16 quantity) {
  6992. Spawn* spawn = GetMerchantTransaction();
  6993. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK)) &&
  6994. spawn->IsClientInMerchantLevelRange(this)) {
  6995. deque<BuyBackItem*>::iterator itr;
  6996. BuyBackItem* buyback = 0;
  6997. BuyBackItem* closest = 0;
  6998. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6999. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  7000. buyback = *itr;
  7001. if (buyback->unique_id == item_id) {
  7002. closest = buyback;
  7003. quantity = buyback->quantity;
  7004. break;
  7005. }
  7006. }
  7007. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  7008. if (closest) {
  7009. Item* item = 0;
  7010. Item* master_item = master_item_list.GetItem(closest->item_id);
  7011. if (master_item) {
  7012. item = new Item(master_item);
  7013. if (closest->quantity >= quantity)
  7014. item->details.count = quantity;
  7015. else
  7016. item->details.count = closest->quantity;
  7017. }
  7018. bool itemDeleted = false;
  7019. bool itemAdded = false;
  7020. sint64 dispFlags = 0;
  7021. if (item && item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buyback_display_flags", item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  7022. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  7023. else if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  7024. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  7025. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  7026. bool removed = false;
  7027. if (closest->quantity == quantity) {
  7028. MBuyBack.writelock(__FUNCTION__, __LINE__);
  7029. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  7030. if (*itr == closest) {
  7031. buy_back_items.erase(itr);
  7032. removed = true;
  7033. break;
  7034. }
  7035. }
  7036. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  7037. }
  7038. else {
  7039. closest->quantity -= quantity;
  7040. closest->save_needed = true;
  7041. }
  7042. itemAdded = AddItem(item, &itemDeleted);
  7043. if (removed) {
  7044. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  7045. safe_delete(closest);
  7046. }
  7047. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  7048. SendBuyBackList();
  7049. }
  7050. else
  7051. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  7052. if(!itemAdded && !itemDeleted) {
  7053. lua_interface->SetLuaUserDataStale(item);
  7054. safe_delete(item);
  7055. }
  7056. }
  7057. }
  7058. }
  7059. void Client::BuyItem(int32 item_id, int16 quantity) {
  7060. // Get the merchant we are buying from
  7061. Spawn* spawn = GetMerchantTransaction();
  7062. // Make sure the spawn has a merchant list
  7063. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7064. int32 total_buy_price = 0;
  7065. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7066. int32 sell_price = 0;
  7067. Item* master_item = master_item_list.GetItem(item_id);
  7068. Item* item = 0;
  7069. int16 total_available = 0;
  7070. vector<MerchantItemInfo>* temp;
  7071. vector<MerchantItemInfo>::iterator itr;
  7072. MerchantItemInfo* ItemInfo = 0;
  7073. temp = world.GetMerchantList(spawn->GetMerchantID());
  7074. for (itr = temp->begin(); itr != temp->end(); itr++) {
  7075. if ((*itr).item_id == item_id) {
  7076. ItemInfo = &(*itr);
  7077. break;
  7078. }
  7079. }
  7080. if (master_item && ItemInfo) {
  7081. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  7082. quantity = 1;
  7083. total_available = 0xFFFF;
  7084. sell_price = master_item->sell_price;
  7085. }
  7086. else {
  7087. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  7088. sell_price = (int32)(master_item->sell_price * multiplier);
  7089. if (quantity > total_available)
  7090. quantity = total_available;
  7091. }
  7092. sint64 dispFlags = 0;
  7093. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buy_display_flags", master_item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  7094. {
  7095. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  7096. return;
  7097. }
  7098. if(quantity < 1)
  7099. {
  7100. SimpleMessage(CHANNEL_COLOR_RED, "Merchant does not have item for purchase (quantity < 1).");
  7101. return;
  7102. }
  7103. total_buy_price = sell_price * quantity;
  7104. item = new Item(master_item);
  7105. item->details.count = quantity;
  7106. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  7107. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  7108. lua_interface->SetLuaUserDataStale(item);
  7109. safe_delete(item);
  7110. }
  7111. else {
  7112. // Price not set in the merchant_inventory table, use the old method
  7113. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  7114. if (player->RemoveCoins(total_buy_price)) {
  7115. item->SetMaxSellValue(sell_price);
  7116. if (quantity > 1)
  7117. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %i %s from %s for%s.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
  7118. else
  7119. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %s from %s for%s.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
  7120. bool itemDeleted = false;
  7121. AddItem(item, &itemDeleted);
  7122. if(!itemDeleted) {
  7123. CheckPlayerQuestsItemUpdate(item);
  7124. if (item && total_available < 0xFF) {
  7125. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  7126. SendBuyMerchantList();
  7127. }
  7128. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  7129. PlayLotto(total_buy_price, item->details.item_id);
  7130. }
  7131. }
  7132. else {
  7133. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7134. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7135. PlaySound("buy_failed");
  7136. }
  7137. }
  7138. else {
  7139. // Price set in merchant_inventory table
  7140. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  7141. // TODO: need to add support for station cash
  7142. if (player->GetInfoStruct()->get_status_points() >= (ItemInfo->price_status * quantity) && player->HasCoins(ItemInfo->price_coins * quantity)) {
  7143. // Check items
  7144. int16 item_quantity = 0;
  7145. // Default these to true in case price_item_id or price_item2_id was never set
  7146. bool hasItem1 = true;
  7147. bool hasItem2 = true;
  7148. Item* tempItem1 = 0;
  7149. Item* tempItem2 = 0;
  7150. if (ItemInfo->price_item_id != 0) {
  7151. // Same item for whatever reason lets add the quantities together
  7152. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  7153. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  7154. else
  7155. item_quantity = ItemInfo->price_item_qty;
  7156. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  7157. if (tempItem1) {
  7158. if (tempItem1->details.count < item_quantity)
  7159. hasItem1 = false;
  7160. }
  7161. else {
  7162. hasItem1 = false;
  7163. }
  7164. }
  7165. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  7166. // as item1 and we already checked for it so we can skip this check
  7167. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  7168. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  7169. if (tempItem2) {
  7170. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  7171. hasItem2 = false;
  7172. }
  7173. else {
  7174. hasItem2 = false;
  7175. }
  7176. }
  7177. // if we have every thing then remove the price and give the item
  7178. if (hasItem1 && hasItem2) {
  7179. player->GetInfoStruct()->set_status_points(player->GetInfoStruct()->get_status_points() - (ItemInfo->price_status * quantity));
  7180. // TODO: station cash
  7181. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  7182. // so there is no need to send it more then that one time
  7183. if (tempItem1) {
  7184. if (tempItem1->details.count > item_quantity) {
  7185. tempItem1->details.count -= item_quantity;
  7186. tempItem1->save_needed = true;
  7187. }
  7188. else {
  7189. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  7190. player->item_list.DestroyItem(tempItem1->details.index);
  7191. }
  7192. }
  7193. if (tempItem2) {
  7194. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  7195. tempItem2->details.count -= ItemInfo->price_item2_qty;
  7196. tempItem2->save_needed = true;
  7197. }
  7198. else {
  7199. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  7200. player->item_list.DestroyItem(tempItem2->details.index);
  7201. }
  7202. }
  7203. // Checked to see if we had enough coins already so don't need to check the return type on RemoveCoins as it will always be true
  7204. player->RemoveCoins(ItemInfo->price_coins * quantity);
  7205. item->SetMaxSellValue(sell_price);
  7206. if (quantity > 1)
  7207. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %i %s from %s for%s.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
  7208. else
  7209. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %s from %s for%s.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
  7210. bool itemDeleted = false;
  7211. AddItem(item, &itemDeleted);
  7212. if(!itemDeleted) {
  7213. CheckPlayerQuestsItemUpdate(item);
  7214. if (item && total_available < 0xFF) {
  7215. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  7216. SendBuyMerchantList();
  7217. }
  7218. SendSellMerchantList();
  7219. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  7220. PlayLotto(total_buy_price, item->details.item_id);
  7221. }
  7222. }
  7223. else {
  7224. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7225. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7226. PlaySound("buy_failed");
  7227. }
  7228. }
  7229. else {
  7230. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7231. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7232. PlaySound("buy_failed");
  7233. }
  7234. }
  7235. }
  7236. }
  7237. }
  7238. }
  7239. void Client::RepairItem(int32 item_id) {
  7240. Spawn* spawn = GetMerchantTransaction();
  7241. if (spawn) {
  7242. Item* item = player->item_list.GetItemFromID(item_id);
  7243. if (!item)
  7244. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  7245. if (item) {
  7246. if(item->CheckFlag2(NO_REPAIR)) {
  7247. Message(CHANNEL_MERCHANT, "The mender was unable to repair your items.");
  7248. PlaySound("buy_failed");
  7249. }
  7250. else {
  7251. int32 repair_cost = item->CalculateRepairCost();
  7252. if (player->RemoveCoins((int32)repair_cost)) {
  7253. item->generic_info.condition = 100;
  7254. item->save_needed = true;
  7255. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  7256. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  7257. QueuePacket(item->serialize(version, false, player));
  7258. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  7259. PlaySound("coin_cha_ching");
  7260. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  7261. SendRepairList();
  7262. }
  7263. else {
  7264. string popup_text = "You do not have enough coin to repair ";
  7265. string popup_item = item->CreateItemLink(GetVersion()).c_str();
  7266. popup_text.append(popup_item);
  7267. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7268. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  7269. PlaySound("buy_failed");
  7270. }
  7271. }
  7272. }
  7273. }
  7274. }
  7275. void Client::RepairAllItems() {
  7276. Spawn* spawn = GetMerchantTransaction();
  7277. if (spawn) {
  7278. vector<Item*>* repairable_items = GetRepairableItems();
  7279. if (repairable_items && repairable_items->size() > 0) {
  7280. vector<Item*>::iterator itr;
  7281. int64 total_cost = 0;
  7282. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  7283. total_cost += (*itr)->CalculateRepairCost();
  7284. if (player->RemoveCoins((int32)total_cost)) {
  7285. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  7286. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  7287. Item* item = *itr;
  7288. if (item) {
  7289. item->generic_info.condition = 100;
  7290. item->save_needed = true;
  7291. QueuePacket(item->serialize(version, false, player));
  7292. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  7293. }
  7294. }
  7295. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  7296. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  7297. PlaySound("coin_cha_ching");
  7298. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  7299. SendRepairList();
  7300. }
  7301. else {
  7302. string popup_text = "You do not have enough coin to repair all of your items. ";
  7303. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7304. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  7305. PlaySound("buy_failed");
  7306. }
  7307. }
  7308. safe_delete(repairable_items);
  7309. }
  7310. }
  7311. void Client::SendAchievementsList()
  7312. {
  7313. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  7314. map<int32, Achievement *>::iterator itr;
  7315. Achievement *achievement;
  7316. vector<AchievementRequirements *> *requirements = 0;
  7317. vector<AchievementRequirements *>::iterator itr2;
  7318. AchievementRequirements *requirement;
  7319. vector<AchievementRewards *> *rewards = 0;
  7320. vector<AchievementRewards *>::iterator itr3;
  7321. AchievementRewards *reward;
  7322. PacketStruct *packet;
  7323. int16 i = 0;
  7324. int16 j = 0;
  7325. int16 k = 0;
  7326. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  7327. return;
  7328. }
  7329. packet->setArrayLengthByName("num_achievements" , achievements->size());
  7330. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  7331. achievement = itr->second;
  7332. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  7333. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  7334. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  7335. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  7336. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  7337. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  7338. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  7339. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  7340. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  7341. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  7342. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  7343. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  7344. requirements = achievement->GetRequirements();
  7345. rewards = achievement->GetRewards();
  7346. j = 0;
  7347. k = 0;
  7348. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  7349. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  7350. requirement = *itr2;
  7351. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  7352. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  7353. j++;
  7354. }
  7355. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  7356. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  7357. reward = *itr3;
  7358. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  7359. k++;
  7360. }
  7361. i++;
  7362. }
  7363. //packet->PrintPacket();
  7364. EQ2Packet* data = packet->serialize();
  7365. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  7366. safe_delete(packet);
  7367. safe_delete(data);
  7368. //DumpPacket(app);
  7369. QueuePacket(app);*/
  7370. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  7371. SendAchievementUpdate(true);
  7372. }
  7373. void Client::SendAchievementUpdate(bool first_login) {
  7374. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  7375. map<int32, AchievementUpdate*>::iterator itr;
  7376. AchievementUpdate* update;
  7377. vector<AchievementUpdateItems*>* update_items = 0;
  7378. vector<AchievementUpdateItems*>::iterator itr2;
  7379. AchievementUpdateItems* update_item;
  7380. int16 i = 0;
  7381. int16 j = 0;
  7382. PacketStruct* packet;
  7383. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  7384. return;
  7385. }
  7386. packet->setDataByName("unknown1", first_login ? 1 : 0);
  7387. packet->setArrayLengthByName("num_achievements", updates->size());
  7388. for (itr = updates->begin(); itr != updates->end(); itr++) {
  7389. update = itr->second;
  7390. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  7391. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  7392. update_items = update->GetUpdateItems();
  7393. j = 0;
  7394. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  7395. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  7396. update_item = *itr2;
  7397. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  7398. j++;
  7399. }
  7400. i++;
  7401. }
  7402. //packet->PrintPacket();
  7403. EQ2Packet* data = packet->serialize();
  7404. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  7405. safe_delete(packet);
  7406. safe_delete(data);
  7407. //DumpPacket(app);
  7408. QueuePacket(app);
  7409. }
  7410. void Client::SendBuyMerchantList(bool sell) {
  7411. Spawn* spawn = GetMerchantTransaction();
  7412. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7413. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  7414. if (items) {
  7415. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7416. if (packet) {
  7417. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7418. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7419. packet->setArrayLengthByName("num_items", items->size());
  7420. vector<MerchantItemInfo>::iterator itr;
  7421. sint8 item_difficulty = 0;
  7422. int32 sell_price = 0;
  7423. int i = 0;
  7424. int tmp_level = 0;
  7425. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  7426. MerchantItemInfo ItemInfo = *itr;
  7427. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  7428. if (!item)
  7429. continue;
  7430. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7431. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7432. packet->setArrayDataByName("stack_size", item->stack_count, i);
  7433. packet->setArrayDataByName("icon", item->details.icon, i);
  7434. if (item->generic_info.adventure_default_level > 0)
  7435. tmp_level = item->generic_info.adventure_default_level;
  7436. else
  7437. tmp_level = item->generic_info.tradeskill_default_level;
  7438. packet->setArrayDataByName("level", tmp_level, i);
  7439. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7440. packet->setArrayDataByName("tier", item->details.tier, i);
  7441. }
  7442. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7443. item_difficulty = player->GetArrowColor(tmp_level);
  7444. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7445. item_difficulty = ARROW_COLOR_WHITE;
  7446. sint64 overrideValue = 0;
  7447. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  7448. item_difficulty = (sint8)overrideValue;
  7449. item_difficulty -= 6;
  7450. if (item_difficulty < 0)
  7451. item_difficulty *= -1;
  7452. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7453. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  7454. packet->setArrayDataByName("unknown5", 255, i);
  7455. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  7456. sint64 dispFlags = 0;
  7457. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buy_display_flags", item, player, nullptr, &dispFlags))
  7458. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  7459. std::string overrideValueStr;
  7460. // classic client isn't properly tracking this field, DoF we don't have it identified yet, but no field to cause any issues (can add later if identified)
  7461. if (GetVersion() >= 546 && item->GetItemScript() && lua_interface && lua_interface->RunItemScriptWithReturnString(item->GetItemScript(), "item_description", item, player, &overrideValueStr))
  7462. packet->setArrayDataByName("description", overrideValueStr.c_str(), i);
  7463. // If no price set in the merchant_inventory table then use the old method
  7464. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  7465. sell_price = (int32)(item->sell_price * multiplier);
  7466. packet->setArrayDataByName("price", sell_price, i);
  7467. }
  7468. else {
  7469. int8 count = 0;
  7470. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  7471. count++;
  7472. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  7473. count++;
  7474. if (count != 0) {
  7475. packet->setSubArrayLengthByName("num_tokens", count, i);
  7476. int8 index = 0;
  7477. Item* token = 0;
  7478. if (ItemInfo.price_item_id != 0) {
  7479. token = master_item_list.GetItem(ItemInfo.price_item_id);
  7480. if (item) {
  7481. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  7482. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  7483. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  7484. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  7485. }
  7486. token = 0;
  7487. index++;
  7488. }
  7489. if (ItemInfo.price_item2_id != 0) {
  7490. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  7491. if (item) {
  7492. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  7493. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  7494. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  7495. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  7496. }
  7497. }
  7498. }
  7499. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  7500. packet->setArrayDataByName("status2", ItemInfo.price_status, i);
  7501. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  7502. }
  7503. }
  7504. if (GetVersion() <= 546) {
  7505. //buy is 0 so dont need to set it
  7506. if (sell)
  7507. packet->setDataByName("type", 1);
  7508. }
  7509. else {
  7510. if (sell)
  7511. packet->setDataByName("type", 130);
  7512. else
  7513. packet->setDataByName("type", 2);
  7514. }
  7515. EQ2Packet* outapp = packet->serialize();
  7516. QueuePacket(outapp);
  7517. safe_delete(packet);
  7518. }
  7519. safe_delete(items);
  7520. }
  7521. else {
  7522. // Need to send an empty packet in the event there is no item list, otherwise the
  7523. // last item list sent to the player will show for this merchant
  7524. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7525. if (packet) {
  7526. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7527. if (GetVersion() <= 546) {
  7528. //buy is 0 so dont need to set it
  7529. if (sell)
  7530. packet->setDataByName("type", 1);
  7531. }
  7532. else {
  7533. if (sell)
  7534. packet->setDataByName("type", 130);
  7535. else
  7536. packet->setDataByName("type", 2);
  7537. }
  7538. EQ2Packet* outapp = packet->serialize();
  7539. QueuePacket(outapp);
  7540. safe_delete(packet);
  7541. }
  7542. }
  7543. }
  7544. }
  7545. void Client::SendSellMerchantList(bool sell) {
  7546. Spawn* spawn = GetMerchantTransaction();
  7547. if (!spawn || (spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) || (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  7548. return;
  7549. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7550. map<int32, Item*>* items = player->GetItemList();
  7551. if (items) {
  7552. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7553. if (packet) {
  7554. vector<Item*> sellable_items;
  7555. map<int32, Item*>::iterator test_itr;
  7556. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  7557. bool isbagwithitems = false;
  7558. if (test_itr->second && test_itr->second->IsBag() && (test_itr->second->details.num_slots - test_itr->second->details.num_free_slots != test_itr->second->details.num_slots))
  7559. isbagwithitems = true;
  7560. if (test_itr->second && !test_itr->second->CheckFlag(NO_VALUE) && (isbagwithitems == false) && (test_itr->second->details.inv_slot_id != -3) && (test_itr->second->details.inv_slot_id != -4))
  7561. sellable_items.push_back(test_itr->second);
  7562. }
  7563. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7564. packet->setArrayLengthByName("num_items", sellable_items.size());
  7565. vector<Item*>::iterator itr;
  7566. Item* item = 0;
  7567. sint8 item_difficulty = 0;
  7568. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  7569. int32 sell_price = 0;
  7570. Item* master_item = 0;
  7571. int i = 0;
  7572. int tmp_level = 0;
  7573. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  7574. item = *itr;
  7575. master_item = master_item_list.GetItem(item->details.item_id);
  7576. if (master_item)
  7577. sell_price = (int32)(master_item->sell_price * multiplier);
  7578. else
  7579. sell_price = 0;
  7580. if (sell_price > item->sell_price)
  7581. sell_price = item->sell_price;
  7582. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7583. string thename = item->name;
  7584. packet->setArrayDataByName("price", sell_price, i);
  7585. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  7586. int8 dispFlags = 0;
  7587. // only city merchants allow selling for status
  7588. if(item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT))
  7589. {
  7590. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  7591. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  7592. if (GetPlayer()->GetGuild() && GetPlayer()->GetGuild()->GetLevel() >= guildMaxLevel) {
  7593. dispFlags += DISPLAY_FLAG_NO_GUILD_STATUS;
  7594. }
  7595. }
  7596. if(item->no_buy_back || (item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  7597. {
  7598. if(GetVersion() < 1188)
  7599. dispFlags += DISPLAY_FLAG_RED_TEXT; // for older clients it isn't "no buy back", you can either have 1 for red text or 255 for 'not for sale' to be checked
  7600. else
  7601. dispFlags += DISPLAY_FLAG_NO_BUYBACK;
  7602. }
  7603. if(item->no_sale)
  7604. dispFlags += DISPLAY_FLAG_NOT_FOR_SALE;
  7605. packet->setArrayDataByName("display_flags", dispFlags, i);
  7606. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7607. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  7608. packet->setArrayDataByName("stack_size", item->details.count, i);
  7609. packet->setArrayDataByName("icon", item->details.icon, i);
  7610. if (item->generic_info.adventure_default_level > 0)
  7611. tmp_level = item->generic_info.adventure_default_level;
  7612. else
  7613. tmp_level = item->generic_info.tradeskill_default_level;
  7614. packet->setArrayDataByName("level", item->details.recommended_level, i);
  7615. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7616. packet->setArrayDataByName("tier", item->details.tier, i);
  7617. }
  7618. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7619. item_difficulty = player->GetArrowColor(tmp_level);
  7620. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7621. item_difficulty = ARROW_COLOR_WHITE;
  7622. sint64 overrideValue = 0;
  7623. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  7624. item_difficulty = (sint8)overrideValue;
  7625. item_difficulty -= 6;
  7626. if (item_difficulty < 0)
  7627. item_difficulty *= -1;
  7628. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7629. if (item->details.count == 1)
  7630. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7631. else
  7632. packet->setArrayDataByName("quantity", item->details.count, i);
  7633. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7634. if (GetVersion() <= 1096)
  7635. packet->setArrayDataByName("description", item->description.c_str(), i);
  7636. }
  7637. if (GetVersion() <= 546) {
  7638. packet->setDataByName("type", 1);
  7639. }
  7640. else {
  7641. if (sell)
  7642. packet->setDataByName("type", 129);
  7643. else
  7644. packet->setDataByName("type", 1);
  7645. }
  7646. packet->setDataByName("unknown8a", 16256, 6);
  7647. packet->setDataByName("unknown8a", 16256, 10);
  7648. //packet->PrintPacket();
  7649. EQ2Packet* outapp = packet->serialize();
  7650. //DumpPacket(outapp);
  7651. QueuePacket(outapp);
  7652. safe_delete(packet);
  7653. }
  7654. safe_delete(items);
  7655. }
  7656. }
  7657. }
  7658. void Client::SendBuyBackList(bool sell) {
  7659. if (GetVersion() <= 546) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  7660. return;
  7661. Spawn* spawn = GetMerchantTransaction();
  7662. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7663. deque<BuyBackItem*>::iterator itr;
  7664. int i = 0;
  7665. Item* master_item = 0;
  7666. BuyBackItem* buyback = 0;
  7667. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7668. if (packet) {
  7669. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7670. packet->setArrayLengthByName("num_items", buy_back_items.size());
  7671. sint8 item_difficulty = 0;
  7672. MBuyBack.readlock(__FUNCTION__, __LINE__);
  7673. int tmp_level = 0;
  7674. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  7675. buyback = *itr;
  7676. master_item = master_item_list.GetItem(buyback->item_id);
  7677. if (master_item) {
  7678. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  7679. packet->setArrayDataByName("price", buyback->price, i);
  7680. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  7681. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  7682. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  7683. packet->setArrayDataByName("icon", master_item->details.icon, i);
  7684. if (master_item->generic_info.adventure_default_level > 0)
  7685. tmp_level = master_item->generic_info.adventure_default_level;
  7686. else
  7687. tmp_level = master_item->generic_info.tradeskill_default_level;
  7688. packet->setArrayDataByName("level", tmp_level, i);
  7689. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7690. packet->setArrayDataByName("tier", master_item->details.tier, i);
  7691. }
  7692. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  7693. item_difficulty = player->GetArrowColor(tmp_level);
  7694. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7695. item_difficulty = ARROW_COLOR_WHITE;
  7696. sint64 overrideValue = 0;
  7697. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "item_difficulty", master_item, player, nullptr, &overrideValue))
  7698. item_difficulty = (sint8)overrideValue;
  7699. item_difficulty -= 6;
  7700. if (item_difficulty < 0)
  7701. item_difficulty *= -1;
  7702. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7703. sint64 dispFlags = 0;
  7704. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buyback_display_flags", master_item, player, nullptr, &dispFlags))
  7705. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  7706. if (buyback->quantity == 1)
  7707. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7708. else
  7709. packet->setArrayDataByName("quantity", buyback->quantity, i);
  7710. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  7711. if (GetVersion() <= 1096)
  7712. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  7713. }
  7714. }
  7715. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  7716. if (sell)
  7717. packet->setDataByName("type", 640);
  7718. else
  7719. packet->setDataByName("type", 512);
  7720. EQ2Packet* outapp = packet->serialize();
  7721. // DumpPacket(outapp);
  7722. QueuePacket(outapp);
  7723. safe_delete(packet);
  7724. }
  7725. }
  7726. }
  7727. void Client::SendRepairList() {
  7728. Spawn* spawn = GetMerchantTransaction();
  7729. if (spawn) {
  7730. vector<Item*>* repairable_items = GetRepairableItems();
  7731. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7732. if (packet) {
  7733. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7734. packet->setArrayLengthByName("num_items", repairable_items->size());
  7735. Item* item = 0;
  7736. sint8 item_difficulty = 0;
  7737. int32 i = 0;
  7738. vector<Item*>::iterator itr;
  7739. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  7740. item = *itr;
  7741. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7742. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  7743. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7744. packet->setArrayDataByName("stack_size", item->details.count, i);
  7745. packet->setArrayDataByName("icon", item->details.icon, i);
  7746. /*if (item->generic_info.adventure_default_level > 0)
  7747. tmp_level = item->generic_info.adventure_default_level;
  7748. else
  7749. tmp_level = item->generic_info.tradeskill_default_level;
  7750. packet->setArrayDataByName("level", tmp_level, i);*/
  7751. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  7752. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7753. packet->setArrayDataByName("tier", item->details.tier, i);
  7754. }
  7755. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7756. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7757. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7758. item_difficulty = ARROW_COLOR_WHITE;
  7759. item_difficulty -= 6;
  7760. if (item_difficulty < 0)
  7761. item_difficulty *= -1;
  7762. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7763. if (item->details.count == 1)
  7764. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7765. else
  7766. packet->setArrayDataByName("quantity", item->details.count, i);
  7767. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7768. if (GetVersion() <= 1096)
  7769. packet->setArrayDataByName("description", item->description.c_str(), i);
  7770. }
  7771. if (GetVersion() <= 546) {
  7772. packet->setDataByName("type", 112);
  7773. }
  7774. else {
  7775. packet->setDataByName("type", 96);
  7776. }
  7777. EQ2Packet* outapp = packet->serialize();
  7778. //DumpPacket(outapp);
  7779. QueuePacket(outapp);
  7780. /*if (GetVersion() <= 546) {
  7781. packet->setDataByName("type", 16);
  7782. EQ2Packet* outapp2 = packet->serialize();
  7783. QueuePacket(outapp2);
  7784. }*/
  7785. safe_delete(packet);
  7786. }
  7787. safe_delete(repairable_items);
  7788. }
  7789. }
  7790. void Client::ShowLottoWindow() {
  7791. Spawn* spawn = GetMerchantTransaction();
  7792. if (spawn) {
  7793. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  7794. if (!item_id)
  7795. {
  7796. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  7797. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  7798. return;
  7799. }
  7800. else if (item_id == 0)
  7801. {
  7802. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  7803. return;
  7804. }
  7805. Item* item = master_item_list.GetItem(item_id);
  7806. if (!item) {
  7807. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  7808. return;
  7809. }
  7810. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  7811. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7812. if (packet) {
  7813. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7814. packet->setArrayLengthByName("num_items", 1);
  7815. packet->setArrayDataByName("item_name", item->name.c_str());
  7816. packet->setArrayDataByName("price", item->sell_price);
  7817. packet->setArrayDataByName("item_id", item->details.item_id);
  7818. packet->setArrayDataByName("stack_size", item->details.count);
  7819. packet->setArrayDataByName("icon", item->details.icon);
  7820. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  7821. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7822. packet->setArrayDataByName("tier", item->details.tier);
  7823. }
  7824. packet->setArrayDataByName("item_id2", item->details.item_id);
  7825. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7826. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7827. item_difficulty = ARROW_COLOR_WHITE;
  7828. item_difficulty -= 6;
  7829. if (item_difficulty < 0)
  7830. item_difficulty *= -1;
  7831. packet->setArrayDataByName("item_difficulty", item_difficulty);
  7832. //if(item->details.count == 1)
  7833. packet->setArrayDataByName("quantity", 0xFFFF);
  7834. //else
  7835. // packet->setArrayDataByName("quantity", item->details.count);
  7836. packet->setArrayDataByName("stack_size2", item->details.count);
  7837. packet->setArrayDataByName("description", item->description.c_str());
  7838. if (GetVersion() <= 546) {
  7839. packet->setDataByName("type", 128);
  7840. }
  7841. else {
  7842. packet->setDataByName("type", 0x00000102);
  7843. }
  7844. QueuePacket(packet->serialize());
  7845. safe_delete(packet);
  7846. }
  7847. }
  7848. }
  7849. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  7850. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  7851. if (packet) {
  7852. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  7853. int32 rolls[6] = { 0 };
  7854. int32 lottery_digits[6] = { 0 };
  7855. int8 num_matches = 0;
  7856. int64 jackpot = 0;
  7857. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  7858. if (!item) {
  7859. return;
  7860. }
  7861. database.DeleteItem(GetCharacterID(), item, 0);
  7862. GetPlayer()->item_list.RemoveItem(item, true);
  7863. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  7864. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  7865. if (!winning_numbers) {
  7866. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  7867. variables.AddVariable(winning_numbers);
  7868. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7869. }
  7870. if (strlen(winning_numbers->GetValue()) != 12) {
  7871. winning_numbers->SetValue("231205182236");
  7872. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7873. }
  7874. try {
  7875. for (int32 i = 0; i < 12; i += 2) {
  7876. char num[4];
  7877. strncpy(num, winning_numbers->GetValue() + i, 2);
  7878. lottery_digits[i / 2] = atoi(num);
  7879. }
  7880. }
  7881. catch (...) {
  7882. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  7883. return;
  7884. }
  7885. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  7886. if (!jackpot_var) {
  7887. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  7888. variables.AddVariable(jackpot_var);
  7889. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7890. }
  7891. try {
  7892. jackpot = atoul(jackpot_var->GetValue());
  7893. if (jackpot < 10000)
  7894. jackpot = 10000;
  7895. }
  7896. catch (...) {
  7897. jackpot = 10000;
  7898. }
  7899. char new_jackpot[128] = { 0 };
  7900. sprintf(new_jackpot, "%llu", jackpot + price);
  7901. jackpot_var->SetValue(new_jackpot);
  7902. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7903. world.PickRandomLottoDigits(rolls);
  7904. packet->setDataByName("roll_digit1", rolls[0]);
  7905. packet->setDataByName("roll_digit2", rolls[1]);
  7906. packet->setDataByName("roll_digit3", rolls[2]);
  7907. packet->setDataByName("roll_digit4", rolls[3]);
  7908. packet->setDataByName("roll_digit5", rolls[4]);
  7909. packet->setDataByName("roll_digit6", rolls[5]);
  7910. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  7911. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  7912. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  7913. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  7914. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  7915. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  7916. QueuePacket(packet->serialize());
  7917. safe_delete(packet);
  7918. for (int32 i = 0; i < 6; i++) {
  7919. for (int32 j = 0; j < 6; j++) {
  7920. if (rolls[i] == lottery_digits[j]) {
  7921. num_matches++;
  7922. break;
  7923. }
  7924. }
  7925. }
  7926. char new_jackpot_str[16];
  7927. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  7928. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  7929. if (num_matches == 6) {
  7930. world.PickRandomLottoDigits(lottery_digits);
  7931. for (int32 i = 0; i < 12; i += 2)
  7932. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  7933. winning_numbers->SetValue(new_jackpot_str);
  7934. jackpot_var->SetValue("10000");
  7935. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7936. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7937. }
  7938. }
  7939. }
  7940. void Client::SendGuildCreateWindow() {
  7941. if (GetVersion() <= 546) {
  7942. SimpleMessage(0, "Not implemented on this client...yet?");
  7943. }
  7944. else {
  7945. Spawn* spawn = GetPlayer()->GetTarget();
  7946. if (spawn) {
  7947. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7948. if (packet) {
  7949. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7950. packet->setArrayLengthByName("num_items", 0);
  7951. packet->setDataByName("type", 0x00008000);
  7952. QueuePacket(packet->serialize());
  7953. safe_delete(packet);
  7954. }
  7955. }
  7956. }
  7957. }
  7958. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  7959. BuyBackItem* item = new BuyBackItem;
  7960. item->item_id = item_id;
  7961. item->unique_id = unique_id;
  7962. item->price = price;
  7963. item->quantity = quantity;
  7964. item->save_needed = save_needed;
  7965. MBuyBack.writelock(__FUNCTION__, __LINE__);
  7966. buy_back_items.push_back(item);
  7967. if (buy_back_items.size() > 10) {
  7968. safe_delete(buy_back_items.front());
  7969. buy_back_items.pop_front();
  7970. }
  7971. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  7972. }
  7973. deque<BuyBackItem*>* Client::GetBuyBacks() {
  7974. return &buy_back_items;
  7975. }
  7976. vector<Item*>* Client::GetRepairableItems() {
  7977. vector<Item*>* repairable_items = new vector<Item*>;
  7978. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  7979. map<int32, Item*>* items = player->GetItemList();
  7980. if (equipped_items && equipped_items->size() > 0) {
  7981. for (int32 i = 0; i < equipped_items->size(); i++) {
  7982. Item* item = equipped_items->at(i);
  7983. if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
  7984. repairable_items->push_back(item);
  7985. }
  7986. }
  7987. if (items && items->size() > 0) {
  7988. map<int32, Item*>::iterator itr;
  7989. for (itr = items->begin(); itr != items->end(); itr++) {
  7990. Item* item = itr->second;
  7991. if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
  7992. repairable_items->push_back(item);
  7993. }
  7994. }
  7995. safe_delete(equipped_items);
  7996. safe_delete(items);
  7997. return repairable_items;
  7998. }
  7999. vector<Item*>* Client::GetItemsByEffectType(ItemEffectType type, ItemEffectType type2) {
  8000. if(type == NO_EFFECT_TYPE)
  8001. return nullptr;
  8002. vector<Item*>* return_items = new vector<Item*>;
  8003. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  8004. map<int32, Item*>* items = player->GetItemList();
  8005. if (equipped_items && equipped_items->size() > 0) {
  8006. for (int32 i = 0; i < equipped_items->size(); i++) {
  8007. Item* item = equipped_items->at(i);
  8008. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  8009. return_items->push_back(item);
  8010. }
  8011. }
  8012. if (items && items->size() > 0) {
  8013. map<int32, Item*>::iterator itr;
  8014. for (itr = items->begin(); itr != items->end(); itr++) {
  8015. Item* item = itr->second;
  8016. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  8017. return_items->push_back(item);
  8018. }
  8019. }
  8020. safe_delete(equipped_items);
  8021. safe_delete(items);
  8022. return return_items;
  8023. }
  8024. void Client::SendMailList() {
  8025. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  8026. if (kiosk_id > 0) {
  8027. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  8028. if (p) {
  8029. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  8030. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  8031. int32 i = 0;
  8032. p->setDataByName("kiosk_id", kiosk_id);
  8033. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  8034. while (itr.Next()) {
  8035. Mail* mail = itr->second;
  8036. p->setArrayDataByName("mail_id", mail->mail_id, i);
  8037. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  8038. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  8039. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  8040. p->setArrayDataByName("already_read", mail->already_read, i);
  8041. if(mail->expire_time)
  8042. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  8043. else
  8044. p->setArrayDataByName("mail_deletion", 0, i);
  8045. p->setArrayDataByName("mail_type", mail->mail_type, i);
  8046. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  8047. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  8048. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  8049. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  8050. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  8051. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  8052. //p->setArrayDataByName("unknown2", 0, i);
  8053. bool successItemAdd = false;
  8054. if(mail->stack || mail->char_item_id)
  8055. {
  8056. Item* item = master_item_list.GetItem(mail->char_item_id);
  8057. if(item)
  8058. {
  8059. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  8060. if (version < 860)
  8061. p->setItemArrayDataByName("item", item, player, i, 0, -1);
  8062. else if (version < 1193)
  8063. p->setItemArrayDataByName("item", item, player, i);
  8064. else
  8065. p->setItemArrayDataByName("item", item, player, i, 0, 2);
  8066. successItemAdd = true;
  8067. }
  8068. }
  8069. if(!successItemAdd)
  8070. {
  8071. p->setArrayDataByName("end_tag2", GetItemPacketType(GetVersion()), i);
  8072. p->setArrayDataByName("end_tag3", 0xFF, i);
  8073. }
  8074. i++;
  8075. }
  8076. // GMs send mail for free!
  8077. if (GetAdminStatus() > 0)
  8078. {
  8079. p->setDataByName("postage_cost", 0);
  8080. p->setDataByName("attachment_cost", 0);
  8081. }
  8082. else
  8083. {
  8084. p->setDataByName("postage_cost", 10);
  8085. p->setDataByName("attachment_cost", 50);
  8086. }
  8087. p->setDataByName("unknown3", 0x01F4);
  8088. p->setDataByName("unknown4", 0x01000000);
  8089. EQ2Packet* pack = p->serialize();
  8090. //DumpPacket(pack);
  8091. QueuePacket(pack);
  8092. safe_delete(p);
  8093. }
  8094. }
  8095. else
  8096. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8097. }
  8098. void Client::DisplayMailMessage(int32 mail_id) {
  8099. Mail* mail = player->GetMail(mail_id);
  8100. if (mail) {
  8101. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  8102. if (kiosk_id > 0) {
  8103. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8104. if (update) {
  8105. update->setDataByName("action", 0x03);
  8106. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  8107. update->setDataByName("packetsubtype", 0xFF);
  8108. QueuePacket(update->serialize());
  8109. safe_delete(update);
  8110. }
  8111. if(!mail->already_read) {
  8112. mail->already_read = true;
  8113. SendMailList();
  8114. }
  8115. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  8116. if (packet) {
  8117. packet->setDataByName("kiosk_id", kiosk_id);
  8118. packet->setDataByName("mail_id", mail->mail_id);
  8119. packet->setDataByName("player_to_id", mail->player_to_id);
  8120. packet->setDataByName("player_from", mail->player_from.c_str());
  8121. packet->setDataByName("subject", mail->subject.c_str());
  8122. packet->setDataByName("mail_body", mail->mail_body.c_str());
  8123. packet->setDataByName("unknown1", 1);
  8124. packet->setDataByName("unknown2", 0);
  8125. packet->setDataByName("lock_report_button", 1);
  8126. packet->setDataByName("unknown3", 0xFFFFFFFF);
  8127. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  8128. packet->setDataByName("coin_copper", mail->coin_copper);
  8129. packet->setDataByName("coin_silver", mail->coin_silver);
  8130. packet->setDataByName("coin_gold", mail->coin_gold);
  8131. packet->setDataByName("coin_plat", mail->coin_plat);
  8132. if(mail->stack || mail->char_item_id)
  8133. {
  8134. Item* item = master_item_list.GetItem(mail->char_item_id);
  8135. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  8136. if (version < 860)
  8137. packet->setItemByName("item", item, player, 0, -1);
  8138. else if (version < 1193)
  8139. packet->setItemByName("item", item, player, 0, 0);
  8140. else
  8141. packet->setItemByName("item", item, player, 0, 2);
  8142. }
  8143. else
  8144. {
  8145. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8146. packet->setDataByName("end_tag3", 0xFF);
  8147. }
  8148. mail->save_needed = true;
  8149. EQ2Packet* pack = packet->serialize();
  8150. QueuePacket(pack);
  8151. safe_delete(packet);
  8152. // trying to update this causes the window not to open
  8153. //SendMailList();
  8154. }
  8155. }
  8156. else
  8157. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8158. }
  8159. }
  8160. /* This is called when the client sends a mail message. This determines whether or not the mail can be sent and must send the reply
  8161. packet back to the client before the mail actually sent. */
  8162. void Client::HandleSentMail(EQApplicationPacket* app) {
  8163. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  8164. if (packet) {
  8165. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  8166. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  8167. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  8168. vector<int32>* ids = 0;
  8169. MMailWindowMutex.lock();
  8170. if (reply_packet) {
  8171. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  8172. if (player_to.length() == 0)
  8173. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  8174. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  8175. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  8176. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  8177. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  8178. else {
  8179. if (GetAdminStatus() > 200 && player_to.compare("<all>") == 0) {
  8180. if (mail_window.char_item_id == 0 && (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat) == 0)
  8181. ids = database.GetAllPlayerIDs();
  8182. else
  8183. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  8184. }
  8185. else {
  8186. ids = new vector<int32>;
  8187. ids->push_back(database.GetCharacterID(player_to.c_str()));
  8188. }
  8189. if (ids) {
  8190. for (int32 i = 0; i < ids->size(); i++) {
  8191. int32 player_to_id = ids->at(i);
  8192. if (player_to_id > 0) {
  8193. reply_type = MAIL_SEND_RESULT_SUCCESS;
  8194. Mail* mail = new Mail;
  8195. mail->mail_id = 0;
  8196. mail->player_to_id = player_to_id;
  8197. mail->player_from = string(GetPlayer()->GetName());
  8198. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  8199. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  8200. mail->already_read = 0;
  8201. mail->mail_type = MAIL_TYPE_REGULAR;
  8202. mail->coin_copper = mail_window.coin_copper;
  8203. mail->coin_silver = mail_window.coin_silver;
  8204. mail->coin_gold = mail_window.coin_gold;
  8205. mail->coin_plat = mail_window.coin_plat;
  8206. mail->char_item_id = mail_window.char_item_id;
  8207. mail->stack = mail_window.stack;
  8208. // GM's send mail for free!
  8209. if (GetAdminStatus() > 0)
  8210. {
  8211. mail->postage_cost = 0;
  8212. mail->attachment_cost = 0;
  8213. }
  8214. else
  8215. {
  8216. mail->postage_cost = 10;
  8217. mail->attachment_cost = 50;
  8218. }
  8219. mail->time_sent = Timer::GetUnixTimeStamp();
  8220. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  8221. mail->save_needed = false;
  8222. database.SavePlayerMail(mail);
  8223. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  8224. if (to_client) {
  8225. to_client->GetPlayer()->AddMail(mail);
  8226. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You have unread mail in your mailbox.");
  8227. string popup_text = "You have unread mail!";
  8228. to_client->SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  8229. }
  8230. else {
  8231. // don't need the pointer the client doesn't exist currently
  8232. safe_delete(mail);
  8233. }
  8234. ResetSendMail(false, false);
  8235. }
  8236. else
  8237. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  8238. }
  8239. }
  8240. }
  8241. string players_to = "";
  8242. if (ids) {
  8243. for (int32 i = 0; i < ids->size(); i++) {
  8244. if (ids->at(i) != 0)
  8245. players_to.append(database.GetCharacterName(ids->at(i)));
  8246. if (i < (ids->size() - 1))
  8247. players_to.append(", ");
  8248. }
  8249. }
  8250. reply_packet->setDataByName("player_to", players_to.c_str());
  8251. reply_packet->setDataByName("reply_type", reply_type);
  8252. QueuePacket(reply_packet->serialize());
  8253. safe_delete(reply_packet);
  8254. safe_delete(ids);
  8255. }
  8256. MMailWindowMutex.unlock();
  8257. }
  8258. safe_delete(packet);
  8259. }
  8260. }
  8261. void Client::DeleteMail(int32 mail_id, bool from_database) {
  8262. player->DeleteMail(mail_id, from_database);
  8263. }
  8264. bool Client::AddMailItem(Item* item)
  8265. {
  8266. if(item && (item->CheckFlag(LORE) || item->CheckFlag(STACK_LORE))) {
  8267. Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "Lore items cannot be mailed.");
  8268. return false;
  8269. }
  8270. bool ret = false;
  8271. if (GetMailTransaction()) {
  8272. MMailWindowMutex.lock();
  8273. if(mail_window.char_item_id == 0)
  8274. {
  8275. mail_window.item = item;
  8276. mail_window.char_item_id = item->details.item_id;
  8277. mail_window.stack = item->details.count;
  8278. ret = true;
  8279. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8280. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8281. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8282. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8283. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8284. if(item)
  8285. {
  8286. packet->setDataByName("stack", mail_window.stack);
  8287. item->stack_count = mail_window.stack;
  8288. if (version < 860)
  8289. packet->setItemByName("item", item, player, 0, -1);
  8290. else if (version < 1193)
  8291. packet->setItemByName("item", item, player, 0, 0);
  8292. else
  8293. packet->setItemByName("item", item, player, 0, 2);
  8294. }
  8295. else
  8296. {
  8297. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8298. packet->setDataByName("end_tag3", 0xFF);
  8299. }
  8300. QueuePacket(packet->serialize());
  8301. }
  8302. MMailWindowMutex.unlock();
  8303. }
  8304. return ret;
  8305. }
  8306. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  8307. bool ret = false;
  8308. if (GetMailTransaction()) {
  8309. MMailWindowMutex.lock();
  8310. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8311. if (packet) {
  8312. if (copper > 0) {
  8313. if (player->RemoveCoins(copper)) {
  8314. mail_window.coin_copper += copper;
  8315. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  8316. ret = true;
  8317. }
  8318. }
  8319. else if (silver > 0) {
  8320. if (player->RemoveCoins(silver * 100)) {
  8321. mail_window.coin_silver += silver;
  8322. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  8323. ret = true;
  8324. }
  8325. }
  8326. else if (gold > 0) {
  8327. if (player->RemoveCoins(gold * 10000)) {
  8328. mail_window.coin_gold += gold;
  8329. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  8330. ret = true;
  8331. }
  8332. }
  8333. else if (plat > 0) {
  8334. if (player->RemoveCoins(plat * 1000000)) {
  8335. mail_window.coin_plat += plat;
  8336. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  8337. ret = true;
  8338. }
  8339. }
  8340. if (ret) {
  8341. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8342. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8343. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8344. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8345. Item* item = master_item_list.GetItem(mail_window.char_item_id);
  8346. if(item)
  8347. {
  8348. packet->setDataByName("stack", mail_window.stack);
  8349. item->stack_count = mail_window.stack;
  8350. if (version < 860)
  8351. packet->setItemByName("item", item, player, 0, -1);
  8352. else if (version < 1193)
  8353. packet->setItemByName("item", item, player, 0, 0);
  8354. else
  8355. packet->setItemByName("item", item, player, 0, 2);
  8356. }
  8357. else
  8358. {
  8359. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8360. packet->setDataByName("end_tag3", 0xFF);
  8361. }
  8362. //packet->PrintPacket();
  8363. QueuePacket(packet->serialize());
  8364. }
  8365. else
  8366. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  8367. safe_delete(packet);
  8368. }
  8369. MMailWindowMutex.unlock();
  8370. }
  8371. else
  8372. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8373. return ret;
  8374. }
  8375. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  8376. bool ret = false;
  8377. if (GetMailTransaction()) {
  8378. MMailWindowMutex.lock();
  8379. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8380. if (packet) {
  8381. if (copper > 0) {
  8382. player->AddCoins(copper);
  8383. mail_window.coin_copper -= copper;
  8384. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  8385. ret = true;
  8386. }
  8387. else if (silver > 0) {
  8388. player->AddCoins(silver * 100);
  8389. mail_window.coin_silver -= silver;
  8390. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  8391. ret = true;
  8392. }
  8393. else if (gold > 0) {
  8394. player->AddCoins(gold * 10000);
  8395. mail_window.coin_gold -= gold;
  8396. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  8397. ret = true;
  8398. }
  8399. else if (plat > 0) {
  8400. player->AddCoins(plat * 1000000);
  8401. mail_window.coin_plat -= plat;
  8402. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  8403. ret = true;
  8404. }
  8405. if (ret) {
  8406. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8407. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8408. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8409. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8410. packet->setDataByName("stack", 0);
  8411. packet->setDataByName("packettype", 0x2BFE);
  8412. packet->setDataByName("packetsubtype", 0xFF);
  8413. packet->setDataByName("unknown2", 0);
  8414. QueuePacket(packet->serialize());
  8415. }
  8416. safe_delete(packet);
  8417. }
  8418. MMailWindowMutex.unlock();
  8419. }
  8420. else
  8421. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8422. return ret;
  8423. }
  8424. void Client::TakeMailAttachments(int32 mail_id) {
  8425. if (GetMailTransaction()) {
  8426. Mail* mail = player->GetMail(mail_id);
  8427. if (mail) {
  8428. int64 amount = 0;
  8429. if (mail->coin_copper > 0) {
  8430. amount += mail->coin_copper;
  8431. mail->coin_copper = 0;
  8432. }
  8433. if (mail->coin_silver > 0) {
  8434. amount += mail->coin_silver * 100;
  8435. mail->coin_silver = 0;
  8436. }
  8437. if (mail->coin_gold > 0) {
  8438. amount += mail->coin_gold * 10000;
  8439. mail->coin_gold = 0;
  8440. }
  8441. if (mail->coin_plat > 0) {
  8442. amount += mail->coin_plat * 1000000;
  8443. mail->coin_plat = 0;
  8444. }
  8445. if (mail->char_item_id > 0) {
  8446. AddItem(mail->char_item_id, mail->stack);
  8447. mail->char_item_id = 0;
  8448. mail->stack = 0;
  8449. }
  8450. /* Can't find the right packet to send to update the player's mail. This packet below updates the mail the player is sending, not
  8451. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  8452. find it in any packet logs.*/
  8453. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8454. if (packet) {
  8455. packet->setDataByName("unknown", 0x03);
  8456. packet->setDataByName("coin_copper", mail->coin_copper);
  8457. packet->setDataByName("coin_silver", mail->coin_silver);
  8458. packet->setDataByName("coin_gold", mail->coin_gold);
  8459. packet->setDataByName("coin_plat", mail->coin_plat);
  8460. packet->setDataByName("stack", 0);
  8461. packet->setDataByName("packettype", 0x2BFE);
  8462. packet->setDataByName("packetsubtype", 0xFF);
  8463. packet->setDataByName("unknown2", 0);
  8464. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  8465. DumpPacket(packet->serialize());
  8466. QueuePacket(packet->serialize());
  8467. safe_delete(packet);
  8468. }*/
  8469. database.SavePlayerMail(mail);
  8470. if (amount > 0)
  8471. player->AddCoins(amount);
  8472. SendMailList();
  8473. }
  8474. }
  8475. else
  8476. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8477. }
  8478. void Client::ResetSendMail(bool cancel, bool needslock) {
  8479. if(cancel && mail_transaction)
  8480. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  8481. if(needslock)
  8482. MMailWindowMutex.lock();
  8483. if(cancel)
  8484. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  8485. if(!cancel)
  8486. mail_transaction = 0;
  8487. mail_window.coin_copper = 0;
  8488. mail_window.coin_silver = 0;
  8489. mail_window.coin_gold = 0;
  8490. mail_window.coin_plat = 0;
  8491. mail_window.char_item_id = 0;
  8492. mail_window.stack = 0;
  8493. if(mail_window.item){
  8494. if(cancel)
  8495. AddItem(mail_window.item);
  8496. else
  8497. safe_delete(mail_window.item);
  8498. }
  8499. mail_window.item = nullptr;
  8500. if(needslock)
  8501. MMailWindowMutex.unlock();
  8502. }
  8503. bool Client::GateAllowed() {
  8504. ZoneServer* zone = GetCurrentZone();
  8505. if (zone){
  8506. bool cangate = zone->GetCanGate();
  8507. return cangate;
  8508. }
  8509. return false;
  8510. }
  8511. bool Client::BindAllowed() {
  8512. ZoneServer* zone = GetCurrentZone();
  8513. if (zone){
  8514. bool canbind = zone->GetCanBind();
  8515. return canbind;
  8516. }
  8517. return false;
  8518. }
  8519. bool Client::Bind() {
  8520. int canbind = BindAllowed();
  8521. if(canbind == 0) {
  8522. Message(CHANNEL_MERCHANT, "You cannot bind at this location.");
  8523. return false;
  8524. }
  8525. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  8526. player->GetPlayerInfo()->SetBindX(player->GetX());
  8527. player->GetPlayerInfo()->SetBindY(player->GetY());
  8528. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  8529. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  8530. Message(CHANNEL_MERCHANT, "Your spirit has been bound to this location.");
  8531. return true;
  8532. }
  8533. bool Client::Gate(bool is_spell) {
  8534. if (player->GetPlayerInfo()->GetBindZoneID() == 0) {
  8535. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells. You have no bind location set.");
  8536. return false;
  8537. }
  8538. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  8539. if (zone) {
  8540. int cangate = GateAllowed();
  8541. if(cangate == 0) {
  8542. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells in this zone.");
  8543. return false;
  8544. }
  8545. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  8546. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  8547. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  8548. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  8549. Zone(zone, false, is_spell);
  8550. return true;
  8551. }
  8552. return false;
  8553. }
  8554. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id, bool is_spell) {
  8555. if (!destinations || !spawn) {
  8556. return;
  8557. }
  8558. bool has_map = false;
  8559. if (transport_id > 0)
  8560. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  8561. transport_spawn = spawn;
  8562. vector<TransportDestination*> transport_list;
  8563. vector<TransportDestination*>::iterator itr;
  8564. TransportDestination* destination = 0;
  8565. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  8566. destination = *itr;
  8567. if (has_map || (destination->type == TRANSPORT_TYPE_ZONE && ((destination->destination_zone_id != GetCurrentZone()->GetZoneID()) || GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) > 100)))
  8568. transport_list.push_back(destination);
  8569. }
  8570. if (transport_list.size() == 0 && destination) {
  8571. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  8572. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  8573. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  8574. else
  8575. {
  8576. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  8577. if (app)
  8578. QueuePacket(app);
  8579. }
  8580. }
  8581. else {
  8582. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  8583. // determine if this is an instanced zone that already exists
  8584. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  8585. if (instance_zone || new_zone) {
  8586. GetPlayer()->SetX(destination->destination_x);
  8587. GetPlayer()->SetY(destination->destination_y);
  8588. GetPlayer()->SetZ(destination->destination_z);
  8589. GetPlayer()->SetHeading(destination->destination_heading);
  8590. if (instance_zone)
  8591. Zone(instance_zone->GetInstanceID(), false, true, is_spell);
  8592. else
  8593. Zone(new_zone, false, is_spell);
  8594. }
  8595. }
  8596. if (destination->message.length() > 0)
  8597. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  8598. }
  8599. else if (transport_list.size() > 0) {
  8600. if (!spawn->IsSoundsDisabled())
  8601. PlaySound("mariner_bell");
  8602. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  8603. if (packet) {
  8604. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  8605. // Put all the destinations the player can go in a new vector
  8606. vector<TransportDestination*> destinations;
  8607. for (int32 i = 0; i < transport_list.size(); i++) {
  8608. destination = transport_list.at(i);
  8609. // Check min level
  8610. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  8611. continue;
  8612. // Check max level
  8613. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  8614. continue;
  8615. // Check quest complete
  8616. if (destination->req_quest_complete > 0 && GetPlayer()->HasQuestBeenCompleted(destination->req_quest_complete) == 0)
  8617. continue;
  8618. // Check req quest and step
  8619. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  8620. continue;
  8621. // If we have a map and our current location is the same as the detination and player is within 20 units from the transport set the "current" elements but don't addt to the destination list
  8622. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  8623. packet->setDataByName("current_zone", destination->display_name.c_str());
  8624. packet->setDataByName("current_map_x", destination->map_x);
  8625. packet->setDataByName("current_map_y", destination->map_y);
  8626. }
  8627. else {
  8628. destinations.push_back(destination);
  8629. }
  8630. }
  8631. // Use the new vector to create the packet
  8632. destination = 0;
  8633. packet->setArrayLengthByName("num_destinations", destinations.size());
  8634. for (int32 i = 0; i < destinations.size(); i++) {
  8635. destination = destinations.at(i);
  8636. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  8637. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  8638. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  8639. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  8640. packet->setArrayDataByName("cost", destination->cost, i);
  8641. if (has_map) {
  8642. packet->setArrayDataByName("map_x", destination->map_x, i);
  8643. packet->setArrayDataByName("map_y", destination->map_y, i);
  8644. }
  8645. }
  8646. if (has_map)
  8647. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  8648. EQ2Packet* app = packet->serialize();
  8649. //DumpPacket(app);
  8650. if (destinations.size() > 0)
  8651. QueuePacket(app);
  8652. safe_delete(packet);
  8653. }
  8654. }
  8655. }
  8656. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  8657. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  8658. if (packet) {
  8659. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  8660. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  8661. int32 unique_id = packet->getType_int32_ByName("unique_id");
  8662. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  8663. int32 cost = packet->getType_int32_ByName("cost");
  8664. vector<TransportDestination*> destinations;
  8665. TransportDestination* destination = 0;
  8666. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  8667. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  8668. vector<TransportDestination*>::iterator itr;
  8669. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  8670. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  8671. destination = *itr;
  8672. break;
  8673. }
  8674. }
  8675. SetTemporaryTransportID(0);
  8676. if (!destination)
  8677. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  8678. else {
  8679. if (cost == 0 || player->RemoveCoins(cost)) {
  8680. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  8681. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  8682. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  8683. else
  8684. {
  8685. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  8686. if (outapp)
  8687. QueuePacket(outapp);
  8688. }
  8689. }
  8690. else {
  8691. GetPlayer()->SetX(destination->destination_x);
  8692. GetPlayer()->SetY(destination->destination_y);
  8693. GetPlayer()->SetZ(destination->destination_z);
  8694. GetPlayer()->SetHeading(destination->destination_heading);
  8695. // Test if where we're going is an Instanced zone
  8696. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  8697. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  8698. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  8699. Zone(new_zone, false);
  8700. }
  8701. }
  8702. if (destination->message.length() > 0)
  8703. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  8704. }
  8705. else
  8706. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  8707. }
  8708. }
  8709. safe_delete(packet);
  8710. }
  8711. }
  8712. void Client::SendNewSpells(int8 class_id) {
  8713. if (class_id > 0) {
  8714. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  8715. AddSendNewSpells(spells);
  8716. safe_delete(spells);
  8717. }
  8718. }
  8719. void Client::SendNewTSSpells(int8 class_id) {
  8720. if (class_id > 0) {
  8721. vector<Spell*>* spells = master_spell_list.GetSpellListByTradeskillClass(class_id, player->GetLevel(), 1);
  8722. AddSendNewSpells(spells);
  8723. safe_delete(spells);
  8724. }
  8725. }
  8726. void Client::AddSendNewSpells(vector<Spell*>* spells) {
  8727. Spell* spell = 0;
  8728. bool send_updates = false;
  8729. vector<Spell*>::iterator itr;
  8730. for (itr = spells->begin(); itr != spells->end(); itr++) {
  8731. spell = *itr;
  8732. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  8733. send_updates = true;
  8734. SendSpellUpdate(spell);
  8735. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  8736. player->UnlockSpell(spell);
  8737. }
  8738. }
  8739. if (send_updates) {
  8740. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  8741. if (outapp)
  8742. QueuePacket(outapp);
  8743. }
  8744. }
  8745. void Client::SetItemSearch(vector<Item*>* items) {
  8746. if (items) {
  8747. safe_delete(search_items);
  8748. search_items = items;
  8749. }
  8750. }
  8751. vector<Item*>* Client::GetSearchItems() {
  8752. return search_items;
  8753. }
  8754. void Client::SearchStore(int32 page) {
  8755. if (search_items) {
  8756. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  8757. if (packet) {
  8758. int32 x = page * 8;
  8759. if (search_items->size() > 8) {
  8760. if ((search_items->size() - x) > 8)
  8761. packet->setArrayLengthByName("num_items", 8);
  8762. else
  8763. packet->setArrayLengthByName("num_items", search_items->size() - x);
  8764. }
  8765. else
  8766. packet->setArrayLengthByName("num_items", search_items->size());
  8767. if (search_items->size() > 0) {
  8768. packet->setArrayLengthByName("num_sellers", 1);
  8769. packet->setArrayDataByName("seller_seller_id", 1);
  8770. packet->setDataByName("per_page", 8);
  8771. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  8772. packet->setDataByName("page", page);
  8773. Item* item = 0;
  8774. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  8775. for (int32 i = 0; i < limit; i++, x++) {
  8776. if (x >= search_items->size())
  8777. break;
  8778. item = search_items->at(x);
  8779. std::string teststr("test ");
  8780. teststr.append(std::to_string(i));
  8781. packet->setArrayDataByName("string_one", teststr.c_str(), i);
  8782. packet->setArrayDataByName("string_two", "testtwo", i);
  8783. packet->setArrayDataByName("seller_name", "EQ2EMuDev", i);
  8784. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8785. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  8786. packet->setArrayDataByName("icon", item->details.icon, i);
  8787. //packet->setArrayDataByName("unknown2b", i, i);
  8788. packet->setArrayDataByName("item_seller_id", 1, i);
  8789. if (item->stack_count == 0)
  8790. packet->setArrayDataByName("quantity", 1, i);
  8791. else
  8792. packet->setArrayDataByName("quantity", item->stack_count, i);
  8793. packet->setArrayDataByName("stack_size", item->stack_count, i);
  8794. packet->setArrayDataByName("sell_price", item->sell_price, i);
  8795. std::string tmpStr("");
  8796. tmpStr.append(item->name.c_str());
  8797. tmpStr.append(" (");
  8798. tmpStr.append(std::to_string(item->details.item_id));
  8799. tmpStr.append(")");
  8800. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  8801. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  8802. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  8803. }
  8804. }
  8805. EQ2Packet* outapp = packet->serialize();
  8806. DumpPacket(outapp);
  8807. QueuePacket(outapp);
  8808. safe_delete(packet);
  8809. }
  8810. }
  8811. }
  8812. void Client::SetReadyForUpdates() {
  8813. if (!ready_for_updates) {
  8814. database.loadCharacterProperties(this);
  8815. SendDefaultGroupOptions();
  8816. }
  8817. ready_for_updates = true;
  8818. if(GetVersion() <= 546) {
  8819. SendRecipeList();
  8820. }
  8821. }
  8822. void Client::SetReadyForSpawns(bool val) {
  8823. ready_for_spawns = val;
  8824. if (GetPlayer()->GetActivityStatus() > 0) {
  8825. GetPlayer()->SetActivityStatus(0);
  8826. if (GetPlayer()->GetGroupMemberInfo()) {
  8827. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  8828. }
  8829. }
  8830. GetPlayer()->SetActiveReward(false);
  8831. zone_list.CheckFriendZoned(this);
  8832. }
  8833. void Client::SendChatRelationship(int8 type, const char* name) {
  8834. if (!name) {
  8835. return;
  8836. }
  8837. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8838. if (packet) {
  8839. packet->setDataByName("account_id", GetAccountID());
  8840. packet->setDataByName("type", type);
  8841. packet->setArrayLengthByName("num_names", 1);
  8842. packet->setArrayDataByName("name", name);
  8843. if (type == 0) {
  8844. Client* client = zone_list.GetClientByCharName(name);
  8845. if (client) {
  8846. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  8847. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  8848. }
  8849. }
  8850. QueuePacket(packet->serialize());
  8851. safe_delete(packet);
  8852. }
  8853. }
  8854. void Client::SendFriendList() {
  8855. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8856. if (packet) {
  8857. packet->setDataByName("account_id", GetAccountID());
  8858. map<string, int8>::iterator itr;
  8859. map<string, int8>* friends = player->GetFriends();
  8860. if (friends && friends->size() > 0) {
  8861. Client* client = 0;
  8862. vector<string> names;
  8863. for (itr = friends->begin(); itr != friends->end(); itr++) {
  8864. if (itr->second == 2)
  8865. continue;
  8866. names.push_back(itr->first);
  8867. }
  8868. packet->setArrayLengthByName("num_names", names.size());
  8869. for (int32 i = 0; i < names.size(); i++) {
  8870. client = zone_list.GetClientByCharName(names[i]);
  8871. packet->setArrayDataByName("name", names[i].c_str(), i);
  8872. if (client) {
  8873. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  8874. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  8875. }
  8876. }
  8877. }
  8878. QueuePacket(packet->serialize());
  8879. safe_delete(packet);
  8880. }
  8881. }
  8882. void Client::SendIgnoreList() {
  8883. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8884. if (packet) {
  8885. packet->setDataByName("account_id", GetAccountID());
  8886. packet->setDataByName("type", 2);
  8887. map<string, int8>::iterator itr;
  8888. map<string, int8>* ignored = player->GetIgnoredPlayers();
  8889. if (ignored && ignored->size() > 0) {
  8890. vector<string> names;
  8891. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  8892. if (itr->second == 2)
  8893. continue;
  8894. names.push_back(itr->first);
  8895. }
  8896. packet->setArrayLengthByName("num_names", names.size());
  8897. for (int32 i = 0; i < names.size(); i++)
  8898. packet->setArrayDataByName("name", names[i].c_str(), i);
  8899. }
  8900. QueuePacket(packet->serialize());
  8901. safe_delete(packet);
  8902. }
  8903. }
  8904. void Client::AddWaypoint(string name, int8 type) {
  8905. waypoint_id++;
  8906. WaypointInfo info;
  8907. info.id = waypoint_id;
  8908. info.type = type;
  8909. waypoints[name] = info;
  8910. }
  8911. void Client::SendWaypoints() {
  8912. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  8913. if (packet) {
  8914. packet->setArrayLengthByName("num_updates", waypoints.size());
  8915. map<string, WaypointInfo>::iterator itr;
  8916. int16 i = 0;
  8917. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  8918. packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
  8919. packet->setArrayDataByName("waypoint_category", itr->second.type, i);
  8920. packet->setArrayDataByName("spawn_id", itr->second.id, i);
  8921. i++;
  8922. }
  8923. packet->setDataByName("unknown", 0xFFFFFFFF);
  8924. QueuePacket(packet->serialize());
  8925. safe_delete(packet);
  8926. }
  8927. }
  8928. void Client::SelectWaypoint(int32 id) {
  8929. string found_name = "";
  8930. map<string, WaypointInfo>::iterator itr;
  8931. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  8932. if (itr->second.id == id) {
  8933. found_name = itr->first;
  8934. break;
  8935. }
  8936. }
  8937. if (found_name.length() > 0) {
  8938. Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
  8939. ShowPathToTarget(spawn);
  8940. }
  8941. }
  8942. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  8943. if (waypoint_name) {
  8944. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  8945. if (packet) {
  8946. packet->setArrayLengthByName("num_updates", 1);
  8947. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  8948. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  8949. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  8950. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  8951. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  8952. packet->setDataByName("unknown", 0xFFFFFFFF);
  8953. QueuePacket(packet->serialize());
  8954. safe_delete(packet);
  8955. }
  8956. }
  8957. }
  8958. void Client::ClearWaypoint() {
  8959. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8960. if (packet) {
  8961. QueuePacket(packet->serialize());
  8962. safe_delete(packet);
  8963. }
  8964. }
  8965. bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
  8966. if (current_zone->pathing) {
  8967. if (GetPlayer()->GetMap()) {
  8968. if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
  8969. return false;
  8970. if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
  8971. return false;
  8972. auto loc = glm::vec3(x, z, y);
  8973. float new_z = GetPlayer()->FindBestZ(loc, nullptr);
  8974. if (new_z != BEST_Z_INVALID) //this is actually y
  8975. y = new_z;
  8976. }
  8977. bool partial = false;
  8978. bool stuck = false;
  8979. PathfinderOptions opts;
  8980. opts.smooth_path = true;
  8981. opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
  8982. opts.offset = y_offset + 1.0f;
  8983. opts.flags = PathingNotDisabled ^ PathingZoneLine;
  8984. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8985. if (packet) {
  8986. auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
  8987. packet->setArrayLengthByName("num_points", path.size());
  8988. int i = 0;
  8989. for (auto& node : path)
  8990. {
  8991. packet->setArrayDataByName("x", node.pos.x, i);
  8992. packet->setArrayDataByName("y", node.pos.z, i);
  8993. packet->setArrayDataByName("z", node.pos.y, i);
  8994. packet->setDataByName("waypoint_x", x);
  8995. packet->setDataByName("waypoint_y", y);
  8996. packet->setDataByName("waypoint_z", z);
  8997. i++;
  8998. }
  8999. if (i > 0)
  9000. QueuePacket(packet->serialize());
  9001. safe_delete(packet);
  9002. return (i > 0);
  9003. }
  9004. }
  9005. return false;
  9006. }
  9007. bool Client::ShowPathToTarget(Spawn* spawn) {
  9008. if (spawn) {
  9009. return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
  9010. }
  9011. return false;
  9012. }
  9013. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  9014. if (waypoint_name) {
  9015. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  9016. if (packet) {
  9017. packet->setArrayLengthByName("num_points", 1);
  9018. packet->setArrayDataByName("x", x, 0);
  9019. packet->setArrayDataByName("y", y, 0);
  9020. packet->setArrayDataByName("z", z, 0);
  9021. packet->setDataByName("waypoint_x", x);
  9022. packet->setDataByName("waypoint_y", y);
  9023. packet->setDataByName("waypoint_z", z);
  9024. packet->setDataByName("waypoint_name", waypoint_name);
  9025. packet->setDataByName("unknown", 0);
  9026. QueuePacket(packet->serialize());
  9027. safe_delete(packet);
  9028. }
  9029. }
  9030. }
  9031. void Client::InspectPlayer(Player* player_to_inspect) {
  9032. int source_pvp_alignment = GetPlayer()->GetPVPAlignment();
  9033. int target_pvp_alignment = player_to_inspect->GetPVPAlignment();
  9034. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  9035. if(pvp_allowed == true){
  9036. if(source_pvp_alignment != target_pvp_alignment){
  9037. Message(CHANNEL_COLOR_RED, "You can not inspect players of different alignments.");
  9038. return;
  9039. }
  9040. }
  9041. if (player_to_inspect && player_to_inspect->GetClient()) {
  9042. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  9043. if (packet) {
  9044. packet->setDataByName("unknown", 0);
  9045. packet->setSmallStringByName("name", player_to_inspect->GetName());
  9046. packet->setDataByName("race", player_to_inspect->GetRace());
  9047. packet->setDataByName("gender", player_to_inspect->GetGender());
  9048. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  9049. int16 effective_level = player_to_inspect->GetInfoStruct()->get_effective_level() != 0 ? player_to_inspect->GetInfoStruct()->get_effective_level() : player_to_inspect->GetLevel();
  9050. packet->setDataByName("adventure_level_effective", effective_level);
  9051. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  9052. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  9053. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  9054. packet->setDataByName("health", player_to_inspect->GetHP());
  9055. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  9056. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  9057. packet->setDataByName("power", player_to_inspect->GetPower());
  9058. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  9059. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  9060. packet->setDataByName("mitigation", player_to_inspect->GetInfoStruct()->get_cur_mitigation());
  9061. packet->setDataByName("unknown1", 0);
  9062. packet->setDataByName("avoidance", player_to_inspect->GetInfoStruct()->get_avoidance_display()*10.0f);
  9063. packet->setDataByName("unknown2", 0);
  9064. packet->setDataByName("mitigation_percentage", 0);
  9065. packet->setDataByName("strength", player_to_inspect->GetStr());
  9066. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  9067. packet->setDataByName("stamina", player_to_inspect->GetSta());
  9068. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  9069. packet->setDataByName("agility", player_to_inspect->GetAgi());
  9070. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  9071. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  9072. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  9073. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  9074. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  9075. packet->setDataByName("unknown4", 0);
  9076. packet->setDataByName("unknown5", 0);
  9077. packet->setDataByName("unknown6", 0);
  9078. packet->setDataByName("unknown7", 0);
  9079. packet->setDataByName("unknown8", 0);
  9080. packet->setDataByName("unknown9", 0);
  9081. packet->setDataByName("unknown10", 0);
  9082. packet->setDataByName("unknown11", 0);
  9083. packet->setDataByName("unknown12", 0);
  9084. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  9085. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  9086. packet->setDataByName("heat_resist_percentage", 0);
  9087. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  9088. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  9089. packet->setDataByName("cold_resist_percentage", 0);
  9090. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  9091. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  9092. packet->setDataByName("magic_resist_percentage", 0);
  9093. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  9094. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  9095. packet->setDataByName("mental_resist_percentage", 0);
  9096. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  9097. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  9098. packet->setDataByName("divine_resist_percentage", 0);
  9099. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  9100. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  9101. packet->setDataByName("disease_resist_percentage", 0);
  9102. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  9103. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  9104. packet->setDataByName("poison_resist_percentage", 0);
  9105. packet->setArrayLengthByName("num_chars", 0x01FF);
  9106. string biography = player_to_inspect->GetBiography();
  9107. for (size_t i = 0; i < biography.length(); i++)
  9108. packet->setArrayDataByName("biography_char", biography[i], i);
  9109. if(GetVersion() <= 546) {
  9110. for(int32 s=0;s<22;s++) {
  9111. int32 slot = s;
  9112. char item_slot_name[64], item_slot_name_appearance[64];
  9113. _snprintf(item_slot_name,64,"slot_%u",slot);
  9114. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, GetVersion()));
  9115. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 5, true, true);
  9116. }
  9117. }
  9118. else {
  9119. for(int32 s=0;s<NUM_SLOTS;s++) {
  9120. int32 slot = s*2;
  9121. char item_slot_name[64], item_slot_name_appearance[64];
  9122. _snprintf(item_slot_name,64,"slot_%u",slot);
  9123. int32 slot_appearance = (s*2)+1;
  9124. _snprintf(item_slot_name_appearance,64,"slot_%u",slot_appearance);
  9125. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, player_to_inspect->GetClient()->GetVersion()));
  9126. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 13, false, true);
  9127. if(s <= EQ2_FEET_SLOT || s == EQ2_RANGE_SLOT || s == EQ2_CLOAK_SLOT) {
  9128. pw = player_to_inspect->GetAppearanceEquipmentList()->GetItem(s);
  9129. packet->setItemByName(item_slot_name_appearance, pw, this->GetPlayer(), 0, 13, false, true);
  9130. }
  9131. else {
  9132. packet->setItemByName(item_slot_name_appearance, nullptr, this->GetPlayer(), 0, 13, false, true);
  9133. }
  9134. }
  9135. }
  9136. QueuePacket(packet->serialize());
  9137. safe_delete(packet);
  9138. }
  9139. }
  9140. }
  9141. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  9142. pending_guild_invite.guild = guild;
  9143. pending_guild_invite.invited_by = invited_by;
  9144. }
  9145. void Client::ShowClaimWindow() {
  9146. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  9147. if (packet) {
  9148. int16 loaded = database.CountCharClaimItems(GetCharacterID());
  9149. vector<ClaimItems> claim = database.LoadCharacterClaimItems(GetCharacterID());
  9150. int32 account_age = database.GetAccountAge(GetAccountID());
  9151. //not sure if there is a message or not, but adding this and a return, so if we have nothing do nothing rather than display an empty window.
  9152. if (loaded == 0 || claim.empty()) {
  9153. Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
  9154. return;
  9155. }
  9156. packet->setArrayLengthByName("num_claim_items", loaded);
  9157. int j = 0; //use this to track skipped vet items.
  9158. for (int i = 0; i < claim.size(); i++)
  9159. {
  9160. if (j == claim.size()) {
  9161. Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
  9162. return;
  9163. }
  9164. Item* item = master_item_list.GetItem(claim[i].item_id);
  9165. int16 claimed = 0;
  9166. if (claim[i].curr_claim < claim[i].max_claim) {
  9167. claimed = claim[i].max_claim - claim[i].curr_claim;
  9168. }
  9169. else {
  9170. claimed = 0;
  9171. }
  9172. //dont display vet rewards until they reach the age required
  9173. if (account_age < claim[i].vet_reward_time) {
  9174. j++;
  9175. continue;
  9176. }
  9177. packet->setArrayDataByName("id", i, i);
  9178. packet->setArrayDataByName("not_yet_claimed", 1, i);
  9179. packet->setArrayDataByName("num_remaining", claim[i].curr_claim, i);
  9180. packet->setArrayDataByName("one_per_character", claim[i].one_per_char, i);
  9181. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  9182. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  9183. packet->setArrayDataByName("text", "If you ever see this text, let a developer know!", i); //I've not seen this!
  9184. //packet->setArrayDataByName("category", "Scott's Shit", i); //devn00b: not using so commenting out, leaving in case we ever do implement categories.
  9185. packet->setArrayDataByName("icon", item->details.icon, i);
  9186. packet->setArrayDataByName("item_id", item->details.item_id, i);
  9187. j++;
  9188. }
  9189. }
  9190. packet->setDataByName("unknown3", 1);
  9191. QueuePacket(packet->serialize());
  9192. safe_delete(packet);
  9193. }
  9194. void Client::ShowGuildSearchWindow() {
  9195. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  9196. if (packet) {
  9197. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  9198. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  9199. packet->setArrayLengthByName("num_guilds", guilds->size());
  9200. int32 i = 0;
  9201. while (itr.Next()) {
  9202. Guild* guild = itr.second;
  9203. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  9204. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  9205. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  9206. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  9207. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  9208. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  9209. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  9210. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  9211. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  9212. packet->setArrayDataByName("unknown7", 0x02, i);
  9213. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  9214. i++;
  9215. }
  9216. QueuePacket(packet->serialize());
  9217. safe_delete(packet);
  9218. }
  9219. }
  9220. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  9221. PacketStruct* packet;
  9222. vector<int8>* slot_data;
  9223. vector<int8>::iterator itr;
  9224. int32 slots = 0;
  9225. assert(item);
  9226. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  9227. return;
  9228. }
  9229. slot_data = &item->slot_data;
  9230. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  9231. if (version >= 1188)
  9232. slots = *itr;
  9233. else
  9234. slots += (int8)pow(2.0, *itr);
  9235. }
  9236. packet->setDataByName("slot", slots);
  9237. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  9238. if (slots == 2) {
  9239. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  9240. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  9241. }
  9242. else {
  9243. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  9244. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  9245. }
  9246. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  9247. if (slots == 4) {
  9248. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  9249. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  9250. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  9251. }
  9252. else if (slots == 7) {
  9253. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  9254. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  9255. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  9256. }
  9257. else {
  9258. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  9259. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  9260. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  9261. }
  9262. packet->setDataByName("icon", item->details.icon);
  9263. packet->setDataByName("item_id", item->details.item_id);
  9264. packet->setDataByName("item_crc", crc);
  9265. packet->setDataByName("unknown2", 0xFFFFFFFF);
  9266. packet->setDataByName("unknown4", 0xFFFFFFFF);
  9267. packet->setDataByName("unknown5", 0xFF, 9);
  9268. packet->setDataByName("unknown5", 0xFF, 10);
  9269. QueuePacket(packet->serialize());
  9270. safe_delete(packet);
  9271. }
  9272. void Client::SendCollectionList() {
  9273. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  9274. map<int32, Collection*>::iterator itr;
  9275. vector<struct CollectionItem*>* collection_items;
  9276. Collection* collection;
  9277. struct CollectionItem* collection_item;
  9278. PacketStruct* packet = 0;
  9279. int16 i = 0, j;
  9280. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  9281. return;
  9282. packet->setArrayLengthByName("num_collections", collections->size());
  9283. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9284. collection = itr->second;
  9285. collection_items = collection->GetCollectionItems();
  9286. packet->setArrayDataByName("unknown", 1, i);
  9287. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  9288. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  9289. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  9290. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  9291. packet->setArrayDataByName("level", collection->GetLevel(), i);
  9292. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  9293. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  9294. for (j = 0; j < collection_items->size(); j++) {
  9295. collection_item = collection_items->at(j);
  9296. Item* item = master_item_list.GetItem(collection_item->item);
  9297. if (item) {
  9298. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  9299. if (version < 955)
  9300. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  9301. else
  9302. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  9303. }
  9304. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  9305. }
  9306. i++;
  9307. }
  9308. packet->setDataByName("new_collection_flag", 1);
  9309. QueuePacket(packet->serialize());
  9310. safe_delete(packet);
  9311. }
  9312. bool Client::SendCollectionsForItem(Item* item) {
  9313. map<int32, Collection*> collections_to_send;
  9314. map<int32, Collection*>* collections;
  9315. map<int32, Collection*>::iterator itr;
  9316. vector<struct CollectionItem*>* collection_items;
  9317. Collection* collection;
  9318. struct CollectionItem* collection_item;
  9319. PacketStruct* packet;
  9320. int16 i;
  9321. assert(item);
  9322. /* get any collections required by this item that the player already has */
  9323. collections = player->GetCollectionList()->GetCollections();
  9324. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9325. collection = itr->second;
  9326. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  9327. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  9328. collections_to_send[collection->GetID()] = collection;
  9329. }
  9330. }
  9331. /* get any collections required by this item that the player does not have and send it to the client */
  9332. collections = master_collection_list.GetCollections();
  9333. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9334. collection = itr->second;
  9335. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  9336. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  9337. return false;
  9338. }
  9339. packet->setArrayLengthByName("num_collections", 1);
  9340. packet->setArrayDataByName("unknown", 1, 0);
  9341. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  9342. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  9343. packet->setArrayDataByName("completed", 0, 0);
  9344. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  9345. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  9346. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  9347. packet->setArrayDataByName("unknown3", 0x28, 0);
  9348. collection_items = collection->GetCollectionItems();
  9349. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  9350. for (i = 0; i < collection_items->size(); i++) {
  9351. collection_item = collection_items->at(i);
  9352. Item* item2 = master_item_list.GetItem(collection_item->item);
  9353. if (item2) {
  9354. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  9355. if (version < 955)
  9356. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  9357. else
  9358. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  9359. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  9360. }
  9361. }
  9362. packet->setDataByName("new_collection_flag", 0);
  9363. QueuePacket(packet->serialize());
  9364. safe_delete(packet);
  9365. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  9366. collections_to_send[collection->GetID()] = collection;
  9367. }
  9368. }
  9369. /* send the client a list of collections that should be filtered for this item */
  9370. if (collections_to_send.size() > 0) {
  9371. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  9372. return false;
  9373. }
  9374. i = 0;
  9375. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  9376. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  9377. collection = itr->second;
  9378. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  9379. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  9380. i++;
  9381. }
  9382. packet->setDataByName("item_icon", item->details.icon);
  9383. packet->setDataByName("item_name", item->name.c_str());
  9384. packet->setDataByName("item_id", item->details.item_id);
  9385. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  9386. QueuePacket(packet->serialize());
  9387. safe_delete(packet);
  9388. }
  9389. return collections_to_send.size() > 0;
  9390. }
  9391. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  9392. Collection* collection;
  9393. struct CollectionItem* collection_item;
  9394. PacketStruct* packet;
  9395. char tmp[200] = { 0 };
  9396. assert(item);
  9397. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  9398. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  9399. /* get the item struct that represents the item for this collection */
  9400. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  9401. SendCollectionList();
  9402. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  9403. return;
  9404. }
  9405. /* sanity check */
  9406. if (collection_item->found) {
  9407. SendCollectionList();
  9408. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' has already found item '%s' for collection '%s'", player->GetName(), item->name.c_str(), collection->GetName());
  9409. return;
  9410. }
  9411. }
  9412. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  9413. collection = new Collection(collection);
  9414. /* get the item struct that represents the item for this collection */
  9415. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  9416. SendCollectionList();
  9417. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  9418. safe_delete(collection);
  9419. return;
  9420. }
  9421. /* add the new collection to the player's collection list */
  9422. if (!player->GetCollectionList()->AddCollection(collection)) {
  9423. SendCollectionList();
  9424. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  9425. safe_delete(collection);
  9426. return;
  9427. }
  9428. }
  9429. else {
  9430. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  9431. return;
  9432. }
  9433. collection_item->found = 1;
  9434. collection->SetSaveNeeded(true);
  9435. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  9436. SendCollectionList();
  9437. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  9438. return;
  9439. }
  9440. packet->setDataByName("collection_id", collection_id);
  9441. packet->setDataByName("collection_item_num", collection_item->index);
  9442. packet->setDataByName("add", 1);
  9443. QueuePacket(packet->serialize());
  9444. Item* item2 = master_item_list.GetItem(collection_item->item);
  9445. if (item2) {
  9446. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  9447. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  9448. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  9449. }
  9450. safe_delete(packet);
  9451. RemoveItem(item, 1);
  9452. SendCollectionList();
  9453. }
  9454. void Client::DisplayCollectionComplete(Collection* collection) {
  9455. vector<struct CollectionRewardItem*>* reward_items;
  9456. vector<struct CollectionRewardItem*>* selectable_reward_items;
  9457. struct CollectionRewardItem* reward_item;
  9458. PacketStruct* packet;
  9459. int32 i;
  9460. assert(collection);
  9461. reward_items = collection->GetRewardItems();
  9462. selectable_reward_items = collection->GetSelectableRewardItems();
  9463. if (GetVersion() <= 546) {
  9464. int32 source_id = collection->GetID();
  9465. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  9466. if (packet2) {
  9467. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  9468. packet2->setSubstructDataByName("reward_data", "reward", "Quest Reward!");
  9469. packet2->setSubstructDataByName("reward_data", "max_coin", collection->GetRewardCoin());
  9470. packet2->setSubstructDataByName("reward_data", "exp_bonus", collection->GetRewardXP());
  9471. if(reward_items){
  9472. int32 item_count = reward_items->size();
  9473. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
  9474. i = 0;
  9475. if(reward_items) {
  9476. for (i = 0; i < reward_items->size(); i++) {
  9477. Item* item = reward_items->at(i)->item;
  9478. if (item) {
  9479. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  9480. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  9481. }
  9482. }
  9483. }
  9484. }
  9485. if (selectable_reward_items) {
  9486. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_reward_items->size());
  9487. for (i = 0; i < selectable_reward_items->size(); i++) {
  9488. Item* item = selectable_reward_items->at(i)->item;
  9489. if (item) {
  9490. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  9491. packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  9492. }
  9493. }
  9494. }
  9495. }
  9496. EQ2Packet* app = packet2->serialize();
  9497. QueuePacket(app);
  9498. safe_delete(packet2);
  9499. return;
  9500. }
  9501. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  9502. return;
  9503. }
  9504. packet->setDataByName("title", "Quest Reward!");
  9505. packet->setDataByName("name", collection->GetName());
  9506. packet->setDataByName("description", collection->GetCategory());
  9507. packet->setDataByName("level", collection->GetLevel());
  9508. packet->setDataByName("max_coin", collection->GetRewardCoin());
  9509. packet->setDataByName("min_coin", collection->GetRewardCoin());
  9510. //packet->setDataByName("status_points", quest->GetStatusPoints());
  9511. packet->setArrayLengthByName("num_rewards", reward_items->size());
  9512. for (i = 0; i < reward_items->size(); i++) {
  9513. reward_item = reward_items->at(i);
  9514. if(!reward_item->item)
  9515. {
  9516. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9517. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9518. continue;
  9519. }
  9520. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  9521. if (version < 860)
  9522. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
  9523. else if (version < 1193)
  9524. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  9525. else
  9526. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  9527. }
  9528. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  9529. for (i = 0; i < selectable_reward_items->size(); i++) {
  9530. reward_item = selectable_reward_items->at(i);
  9531. if(!reward_item->item)
  9532. {
  9533. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9534. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9535. continue;
  9536. }
  9537. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  9538. if (version < 860)
  9539. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
  9540. else if (version < 1193)
  9541. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  9542. else
  9543. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  9544. }
  9545. QueuePacket(packet->serialize());
  9546. safe_delete(packet);
  9547. }
  9548. void Client::HandInCollections() {
  9549. map<int32, Collection*>* collections;
  9550. map<int32, Collection*>::iterator itr;
  9551. Collection* collection;
  9552. /* only show 1 collection reward dialog at a time */
  9553. if (player->GetPendingCollectionReward()) {
  9554. return;
  9555. }
  9556. collections = player->GetCollectionList()->GetCollections();
  9557. /* we only want to display 1 collection reward dialog at a time. so once we find one to display, send it and return. once the player accepts the reward
  9558. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  9559. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9560. collection = itr->second;
  9561. if (collection->GetIsReadyToTurnIn()) {
  9562. player->SetPendingCollectionReward(collection);
  9563. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  9564. QuestRewardData* data = new QuestRewardData;
  9565. data->quest_id = 0;
  9566. data->is_temporary = false;
  9567. data->description = std::string("");
  9568. data->is_collection = true;
  9569. data->has_displayed = false;
  9570. data->tmp_coin = 0;
  9571. data->tmp_status = 0;
  9572. data->db_saved = false;
  9573. data->db_index = 0;
  9574. quest_pending_reward.push_back(data);
  9575. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  9576. quest_updates = true;
  9577. break;
  9578. }
  9579. }
  9580. if(quest_updates) {
  9581. SaveQuestRewardData(true);
  9582. }
  9583. }
  9584. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  9585. vector<struct CollectionRewardItem*>* reward_items;
  9586. vector<struct CollectionRewardItem*>::iterator itr;
  9587. struct CollectionRewardItem* reward_item;
  9588. int16 num_slots_needed;
  9589. int16 num_slots;
  9590. assert(collection);
  9591. reward_items = collection->GetRewardItems();
  9592. num_slots_needed = (int16)reward_items->size();
  9593. if (selectable_item_id > 0)
  9594. num_slots_needed++;
  9595. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  9596. if (num_slots < num_slots_needed) {
  9597. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  9598. DisplayCollectionComplete(collection);
  9599. return;
  9600. }
  9601. /* add manditory items */
  9602. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  9603. reward_item = *itr;
  9604. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  9605. }
  9606. /* find and add the selectable item if there's one */
  9607. if (selectable_item_id > 0) {
  9608. reward_items = collection->GetSelectableRewardItems();
  9609. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  9610. reward_item = *itr;
  9611. if (reward_item->item->details.item_id == selectable_item_id) {
  9612. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  9613. break;
  9614. }
  9615. }
  9616. }
  9617. if (collection->GetRewardXP() > 0) {
  9618. player->AddXP((int32)collection->GetRewardXP());
  9619. }
  9620. if (collection->GetRewardCoin() > 0) {
  9621. player->AddCoins(collection->GetRewardCoin());
  9622. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  9623. }
  9624. collection->SetCompleted(true);
  9625. //update achievements for completeing collection here
  9626. collection->SetSaveNeeded(true);
  9627. SendCollectionList();
  9628. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  9629. player->SetPendingCollectionReward(0);
  9630. RemoveQueuedQuestReward();
  9631. GetPlayer()->SetActiveReward(false);
  9632. HandInCollections();
  9633. GetPlayer()->GetZone()->SendSubSpawnUpdates(SUBSPAWN_TYPES::COLLECTOR);
  9634. }
  9635. void Client::SendRecipeList() {
  9636. if(GetRecipeListSent()) {
  9637. return;
  9638. }
  9639. PacketStruct* packet = 0;
  9640. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  9641. map<int32, Recipe*>::iterator itr;
  9642. int16 i = 0;
  9643. Recipe* recipe;
  9644. if(version <= 546) {
  9645. PacketStruct* packet = 0;
  9646. if (!(packet = configReader.getStruct("WS_UpdateRecipeBook", GetVersion()))) {
  9647. return;
  9648. }
  9649. packet->setArrayLengthByName("recipe_count", recipes->size());
  9650. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9651. recipe = itr->second;
  9652. int32 recipe_id = recipe->GetID();
  9653. packet->setArrayDataByName("recipe_id", recipe_id, i);
  9654. packet->setArrayDataByName("recipe_data_crc", GetRecipeCRC(recipe), i);
  9655. packet->setArrayDataByName("unknown", 0x7005BE3, i); //0x7005BE3
  9656. i++;
  9657. }
  9658. //packet->PrintPacket();
  9659. EQ2Packet* ret = packet->serializeCountPacket(GetVersion(), 0, nullptr, nullptr);
  9660. QueuePacket(ret);
  9661. safe_delete(packet);
  9662. SetRecipeListSent(true);
  9663. return;
  9664. }
  9665. else if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  9666. return;
  9667. }
  9668. int8 level = player->GetTSLevel();
  9669. int index = 0;
  9670. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9671. recipe = itr->second;
  9672. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  9673. if (res != devices.end())
  9674. index = res - devices.begin();
  9675. else
  9676. devices.push_back(recipe->GetDevice());
  9677. }
  9678. packet->setDataByName("command_type", 0);
  9679. packet->setArrayLengthByName("num_recipes", recipes->size());
  9680. int stringsize = 0;
  9681. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9682. recipe = itr->second;
  9683. int32 myid = recipe->GetID();
  9684. int8 rlevel = recipe->GetLevel();
  9685. int8 even = level - level * .05 + .5;
  9686. int8 easymin = level - level * .25 + .5;
  9687. int8 veasymin = level - level * .35 + .5;
  9688. if (rlevel > level )
  9689. packet->setArrayDataByName("tier", 4, i);
  9690. else if ((rlevel <= level) & (rlevel >= even))
  9691. packet->setArrayDataByName("tier", 3, i);
  9692. else if ((rlevel <= even) & (rlevel >= easymin))
  9693. packet->setArrayDataByName("tier", 2, i);
  9694. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  9695. packet->setArrayDataByName("tier", 1, i);
  9696. else if ((rlevel <= veasymin) & (rlevel >= 0))
  9697. packet->setArrayDataByName("tier", 0, i);
  9698. if (rlevel == 2)
  9699. int xxx = 1;
  9700. packet->setArrayDataByName("recipe_id", myid, i);
  9701. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  9702. packet->setArrayDataByName("unknown1", recipe->GetLevel(), i);
  9703. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  9704. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  9705. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  9706. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  9707. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  9708. if (recipe_device != devices.end())
  9709. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), i);
  9710. else
  9711. {//TODO error should never get here
  9712. }
  9713. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  9714. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  9715. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  9716. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  9717. i++;
  9718. }
  9719. //packet->PrintPacket();
  9720. EQ2Packet* pack = packet->serialize();
  9721. QueuePacket(pack);
  9722. safe_delete(packet);
  9723. SetRecipeListSent(true);
  9724. }
  9725. void Client::ShowRecipeBook() {
  9726. PacketStruct* packet = 0;
  9727. Spawn* target = 0;
  9728. int index = 0;
  9729. if (!(target = player->GetTarget())) {
  9730. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  9731. return;
  9732. }
  9733. if (!target->IsObject()) {
  9734. return;
  9735. }
  9736. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  9737. return;
  9738. }
  9739. packet->setDataByName("device", target->GetName());
  9740. packet->setDataByName("unknown1", 1);
  9741. auto res = std::find(devices.begin(), devices.end(), target->GetName());
  9742. if (res != devices.end()){
  9743. index = res - devices.begin();
  9744. int32 deviceID = 0;
  9745. deviceID |= 1UL << index;
  9746. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  9747. packet->setDataByName("unknown2", devices.size());
  9748. packet->setDataByName("unknown3", deviceID);
  9749. }
  9750. else
  9751. packet->setDataByName("unknown2", devices.size());
  9752. QueuePacket(packet->serialize());
  9753. safe_delete(packet);
  9754. }
  9755. void Client::SendTitleUpdate() {
  9756. // must call release read lock before leaving function on GetPlayerTitles
  9757. vector<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  9758. vector<Title*>::iterator itr;
  9759. Title* title;
  9760. sint32 i = 0;
  9761. sint32 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  9762. sint32 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  9763. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  9764. if (packet) {
  9765. packet->setArrayLengthByName("num_titles", titles->size());
  9766. for (itr = titles->begin(); itr != titles->end(); itr++) {
  9767. title = *itr;
  9768. packet->setArrayDataByName("title", title->GetName(), i);
  9769. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  9770. i++;
  9771. }
  9772. packet->setDataByName("current_prefix", prefix_index);
  9773. packet->setDataByName("current_suffix", suffix_index);
  9774. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  9775. #if EQDEBUG >= 9
  9776. packet->PrintPacket();
  9777. #endif
  9778. QueuePacket(packet->serialize());
  9779. safe_delete(packet);
  9780. SendUpdateTitles(prefix_index, suffix_index);
  9781. }
  9782. player->GetPlayerTitles()->ReleaseReadLock();
  9783. }
  9784. void Client::SendUpdateTitles(sint32 prefix, sint32 suffix) {
  9785. Title* suffix_title = 0;
  9786. Title* prefix_title = 0;
  9787. if (suffix != -1) {
  9788. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  9789. if(suffix_title)
  9790. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  9791. }
  9792. else
  9793. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  9794. if (prefix != -1) {
  9795. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  9796. if(prefix_title)
  9797. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  9798. }
  9799. else
  9800. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  9801. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  9802. }
  9803. void Client::SendLanguagesUpdate(int32 id, bool setlang) {
  9804. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  9805. list<Language*>::iterator itr;
  9806. Language* language;
  9807. int32 i = 0;
  9808. if(setlang==1){
  9809. GetPlayer()->SetCurrentLanguage(id);
  9810. }
  9811. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  9812. if (packet) {
  9813. packet->setArrayLengthByName("num_languages", languages->size());
  9814. for (itr = languages->begin(); itr != languages->end(); itr++) {
  9815. language = *itr;
  9816. packet->setArrayDataByName("language_id", language->GetID(), i);
  9817. i++;
  9818. }
  9819. packet->setDataByName("current_language", id);
  9820. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  9821. #if EQDEBUG >= 9
  9822. packet->PrintPacket();
  9823. #endif
  9824. QueuePacket(packet->serialize());
  9825. safe_delete(packet);
  9826. }
  9827. }
  9828. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  9829. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  9830. if (packet) {
  9831. if (pet_name)
  9832. packet->setDataByName("pet_name", pet_name);
  9833. if (player->GetInfoStruct()->get_pet_behavior() & 1)
  9834. packet->setDataByName("protect_master", 1);
  9835. if (player->GetInfoStruct()->get_pet_behavior() & 2)
  9836. packet->setDataByName("protect_self", 1);
  9837. if (player->GetInfoStruct()->get_pet_movement() == 2)
  9838. packet->setDataByName("stay_follow_toggle", 1);
  9839. packet->setDataByName("pet_type", type);
  9840. QueuePacket(packet->serialize());
  9841. }
  9842. safe_delete(packet);
  9843. }
  9844. bool Client::IsCrafting() {
  9845. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  9846. }
  9847. void Client::SendBiography() {
  9848. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  9849. if (packet) {
  9850. char biography[512];
  9851. if(player->GetInfoStruct()->get_biography().size() < 1)
  9852. {
  9853. safe_delete(packet);
  9854. return;
  9855. }
  9856. else
  9857. {
  9858. int16 size = player->GetInfoStruct()->get_biography().size();
  9859. if(size>511)
  9860. size = 511;
  9861. strncpy(biography, player->GetInfoStruct()->get_biography().c_str(), player->GetInfoStruct()->get_biography().size());
  9862. biography[player->GetInfoStruct()->get_biography().size()] = '\0';
  9863. }
  9864. packet->setDataByName("biography", biography);
  9865. QueuePacket(packet->serialize());
  9866. }
  9867. safe_delete(packet);
  9868. }
  9869. PendingResurrection* Client::GetCurrentRez() {
  9870. return &current_rez;
  9871. }
  9872. Mutex* Client::GetResurrectMutex() {
  9873. return &m_resurrect;
  9874. }
  9875. void Client::SendResurrectionWindow() {
  9876. Spawn* caster = current_rez.caster;
  9877. if (!caster || !player)
  9878. return;
  9879. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  9880. if (!packet)
  9881. return;
  9882. char* tmp = new char[512];
  9883. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  9884. packet->setMediumStringByName("text", tmp);
  9885. packet->setMediumStringByName("accept_text", "Yes");
  9886. packet->setMediumStringByName("cancel_text", "No");
  9887. sprintf(tmp, "accept_resurrection %u", player->GetID());
  9888. packet->setMediumStringByName("accept_command", tmp);
  9889. sprintf(tmp, "decline_resurrection %u", player->GetID());
  9890. packet->setMediumStringByName("cancel_command", tmp);
  9891. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  9892. QueuePacket(packet->serialize());
  9893. safe_delete(packet);
  9894. safe_delete_array(tmp);
  9895. }
  9896. void Client::AcceptResurrection() {
  9897. Spawn* caster = current_rez.caster;
  9898. if (!player || !caster)
  9899. return;
  9900. if (player->Alive())
  9901. return;
  9902. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  9903. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  9904. SendResurrectionWindow();
  9905. return;
  9906. }
  9907. player->GetZone()->ResurrectSpawn(player, this);
  9908. current_rez.should_delete = true;
  9909. }
  9910. void Client::SetPendingLastName(string last_name) {
  9911. pending_last_name = new string;
  9912. pending_last_name->assign(last_name);
  9913. }
  9914. string* Client::GetPendingLastName() {
  9915. return pending_last_name;
  9916. }
  9917. void Client::RemovePendingLastName() {
  9918. safe_delete(pending_last_name);
  9919. }
  9920. void Client::SendLastNameConfirmation() {
  9921. if (!pending_last_name)
  9922. return;
  9923. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  9924. if (packet) {
  9925. char* text = new char[128];
  9926. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  9927. packet->setDataByName("text", text);
  9928. packet->setDataByName("accept_text", "Yes");
  9929. packet->setDataByName("accept_command", "confirmedlastname");
  9930. packet->setDataByName("cancel_text", "No");
  9931. packet->setDataByName("max_length", 50);
  9932. packet->setDataByName("unknown4", 1);
  9933. packet->setDataByName("unknown5", 1);
  9934. QueuePacket(packet->serialize());
  9935. safe_delete(packet);
  9936. safe_delete_array(text);
  9937. }
  9938. }
  9939. void Client::AddQuestTimer(int32 quest_id) {
  9940. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  9941. quest_timers.push_back(quest_id);
  9942. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  9943. }
  9944. void Client::RemoveQuestTimer(int32 quest_id) {
  9945. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  9946. vector<int32>::iterator itr;
  9947. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  9948. if ((*itr) == quest_id) {
  9949. quest_timers.erase(itr);
  9950. break;
  9951. }
  9952. }
  9953. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  9954. }
  9955. void Client::SavePlayerImages() {
  9956. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  9957. // Save the paperdoll image if the server allows it
  9958. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  9959. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9960. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  9961. // Save the head shot if the server allows it
  9962. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  9963. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9964. // Send the head shot to the login server
  9965. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  9966. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  9967. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  9968. memset(packet->pBuffer, 0, size);
  9969. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  9970. pic->account_id = GetAccountID();
  9971. pic->char_id = GetCharacterID();
  9972. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  9973. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9974. loginserver.SendPacket(packet);
  9975. safe_delete(packet);
  9976. }
  9977. }
  9978. safe_delete_array(incoming_paperdoll.image_bytes);
  9979. incoming_paperdoll.current_size_bytes = 0;
  9980. }
  9981. void Client::EndAutoMount() {
  9982. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  9983. if (packet) {
  9984. packet->setDataByName("parameter1", 128);
  9985. packet->setDataByName("parameter2", 64);
  9986. packet->setDataByName("value", 1);
  9987. QueuePacket(packet->serialize());
  9988. safe_delete(packet);
  9989. }
  9990. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  9991. if (packet) {
  9992. packet->setDataByName("parameter3", 4);
  9993. packet->setDataByName("parameter5", 2);
  9994. packet->setDataByName("value", 0);
  9995. QueuePacket(packet->serialize());
  9996. safe_delete(packet);
  9997. }
  9998. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  9999. if (packet) {
  10000. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  10001. QueuePacket(packet->serialize());
  10002. safe_delete(packet);
  10003. }
  10004. on_auto_mount = false;
  10005. player->SetMount(((Player*)player)->GetTempMount());
  10006. EQ2_Color mount_color = player->GetTempMountColor();
  10007. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  10008. player->SetMountColor(&mount_color);
  10009. player->SetMountSaddleColor(&saddle_color);
  10010. player->SetTempMount(0);
  10011. }
  10012. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  10013. const char* spawn_script = spawn->GetSpawnScript();
  10014. bool should_use_spawn = true;
  10015. if (spawn_script) {
  10016. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  10017. if (state) {
  10018. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  10019. if (state_mutex)
  10020. state_mutex->writelock(__FUNCTION__, __LINE__);
  10021. lua_getglobal(state, "can_use_command");
  10022. if (lua_isfunction(state, -1)) {
  10023. lua_interface->SetSpawnValue(state, spawn);
  10024. lua_interface->SetSpawnValue(state, GetPlayer());
  10025. lua_interface->SetStringValue(state, command ? command : "");
  10026. if (lua_pcall(state, 3, 1, 0) == 0) {
  10027. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  10028. }
  10029. }
  10030. lua_interface->ResetFunctionStack(state);
  10031. if (state_mutex)
  10032. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  10033. }
  10034. }
  10035. return should_use_spawn;
  10036. }
  10037. bool Client::IsCurrentTransmuteID(int32 req_id) {
  10038. return req_id == transmuteID;
  10039. }
  10040. void Client::SetTransmuteID(int32 trans_id) {
  10041. transmuteID = trans_id;
  10042. }
  10043. int32 Client::GetTransmuteID() {
  10044. return transmuteID;
  10045. }
  10046. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  10047. {
  10048. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  10049. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  10050. if (zar)
  10051. {
  10052. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  10053. if (database.IsActiveQuery(charID))
  10054. {
  10055. delayedLogin = true;
  10056. delayedAccountID = account_id;
  10057. delayedAccessKey = access_code;
  10058. delayTimer.Start(500);
  10059. LogWrite(ZONE__INFO, 0, "ZoneAuth", "Attempt to Login must be delayed, async character save in progress! ... Access Key: %u, Character Name: %s, Account ID: %u, Client Data Version: %u", zar->GetAccessKey(), zar->GetCharacterName(), zar->GetAccountID(), version);
  10060. return true;
  10061. }
  10062. delayedLogin = false;
  10063. delayTimer.Disable();
  10064. firstlogin = zar->isFirstLogin();
  10065. SetReadyForSpawns(false);
  10066. ready_for_updates = false;
  10067. LogWrite(ZONE__INFO, 0, "ZoneAuth", "Access Key: %u, Character Name: %s, Account ID: %u, Client Data Version: %u", zar->GetAccessKey(), zar->GetCharacterName(), zar->GetAccountID(), version);
  10068. Client* client = zone_list.GetClientByCharName(zar->GetCharacterName());
  10069. if (client || database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  10070. GetPlayer()->CalculateOfflineDebtRecovery(GetLastSavedTimeStamp());
  10071. GetPlayer()->vis_changed = false;
  10072. GetPlayer()->info_changed = false;
  10073. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  10074. if (pvp_allowed)
  10075. this->GetPlayer()->SetAttackable(1);
  10076. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  10077. if (client) {
  10078. if (client->getConnection())
  10079. client->getConnection()->SendDisconnect(true);
  10080. bool restore_ld_success = false;
  10081. if (client->GetCurrentZone() && !client->IsZoning()) {
  10082. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  10083. if (client->GetVersion() == version) {
  10084. client->DisableSave();
  10085. client->ReplaceGroupClient(this);
  10086. Player* current_player = GetPlayer();
  10087. SetPlayer(client->GetPlayer());
  10088. GetPlayer()->SetClient(this);
  10089. GetPlayer()->SetReturningFromLD(true);
  10090. SetCharacterID(client->GetCharacterID());
  10091. SetAccountID(client->GetAccountID());
  10092. SetAdminStatus(client->GetAdminStatus());
  10093. SetCurrentZone(GetPlayer()->GetZone());
  10094. client->SetPlayer(current_player);
  10095. GetPlayer()->ResetSavedSpawns();
  10096. restore_ld_success = true;
  10097. char tmpldname[128];
  10098. snprintf(tmpldname, 128, "%s Linkdead",GetPlayer()->GetName());
  10099. client->GetPlayer()->SetName(tmpldname, false);
  10100. }
  10101. ZoneServer* tmpZone = client->GetCurrentZone();
  10102. tmpZone->RemoveClientImmediately(client);
  10103. }
  10104. if(!restore_ld_success && !database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  10105. LogWrite(ZONE__ERROR, 0, "Zone", "Error reloading LD character and loading DB character: %s", player->GetName());
  10106. ClientPacketFunctions::SendLoginDenied(this);
  10107. Disconnect();
  10108. return false;
  10109. }
  10110. }
  10111. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  10112. if (!GetCurrentZone()) {
  10113. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  10114. ClientPacketFunctions::SendLoginDenied(this);
  10115. Disconnect();
  10116. return false;
  10117. }
  10118. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  10119. getConnection()->SetClientVersion(version);
  10120. GetCurrentZone()->SetSpawnStructs(this);
  10121. connected_to_zone = true;
  10122. client_list.Remove(this); //remove from master client list
  10123. GetCurrentZone()->AddClient(this); //add to zones client list
  10124. zone_list.AddClientToMap(player->GetName(), this);
  10125. // this initiates additional DB loading and client offloading within the Zone the player resides, need the client already added in zone and to the map above.
  10126. if(GetCurrentZone()->IsLoading()) {
  10127. new_client_login = NewLoginState::LOGIN_DELAYED;
  10128. }
  10129. else {
  10130. new_client_login = NewLoginState::LOGIN_ALLOWED;
  10131. }
  10132. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  10133. if (zone_script && lua_interface)
  10134. lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
  10135. }
  10136. else {
  10137. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  10138. version = 0;
  10139. ClientPacketFunctions::SendLoginDenied(this);
  10140. Disconnect();
  10141. return false;
  10142. }
  10143. }
  10144. else {
  10145. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  10146. ClientPacketFunctions::SendLoginDenied(this);
  10147. Disconnect();
  10148. return false;
  10149. }
  10150. zone_auth.RemoveAuth(zar);
  10151. }
  10152. else
  10153. {
  10154. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  10155. Disconnect();
  10156. return false;
  10157. }
  10158. return true;
  10159. }
  10160. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  10161. if (!IsReadyForUpdates())
  10162. return;
  10163. map<int32, SpawnData> info_changes;
  10164. map<int32, SpawnData> pos_changes;
  10165. map<int32, SpawnData> vis_changes;
  10166. map<int32, SpawnData> empty_changes;
  10167. int32 info_size = 0;
  10168. int32 pos_size = 0;
  10169. int32 vis_size = 0;
  10170. int count = 0;
  10171. for (const auto& spawn : spawns) {
  10172. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  10173. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()))
  10174. continue;
  10175. int16 tmp_info_size = 0;
  10176. int16 tmp_pos_size = 0;
  10177. int16 tmp_vis_size = 0;
  10178. if (spawn->vis_changed)
  10179. {
  10180. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
  10181. if (vis_change) {
  10182. SpawnData data;
  10183. data.spawn = spawn;
  10184. data.data = vis_change;
  10185. data.size = tmp_vis_size;
  10186. map<int32, SpawnData> tmp_vis_changes;
  10187. tmp_vis_changes[index] = data;
  10188. map<int32, SpawnData> tmp_info_changes;
  10189. map<int32, SpawnData> tmp_pos_changes;
  10190. if (spawn->info_changed) {
  10191. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
  10192. if (info_change) {
  10193. SpawnData data;
  10194. data.spawn = spawn;
  10195. data.data = info_change;
  10196. data.size = tmp_info_size;
  10197. tmp_info_changes[index] = data;
  10198. }
  10199. }
  10200. if (spawn->position_changed) {
  10201. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
  10202. if (pos_change) {
  10203. SpawnData data;
  10204. data.spawn = spawn;
  10205. data.data = pos_change;
  10206. data.size = tmp_pos_size;
  10207. tmp_pos_changes[index] = data;
  10208. }
  10209. }
  10210. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  10211. for (auto& kv : tmp_info_changes) {
  10212. safe_delete_array(kv.second.data);
  10213. }
  10214. for (auto& kv : tmp_pos_changes) {
  10215. safe_delete_array(kv.second.data);
  10216. }
  10217. for (auto& kv : tmp_vis_changes) {
  10218. safe_delete_array(kv.second.data);
  10219. }
  10220. continue;
  10221. }
  10222. }
  10223. if (spawn->info_changed) {
  10224. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
  10225. if (info_change) {
  10226. SpawnData data;
  10227. data.spawn = spawn;
  10228. data.data = info_change;
  10229. data.size = tmp_info_size;
  10230. info_size += tmp_info_size;
  10231. info_changes[index] = data;
  10232. }
  10233. count++;
  10234. }
  10235. if (spawn->position_changed) {
  10236. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
  10237. if (pos_change) {
  10238. SpawnData data;
  10239. data.spawn = spawn;
  10240. data.data = pos_change;
  10241. data.size = tmp_pos_size;
  10242. pos_size += tmp_pos_size;
  10243. pos_changes[index] = data;
  10244. }
  10245. count++;
  10246. }
  10247. if (spawn->vis_changed) {
  10248. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
  10249. if (vis_change) {
  10250. SpawnData data;
  10251. data.spawn = spawn;
  10252. data.data = vis_change;
  10253. data.size = tmp_vis_size;
  10254. vis_size += tmp_vis_size;
  10255. vis_changes[index] = data;
  10256. }
  10257. count++;
  10258. }
  10259. }
  10260. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  10261. return;
  10262. }
  10263. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  10264. for (auto& kv : info_changes) {
  10265. safe_delete_array(kv.second.data);
  10266. }
  10267. for (auto& kv : pos_changes) {
  10268. safe_delete_array(kv.second.data);
  10269. }
  10270. for (auto& kv : vis_changes) {
  10271. safe_delete_array(kv.second.data);
  10272. }
  10273. }
  10274. void Client::MakeSpawnChangePacket(map<int32, SpawnData> info_changes, map<int32, SpawnData> pos_changes, map<int32, SpawnData> vis_changes, int32 info_size, int32 pos_size, int32 vis_size)
  10275. {
  10276. static const int8 oversized = 255;
  10277. int16 opcode_val = 0;
  10278. if (EQOpcodeManager.count(GetOpcodeVersion(version)) != 0) {
  10279. opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  10280. }
  10281. int32 size = info_size + pos_size + vis_size + 8;
  10282. if (version > 283) //version 283 and below uses an overload for size, not always 4 bytes
  10283. size += 3;
  10284. size += CheckOverLoadSize(info_size);
  10285. size += CheckOverLoadSize(pos_size);
  10286. size += CheckOverLoadSize(vis_size);
  10287. if (version <= 283 && size >= 255) {//1 byte to 3 for overloaded val
  10288. size += 2;
  10289. }
  10290. uchar* tmp = new uchar[size];
  10291. uchar* ptr = tmp;
  10292. memset(tmp, 0, size);
  10293. if (version <= 283) {
  10294. if (size >= 255) {
  10295. size -= 3;
  10296. memcpy(ptr, &oversized, sizeof(int8));
  10297. ptr += sizeof(int8);
  10298. memcpy(ptr, &size, sizeof(int16));
  10299. ptr += sizeof(int16);
  10300. size += 3;
  10301. }
  10302. else {
  10303. size -= 1;
  10304. memcpy(ptr, &size, sizeof(int8));
  10305. ptr += sizeof(int8);
  10306. size += 1;
  10307. }
  10308. }
  10309. else {
  10310. size -= 4;
  10311. memcpy(ptr, &size, sizeof(int32));
  10312. ptr += sizeof(int32);
  10313. size += 4;
  10314. }
  10315. memcpy(ptr, &oversized, sizeof(int8));
  10316. ptr += sizeof(int8);
  10317. memcpy(ptr, &opcode_val, sizeof(int16));
  10318. ptr += sizeof(int16);
  10319. int32 current_time = Timer::GetCurrentTime2();
  10320. memcpy(ptr, &current_time, sizeof(int32));
  10321. ptr += sizeof(int32);
  10322. ptr += DoOverLoad(info_size, ptr);
  10323. for (const auto& kv : info_changes) {
  10324. auto info = kv.second;
  10325. memcpy(ptr, info.data, info.size);
  10326. ptr += info.size;
  10327. }
  10328. ptr += DoOverLoad(pos_size, ptr);
  10329. for (const auto& kv : pos_changes) {
  10330. auto pos = kv.second;
  10331. memcpy(ptr, pos.data, pos.size);
  10332. ptr += pos.size;
  10333. }
  10334. ptr += DoOverLoad(vis_size, ptr);
  10335. for (const auto& kv : vis_changes) {
  10336. auto vis = kv.second;
  10337. memcpy(ptr, vis.data, vis.size);
  10338. ptr += vis.size;
  10339. }
  10340. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  10341. if (packet) {
  10342. /*char blah[64];
  10343. snprintf(blah, 64, "Sending %i", current_time);
  10344. SimpleMessage(4, blah);*/
  10345. QueuePacket(packet);
  10346. }
  10347. delete[] tmp;
  10348. }
  10349. void Client::SendHailCommand(Spawn* spawn)
  10350. {
  10351. // hardcoded 'hail' entity commands
  10352. switch (spawn->secondary_command_list_id)
  10353. {
  10354. case 9:
  10355. case 1262:
  10356. case 1265:
  10357. case 1267:
  10358. {
  10359. EQ2_16BitString* command = new EQ2_16BitString();
  10360. command->data = "";
  10361. command->size = 0;
  10362. commands.Process(COMMAND_HAIL, command, this, spawn);
  10363. safe_delete(command);
  10364. break;
  10365. }
  10366. }
  10367. }
  10368. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  10369. {
  10370. if (GetPlayer()->WasSentSpawn(spawn->GetID())) {
  10371. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  10372. if (packet) {
  10373. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  10374. packet->setMediumStringByName("command_name", command);
  10375. packet->setDataByName("distance", distance);
  10376. QueuePacket(packet->serialize());
  10377. safe_delete(packet);
  10378. }
  10379. }
  10380. }
  10381. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  10382. {
  10383. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  10384. return false;
  10385. if (command == "house_spawn_examine")
  10386. {
  10387. uint32 itemID = spawn->GetPickupItemID();
  10388. if (itemID)
  10389. {
  10390. Item* item = master_item_list.GetItem(itemID);
  10391. if (item)
  10392. {
  10393. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  10394. //DumpPacket(app);
  10395. QueuePacket(app);
  10396. }
  10397. }
  10398. return true;
  10399. }
  10400. return false;
  10401. }
  10402. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  10403. {
  10404. if (GetTempPlacementSpawn())
  10405. {
  10406. Spawn* tmp = GetTempPlacementSpawn();
  10407. int32 spawn_group_id = database.GetNextSpawnLocation();
  10408. tmp->SetSpawnLocationID(spawn_group_id);
  10409. float newHeading = place_object->getType_float_ByName("heading") + 180;
  10410. int32 spawnDBID = 0;
  10411. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  10412. {
  10413. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  10414. tmp->SetDatabaseID(spawnDBID);
  10415. }
  10416. else
  10417. {
  10418. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  10419. if (spawnDBID)
  10420. {
  10421. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  10422. tmp->SetDatabaseID(spawnDBID);
  10423. }
  10424. }
  10425. tmp->SetX(place_object->getType_float_ByName("x"));
  10426. tmp->SetY(place_object->getType_float_ByName("y"));
  10427. tmp->SetZ(place_object->getType_float_ByName("z"));
  10428. tmp->SetHeading(newHeading);
  10429. tmp->SetSpawnOrigX(tmp->GetX());
  10430. tmp->SetSpawnOrigY(tmp->GetY());
  10431. tmp->SetSpawnOrigZ(tmp->GetZ());
  10432. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  10433. database.SaveSpawnInfo(tmp);
  10434. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  10435. if (!spawnDBID)
  10436. {
  10437. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  10438. // we need to copy as to not delete the ZoneServer object_list entry this on house item pickup
  10439. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), ((Object*)tmp)->Copy());
  10440. }
  10441. return true;
  10442. }
  10443. return false;
  10444. }
  10445. bool Client::PopulateHouseSpawnFinalize()
  10446. {
  10447. if (GetTempPlacementSpawn())
  10448. {
  10449. Spawn* tmp = GetTempPlacementSpawn();
  10450. GetCurrentZone()->AddSpawn(tmp);
  10451. GetCurrentZone()->SendSpawnChanges(tmp, this);
  10452. SetTempPlacementSpawn(nullptr);
  10453. int32 uniqueID = GetPlacementUniqueItemID();
  10454. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  10455. tmp->SetPickupItemID(uniqueItem->details.item_id);
  10456. tmp->SetPickupUniqueItemID(uniqueID);
  10457. if (uniqueItem)
  10458. {
  10459. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  10460. {
  10461. Query query;
  10462. query.RunQuery2(Q_INSERT, "insert into spawn_instance_data set spawn_id = %u, spawn_location_id = %u, pickup_item_id = %u, pickup_unique_item_id = %u", tmp->GetDatabaseID(), tmp->GetSpawnLocationID(), tmp->GetPickupItemID(), uniqueID);
  10463. }
  10464. if(uniqueItem->GetItemScript() &&
  10465. lua_interface->RunItemScript(uniqueItem->GetItemScript(), "placed", uniqueItem, GetPlayer(), tmp))
  10466. {
  10467. uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  10468. }
  10469. if(uniqueItem) {
  10470. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  10471. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  10472. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  10473. }
  10474. SetPlacementUniqueItemID(0);
  10475. }
  10476. return true;
  10477. }
  10478. return false;
  10479. }
  10480. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  10481. {
  10482. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  10483. packet->setDataByName("placement_mode", placementMode);
  10484. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  10485. packet->setDataByName("model_type", spawn->GetModelType());
  10486. packet->setDataByName("unknown", 1); //size
  10487. packet->setDataByName("unknown2", 1); //size 2
  10488. packet->setDataByName("unknown2", .5, 1); //size 3
  10489. packet->setDataByName("unknown2", 3, 2);
  10490. packet->setDataByName("unknown2", unknown2_3, 3);
  10491. packet->setDataByName("max_distance", 500);
  10492. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  10493. QueuePacket(packet->serialize());
  10494. safe_delete(packet);
  10495. }
  10496. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  10497. {
  10498. SetPendingFlightPath(path_id);
  10499. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  10500. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  10501. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  10502. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  10503. if (packet) {
  10504. QueuePacket(packet->serialize());
  10505. safe_delete(packet);
  10506. }
  10507. if (mount_id)
  10508. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  10509. }
  10510. void Client::SendShowBook(Spawn* sender, string title, int8 language, int8 num_pages, ...)
  10511. {
  10512. if (!sender)
  10513. {
  10514. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  10515. return;
  10516. }
  10517. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  10518. if (!packet) {
  10519. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  10520. return;
  10521. }
  10522. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  10523. packet->setDataByName("book_title", title.c_str());
  10524. packet->setDataByName("book_type", "simple");
  10525. packet->setDataByName("unknown2", 1);
  10526. if(language > 0 && !GetPlayer()->HasLanguage(language))
  10527. packet->setDataByName("language", language);
  10528. if (GetVersion() > 546)
  10529. packet->setDataByName("unknown5", 1, 4);
  10530. packet->setArrayLengthByName("num_pages", num_pages);
  10531. va_list args;
  10532. va_start(args, num_pages);
  10533. std::string endString("");
  10534. for (int8 p = 0; p < num_pages; p++)
  10535. {
  10536. std::string page = va_arg(args, string);
  10537. switch (GetVersion())
  10538. {
  10539. // release client
  10540. case 283:
  10541. {
  10542. endString.append(page);
  10543. break;
  10544. }
  10545. // DoF trial
  10546. case 546:
  10547. {
  10548. if (p == 0)
  10549. packet->setDataByName("cover_page", page.c_str());
  10550. else
  10551. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  10552. break;
  10553. }
  10554. // all other clients
  10555. default:
  10556. {
  10557. packet->setArrayDataByName("page_text", page.c_str(), p);
  10558. break;
  10559. }
  10560. }
  10561. }
  10562. if (GetVersion() == 283)
  10563. {
  10564. packet->setDataByName("page_text", endString.c_str());
  10565. }
  10566. va_end(args);
  10567. QueuePacket(packet->serialize());
  10568. safe_delete(packet);
  10569. }
  10570. void Client::SendShowBook(Spawn* sender, string title, int8 language, vector<Item::BookPage*> pages)
  10571. {
  10572. if (!sender)
  10573. {
  10574. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  10575. return;
  10576. }
  10577. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  10578. if (!packet) {
  10579. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  10580. return;
  10581. }
  10582. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  10583. packet->setDataByName("book_title", title.c_str());
  10584. packet->setDataByName("book_type", "simple");
  10585. packet->setDataByName("unknown2", 1);
  10586. if(language > 0 && !GetPlayer()->HasLanguage(language))
  10587. packet->setDataByName("language", language);
  10588. if (GetVersion() > 546)
  10589. packet->setDataByName("unknown5", 1, 4);
  10590. packet->setArrayLengthByName("num_pages", pages.size());
  10591. std::string endString("");
  10592. for (int8 p = 0; p < pages.size(); p++)
  10593. {
  10594. Item::BookPage* page = pages[p];
  10595. std::string pageText = string(page->page_text.data);
  10596. switch (GetVersion())
  10597. {
  10598. // release client
  10599. case 283:
  10600. {
  10601. endString.append(pageText);
  10602. break;
  10603. }
  10604. // DoF trial
  10605. case 546:
  10606. {
  10607. if (p == 0)
  10608. packet->setDataByName("cover_page", pageText.c_str());
  10609. else
  10610. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  10611. break;
  10612. }
  10613. // all other clients
  10614. default:
  10615. {
  10616. int8 valign = int8(page->valign);
  10617. int8 halign = int8(page->halign);
  10618. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  10619. packet->setArrayDataByName("page_text_valign", valign, p);
  10620. packet->setArrayDataByName("page_text_halign", halign, p);
  10621. break;
  10622. }
  10623. }
  10624. }
  10625. if (GetVersion() == 283)
  10626. {
  10627. packet->setDataByName("page_text", endString.c_str());
  10628. }
  10629. QueuePacket(packet->serialize());
  10630. safe_delete(packet);
  10631. }
  10632. void Client::ReplaceGroupClient(Client* new_client)
  10633. {
  10634. if (this->GetPlayer()->GetGroupMemberInfo())
  10635. {
  10636. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  10637. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  10638. if(group)
  10639. {
  10640. group->MGroupMembers.writelock();
  10641. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  10642. this->GetPlayer()->GetGroupMemberInfo()->client = new_client;
  10643. this->GetPlayer()->GetGroupMemberInfo()->member = GetPlayer();
  10644. group->MGroupMembers.releasewritelock();
  10645. }
  10646. else
  10647. {
  10648. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10649. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10650. this->GetPlayer()->SetGroupMemberInfo(0);
  10651. }
  10652. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  10653. }
  10654. }
  10655. void Client::TempRemoveGroup()
  10656. {
  10657. if (this->GetPlayer()->GetGroupMemberInfo())
  10658. {
  10659. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  10660. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  10661. if(group)
  10662. {
  10663. group->MGroupMembers.writelock();
  10664. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  10665. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10666. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10667. this->GetPlayer()->SetGroupMemberInfo(0);
  10668. group->MGroupMembers.releasewritelock();
  10669. group->RemoveClientReference(this);
  10670. }
  10671. else
  10672. {
  10673. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10674. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10675. this->GetPlayer()->SetGroupMemberInfo(0);
  10676. }
  10677. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  10678. }
  10679. }
  10680. void Client::CreateMail(int32 charID, std::string fromName, std::string subjectName, std::string mailBody,
  10681. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  10682. {
  10683. Mail mail;
  10684. mail.mail_id = 0;
  10685. mail.already_read = 0;
  10686. mail.postage_cost = 0;
  10687. mail.attachment_cost = 0;
  10688. mail.save_needed = 1;
  10689. //uhh...mail has std::strings so
  10690. //memset(&mail,0,sizeof(Mail));
  10691. mail.player_to_id = charID;
  10692. mail.player_from = fromName;
  10693. mail.subject = subjectName;
  10694. mail.mail_body = mailBody;
  10695. mail.mail_type = mailType;
  10696. mail.coin_copper = copper;
  10697. mail.coin_silver = silver;
  10698. mail.coin_gold = gold;
  10699. mail.coin_plat = platinum;
  10700. mail.char_item_id = item_id;
  10701. mail.stack = stack_size;
  10702. mail.time_sent = time_sent;
  10703. mail.expire_time = expire_time;
  10704. database.SavePlayerMail(&mail);
  10705. }
  10706. void Client::CreateAndUpdateMail(std::string fromName, std::string subjectName, std::string mailBody,
  10707. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  10708. {
  10709. Mail* mail = new Mail();
  10710. mail->player_to_id = GetCharacterID();
  10711. mail->player_from = fromName;
  10712. mail->subject = subjectName;
  10713. mail->mail_body = mailBody;
  10714. mail->mail_type = mailType;
  10715. mail->coin_copper = copper;
  10716. mail->coin_silver = silver;
  10717. mail->coin_gold = gold;
  10718. mail->coin_plat = platinum;
  10719. mail->char_item_id = item_id;
  10720. mail->stack = stack_size;
  10721. mail->time_sent = time_sent;
  10722. mail->expire_time = expire_time;
  10723. mail->postage_cost = 0;
  10724. mail->save_needed = 1;
  10725. mail->already_read = 0;
  10726. database.SavePlayerMail(mail);
  10727. GetPlayer()->AddMail(mail);
  10728. }
  10729. void Client::SendEquipOrInvUpdateBySlot(int8 slot)
  10730. {
  10731. if(slot < NUM_SLOTS)
  10732. {
  10733. EQ2Packet* app = GetPlayer()->GetEquipmentList()->serialize(GetVersion(), GetPlayer());
  10734. if (app)
  10735. QueuePacket(app);
  10736. }
  10737. else
  10738. {
  10739. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  10740. if (outapp)
  10741. QueuePacket(outapp);
  10742. }
  10743. }
  10744. void Client::QueueStateCommand(int32 spawn_player_id, int32 state)
  10745. {
  10746. if(spawn_player_id < 1)
  10747. return;
  10748. MQueueStateCmds.writelock();
  10749. queued_state_commands.insert(make_pair(spawn_player_id, state));
  10750. MQueueStateCmds.releasewritelock();
  10751. }
  10752. void Client::ProcessStateCommands()
  10753. {
  10754. if(!IsReadyForUpdates())
  10755. return;
  10756. MQueueStateCmds.writelock();
  10757. map<int32, int32>::iterator itr = queued_state_commands.begin();
  10758. for(; itr != queued_state_commands.end(); itr++)
  10759. ClientPacketFunctions::SendStateCommand(this, itr->first, itr->second);
  10760. queued_state_commands.clear();
  10761. MQueueStateCmds.releasewritelock();
  10762. }
  10763. void Client::PurgeItem(Item* item)
  10764. {
  10765. std::unique_lock lock(MConversation);
  10766. map<int32, Item*>::iterator itr;
  10767. for(itr = conversation_items.begin(); itr != conversation_items.end(); itr++)
  10768. {
  10769. if ( itr->second == item )
  10770. {
  10771. conversation_items.erase(itr);
  10772. break;
  10773. }
  10774. }
  10775. }
  10776. void Client::ConsumeFoodDrink(Item* item, int32 slot)
  10777. {
  10778. if(GetPlayer()->StopSaveSpellEffects())
  10779. return;
  10780. if(item) {
  10781. LogWrite(MISC__INFO, 1, "Command", "ItemID: %u, ItemName: %s ItemCount: %i ", item->details.item_id, item->name.c_str(), item->details.count);
  10782. if(item->GetItemScript() && lua_interface){
  10783. lua_interface->RunItemScript(item->GetItemScript(), "cast", item, GetPlayer());
  10784. if (slot == 22)
  10785. Message(CHANNEL_NARRATIVE, "You eat a %s.", item->name.c_str());
  10786. else
  10787. Message(CHANNEL_NARRATIVE, "You drink a %s.", item->name.c_str());
  10788. }
  10789. if (item->details.count > 1) {
  10790. item->details.count -= 1;
  10791. item->save_needed = true;
  10792. }
  10793. else {
  10794. database.DeleteItem(GetPlayer()->GetCharacterID(), item, "EQUIPPED");
  10795. GetPlayer()->GetEquipmentList()->RemoveItem(slot, true);
  10796. }
  10797. GetPlayer()->SetCharSheetChanged(true);
  10798. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  10799. }
  10800. }
  10801. void Client::AwardCoins(int64 total_coins, std::string reason)
  10802. {
  10803. if (total_coins > 0) {
  10804. player->AddCoins(total_coins);
  10805. PlaySound("coin_cha_ching");
  10806. char tmp[64] = { 0 };
  10807. string message = "You receive ";
  10808. int32 val = 0;
  10809. if (total_coins >= 1000000) {
  10810. val = total_coins / 1000000;
  10811. total_coins -= 1000000 * val;
  10812. sprintf(tmp, "%u Platinum ", val);
  10813. message.append(tmp);
  10814. memset(tmp, 0, 64);
  10815. }
  10816. if (total_coins >= 10000) {
  10817. val = total_coins / 10000;
  10818. total_coins -= 10000 * val;
  10819. sprintf(tmp, "%u Gold ", val);
  10820. message.append(tmp);
  10821. memset(tmp, 0, 64);
  10822. }
  10823. if (total_coins >= 100) {
  10824. val = total_coins / 100;
  10825. total_coins -= 100 * val;
  10826. sprintf(tmp, "%u Silver ", val);
  10827. message.append(tmp);
  10828. memset(tmp, 0, 64);
  10829. }
  10830. if (total_coins > 0) {
  10831. sprintf(tmp, "%u Copper ", (int32)total_coins);
  10832. message.append(tmp);
  10833. }
  10834. message.append(reason);
  10835. int8 type = CHANNEL_LOOT;
  10836. SimpleMessage(type, message.c_str());
  10837. }
  10838. }
  10839. void Client::TriggerSpellSave()
  10840. {
  10841. int32 interval = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateWaitInterval)->GetInt32();
  10842. // default to not have some bogus value in the rule
  10843. if(interval < 1)
  10844. interval = 100;
  10845. MSaveSpellStateMutex.lock();
  10846. if(!save_spell_state_timer.Enabled())
  10847. {
  10848. save_spell_state_time_bucket = 0;
  10849. save_spell_state_timer.Start(interval, true);
  10850. }
  10851. else
  10852. {
  10853. int32 elapsed_time = save_spell_state_timer.GetElapsedTime();
  10854. save_spell_state_time_bucket += elapsed_time;
  10855. int32 save_wait_cap = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateCap)->GetInt32();
  10856. // default to not have some bogus value in the rule
  10857. if(save_wait_cap < interval)
  10858. save_wait_cap = interval+1;
  10859. if(save_spell_state_time_bucket >= save_wait_cap)
  10860. {
  10861. save_spell_state_timer.Trigger();
  10862. }
  10863. }
  10864. MSaveSpellStateMutex.unlock();
  10865. }
  10866. void Client::UpdateSentSpellList() {
  10867. MSpellDetails.readlock(__FUNCTION__, __LINE__);
  10868. std::map<int32, int32>::iterator itr;
  10869. for(itr = sent_spell_details.begin(); itr != sent_spell_details.end(); itr++) {
  10870. Spell* spell = master_spell_list.GetSpell(itr->first, itr->second);
  10871. EQ2Packet* app = spell->SerializeSpell(this, false, false);
  10872. QueuePacket(app);
  10873. }
  10874. MSpellDetails.releasereadlock(__FUNCTION__, __LINE__);
  10875. }
  10876. void Client::SetTempPlacementSpawn(Spawn* tmp) {
  10877. tempPlacementSpawn = tmp;
  10878. hasSentTempPlacementSpawn = false;
  10879. if(tempPlacementSpawn)
  10880. temp_placement_timer.Start();
  10881. else
  10882. temp_placement_timer.Disable();
  10883. }
  10884. void Client::SetPlayer(Player* new_player) {
  10885. if (player && player != new_player)
  10886. zone_list.RemoveClientFromMap(player->GetName(), this);
  10887. player = new_player;
  10888. player->SetClient(this);
  10889. }
  10890. bool Client::UseItem(Item* item, Spawn* target) {
  10891. if (item && item->GetItemScript()) {
  10892. int16 item_index = item->details.index;
  10893. if(!item->CheckFlag2(INDESTRUCTABLE) && item->generic_info.condition == 0) {
  10894. SimpleMessage(CHANNEL_COLOR_RED, "This item is broken and must be repaired at a mender before it can be used");
  10895. }
  10896. else if (item->CheckFlag(EVIL_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_EVIL) {
  10897. Message(0, "%s requires an evil race.", item->name.c_str());
  10898. }
  10899. else if (item->CheckFlag(GOOD_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_GOOD) {
  10900. Message(0, "%s requires a good race.", item->name.c_str());
  10901. }
  10902. else if (item->generic_info.max_charges == 0 || item->generic_info.max_charges == 0xFFFF) {
  10903. lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target);
  10904. return true;
  10905. }
  10906. else {
  10907. if (item->details.count > 0) {
  10908. std::string itemName = string(item->name);
  10909. int32 item_id = item->details.item_id;
  10910. sint64 flags = 0;
  10911. if(lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target, &flags) && flags >= 0)
  10912. {
  10913. //reobtain item make sure it wasn't removed
  10914. item = player->item_list.GetItemFromIndex(item_index);
  10915. if(!item) {
  10916. LogWrite(PLAYER__WARNING, 0, "Command", "%s: Item %s (%i) was used, however after the item looks to be removed.", GetPlayer()->GetName(), itemName.c_str(), item_id);
  10917. return true;
  10918. }
  10919. else if(!item->generic_info.display_charges && item->generic_info.max_charges == 1) {
  10920. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  10921. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  10922. return true;
  10923. }
  10924. else
  10925. {
  10926. item->details.count--; // charges
  10927. item->save_needed = true;
  10928. QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  10929. if(!item->details.count) {
  10930. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  10931. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  10932. }
  10933. return true;
  10934. }
  10935. }
  10936. else {
  10937. LogWrite(PLAYER__WARNING, 0, "Command", "%s: Item %s (%i) was used, after it returned %i, bypassing any removal/update of items.", GetPlayer()->GetName(), itemName.c_str(), item_id, flags);
  10938. return true;
  10939. }
  10940. }
  10941. else
  10942. {
  10943. //reobtain item make sure it wasn't removed
  10944. item = player->item_list.GetItemFromIndex(item_index);
  10945. SimpleMessage(CHANNEL_COLOR_YELLOW, "Item is out of charges.");
  10946. if(item) {
  10947. LogWrite(PLAYER__ERROR, 0, "Command", "%s: Item %s (%i) attempted to be used, however details.count is 0.", GetPlayer()->GetName(), item->name.c_str(), item->details.item_id);
  10948. }
  10949. }
  10950. }
  10951. }
  10952. return false;
  10953. }
  10954. void Client::SendPlayFlavor(Spawn* spawn, int8 language, VoiceOverStruct* non_garble,
  10955. VoiceOverStruct* garble, bool success, bool garble_success) {
  10956. VoiceOverStruct* resStruct = nullptr;
  10957. if(language == 0 || GetPlayer()->HasLanguage(language)) {
  10958. if(success) {
  10959. resStruct = non_garble;
  10960. }
  10961. }
  10962. else if(garble_success) {
  10963. resStruct = garble;
  10964. }
  10965. if(resStruct) {
  10966. GetPlayer()->GetZone()->PlayFlavor(this, spawn, resStruct->mp3_string.c_str(), resStruct->text_string.c_str(), resStruct->emote_string.c_str(), resStruct->key1, resStruct->key2, language);
  10967. }
  10968. }
  10969. void Client::SaveQuestRewardData(bool force_refresh) {
  10970. Query query;
  10971. if(force_refresh) {
  10972. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_rewards where char_id = %u",
  10973. GetCharacterID());
  10974. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_temporary_rewards where char_id = %u",
  10975. GetCharacterID());
  10976. }
  10977. vector<QuestRewardData*>::iterator itr;
  10978. vector<QuestRewardData*> tmp_quest_rewards;
  10979. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  10980. int index = 0;
  10981. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  10982. int32 questID = (*itr)->quest_id;
  10983. if(!(*itr)->db_saved || force_refresh) {
  10984. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_rewards (char_id, indexed, quest_id, is_temporary, is_collection, has_displayed, tmp_coin, tmp_status, description) values(%u, %u, %u, %u, %u, %u, %llu, %u, '%s')",
  10985. GetCharacterID(), index, questID, (*itr)->is_temporary, (*itr)->is_collection, (*itr)->has_displayed, (*itr)->tmp_coin, (*itr)->tmp_status, database.getSafeEscapeString((*itr)->description.c_str()).c_str());
  10986. (*itr)->db_saved = true;
  10987. (*itr)->db_index = index;
  10988. if(questID && (*itr)->is_temporary) {
  10989. std::vector<Item*> items;
  10990. GetPlayer()->GetQuestTemporaryRewards(questID, &items);
  10991. if(!force_refresh && items.size() > 0) {
  10992. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "delete from character_quest_temporary_rewards where char_id = %u and quest_id = %u",
  10993. GetCharacterID(), questID);
  10994. }
  10995. for(int i=0;i<items.size();i++) {
  10996. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_temporary_rewards (char_id, quest_id, item_id, count) values(%u, %u, %u, %u)",
  10997. GetCharacterID(), questID, items[i]->details.item_id, items[i]->details.count);
  10998. }
  10999. }
  11000. }
  11001. index++;
  11002. }
  11003. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  11004. }
  11005. void Client::UpdateCharacterRewardData(QuestRewardData* data) {
  11006. if(!data)
  11007. return;
  11008. if(data->db_saved) {
  11009. Query query;
  11010. query.AddQueryAsync(GetCharacterID(), &database, Q_INSERT, "update character_quest_rewards set is_temporary = %u, is_collection = %u, has_displayed = %u, tmp_coin = %llu, tmp_status = %u, description = '%s' where char_id=%u and indexed=%u and quest_id=%u",
  11011. data->is_temporary, data->is_collection, data->has_displayed, data->tmp_coin, data->tmp_status, database.getSafeEscapeString(data->description.c_str()).c_str(), GetCharacterID(), data->db_index, data->quest_id);
  11012. }
  11013. }
  11014. void Client::AddRecipeToPlayerPack(Recipe* recipe, PacketStruct* packet, int16* i) {
  11015. int index = 0;
  11016. if(recipe == nullptr)
  11017. return;
  11018. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  11019. if (prl->GetRecipe(recipe->GetID())) {
  11020. delete recipe;
  11021. return;
  11022. }
  11023. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11024. if (res != devices.end())
  11025. index = res - devices.begin();
  11026. else
  11027. devices.push_back(recipe->GetDevice());
  11028. prl->AddRecipe(recipe);
  11029. database.SavePlayerRecipe(GetPlayer(), recipe->GetID());
  11030. Message(CHANNEL_NARRATIVE, "Recipe: \"%s\" put in recipe book.", recipe->GetName());
  11031. if (packet && GetRecipeListSent()) {
  11032. packet->setArrayDataByName("id", recipe->GetID(), *i);
  11033. packet->setArrayDataByName("tier", recipe->GetTier(), *i);
  11034. packet->setArrayDataByName("level", recipe->GetLevel(), *i);
  11035. packet->setArrayDataByName("icon", recipe->GetIcon(), *i);
  11036. packet->setArrayDataByName("classes", recipe->GetClasses(), *i);
  11037. //packet->setArrayDataByName("skill", recipe->GetSkill(), *i);
  11038. packet->setArrayDataByName("technique", recipe->GetTechnique(), *i);
  11039. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), *i);
  11040. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11041. if (recipe_device != devices.end())
  11042. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), *i);
  11043. else
  11044. {//TODO error should never get here
  11045. }
  11046. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), *i);
  11047. packet->setArrayDataByName("recipe_name", recipe->GetName(), *i);
  11048. packet->setArrayDataByName("recipe_book", recipe->GetBook(), *i);
  11049. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), *i);
  11050. if(i) {
  11051. (*i)++;
  11052. }
  11053. }
  11054. }
  11055. bool Client::SetPlayerPOVGhost(Spawn* spawn) {
  11056. if(!spawn) {
  11057. pov_ghost_spawn_id = 0;
  11058. SendCharPOVGhost();
  11059. return true;
  11060. }
  11061. int32 ghost_id = player->GetIDWithPlayerSpawn(spawn);
  11062. if(ghost_id) {
  11063. pov_ghost_spawn_id = spawn->GetID();
  11064. SendCharPOVGhost();
  11065. return true;
  11066. }
  11067. return false;
  11068. }
  11069. void Client::HandleDialogSelectMsg(int32 conversation_id, int32 response_index) {
  11070. std::string conversation = "";
  11071. bool conv_established = false;
  11072. MConversation.lock_shared();
  11073. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  11074. conversation = std::string(conversation_map[conversation_id][response_index].c_str());
  11075. conv_established = true;
  11076. }
  11077. int32 spawn_id = conversation_spawns[conversation_id];
  11078. Item* item = conversation_items[conversation_id];
  11079. MConversation.unlock_shared();
  11080. if (GetCurrentZone()) {
  11081. Spawn* spawn = nullptr;
  11082. if(spawn_id) {
  11083. spawn = GetCurrentZone()->GetSpawnByID(spawn_id);
  11084. }
  11085. if (conv_established) {
  11086. if (spawn) {
  11087. if(conversation == "CloseItemConversation") {
  11088. LogWrite(LUA__ERROR, 0, "LUA", "CloseItemConversation is an invalid function call for this conversation with spawn id %u", spawn_id);
  11089. }
  11090. else {
  11091. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation.c_str());
  11092. }
  11093. }
  11094. else if (item && lua_interface && item->GetItemScript())
  11095. lua_interface->RunItemScript(item->GetItemScript(), conversation.c_str(), item, player);
  11096. else
  11097. CloseDialog(conversation_id);
  11098. }
  11099. else
  11100. CloseDialog(conversation_id);
  11101. }
  11102. }
  11103. bool Client::SetPetName(const char* petName) {
  11104. int8 result = database.CheckNameFilter(petName,4,31);
  11105. if (result == BADNAMELENGTH_REPLY) {
  11106. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name length is invalid, must be greater then 3 characters and less then 31.");
  11107. return false;
  11108. }
  11109. else if (result == NAMEINVALID_REPLY) {
  11110. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is invalid, can only contain letters.");
  11111. return false;
  11112. }
  11113. else if (result == NAMETAKEN_REPLY) {
  11114. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is already taken, please choose another.");
  11115. return false;
  11116. }
  11117. else if (result == NAMEFILTER_REPLY) {
  11118. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name failed the filter check.");
  11119. return false;
  11120. }
  11121. else if (result == UNKNOWNERROR_REPLY) {
  11122. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unknown error while checking the name.");
  11123. return false;
  11124. }
  11125. GetPlayer()->GetInfoStruct()->set_pet_name(petName);
  11126. return true;
  11127. }
  11128. bool Client::CheckConsumptionAllowed(int16 slot, bool send_message) {
  11129. switch(slot) {
  11130. case EQ2_FOOD_SLOT: {
  11131. if(GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_FOOD)) {
  11132. if(send_message) {
  11133. Message(CHANNEL_NARRATIVE, "If you ate anymore you would explode!");
  11134. }
  11135. return false;
  11136. }
  11137. break;
  11138. }
  11139. case EQ2_DRINK_SLOT: {
  11140. if (GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_DRINK))
  11141. {
  11142. if(send_message) {
  11143. Message(CHANNEL_NARRATIVE, "If you drank anymore you would explode!");
  11144. }
  11145. return false;
  11146. }
  11147. break;
  11148. }
  11149. default: {
  11150. return false;
  11151. break;
  11152. }
  11153. }
  11154. return true;
  11155. }
  11156. void Client::StartLinkdeadTimer() {
  11157. if(!linkdead_timer) {
  11158. int32 LD_Timer = rule_manager.GetGlobalRule(R_World, LinkDeadTimer)->GetInt32();
  11159. LogWrite(CCLIENT__DEBUG, 0, "Client", "Starting linkdead timer for %s (timer %u seconds)", GetPlayer()->GetName(), (LD_Timer/1000));
  11160. linkdead_timer = new Timer(LD_Timer);
  11161. linkdead_timer->Enable();
  11162. if(GetPlayer()->GetGroupMemberInfo()) {
  11163. LogWrite(CCLIENT__DEBUG, 0, "Client", "Telling player %s group they are disconnecting", GetPlayer()->GetName());
  11164. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has gone Linkdead.", GetPlayer()->GetName());
  11165. }
  11166. }
  11167. }
  11168. bool Client::IsLinkdeadTimerEnabled() {
  11169. if(linkdead_timer) {
  11170. return linkdead_timer->Enabled();
  11171. }
  11172. return false;
  11173. }
  11174. void Client::SendNewAdventureSpells() {
  11175. SendNewSpells(player->GetAdventureClass());
  11176. int8 base_class = classes.GetBaseClass(player->GetAdventureClass());
  11177. int secondary_class = classes.GetSecondaryBaseClass(player->GetAdventureClass());
  11178. if(base_class != player->GetAdventureClass()) {
  11179. SendNewSpells(base_class);
  11180. }
  11181. if(secondary_class != player->GetAdventureClass() && secondary_class != base_class) {
  11182. SendNewSpells(secondary_class);
  11183. }
  11184. }
  11185. void Client::SendNewTradeskillSpells() {
  11186. SendNewTSSpells(player->GetTradeskillClass());
  11187. int8 secondary_class = classes.GetSecondaryTSBaseClass(player->GetTradeskillClass());
  11188. if(secondary_class != player->GetTradeskillClass()) {
  11189. SendNewTSSpells(secondary_class);
  11190. }
  11191. }
  11192. bool Client::AddRecipeBookToPlayer(int32 recipe_book_id, Item* item) {
  11193. Recipe* master_recipe = master_recipebook_list.GetRecipeBooks(recipe_book_id);
  11194. if(master_recipe) {
  11195. Recipe* recipe_book = new Recipe(master_recipe);
  11196. // if valid recipe book and the player doesn't have it
  11197. if (recipe_book && recipe_book->GetLevel() > GetPlayer()->GetTSLevel()) {
  11198. if(item) {
  11199. Message(CHANNEL_NARRATIVE, "Your tradeskill level is not high enough to scribe this book.");
  11200. }
  11201. safe_delete(recipe_book);
  11202. }
  11203. else if(recipe_book && item && !recipe_book->CanUseRecipeByClass(item, GetPlayer()->GetTradeskillClass())) {
  11204. if(item) {
  11205. Message(CHANNEL_NARRATIVE, "Your tradeskill class cannot use this recipe.");
  11206. }
  11207. safe_delete(recipe_book);
  11208. }
  11209. else if (recipe_book && (!item || !(GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)))){
  11210. LogWrite(PLAYER__DEBUG, 0, "Recipe", "Valid recipe book that the player doesn't have");
  11211. // Add recipe book to the players list
  11212. if(!GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)) {
  11213. GetPlayer()->GetRecipeBookList()->AddRecipeBook(recipe_book);
  11214. }
  11215. std::vector<Recipe*> recipes;
  11216. // Get a list of all recipes this book contains
  11217. if (item && item->recipebook_info) {
  11218. //Backup I guess if the recipe book is empty for whatever reason?
  11219. for (auto& itr : item->recipebook_info->recipes) {
  11220. Recipe* r = master_recipe_list.GetRecipeByCRC(itr); //GetRecipeByName(itr.c_str());
  11221. if (r) {
  11222. recipes.push_back(r);
  11223. }
  11224. }
  11225. LogWrite(PLAYER__DEBUG, 0, "Recipe", "%i recipes found for %s book", recipes.size(), recipe_book->GetBookName());
  11226. }
  11227. else {
  11228. LogWrite(PLAYER__ERROR, 0, "Recipe", "no recipes found for %s book", recipe_book->GetBookName());
  11229. }
  11230. //Filter out duplicate recipes the player already has
  11231. for (auto itr = recipes.begin(); itr != recipes.end();) {
  11232. Recipe* recipe = *itr;
  11233. if (GetPlayer()->GetRecipeList()->GetRecipe(recipe->GetID())) {
  11234. itr = recipes.erase(itr);
  11235. }
  11236. else itr++;
  11237. }
  11238. int16 i = 0;
  11239. // Create the packet to send to update the players recipe list
  11240. PacketStruct* packet = 0;
  11241. if (!recipes.empty() && GetRecipeListSent()) {
  11242. packet = configReader.getStruct("WS_RecipeList", GetVersion());
  11243. if (packet) {
  11244. packet->setArrayLengthByName("num_recipes", recipes.size());
  11245. }
  11246. }
  11247. for (int32 r = 0; r < recipes.size(); r++) {
  11248. Recipe* recipe = recipes[r];
  11249. if (recipe) {
  11250. Recipe* player_recipe = new Recipe(recipe);
  11251. AddRecipeToPlayerPack(player_recipe, packet, &i);
  11252. }
  11253. }
  11254. LogWrite(TRADESKILL__DEBUG, 0, "Recipe", "Done adding recipes");
  11255. database.SavePlayerRecipeBook(GetPlayer(), recipe_book->GetBookID());
  11256. if(item) {
  11257. database.DeleteItem(GetCharacterID(), item, 0);
  11258. GetPlayer()->item_list.RemoveItem(item, true);
  11259. }
  11260. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  11261. SetRecipeListSent(false);
  11262. SendRecipeList();
  11263. safe_delete(packet);
  11264. return true;
  11265. }
  11266. else {
  11267. if (recipe_book && item) {
  11268. Message(CHANNEL_NARRATIVE, "You have already learned all you can from this item.");
  11269. }
  11270. safe_delete(recipe_book);
  11271. }
  11272. }
  11273. else {
  11274. LogWrite(PLAYER__ERROR, 0, "Player", "%u recipe book id does not exist. Cannot AddRecipeToPlayer.", recipe_book_id);
  11275. }
  11276. return false;
  11277. }
  11278. bool Client::RemoveRecipeFromPlayer(int32 recipe_id) {
  11279. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  11280. PacketStruct* packet = configReader.getStruct("WS_RecipeList", version);
  11281. Recipe* recipe = prl->GetRecipe(recipe_id);
  11282. int8 level = player->GetTSLevel();
  11283. if(packet && recipe) {
  11284. packet->setDataByName("command_type", 1);
  11285. packet->setArrayLengthByName("num_recipes", 1);
  11286. int32 myid = recipe->GetID();
  11287. int8 rlevel = recipe->GetLevel();
  11288. int8 even = level - level * .05 + .5;
  11289. int8 easymin = level - level * .25 + .5;
  11290. int8 veasymin = level - level * .35 + .5;
  11291. if (rlevel > level )
  11292. packet->setArrayDataByName("tier", 4, 0);
  11293. else if ((rlevel <= level) & (rlevel >= even))
  11294. packet->setArrayDataByName("tier", 3, 0);
  11295. else if ((rlevel <= even) & (rlevel >= easymin))
  11296. packet->setArrayDataByName("tier", 2, 0);
  11297. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  11298. packet->setArrayDataByName("tier", 1, 0);
  11299. else if ((rlevel <= veasymin) & (rlevel >= 0))
  11300. packet->setArrayDataByName("tier", 0, 0);
  11301. if (rlevel == 2)
  11302. int xxx = 1;
  11303. packet->setArrayDataByName("recipe_id", myid, 0);
  11304. packet->setArrayDataByName("level", recipe->GetLevel(), 0);
  11305. packet->setArrayDataByName("unknown1", recipe->GetLevel(), 0);
  11306. packet->setArrayDataByName("icon", recipe->GetIcon(), 0);
  11307. packet->setArrayDataByName("classes", recipe->GetClasses(), 0);
  11308. packet->setArrayDataByName("technique", recipe->GetTechnique(), 0);
  11309. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), 0);
  11310. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11311. if (recipe_device != devices.end())
  11312. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), 0);
  11313. else
  11314. {//TODO error should never get here
  11315. }
  11316. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), 0);
  11317. packet->setArrayDataByName("recipe_name", recipe->GetName(), 0);
  11318. packet->setArrayDataByName("recipe_book", recipe->GetBook(), 0);
  11319. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), 0);
  11320. QueuePacket(packet->serialize());
  11321. }
  11322. safe_delete(packet);
  11323. bool res = prl->RemoveRecipe(recipe_id);
  11324. if(res) {
  11325. Query query;
  11326. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "DELETE FROM character_recipes where char_id=%u and recipe_id=%u", GetCharacterID(), recipe_id);
  11327. }
  11328. return res;
  11329. }
  11330. void Client::SaveSpells() {
  11331. MSaveSpellStateMutex.lock();
  11332. player->SaveSpellEffects();
  11333. player->SetSaveSpellEffects(true);
  11334. MSaveSpellStateMutex.unlock();
  11335. }
  11336. void Client::SendReplaceWidget(int32 widget_id, bool delete_widget, float x, float y, float z, int32 grid_id) {
  11337. Widget* new_spawn = new Widget();
  11338. new_spawn->SetWidgetID(widget_id);
  11339. new_spawn->SetLocation(grid_id);
  11340. new_spawn->SetWidgetX(x);
  11341. new_spawn->SetWidgetY(y);
  11342. new_spawn->SetWidgetZ(z);
  11343. new_spawn->SetX(x);
  11344. new_spawn->SetY(y);
  11345. new_spawn->SetZ(z);
  11346. EQ2Packet* ret = new_spawn->serialize(GetPlayer(), GetVersion());
  11347. QueuePacket(ret);
  11348. // we have to delete spawn* references anyway, we don't keep this widget live in the spawn list
  11349. GetPlayer()->RemoveSpawn(new_spawn, delete_widget);
  11350. safe_delete(new_spawn);
  11351. }
  11352. void Client::ProcessZoneIgnoreWidgets() {
  11353. GetPlayer()->MIgnoredWidgets.lock_shared();
  11354. std::map<int32, bool>::iterator itr;
  11355. for(itr = GetPlayer()->ignored_widgets.begin(); itr != GetPlayer()->ignored_widgets.end(); itr++) {
  11356. SendReplaceWidget(itr->first, true);
  11357. }
  11358. GetPlayer()->MIgnoredWidgets.unlock_shared();
  11359. }
  11360. void Client::PopulateRecipeData(Recipe* recipe, PacketStruct* packet, int i) {
  11361. if(!recipe || !packet)
  11362. return;
  11363. int8 level = player->GetTSLevel();
  11364. int32 myid = recipe->GetID();
  11365. int8 rlevel = recipe->GetLevel();
  11366. int8 even = level - level * .05 + .5;
  11367. int8 easymin = level - level * .25 + .5;
  11368. int8 veasymin = level - level * .35 + .5;
  11369. if (rlevel > level )
  11370. packet->setArrayDataByName("tier", 4, i);
  11371. else if ((rlevel <= level) & (rlevel >= even))
  11372. packet->setArrayDataByName("tier", 3, i);
  11373. else if ((rlevel <= even) & (rlevel >= easymin))
  11374. packet->setArrayDataByName("tier", 2, i);
  11375. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  11376. packet->setArrayDataByName("tier", 1, i);
  11377. else if ((rlevel <= veasymin) & (rlevel >= 0))
  11378. packet->setArrayDataByName("tier", 0, i);
  11379. if (rlevel == 2)
  11380. int xxx = 1;
  11381. packet->setArrayDataByName("recipe_id", myid, i);
  11382. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  11383. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  11384. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  11385. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  11386. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  11387. packet->setArrayDataByName("device", recipe->GetDevice(), i);
  11388. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  11389. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  11390. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  11391. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  11392. packet->setArrayDataByName("book_volume", 0x01, i);
  11393. packet->setArrayDataByName("device_id", 0x01, i);
  11394. }
  11395. int32 Client::GetRecipeCRC(Recipe* recipe) {
  11396. PacketStruct* packet = 0;
  11397. if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
  11398. return 0;
  11399. }
  11400. packet->setArrayLengthByName("num_recipes", 1);
  11401. PopulateRecipeData(recipe, packet);
  11402. string* generic_string_data = packet->serializeString();
  11403. int32 size = generic_string_data->length();
  11404. if(size < 5)
  11405. return 0;
  11406. uchar* out_data = new uchar[size+1];
  11407. uchar* out_ptr = out_data;
  11408. memcpy(out_ptr, (uchar*)generic_string_data->c_str()+4, generic_string_data->length()-4);
  11409. uint32 out_crc = GenerateCRCRecipe(0, (void*)out_ptr, size-4);
  11410. safe_delete(packet);
  11411. safe_delete_array(out_data);
  11412. return out_crc;
  11413. }
  11414. void Client::SendRecipeDetails(vector<int32>* recipes) {
  11415. if(!recipes || recipes->size() == 0)
  11416. return;
  11417. PacketStruct* packet = 0;
  11418. if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
  11419. return;
  11420. }
  11421. int32 recipe_size = player->GetRecipeList()->Size();
  11422. packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
  11423. int16 i = 0;
  11424. int32 count = 0;
  11425. vector<int32>::iterator recipe_itr;
  11426. for(recipe_itr = recipes->begin(); recipe_itr != recipes->end(); recipe_itr++) {
  11427. Recipe* recipe = player->GetRecipeList()->GetRecipe(*recipe_itr);
  11428. if(!recipe) {
  11429. continue;
  11430. }
  11431. else if(i > 99) {
  11432. QueuePacket(packet->serialize());
  11433. safe_delete(packet);
  11434. packet = configReader.getStruct("WS_RecipeDetailList", GetVersion());
  11435. recipe_size -= i;
  11436. packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
  11437. i = 0;
  11438. }
  11439. count++;
  11440. PopulateRecipeData(recipe, packet, i);
  11441. i++;
  11442. }
  11443. //packet->PrintPacket();
  11444. QueuePacket(packet->serialize());
  11445. safe_delete(packet);
  11446. }
  11447. ZoneServer* Client::GetHouseZoneServer(int32 spawn_id, int64 house_id) {
  11448. PlayerHouse* ph = nullptr;
  11449. HouseZone* hz = nullptr;
  11450. if(spawn_id) {
  11451. Spawn* houseWidget = GetPlayer()->GetSpawnByIndex(spawn_id);
  11452. if(houseWidget && houseWidget->IsWidget() && ((Widget*)houseWidget)->GetHouseID()) {
  11453. hz = world.GetHouseZone(((Widget*)houseWidget)->GetHouseID());
  11454. if (hz) {
  11455. ph = world.GetPlayerHouseByHouseID(GetPlayer()->GetCharacterID(), hz->id);
  11456. } else {
  11457. Message(CHANNEL_COLOR_YELLOW, "HouseWidget spawn index %u house zone could not be found.", spawn_id);
  11458. }
  11459. }
  11460. }
  11461. if(!ph && house_id) {
  11462. ph = world.GetPlayerHouseByUniqueID(house_id);
  11463. if (ph) {
  11464. hz = world.GetHouseZone(ph->house_id);
  11465. }
  11466. }
  11467. if (ph && hz) {
  11468. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id, false, true);
  11469. return house;
  11470. }
  11471. return nullptr;
  11472. }
  11473. void Client::SendHearCast(Spawn* caster, Spawn* target, int32 spell_visual, int16 cast_time) {
  11474. PacketStruct* packet = configReader.getStruct("WS_HearCastSpell", GetVersion());
  11475. if (packet) {
  11476. int32 caster_id = GetPlayer()->GetIDWithPlayerSpawn(caster);
  11477. int32 target_id = GetPlayer()->GetIDWithPlayerSpawn(target);
  11478. packet->setDataByName("spawn_id", caster_id);
  11479. packet->setArrayLengthByName("num_targets", 1);
  11480. packet->setArrayDataByName("target", target_id);
  11481. packet->setDataByName("num_targets", 1);
  11482. int32 visual = GetSpellVisualOverride(spell_visual);
  11483. packet->setDataByName("spell_visual", visual); //result
  11484. packet->setDataByName("cast_time", cast_time*.01f); //delay
  11485. packet->setDataByName("spell_id", 1);
  11486. packet->setDataByName("spell_level", 1);
  11487. packet->setDataByName("spell_tier", 1);
  11488. EQ2Packet* outapp = packet->serialize();
  11489. DumpPacket(outapp);
  11490. QueuePacket(outapp);
  11491. safe_delete(packet);
  11492. }
  11493. }
  11494. int32 Client::GetSpellVisualOverride(int32 spell_visual) {
  11495. int32 visual = spell_visual;
  11496. if(GetVersion() <= 546) { // spell's spell_visual field is based on newer clients, DoF has to convert
  11497. Emote* spellVisualEmote = visual_states.FindSpellVisualByID(visual, 60085);
  11498. if(spellVisualEmote != nullptr && spellVisualEmote->GetMessageString().size() > 0) {
  11499. spellVisualEmote = visual_states.FindSpellVisual(spellVisualEmote->GetMessageString(), GetVersion());
  11500. if(spellVisualEmote) {
  11501. visual = (int32)spellVisualEmote->GetVisualState();
  11502. }
  11503. }
  11504. }
  11505. return visual;
  11506. }