9
3

client.cpp 471 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140
  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. player_pos_timer = Timer::GetCurrentTime2()+1000;
  149. enabled_player_pos_timer = true;
  150. ++numclients;
  151. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  152. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  153. remove_from_list = false;
  154. new_client_login = NewLoginState::LOGIN_NONE;
  155. UpdateWindowTitle(0);
  156. num_active_failures = 0;
  157. player = new Player();
  158. player->SetClient(this);
  159. combine_spawn = 0;
  160. lua_debug = false;
  161. ready_for_spawns = false;
  162. ready_for_updates = false;
  163. lua_debug_timer.Disable();
  164. transport_spawn = 0;
  165. MBuyBack.SetName("Client::MBuyBack");
  166. MDeletePlayer.SetName("Client::MDeletePlayer");
  167. MQuestPendingUpdates.SetName("Client::MQuestPendingUpdates");
  168. search_items = 0;
  169. version = 0;
  170. next_conversation_id = 0;
  171. pending_guild_invite.guild = 0;
  172. pending_guild_invite.invited_by = 0;
  173. m_recipeListSent = false;
  174. m_resurrect.SetName("Client::m_resurrect");
  175. current_rez.expire_timer = 0;
  176. current_rez.should_delete = true;
  177. pending_last_name = 0;
  178. should_target = false;
  179. initial_spawns_sent = false;
  180. MQuestTimers.SetName("Client::quest_timers");
  181. memset(&incoming_paperdoll, 0, sizeof(incoming_paperdoll));
  182. on_auto_mount = false;
  183. should_load_spells = true;
  184. spawnPlacementMode = ServerSpawnPlacementMode::DEFAULT;
  185. delayedLogin = false;
  186. delayedAccountID = 0;
  187. delayedAccessKey = 0;
  188. delayTimer.Disable();
  189. tempPlacementSpawn = nullptr;
  190. placement_unique_item_id = 0;
  191. SetHasOwnerOrEditAccess(false);
  192. temporary_transport_id = 0;
  193. rejoin_group_id = 0;
  194. lastRegionRemapTime = 0;
  195. regionDebugMessaging = false;
  196. client_reloading_zone = false;
  197. last_saved_timestamp = 0;
  198. MQueueStateCmds.SetName("Client::MQueueStateCmds");
  199. save_spell_state_timer.Disable();
  200. save_spell_state_time_bucket = 0;
  201. player_loading_complete = false;
  202. MItemDetails.SetName("Client::MItemDetails");
  203. MSpellDetails.SetName("Client::MSpellDetails");
  204. hasSentTempPlacementSpawn = false;
  205. spawn_removal_timer.Start();
  206. disable_save = false;
  207. SetZoningDestination(nullptr);
  208. underworld_cooldown_timer.Disable();
  209. player_pos_change_count = 0;
  210. pov_ghost_spawn_id = 0;
  211. recipe_orig_packet = nullptr;
  212. recipe_xor_packet = nullptr;
  213. recipe_packet_count = 0;
  214. recipe_orig_packet_size = 0;
  215. }
  216. Client::~Client() {
  217. RemoveClientFromZone();
  218. //let the stream factory know were done with this stream
  219. if (eqs) {
  220. eqs->Close();
  221. try {
  222. eqs->ReleaseFromUse();
  223. }
  224. catch (...) {}
  225. }
  226. eqs = NULL;
  227. //safe_delete(autobootup_timeout);
  228. safe_delete(linkdead_timer);
  229. vector<QueuedQuest*>::iterator itr;
  230. QueuedQuest* queued_quest = 0;
  231. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  232. queued_quest = *itr;
  233. safe_delete(queued_quest);
  234. }
  235. quest_queue.clear();
  236. vector<QuestRewardData*>::iterator rwd_itr;
  237. QuestRewardData* quest_rwd_data = 0;
  238. for (rwd_itr = quest_pending_reward.begin(); rwd_itr != quest_pending_reward.end(); rwd_itr++) {
  239. quest_rwd_data = *rwd_itr;
  240. safe_delete(quest_rwd_data);
  241. }
  242. quest_pending_reward.clear();
  243. safe_delete(CLE_keepalive_timer);
  244. safe_delete(connect);
  245. --numclients;
  246. UpdateWindowTitle(0);
  247. }
  248. void Client::RemoveClientFromZone() {
  249. if(player && player->GetZone())
  250. player->GetZone()->GetSpellProcess()->RemoveSpellTimersFromSpawn(player, true, false, true, true);
  251. if (GetTempPlacementSpawn() && GetCurrentZone()) {
  252. Spawn* tmp = GetTempPlacementSpawn();
  253. SetTempPlacementSpawn(nullptr);
  254. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  255. }
  256. if (current_zone && player) {
  257. if (player->GetGroupMemberInfo()) {
  258. TempRemoveGroup();
  259. }
  260. world.GetGroupManager()->ClearPendingInvite(player);
  261. }
  262. if (lua_interface)
  263. lua_interface->RemoveDebugClients(this);
  264. if (player)
  265. zone_list.RemoveClientFromMap(player->GetName(), this);
  266. safe_delete(camp_timer);
  267. safe_delete(search_items);
  268. safe_delete(current_rez.expire_timer);
  269. safe_delete(pending_last_name);
  270. safe_delete_array(incoming_paperdoll.image_bytes);
  271. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  272. player = nullptr;
  273. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  274. deque<BuyBackItem*>::iterator itr;
  275. MBuyBack.writelock(__FUNCTION__, __LINE__);
  276. for (itr = buy_back_items.begin(); itr != buy_back_items.end();) {
  277. safe_delete(*itr);
  278. itr = buy_back_items.erase(itr);
  279. }
  280. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  281. }
  282. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  283. if (eqs) {
  284. if (!eqs->CheckActive()) {
  285. client_list.Remove(this);
  286. eqs = 0;
  287. }
  288. }
  289. if (app && eqs && version > 0)
  290. eqs->EQ2QueuePacket(app, attemptedCombine);
  291. else {
  292. safe_delete(app);
  293. }
  294. }
  295. void Client::PopulateSkillMap() {
  296. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  297. if (app)
  298. QueuePacket(app);
  299. else {
  300. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  301. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  302. }
  303. }
  304. void Client::SendLoginInfo() {
  305. if(GetPlayer()->IsReturningFromLD())
  306. firstlogin = true;
  307. if (firstlogin) {
  308. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  309. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  310. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  311. PopulateSkillMap();
  312. // 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!
  313. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  314. }
  315. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  316. database.ToggleCharacterOnline(this, 1);
  317. int32 count = 0;
  318. if(!GetPlayer()->IsReturningFromLD())
  319. {
  320. count = database.LoadCharacterTitles(GetCharacterID(), player);
  321. if (count == 0) {
  322. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  323. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  324. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  325. }
  326. }
  327. if(!GetPlayer()->IsReturningFromLD())
  328. {
  329. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  330. if (count == 0)
  331. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  332. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  333. if (count == 0)
  334. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  335. }
  336. ClientPacketFunctions::SendLoginAccepted(this);
  337. ClientPacketFunctions::SendAbilities ( this );
  338. ClientPacketFunctions::SendCommandNamePacket(this);
  339. ClientPacketFunctions::SendQuickBarInit(this);
  340. // we only need to send the MOTD if it is the first time the person is logging in.
  341. if (firstlogin) {
  342. ClientPacketFunctions::SendMOTD(this);
  343. ClientPacketFunctions::SendCharacterMacros(this);
  344. zone_list.CheckFriendList(this);
  345. }
  346. if(!GetPlayer()->IsReturningFromLD())
  347. {
  348. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  349. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  350. {
  351. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  352. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  353. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  354. }
  355. GetPlayer()->item_list.SetMaxItemIndex();
  356. database.LoadPlayerFactions(this);
  357. database.LoadCharacterQuests(this);
  358. database.LoadCharacterQuestRewards(this);
  359. database.LoadPlayerMail(this);
  360. }
  361. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  362. SendQuestJournal(true, 0, false);
  363. if (version > 561) // right version? possibly not!
  364. master_aa_list.DisplayAA(this, 0, 3);
  365. if (version > 373)
  366. SendCollectionList();
  367. SendBiography();
  368. map<int32, Quest*>::iterator itr;
  369. Quest* quest = 0;
  370. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  371. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  372. quest = itr->second;
  373. if (quest->IsTracked()) {
  374. quest->SetTracked(false);
  375. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  376. quest->SetTracked(true);
  377. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  378. }
  379. }
  380. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  381. // SendAchievementsList();
  382. /*Guild* guild = player->GetGuild();
  383. if (guild) {
  384. guild->UpdateGuildMemberInfo(GetPlayer());
  385. if (firstlogin)
  386. guild->SendGuildMOTD(this);
  387. guild->SendGuildUpdate(this);
  388. guild->SendGuildMember(GetPlayer(), firstlogin);
  389. guild->SendGuildEventList(this);
  390. guild->SendGuildBankEventList(this);
  391. guild->SendAllGuildEvents(this);
  392. guild->SendGuildMemberList(this);
  393. }*/
  394. if (version > 373) {
  395. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  396. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  397. if (outapp) {
  398. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  399. //DumpPacket(outapp);
  400. QueuePacket(outapp);
  401. }
  402. }
  403. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  404. ClientPacketFunctions::SendCommandList(this);
  405. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  406. // kos doesn't like one of these language or instance list
  407. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  408. //ClientPacketFunctions::SendInstanceList(this);
  409. SendZoneInfo();
  410. /*Spell* spell = 0;
  411. vector<QuickBarItem*>::iterator itr;
  412. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  413. if((*itr)->type == 1){
  414. spell = master_spell_list.GetSpell((*itr)->id);
  415. if(spell)
  416. QueuePacket(spell->serialize(this, false, 0x20));
  417. }
  418. }*/
  419. }
  420. void Client::SendPlayerDeathWindow()
  421. {
  422. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  423. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  424. vector<RevivePoint*>::iterator itr;
  425. if (results && results->size() > 0)
  426. {
  427. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  428. if (packet)
  429. {
  430. packet->setArrayLengthByName("location_count", results->size());
  431. RevivePoint* point = 0;
  432. int32 i = 0;
  433. for (itr = results->begin(); itr != results->end(); itr++, i++)
  434. {
  435. point = *itr;
  436. if (point)
  437. {
  438. packet->setArrayDataByName("location_id", point->id, i);
  439. //zone_name = database.GetZoneName(point->zone_id);
  440. string zone_name = database.GetZoneDescription(point->zone_id);
  441. if (zone_name.length() > 0)
  442. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  443. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  444. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  445. }
  446. if (point->id == 0xFFFFFFFF)//tmp location
  447. safe_delete(point);
  448. }
  449. #if EQDEBUG >= 3
  450. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  451. packet->PrintPacket();
  452. #endif
  453. EQ2Packet* outapp = packet->serialize();
  454. QueuePacket(outapp);
  455. safe_delete(packet);
  456. }
  457. // done with the revive points so lets free up the pointer
  458. safe_delete(results);
  459. }
  460. }
  461. void Client::DisplayDeadWindow()
  462. {
  463. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  464. player->SetHP(0);
  465. player->SetPower(0);
  466. GetCurrentZone()->TriggerCharSheetTimer();
  467. if(GetVersion() <= 561) {
  468. ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 1);
  469. ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 1);
  470. }
  471. else {
  472. ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 1);
  473. ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 1);
  474. }
  475. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  476. if (packet)
  477. {
  478. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  479. QueuePacket(packet->serialize());
  480. safe_delete(packet);
  481. }
  482. SendPlayerDeathWindow();
  483. }
  484. void Client::HandlePlayerRevive(int32 point_id)
  485. {
  486. if(GetVersion() <= 561) {
  487. ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 0);
  488. ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 0);
  489. }
  490. else {
  491. ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 0);
  492. ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 0);
  493. }
  494. SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
  495. PacketStruct* packet = configReader.getStruct("WS_Resurrected", GetVersion());
  496. if (packet)
  497. {
  498. QueuePacket(packet->serialize());
  499. safe_delete(packet);
  500. }
  501. float origX, origY, origZ, origHeading = 0.0f;
  502. origX = player->GetX();
  503. origY = player->GetY();
  504. origZ = player->GetZ();
  505. origHeading = player->GetHeading();
  506. ZoneServer* originalZone = GetCurrentZone();
  507. int32 origGridID = GetPlayer()->GetLocation();
  508. float x, y, z, heading;
  509. RevivePoint* revive_point = 0;
  510. if (point_id != 0xFFFFFFFF)
  511. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  512. string zone_desc;
  513. const char* location_name = "Unknown";
  514. player->SetAlive(true);
  515. player->SetResurrecting(true);
  516. player->SetHP(player->GetTotalHP());
  517. player->SetPower(player->GetTotalPower());
  518. //revive at zone safe coords
  519. if (!revive_point)
  520. {
  521. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  522. x = GetCurrentZone()->GetSafeX();
  523. y = GetCurrentZone()->GetSafeY();
  524. z = GetCurrentZone()->GetSafeZ();
  525. heading = GetCurrentZone()->GetSafeHeading();
  526. zone_desc = GetCurrentZone()->GetZoneDescription();
  527. location_name = "Zone Safe Point";
  528. Zone(GetCurrentZone()->GetZoneName(), false);
  529. }
  530. else
  531. {
  532. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  533. x = revive_point->x;
  534. y = revive_point->y;
  535. z = revive_point->z;
  536. heading = revive_point->heading;
  537. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  538. location_name = revive_point->location_name.c_str();
  539. Zone(GetCurrentZone()->GetZoneName(), false);
  540. }
  541. player->SetX(x);
  542. player->SetY(y);
  543. player->SetZ(z);
  544. player->SetHeading(heading);
  545. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  546. zone_desc.c_str(),
  547. player->GetX(),
  548. player->GetY(),
  549. player->GetZ(),
  550. player->GetHeading(),
  551. player->GetHP(),
  552. player->GetPower(),
  553. location_name);
  554. //player->ClearEverything();
  555. Save();
  556. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  557. {
  558. string zone_name = database.GetZoneName(revive_point->zone_id);
  559. if (zone_name.length() == 0)
  560. {
  561. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  562. x = GetCurrentZone()->GetSafeX();
  563. y = GetCurrentZone()->GetSafeY();
  564. z = GetCurrentZone()->GetSafeZ();
  565. heading = GetCurrentZone()->GetSafeHeading();
  566. location_name = "Zone Safe Point";
  567. }
  568. else
  569. {
  570. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  571. location_name = revive_point->location_name.c_str();
  572. //player->ClearEverything();
  573. Save();
  574. Zone(zone_name.c_str(), false);
  575. }
  576. }
  577. zone_desc = GetCurrentZone()->GetZoneDescription();
  578. Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  579. player->SetSpawnType(4);
  580. if (version > 373) {
  581. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  582. if (packet)
  583. {
  584. QueuePacket(packet->serialize());
  585. safe_delete(packet);
  586. }
  587. }
  588. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  589. if (packet)
  590. {
  591. packet->setDataByName("x", x);
  592. packet->setDataByName("y", y);
  593. packet->setDataByName("z", z);
  594. QueuePacket(packet->serialize());
  595. safe_delete(packet);
  596. }
  597. SendControlGhost();
  598. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  599. if (packet)
  600. {
  601. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  602. QueuePacket(packet->serialize());
  603. safe_delete(packet);
  604. }
  605. if(rule_manager.GetGlobalRule(R_Combat, EnableSpiritShards)->GetBool())
  606. {
  607. NPC* shard = player->InstantiateSpiritShard(origX, origY, origZ, origHeading, origGridID, originalZone);
  608. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  609. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_PRESPAWN);
  610. originalZone->RemoveSpawn(player, false, true, true, true, true);
  611. originalZone->AddSpawn(shard);
  612. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  613. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_SPAWN);
  614. }
  615. m_resurrect.writelock(__FUNCTION__, __LINE__);
  616. if (current_rez.active)
  617. current_rez.should_delete = true;
  618. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  619. }
  620. void Client::SendControlGhost(int32 send_id, int8 unknown2) {
  621. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  622. if (packet) {
  623. packet->setDataByName("spawn_id", send_id);
  624. packet->setDataByName("speed", GetPlayer()->GetSpeed());
  625. packet->setDataByName("size", 0.51);
  626. packet->setDataByName("unknown2", unknown2);
  627. packet->setDataByName("air_speed", player->GetAirSpeed());
  628. EQ2Packet* app = packet->serialize();
  629. QueuePacket(app);
  630. safe_delete(packet);
  631. }
  632. }
  633. void Client::SendCharInfo() {
  634. EQ2Packet* app;
  635. player->SetEquippedItemAppearances();
  636. ClientPacketFunctions::SendCharacterData(this);
  637. SendCharPOVGhost();
  638. SendControlGhost(player->GetIDWithPlayerSpawn(player), 255);
  639. //sending bad spawn packet?
  640. //SendAchievementsList();
  641. //if (version > 561)
  642. //ClientPacketFunctions::SendHousingList(this);
  643. ClientPacketFunctions::SendCharacterSheet(this);
  644. ClientPacketFunctions::SendTraitList(this);// moved from below
  645. ClientPacketFunctions::SendAbilities(this);
  646. ClientPacketFunctions::SendSkillBook(this);
  647. if (!IsReloadingZone() && !player->IsResurrecting() && GetVersion() >= 546) {
  648. ClientPacketFunctions::SendUpdateSpellBook(this);
  649. }
  650. else {
  651. player->SetResurrecting(false);
  652. }
  653. GetCurrentZone()->AddSpawn(player);
  654. if(IsReloadingZone() && (zoning_x || zoning_y || zoning_z)) {
  655. GetPlayer()->SetX(zoning_x);
  656. GetPlayer()->SetY(zoning_y);
  657. GetPlayer()->SetZ(zoning_z);
  658. GetPlayer()->SetHeading(zoning_h);
  659. EQ2Packet* packet = GetPlayer()->Move(zoning_x, zoning_y, zoning_z, GetVersion(), zoning_h);
  660. QueuePacket(packet);
  661. }
  662. //SendCollectionList();
  663. Guild* guild = player->GetGuild();
  664. if (guild)
  665. guild->GuildMemberLogin(this, firstlogin);
  666. app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  667. if (app) {
  668. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  669. //DumpPacket(app);
  670. QueuePacket(app);
  671. }
  672. app = player->GetEquipmentList()->serialize(GetVersion(), player);
  673. if (app) {
  674. QueuePacket(app);
  675. }
  676. app = player->GetAppearanceEquipmentList()->serialize(GetVersion(), player);
  677. if (app) {
  678. QueuePacket(app);
  679. }
  680. vector<Item*>* items = player->GetPlayerItemList()->GetItemsFromBagID(-3); // bank items
  681. if (items && items->size() > 0) {
  682. for (int32 i = 0; i < items->size(); i++) {
  683. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  684. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  685. //DumpPacket(outapp);
  686. QueuePacket(outapp);
  687. }
  688. }
  689. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  690. QueuePacket(app);
  691. safe_delete(items);
  692. items = player->GetPlayerItemList()->GetItemsFromBagID(-4); //shared bank items
  693. if (items && items->size() > 0) {
  694. for (int32 i = 0; i < items->size(); i++)
  695. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  696. }
  697. safe_delete(items);
  698. if (version >= 373) {
  699. SendTitleUpdate();
  700. }
  701. GetPlayer()->UpdateWeapons();
  702. if(!GetPlayer()->IsReturningFromLD()) {
  703. database.LoadBuyBacks(this);
  704. }
  705. if (version > 561)
  706. master_aa_list.DisplayAA(this, 0, 0);
  707. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  708. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  709. string zone_motd_send = "Zone MOTD: " + zone_motd;
  710. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  711. }
  712. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  713. if (zone_script && lua_interface)
  714. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  715. this->client_zoning = false;
  716. this->zoning_id = 0;
  717. this->zoning_instance_id = 0;
  718. SetZoningDestination(nullptr);
  719. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  720. GetCurrentZone()->AddDamagedSpawn(player);
  721. if (firstlogin)
  722. firstlogin = false;
  723. player->ClearProcs();
  724. items = player->GetEquippedItemList();
  725. if (items && items->size() > 0) {
  726. for (int32 i = 0; i < items->size(); i++) {
  727. Item* item = items->at(i);
  728. if (item && item->GetItemScript() && lua_interface)
  729. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  730. }
  731. }
  732. //Allow this player to change their last name if they meet the level requirement
  733. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  734. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  735. safe_delete(items);
  736. if (!player->Alive())
  737. DisplayDeadWindow();
  738. ClientPacketFunctions::SendLocalizedTextMessage(this);
  739. if (GetCurrentZone()->GetInstanceID())
  740. {
  741. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  742. if (ph) {
  743. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  744. string name = string(GetPlayer()->GetName());
  745. if (name.compare(ph->player_name) == 0)
  746. SetHasOwnerOrEditAccess(true);
  747. }
  748. }
  749. bool groupMentor = false;
  750. GetPlayer()->group_id = rejoin_group_id;
  751. if(!world.RejoinGroup(this, rejoin_group_id))
  752. GetPlayer()->group_id = 0;
  753. else
  754. {
  755. Entity* ent = world.GetGroupManager()->IsPlayerInGroup(rejoin_group_id, GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id);
  756. if(ent && ent->IsPlayer())
  757. {
  758. GetPlayer()->SetMentorStats(ent->GetLevel(), ent->GetID(), false);
  759. groupMentor = true;
  760. }
  761. }
  762. if(!groupMentor)
  763. GetPlayer()->SetMentorStats(GetPlayer()->GetLevel(), 0, false);
  764. if(!GetPlayer()->IsReturningFromLD()) {
  765. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_MAINTAINEDEFFECTS);
  766. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_SPELLEFFECTS);
  767. }
  768. else {
  769. Spawn* pet_spawn = nullptr;
  770. if(GetPlayer()->GetPet())
  771. pet_spawn = GetPlayer()->GetPet();
  772. else if(GetPlayer()->GetCharmedPet())
  773. pet_spawn = GetPlayer()->GetCharmedPet();
  774. else if(GetPlayer()->GetCosmeticPet())
  775. pet_spawn = GetPlayer()->GetCosmeticPet();
  776. else if(GetPlayer()->GetDeityPet())
  777. pet_spawn = GetPlayer()->GetDeityPet();
  778. if(pet_spawn) {
  779. GetPlayer()->GetInfoStruct()->set_pet_id(GetPlayer()->GetIDWithPlayerSpawn(pet_spawn));
  780. }
  781. }
  782. GetPlayer()->SetSaveSpellEffects(false);
  783. GetPlayer()->SetCharSheetChanged(true);
  784. GetPlayer()->SetReturningFromLD(false);
  785. }
  786. void Client::SendZoneSpawns() {
  787. //Allows us to place spawns almost anywhere
  788. if (version > 373) {
  789. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  790. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  791. QueuePacket(app);
  792. }
  793. ClientPacketFunctions::SendSkillSlotMappings(this);
  794. ClientPacketFunctions::SendGameWorldTime(this);
  795. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  796. }
  797. void Client::SendCharPOVGhost() {
  798. bool use_ghost_pov = false;
  799. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  800. int32 ghost_id = 0;
  801. if (set_pov) {
  802. if(pov_ghost_spawn_id) {
  803. Spawn* spawn = GetCurrentZone()->GetSpawnByID(pov_ghost_spawn_id);
  804. ghost_id = player->GetIDWithPlayerSpawn(spawn);
  805. if(spawn) {
  806. use_ghost_pov = true;
  807. }
  808. }
  809. if(use_ghost_pov) {
  810. set_pov->setDataByName("spawn_id", ghost_id);
  811. }
  812. else {
  813. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  814. }
  815. EQ2Packet* app_pov = set_pov->serialize();
  816. QueuePacket(app_pov);
  817. safe_delete(set_pov);
  818. }
  819. }
  820. void Client::SendZoneInfo() {
  821. ZoneServer* zone = GetCurrentZone();
  822. if (zone) {
  823. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  824. QueuePacket(packet);
  825. if (version > 561) {
  826. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  827. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  828. #if EQDEBUG >= 9
  829. fog_packet->PrintPacket();
  830. #endif
  831. if (fog_packet) {
  832. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  833. QueuePacket(fog_packet->serialize());
  834. safe_delete(fog_packet);
  835. }
  836. zone->SendFlightPathsPackets(this);
  837. }
  838. }
  839. /*
  840. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  841. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  842. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  843. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  844. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  845. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,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,0x00,0x00
  873. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  874. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  875. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
  876. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  877. QueuePacket(appA);
  878. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  879. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  880. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  881. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  882. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  883. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  884. QueuePacket(appB);
  885. */
  886. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  887. SendFriendList();
  888. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  889. SendIgnoreList();
  890. }
  891. void Client::SendDefaultGroupOptions() {
  892. /*
  893. 0 - loot method
  894. 1 - loot items rarity
  895. 2 - Auto split coin
  896. 4 - default yell method
  897. 6 - group autolock
  898. 7 - solo autolock
  899. */
  900. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  901. if (default_options) {
  902. default_options->setDataByName("loot_method", GetPlayer()->GetInfoStruct()->get_group_loot_method());
  903. default_options->setDataByName("loot_items_rarity", GetPlayer()->GetInfoStruct()->get_group_loot_items_rarity());
  904. default_options->setDataByName("auto_split_coin", GetPlayer()->GetInfoStruct()->get_group_auto_split());
  905. default_options->setDataByName("default_yell_method", GetPlayer()->GetInfoStruct()->get_group_default_yell());
  906. default_options->setDataByName("group_autolock", GetPlayer()->GetInfoStruct()->get_group_autolock());
  907. default_options->setDataByName("default_group_lock_method", GetPlayer()->GetInfoStruct()->get_group_lock_method());
  908. if(GetVersion() > 561) {
  909. default_options->setDataByName("solo_autolock", GetPlayer()->GetInfoStruct()->get_group_solo_autolock());
  910. default_options->setDataByName("auto_loot_method", GetPlayer()->GetInfoStruct()->get_group_auto_loot_method());
  911. }
  912. EQ2Packet* app7 = default_options->serialize();
  913. QueuePacket(app7);
  914. safe_delete(default_options);
  915. }
  916. }
  917. bool Client::HandlePacket(EQApplicationPacket* app) {
  918. bool ret = true;
  919. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  920. //DumpPacket(app);
  921. #if EQDEBUG >= 9
  922. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  923. DumpPacket(app, true);
  924. #endif
  925. EmuOpcode opcode = app->GetOpcode();
  926. #if EQDEBUG >= 9
  927. const char* name = app->GetOpcodeName();
  928. if (name)
  929. cout << name;
  930. else
  931. cout << "Unknown";
  932. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  933. DumpPacket(app);
  934. #endif
  935. //if (opcode != OP_UpdatePositionMsg) {
  936. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  937. //}
  938. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  939. {
  940. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  941. }
  942. switch (opcode) {
  943. case _maxEmuOpcode:
  944. break;
  945. case OP_LoginByNumRequestMsg: {
  946. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  947. PacketStruct* request;
  948. request = configReader.getStruct("LoginByNumRequest", 1);
  949. if (request) {
  950. if(request->LoadPacketData(app->pBuffer, app->size)) {
  951. // test the original location of Version for clients older than 1212
  952. version = request->getType_int16_ByName("version");
  953. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  954. // must be new client data version method, re-fetch the packet
  955. safe_delete(request);
  956. request = configReader.getStruct("LoginByNumRequest", 1208);
  957. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  958. // Xinux suggests using an INT16 here. Our first new version = 57000
  959. version = request->getType_int16_ByName("version");
  960. }
  961. else {
  962. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  963. break;
  964. }
  965. }
  966. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  967. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  968. ClientPacketFunctions::SendLoginDenied(this);
  969. /* reset version and protect server from trying to send packets out to a bad client
  970. ** cause of Dec 6th/Dec 7th 2023 crash
  971. ** Client::MakeSpawnChangePacket
  972. ** int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd); <-- crashes pulling opcode with bad version
  973. */
  974. version = 546;
  975. ready_for_updates = false;
  976. ready_for_spawns = false;
  977. return false;
  978. }
  979. int32 account_id = request->getType_int32_ByName("account_id");
  980. int32 access_code = request->getType_int32_ByName("access_code");
  981. if (!HandleNewLogin(account_id, access_code))
  982. return false;
  983. }
  984. }
  985. safe_delete(request);
  986. break;
  987. }
  988. case OP_DefaultGroupOptionsMsg: {
  989. PacketStruct* packet = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  990. if (packet) {
  991. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  992. packet->PrintPacket();
  993. int8 loot_method = packet->getType_int8_ByName("loot_method");
  994. int8 loot_items_rarity = packet->getType_int8_ByName("loot_items_rarity");
  995. int8 auto_split_coin = packet->getType_int8_ByName("auto_split_coin");
  996. int8 default_yell_method = packet->getType_int8_ByName("default_yell_method");
  997. int8 autolock = packet->getType_int8_ByName("group_autolock");
  998. int8 group_lock_method = packet->getType_int8_ByName("default_group_lock_method");
  999. int8 solo_autolock = packet->getType_int8_ByName("solo_autolock");
  1000. int8 auto_loot_method = 0;
  1001. if (GetVersion() > 561) {
  1002. auto_loot_method = packet->getType_int8_ByName("auto_loot_method");
  1003. if (auto_loot_method > AutoLootMode::METHOD_DECLINE)
  1004. auto_loot_method = AutoLootMode::METHOD_DECLINE;
  1005. }
  1006. GetPlayer()->GetInfoStruct()->set_group_loot_method(loot_method);
  1007. GetPlayer()->GetInfoStruct()->set_group_loot_items_rarity(loot_items_rarity);
  1008. GetPlayer()->GetInfoStruct()->set_group_auto_split(auto_split_coin);
  1009. GetPlayer()->GetInfoStruct()->set_group_default_yell(default_yell_method);
  1010. GetPlayer()->GetInfoStruct()->set_group_autolock(autolock);
  1011. GetPlayer()->GetInfoStruct()->set_group_lock_method(group_lock_method);
  1012. GetPlayer()->GetInfoStruct()->set_group_solo_autolock(solo_autolock);
  1013. GetPlayer()->GetInfoStruct()->set_group_auto_loot_method(auto_loot_method);
  1014. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTMETHOD, (char*)std::to_string(loot_method).c_str());
  1015. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTITEMRARITY, (char*)std::to_string(loot_items_rarity).c_str());
  1016. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOSPLIT, (char*)std::to_string(auto_split_coin).c_str());
  1017. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPDEFAULTYELL, (char*)std::to_string(default_yell_method).c_str());
  1018. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOLOCK, (char*)std::to_string(autolock).c_str());
  1019. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOCKMETHOD, (char*)std::to_string(group_lock_method).c_str());
  1020. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPSOLOAUTOLOCK, (char*)std::to_string(solo_autolock).c_str());
  1021. database.insertCharacterProperty(this, CHAR_PROPERTY_AUTOLOOTMETHOD, (char*)std::to_string(auto_loot_method).c_str());
  1022. if (this->GetPlayer()->GetGroupMemberInfo() && this->GetPlayer()->GetGroupMemberInfo()->leader)
  1023. {
  1024. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  1025. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  1026. if (group)
  1027. {
  1028. GroupOptions goptions;
  1029. goptions.loot_method = loot_method;
  1030. goptions.loot_items_rarity = loot_items_rarity;
  1031. goptions.auto_split = auto_split_coin;
  1032. goptions.default_yell = default_yell_method;
  1033. goptions.group_autolock = autolock;
  1034. goptions.solo_autolock = solo_autolock;
  1035. goptions.auto_loot_method = auto_loot_method;
  1036. group->SetDefaultGroupOptions(&goptions);
  1037. }
  1038. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  1039. }
  1040. }
  1041. safe_delete(packet);
  1042. }
  1043. break;
  1044. }
  1045. case OP_MapRequest: {
  1046. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  1047. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  1048. if (packet && app->size > 2 && GetCurrentZone()) {
  1049. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1050. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  1051. if (fog_packet) {
  1052. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  1053. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  1054. fog_packet->setDataByName("unknown1", 1);
  1055. fog_packet->setDataByName("unknown3", 1);
  1056. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1057. //fog_packet->PrintPacket();
  1058. QueuePacket(fog_packet->serialize());
  1059. safe_delete(fog_packet);
  1060. }
  1061. }
  1062. safe_delete(packet);
  1063. }
  1064. break;
  1065. }
  1066. case OP_RequestCampMsg: {
  1067. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  1068. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  1069. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1070. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1071. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1072. request->getType_int8_ByName("quit"),
  1073. request->getType_int8_ByName("camp_desktop"),
  1074. request->getType_int16_ByName("camp_char_select"),
  1075. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1076. //DumpPacket(app->pBuffer, app->size);
  1077. //request->PrintPacket();
  1078. if (!camp_timer) {
  1079. int16 camp_time = 20; // default if rule cannot be found
  1080. if (GetAdminStatus() >= 100)
  1081. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  1082. else
  1083. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  1084. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  1085. if (response) {
  1086. bool disconnect = false;
  1087. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  1088. // Command: /camp desktop
  1089. // Command: /quit
  1090. response->setDataByName("camp_desktop", 1);
  1091. disconnect = true;
  1092. }
  1093. else {
  1094. // Command: /camp
  1095. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  1096. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  1097. response->setDataByName("seconds", camp_time);
  1098. }
  1099. camp_timer = new Timer(camp_time * 1000);
  1100. camp_timer->Enable();
  1101. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  1102. // /camp {char_name}
  1103. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  1104. }
  1105. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  1106. // /camp (go back to char selection screen)
  1107. response->setDataByName("char_name", " ");
  1108. response->setDataByName("camp_char_select", 1);
  1109. }
  1110. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1111. response->getType_int8_ByName("seconds"),
  1112. response->getType_int8_ByName("camp_desktop"),
  1113. response->getType_int8_ByName("camp_char_select"),
  1114. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1115. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  1116. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  1117. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  1118. //response->PrintPacket();
  1119. QueuePacket(response->serialize());
  1120. safe_delete(response);
  1121. if (disconnect)
  1122. Disconnect();
  1123. }
  1124. }
  1125. }
  1126. safe_delete(request);
  1127. break;
  1128. }
  1129. case OP_StoodMsg: {
  1130. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  1131. if (camp_timer)
  1132. {
  1133. // JA: clear camping flag
  1134. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1135. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1136. safe_delete(camp_timer);
  1137. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1138. QueuePacket(outapp);
  1139. }
  1140. player->SetTempVisualState(0);
  1141. break;
  1142. }
  1143. case OP_StandMsg: {
  1144. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  1145. if (camp_timer)
  1146. {
  1147. // JA: clear camping flag
  1148. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1149. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1150. safe_delete(camp_timer);
  1151. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1152. QueuePacket(outapp);
  1153. }
  1154. player->SetTempVisualState(539);
  1155. break;
  1156. }
  1157. case OP_SitMsg: {
  1158. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  1159. player->SetTempVisualState(538);
  1160. break;
  1161. }
  1162. case OP_SatMsg: {
  1163. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  1164. player->SetTempVisualState(540);
  1165. break;
  1166. }
  1167. case OP_QuestJournalOpenMsg:
  1168. case OP_QuestJournalInspectMsg: {
  1169. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  1170. if (app->size < sizeof(int32))
  1171. break;
  1172. int32 quest_id = 0;
  1173. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  1174. GetPlayer()->SendQuest(quest_id);
  1175. break;
  1176. }
  1177. case OP_QuestJournalSetVisibleMsg: {
  1178. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  1179. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  1180. if (packet) {
  1181. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1182. int32 quest_id = packet->getType_int32_ByName("quest_id");
  1183. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  1184. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  1185. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  1186. if (player_quests) {
  1187. if (player_quests->count(quest_id) > 0)
  1188. player_quests->at(quest_id)->SetHidden(hidden);
  1189. else
  1190. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1191. }
  1192. else
  1193. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1194. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  1195. }
  1196. safe_delete(packet);
  1197. }
  1198. break;
  1199. }
  1200. case OP_MacroUpdateMsg: {
  1201. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1202. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1203. if (macro_update) {
  1204. if(macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1205. vector<string>* update = new vector<string>;
  1206. int8 number = macro_update->getType_int8_ByName("number");
  1207. int16 icon = macro_update->getType_int16_ByName("icon");
  1208. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1209. int8 count = macro_update->getType_int8_ByName("macro_count");
  1210. if (GetVersion() <= 373) {
  1211. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1212. }
  1213. else {
  1214. for (int8 i = 0; i < count; i++) {
  1215. char tmp_command[15] = { 0 };
  1216. sprintf(tmp_command, "command_%i", i);
  1217. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1218. }
  1219. }
  1220. if (name.length() == 0)
  1221. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1222. else
  1223. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1224. safe_delete(update);
  1225. }
  1226. safe_delete(macro_update);
  1227. }
  1228. break;
  1229. }
  1230. case OP_DialogSelectMsg: {
  1231. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1232. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1233. if (packet) {
  1234. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1235. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1236. int32 response_index = packet->getType_int32_ByName("response");
  1237. HandleDialogSelectMsg(conversation_id, response_index);
  1238. }
  1239. }
  1240. safe_delete(packet);
  1241. break;
  1242. }
  1243. case OP_CancelMoveObjectModeMsg: {
  1244. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1245. if (GetTempPlacementSpawn())
  1246. {
  1247. Spawn* tmp = GetTempPlacementSpawn();
  1248. SetTempPlacementSpawn(nullptr);
  1249. SetPlacementUniqueItemID(0);
  1250. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  1251. break; // break out early if we are tied to a temp spawn
  1252. }
  1253. // if we are moving some other object? other use-cases not covered
  1254. break;
  1255. }
  1256. case OP_PositionMoveableObject: {
  1257. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1258. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1259. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1260. Spawn* spawn = 0;
  1261. if (GetTempPlacementSpawn())
  1262. spawn = GetTempPlacementSpawn();
  1263. else
  1264. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1265. if (!spawn) {
  1266. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1267. break;
  1268. }
  1269. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1270. {
  1271. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1272. break;
  1273. }
  1274. int32 uniqueID = spawn->GetPickupUniqueItemID();
  1275. if(uniqueID) {
  1276. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  1277. if(uniqueItem && uniqueItem->CheckFlag2(HOUSE_LORE) && GetCurrentZone()->HouseItemSpawnExists(uniqueItem->details.item_id)) {
  1278. Message(CHANNEL_COLOR_RED, "Item %s is house lore and you cannot place another.", uniqueItem->name.c_str());
  1279. break;
  1280. }
  1281. }
  1282. // handles instantiation logic + adding to zone of a new house object
  1283. PopulateHouseSpawn(place_object);
  1284. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1285. char query[256];
  1286. switch (GetSpawnPlacementMode())
  1287. {
  1288. case ServerSpawnPlacementMode::OPEN_HEADING:
  1289. {
  1290. if (spawn && spawn->IsWidget())
  1291. {
  1292. Widget* widget = (Widget*)spawn;
  1293. widget->SetOpenHeading(newHeading);
  1294. widget->SetIncludeHeading(true);
  1295. spawn->position_changed = true;
  1296. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1297. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1298. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1299. }
  1300. else
  1301. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1302. break;
  1303. }
  1304. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1305. {
  1306. if (spawn && spawn->IsWidget())
  1307. {
  1308. Widget* widget = (Widget*)spawn;
  1309. widget->SetClosedHeading(newHeading);
  1310. widget->SetIncludeHeading(true);
  1311. spawn->position_changed = true;
  1312. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1313. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1314. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1315. if (spawn->GetSpawnLocationID())
  1316. {
  1317. Query query;
  1318. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1319. }
  1320. }
  1321. else
  1322. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1323. break;
  1324. }
  1325. default:
  1326. {
  1327. spawn->SetX(place_object->getType_float_ByName("x"));
  1328. spawn->SetY(place_object->getType_float_ByName("y"));
  1329. spawn->SetZ(place_object->getType_float_ByName("z"));
  1330. spawn->SetHeading(newHeading);
  1331. spawn->SetSpawnOrigX(spawn->GetX());
  1332. spawn->SetSpawnOrigY(spawn->GetY());
  1333. spawn->SetSpawnOrigZ(spawn->GetZ());
  1334. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1335. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1336. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1337. else if (spawn->GetSpawnLocationID() > 0)
  1338. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1339. }
  1340. }
  1341. PopulateHouseSpawnFinalize();
  1342. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1343. }
  1344. safe_delete(place_object);
  1345. break;
  1346. }
  1347. case OP_CampAbortedMsg: {
  1348. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1349. if (camp_timer)
  1350. {
  1351. // JA: clear camping flag
  1352. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1353. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1354. safe_delete(camp_timer);
  1355. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1356. QueuePacket(outapp);
  1357. }
  1358. break;
  1359. }
  1360. case OP_DoneLoadingUIResourcesMsg: {
  1361. if(GetVersion() <= 561) {
  1362. ClientPacketFunctions::SendUpdateSpellBook(this);
  1363. }
  1364. // need to quickly flash the DoF client the rest of their inventory
  1365. if(GetVersion() <= 561) {
  1366. EQ2Packet* item_app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  1367. if (item_app) {
  1368. QueuePacket(item_app);
  1369. }
  1370. }
  1371. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1372. QueuePacket(app);
  1373. if(!player_loading_complete)
  1374. {
  1375. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  1376. if (zone_script && lua_interface)
  1377. lua_interface->RunZoneScript(zone_script, "player_loadcomplete", GetCurrentZone(), GetPlayer());
  1378. player_loading_complete = true;
  1379. }
  1380. break;
  1381. }
  1382. case OP_DoneLoadingZoneResourcesMsg: {
  1383. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1384. SendZoneSpawns();
  1385. break;
  1386. }
  1387. case OP_DefaultGroupOptionsRequestMsg: {
  1388. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1389. SendDefaultGroupOptions();
  1390. break;
  1391. }
  1392. case OP_DoneLoadingEntityResourcesMsg: {
  1393. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1394. if (!IsReadyForSpawns()) {
  1395. if(GetPlayer()->GetMap()) {
  1396. auto loc = glm::vec3(GetPlayer()->GetX(), GetPlayer()->GetZ(), GetPlayer()->GetY());
  1397. uint32 GridID = 0;
  1398. float new_z = GetPlayer()->FindBestZ(loc, nullptr, &GridID);
  1399. GetPlayer()->SetLocation(GridID);
  1400. }
  1401. SetReadyForSpawns(true);
  1402. }
  1403. player->CalculateApplyWeight();
  1404. SendCharInfo();
  1405. GetPlayer()->GetZone()->GetSpellProcess()->SendSpellBookUpdate(this);
  1406. pos_update.Start();
  1407. quest_pos_timer.Start();
  1408. break;
  1409. }
  1410. case OP_LootItemsRequestMsg: {
  1411. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1412. HandleLootItemRequestPacket(app);
  1413. break;
  1414. }
  1415. case OP_StoppedLootingMsg: {
  1416. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoppedLootingMsg", opcode, opcode);
  1417. if (app->size < sizeof(int32))
  1418. break;
  1419. int32 loot_id = 0;
  1420. memcpy(&loot_id, app->pBuffer, sizeof(int32));
  1421. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  1422. if(spawn) {
  1423. spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  1424. spawn->SetLooterSpawnID(0);
  1425. }
  1426. break;
  1427. }
  1428. case OP_WaypointSelectMsg: {
  1429. PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
  1430. if (packet) {
  1431. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1432. int32 selection = packet->getType_int32_ByName("selection");
  1433. if (selection > 0) {
  1434. SelectWaypoint(selection);
  1435. }
  1436. }
  1437. }
  1438. safe_delete(packet);
  1439. break;
  1440. }
  1441. case OP_KnowledgeWindowSlotMappingMsg: {
  1442. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1443. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1444. if (packet) {
  1445. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1446. int num_updates = packet->getType_int16_ByName("spell_count");
  1447. int32 spell_id = 0;
  1448. int16 slot_id = 0;
  1449. char tmp_spell_id[15];
  1450. char tmp_slot[15];
  1451. for (int i = 0; i < num_updates; i++) {
  1452. memset(tmp_spell_id, 0, 15);
  1453. memset(tmp_slot, 0, 15);
  1454. sprintf(tmp_spell_id, "spell_id_%i", i);
  1455. sprintf(tmp_slot, "slot_id_%i", i);
  1456. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1457. if (spell_id > 0) {
  1458. slot_id = packet->getType_int16_ByName(tmp_slot);
  1459. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1460. if (spell && spell->slot != slot_id) {
  1461. spell->slot = slot_id;
  1462. spell->save_needed = true;
  1463. }
  1464. }
  1465. }
  1466. }
  1467. safe_delete(packet);
  1468. }
  1469. //SendKnowledgeWindowSlot();
  1470. break;
  1471. }
  1472. case OP_ReadyToZoneMsg: {
  1473. if (!IsReadyForSpawns())
  1474. {
  1475. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1476. }
  1477. else
  1478. {
  1479. if(zoning_destination) {
  1480. SetCurrentZone(zoning_destination);
  1481. }
  1482. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1483. bool succeed_override_zone = true;
  1484. if(!GetCurrentZone()) {
  1485. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone and zone is not there! Emergency boot!", player->GetName());
  1486. if(zoning_instance_id) {
  1487. ZoneServer* zone = zone_list.GetByInstanceID(zoning_instance_id, zoning_id, true);
  1488. if(!zone) {
  1489. 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);
  1490. succeed_override_zone = false;
  1491. }
  1492. else {
  1493. SetCurrentZone(zone);
  1494. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique instance has been created for %s through emergency boot!", player->GetName());
  1495. }
  1496. }
  1497. else if(zoning_id) {
  1498. ZoneServer* zone = zone_list.Get(zoning_id, true, true);
  1499. if(!zone) {
  1500. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver zone id %u.", player->GetName(), zoning_id);
  1501. succeed_override_zone = false;
  1502. }
  1503. else {
  1504. SetCurrentZone(zone);
  1505. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique zone has been created for %s through emergency boot!", player->GetName());
  1506. }
  1507. }
  1508. }
  1509. if (client_zoning)
  1510. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1511. else
  1512. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1513. Disconnect();
  1514. }
  1515. break;
  1516. }
  1517. case OP_ClientFellMsg: {
  1518. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1519. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1520. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1521. float height = request->getType_float_ByName("height");
  1522. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1523. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1524. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1525. break;
  1526. }*/
  1527. float safe_height = 13.0f;
  1528. float safe_skill_with_bonus = GetPlayer()->CalculateSkillWithBonus("Safe Fall", ITEM_STAT_SAFE_FALL, true);
  1529. if (safe_skill_with_bonus > 0.0f)
  1530. safe_height += (1 + safe_skill_with_bonus) / 5;
  1531. if (height > safe_height) {
  1532. int16 damage = (int16)ceil((height - safe_height) * 125);
  1533. if (height >= 80)
  1534. damage = 30000;
  1535. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1536. if (damage > 0) {
  1537. GetPlayer()->TakeDamage(damage);
  1538. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1539. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1540. if (!GetPlayer()->GetInvulnerable())
  1541. GetPlayer()->SetCharSheetChanged(true);
  1542. 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);
  1543. if (GetPlayer()->GetHP() == 0) {
  1544. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1545. }
  1546. }
  1547. }
  1548. }
  1549. safe_delete(request);
  1550. break;
  1551. }
  1552. case OP_MapFogDataUpdateMsg: {
  1553. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1554. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1555. break;
  1556. }
  1557. case OP_SelectZoneTeleporterDestinatio: {
  1558. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1559. ProcessTeleportLocation(app);
  1560. break;
  1561. }
  1562. case OP_SendLatestRequestMsg: {
  1563. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1564. if(GetVersion() < 60085) {
  1565. // this does not exist in newer clients like AoM, confirmed to exist in DoF, other clients will need review at a later time
  1566. uchar blah25[] = { 0x01 };
  1567. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1568. QueuePacket(app25);
  1569. }
  1570. break;
  1571. }
  1572. case OP_RequestRecipeDetailsMsg: {
  1573. PacketStruct* packet = configReader.getStruct("WS_RequestRecipeDetail", GetVersion());
  1574. if (packet) {
  1575. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1576. vector<int32> recipes;
  1577. int32 recipe_id = 0;
  1578. char recipe_prop_name[30];
  1579. int32 num_recipes = packet->getType_int32_ByName("num_recipes");
  1580. // WS_RecipeDetails
  1581. for (int32 i = 0; i < num_recipes; i++) {
  1582. memset(recipe_prop_name, 0, 30);
  1583. snprintf(recipe_prop_name, 30, "recipe_id_%i", i);
  1584. recipe_id = packet->getType_int32_ByName(recipe_prop_name);
  1585. if(recipe_id > 0) {
  1586. recipes.push_back(recipe_id);
  1587. }
  1588. }
  1589. SendRecipeDetails(&recipes);
  1590. }
  1591. safe_delete(packet);
  1592. }
  1593. break;
  1594. }
  1595. case OP_ShowCreateFromRecipeUIMsg: {
  1596. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1597. break;
  1598. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1599. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1600. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1601. QueuePacket(app);
  1602. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1603. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1604. QueuePacket(app);
  1605. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1606. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1607. ,0xff,0xff,0xff};
  1608. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1609. QueuePacket(app);
  1610. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1611. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1612. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1613. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1614. QueuePacket(app);
  1615. uchar blah5[] ={0x00,0x00};
  1616. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1617. QueuePacket(app);
  1618. break;*/
  1619. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1620. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1621. //QueuePacket(app);
  1622. }
  1623. case OP_BeginItemCreationMsg: {
  1624. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1625. //DumpPacket(app->pBuffer, app->size);
  1626. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1627. if (packet) {
  1628. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1629. Recipe* recipe = master_recipe_list.GetRecipe(GetPlayer()->GetCurrentRecipe());
  1630. if(recipe) {
  1631. int32 item = 0;
  1632. int8 qty = 0;
  1633. vector<pair<int32, int16>> items;
  1634. char tmp_item_id[30];
  1635. if(GetVersion() > 1193) {
  1636. int8 num_primary_selected_items = packet->getType_int8_ByName("num_primary_selected_items");
  1637. for (int8 i = 0; i < num_primary_selected_items; i++) {
  1638. memset(tmp_item_id, 0, 30);
  1639. sprintf(tmp_item_id, "primary_selected_item_id_%i", i);
  1640. item = packet->getType_int32_ByName(tmp_item_id);
  1641. sprintf(tmp_item_id, "primary_selected_item_qty_%i", i);
  1642. qty = packet->getType_int16_ByName(tmp_item_id);
  1643. if (item > 0)
  1644. items.push_back(make_pair(item,qty));
  1645. item = 0;
  1646. }
  1647. }
  1648. else {
  1649. item = packet->getType_int32_ByName("primary_component_id");
  1650. qty = 1;
  1651. if (item > 0)
  1652. items.push_back(make_pair(item,qty));
  1653. }
  1654. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1655. if(GetVersion() > 1193) {
  1656. for (int8 i = 0; i < build_components; i++) {
  1657. memset(tmp_item_id, 0, 30);
  1658. sprintf(tmp_item_id, "num_selected_items_%i", i);
  1659. int8 num_selected_items = packet->getType_int8_ByName(tmp_item_id);
  1660. for (int8 j = 0; j < num_selected_items; j++) {
  1661. memset(tmp_item_id, 0, 30);
  1662. sprintf(tmp_item_id, "selected_id%i_%i", i,j);
  1663. item = packet->getType_int32_ByName(tmp_item_id);
  1664. sprintf(tmp_item_id, "selected_qty%i_%i", i, j);
  1665. qty = packet->getType_int16_ByName(tmp_item_id);
  1666. if (item > 0)
  1667. items.push_back(make_pair(item, qty));
  1668. item = 0;
  1669. }
  1670. }
  1671. }
  1672. else {
  1673. for (int8 i = 0; i < build_components; i++) {
  1674. memset(tmp_item_id, 0, 30);
  1675. sprintf(tmp_item_id, "component_id_%i", i);
  1676. int32 item = packet->getType_int32_ByName(tmp_item_id);
  1677. sprintf(tmp_item_id, "component_qty_%i", i);
  1678. qty = packet->getType_int32_ByName(tmp_item_id);
  1679. if (item > 0)
  1680. items.push_back(make_pair(item, qty));
  1681. }
  1682. }
  1683. if(GetVersion() > 1193) {
  1684. int8 num_fuel_items = packet->getType_int8_ByName("num_fuel_items");
  1685. for (int8 i = 0; i < num_fuel_items; i++) {
  1686. memset(tmp_item_id, 0, 30);
  1687. sprintf(tmp_item_id, "fuel_id_%i", i);
  1688. item = packet->getType_int32_ByName(tmp_item_id);
  1689. sprintf(tmp_item_id, "fuel_qty_%i", i);
  1690. qty = packet->getType_int16_ByName(tmp_item_id);
  1691. if (item > 0)
  1692. items.push_back(make_pair(item, qty));
  1693. item = 0;
  1694. }
  1695. }
  1696. else {
  1697. item = packet->getType_int32_ByName("fuel_id");
  1698. qty = packet->getType_int16_ByName("fuel_qty");
  1699. if (item > 0)
  1700. items.push_back(make_pair(item, qty));
  1701. }
  1702. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1703. }
  1704. else {
  1705. LogWrite(CCLIENT__ERROR, 0, "Client", "Client '%s' (%u) attempted to call OP_BeginItemCreationMsg, but with no recipe selected.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1706. }
  1707. }
  1708. safe_delete(packet);
  1709. }
  1710. break;
  1711. }
  1712. case OP_StopItemCreationMsg: {
  1713. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1714. //DumpPacket(app->pBuffer, app->size);
  1715. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1716. break;
  1717. }
  1718. case OP_SysClient:
  1719. case OP_SignalMsg: {
  1720. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient/OP_SignalMsg", opcode, opcode);
  1721. PacketStruct* packet = configReader.getStruct("WS_Signal", 1);
  1722. if (packet) {
  1723. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1724. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1725. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1726. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1727. SetReloadingZone(false);
  1728. if(GetPlayer()->IsDeletedSpawn()) {
  1729. GetPlayer()->SetDeletedSpawn(false);
  1730. }
  1731. ResetZoningCoords();
  1732. SetReadyForUpdates();
  1733. GetPlayer()->SendSpawnChanges(true);
  1734. ProcessStateCommands();
  1735. GetPlayer()->changed = true;
  1736. GetPlayer()->info_changed = true;
  1737. GetPlayer()->vis_changed = true;
  1738. player_pos_changed = true;
  1739. GetPlayer()->AddChangedZoneSpawn();
  1740. ProcessZoneIgnoreWidgets();
  1741. if (version <= 561) {
  1742. master_trait_list.ChooseNextTrait(this);
  1743. }
  1744. const char* zone_script = world.GetZoneScript(GetPlayer()->GetZone()->GetZoneID());
  1745. if (zone_script && lua_interface) {
  1746. lua_interface->RunZoneScript(zone_script, "enter_location", GetPlayer()->GetZone(), GetPlayer(), GetPlayer()->GetLocation());
  1747. }
  1748. if (GetPlayer()->GetHP() < GetPlayer()->GetTotalHP() || GetPlayer()->GetPower() < GetPlayer()->GetTotalPower())
  1749. GetCurrentZone()->AddDamagedSpawn(GetPlayer());
  1750. }
  1751. else {
  1752. LogWrite(CCLIENT__WARNING, 0, "Client", "Player %s reported SysClient/SignalMsg state %s.", GetPlayer()->GetName(), str.data.c_str());
  1753. }
  1754. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1755. if (zone_script && lua_interface)
  1756. {
  1757. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1758. }
  1759. }
  1760. safe_delete(packet);
  1761. }
  1762. break;
  1763. }
  1764. case OP_EntityVerbsRequestMsg: {
  1765. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1766. HandleVerbRequest(app);
  1767. break;
  1768. }
  1769. case OP_EntityVerbsVerbMsg: {
  1770. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1771. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1772. if (packet) {
  1773. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1774. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1775. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1776. Spawn* spawn = player->GetTarget();
  1777. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1778. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1779. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1780. {
  1781. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1782. if (spawn->IsGroundSpawn())
  1783. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1784. else if (spawn->IsObject())
  1785. ((Object*)spawn)->HandleUse(this, command);
  1786. else if (spawn->IsWidget())
  1787. ((Widget*)spawn)->HandleUse(this, command);
  1788. else if (spawn->IsSign())
  1789. ((Sign*)spawn)->HandleUse(this, command);
  1790. }
  1791. }
  1792. }
  1793. else {
  1794. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1795. if (command.size > 0) {
  1796. string command_name = command.data;
  1797. if (command_name.find(" ") < 0xFFFFFFFF) {
  1798. if (GetVersion() <= 561) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
  1799. string::size_type pos = command_name.find(" ");
  1800. while(pos != string::npos){
  1801. command_name.replace(pos, 1, "_");
  1802. pos = command_name.find(" ");
  1803. }
  1804. }
  1805. else
  1806. command_name = command_name.substr(0, command_name.find(" "));
  1807. }
  1808. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1809. if (handler != 0xFFFFFFFF) {
  1810. if (command.data == command_name) {
  1811. command.data = "";
  1812. command.size = 0;
  1813. }
  1814. else {
  1815. command.data = command.data.substr(command.data.find(" ") + 1);
  1816. command.size = command.data.length();
  1817. }
  1818. commands.Process(handler, &command, this);
  1819. }
  1820. else {
  1821. if (spawn && spawn->IsNPC()) {
  1822. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1823. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1824. command_name = command.data;
  1825. string::size_type pos = command_name.find(" ");
  1826. while (pos != string::npos) {
  1827. command_name.replace(pos, 1, "_");
  1828. pos = command_name.find(" ");
  1829. }
  1830. if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
  1831. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1832. }
  1833. }
  1834. }
  1835. }
  1836. else
  1837. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1838. }
  1839. }
  1840. }
  1841. }
  1842. safe_delete(packet);
  1843. }
  1844. break;
  1845. }
  1846. case OP_SkillInfoRequest: {
  1847. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1848. HandleSkillInfoRequest(app);
  1849. break;
  1850. }
  1851. case OP_UpdateTargetMsg: {
  1852. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1853. int16 index = 0;
  1854. memcpy(&index, app->pBuffer, sizeof(int16));
  1855. if (index == 0xFFFF)
  1856. GetPlayer()->SetTarget(0);
  1857. else {
  1858. Spawn* spawn = GetPlayer()->GetSpawnByIndex(index);
  1859. if(spawn)
  1860. GetPlayer()->SetTarget(spawn);
  1861. else {
  1862. LogWrite(PLAYER__ERROR, 1, "Player", "Player %s tried to target %u index, but that index was not valid.", GetPlayer()->GetName(), index);
  1863. }
  1864. }
  1865. if (GetPlayer()->GetTarget())
  1866. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1867. //player->SetTarget((int16*)app->pBuffer);
  1868. break;
  1869. }
  1870. case OP_ExamineInfoRequestMsg: {
  1871. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1872. HandleExamineInfoRequest(app);
  1873. break;
  1874. }
  1875. case OP_QuickbarUpdateMsg:
  1876. //case OP_QuickbarAddMsg:
  1877. {
  1878. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1879. HandleQuickbarUpdateRequest(app);
  1880. break;
  1881. }
  1882. case OP_PredictionUpdateMsg: {
  1883. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg from %s", opcode, opcode, GetPlayer()->GetName());
  1884. if (version <= 561) {
  1885. int8 offset = 9;
  1886. if (app->pBuffer[0] == 0xFF)
  1887. offset += 2;
  1888. if (app->size > offset) {
  1889. if (player->IsCasting()) {
  1890. float distance = 0;
  1891. float x = player->GetX();
  1892. float y = player->GetY();
  1893. float z = player->GetZ();
  1894. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1895. distance = player->GetDistance(x, y, z, false);
  1896. if (distance > .5)
  1897. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1898. }
  1899. else
  1900. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1901. player_pos_changed = true;
  1902. GetPlayer()->changed = true;
  1903. GetPlayer()->info_changed = true;
  1904. GetPlayer()->vis_changed = true;
  1905. GetPlayer()->AddChangedZoneSpawn();
  1906. //DumpPacket(app);
  1907. }
  1908. }
  1909. else {
  1910. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1911. QueuePacket(app);
  1912. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1913. }
  1914. break;
  1915. }
  1916. case OP_RemoteCmdMsg: {
  1917. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1918. if (app->size > 0) {
  1919. EQ2_CommandString remote(app->pBuffer, app->size);
  1920. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1921. #if EQDEBUG >= 9
  1922. DumpPacket(app);
  1923. #endif
  1924. commands.Process(remote.handler, &remote.command, this);
  1925. }
  1926. else //bad client, disconnect
  1927. Disconnect();
  1928. break;
  1929. }
  1930. case OP_CancelSpellCast: {
  1931. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1932. current_zone->Interrupted(player, 0, 0, true);
  1933. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1934. break;
  1935. }
  1936. case OP_UpdatePositionMsg: {
  1937. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg from %s", opcode, opcode, GetPlayer()->GetName());
  1938. int8 offset = 13;
  1939. if (app->pBuffer[0] == 0xFF)
  1940. offset += 2;
  1941. if (app->size > offset) {
  1942. if (player->IsCasting()) {
  1943. float distance = 0;
  1944. float x = player->GetX();
  1945. float y = player->GetY();
  1946. float z = player->GetZ();
  1947. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1948. distance = player->GetDistance(x, y, z, false);
  1949. if (distance > .5)
  1950. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1951. }
  1952. else
  1953. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1954. player_pos_changed = true;
  1955. GetPlayer()->changed = true;
  1956. GetPlayer()->info_changed = true;
  1957. GetPlayer()->vis_changed = true;
  1958. GetPlayer()->AddChangedZoneSpawn();
  1959. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1960. //DumpPacket(app);
  1961. }
  1962. break;
  1963. }
  1964. case OP_MailSendMessageMsg: {
  1965. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1966. HandleSentMail(app);
  1967. break;
  1968. }
  1969. case OP_StopTrackingMsg: {
  1970. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1971. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1972. break;
  1973. }
  1974. case OP_BeginTrackingMsg: {
  1975. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1976. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1977. if (packet) {
  1978. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1979. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1980. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1981. if (spawn) {
  1982. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1983. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1984. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1985. }
  1986. }
  1987. safe_delete(packet);
  1988. }
  1989. break;
  1990. }
  1991. case OP_BioUpdateMsg: {
  1992. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1993. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1994. if (packet) {
  1995. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1996. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1997. }
  1998. safe_delete(packet);
  1999. }
  2000. break;
  2001. }
  2002. case OP_RewardPackMsg: {
  2003. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  2004. /* 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
  2005. when we come across it (scatman) */
  2006. const char* name = app->GetOpcodeName();
  2007. if (name)
  2008. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  2009. else
  2010. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  2011. //DumpPacket(app);
  2012. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  2013. if (packet) {
  2014. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2015. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  2016. /* Player has contacted a guild recruiter */
  2017. if (recruiter_name.length() > 0) {
  2018. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  2019. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  2020. if (recruiter && guild) {
  2021. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  2022. 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()));
  2023. recruiter->PlaySound("ui_guild_page");
  2024. }
  2025. }
  2026. /* New picture taken for guild recruiting */
  2027. else {
  2028. //DumpPacket(app->pBuffer, app->size);
  2029. int32 guild_id = 0;
  2030. int16 picture_data_size = 0;
  2031. unsigned char* recruiter_picture_data = 0;
  2032. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  2033. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  2034. Guild* guild = guild_list.GetGuild(guild_id);
  2035. if (guild) {
  2036. GuildMember* gm = guild->GetGuildMember(player);
  2037. if (gm) {
  2038. safe_delete_array(gm->recruiter_picture_data);
  2039. recruiter_picture_data = new unsigned char[picture_data_size];
  2040. for (int16 i = 0; i < picture_data_size; i++)
  2041. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  2042. gm->recruiter_picture_data = recruiter_picture_data;
  2043. gm->recruiter_picture_data_size = picture_data_size;
  2044. guild->SetMemberSaveNeeded(true);
  2045. }
  2046. }
  2047. }
  2048. }
  2049. safe_delete(packet);
  2050. }
  2051. break;
  2052. }
  2053. case OP_PetOptions: {
  2054. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  2055. Spawn* target = player->GetTarget();
  2056. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  2057. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  2058. bool change = false;
  2059. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2060. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  2061. if (strlen(name.c_str()) != 0 && SetPetName(name.c_str())) {
  2062. target->SetName(name.c_str());
  2063. GetCurrentZone()->SendUpdateTitles(target);
  2064. change = true;
  2065. }
  2066. int8 pet_behavior = player->GetInfoStruct()->get_pet_behavior();
  2067. // Check protect self setting and update if needed
  2068. if (packet->getType_int8_ByName("protect_self") == 1) {
  2069. if ((pet_behavior & 2) == 0) {
  2070. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 2);
  2071. change = true;
  2072. }
  2073. }
  2074. else {
  2075. if ((pet_behavior & 2) != 0) {
  2076. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 2);
  2077. change = true;
  2078. }
  2079. }
  2080. // Check protect master setting and update if needed
  2081. if (packet->getType_int8_ByName("protect_master") == 1) {
  2082. if ((pet_behavior & 1) == 0) {
  2083. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 1);
  2084. change = true;
  2085. }
  2086. }
  2087. else {
  2088. if ((pet_behavior & 1) != 0) {
  2089. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 1);
  2090. change = true;
  2091. }
  2092. }
  2093. int8 pet_movement = player->GetInfoStruct()->get_pet_movement();
  2094. // Check stay/follow setting and update if needed
  2095. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  2096. if (pet_movement != 2) {
  2097. player->GetInfoStruct()->set_pet_movement(2);
  2098. change = true;
  2099. }
  2100. }
  2101. else {
  2102. if (pet_movement != 1) {
  2103. player->GetInfoStruct()->set_pet_movement(1);
  2104. change = true;
  2105. }
  2106. }
  2107. // Ranged/Melee settings are not implemented yet
  2108. if (change)
  2109. player->SetCharSheetChanged(true);
  2110. }
  2111. safe_delete(packet);
  2112. }
  2113. break;
  2114. }
  2115. case OP_RecipeBook: {
  2116. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  2117. SendRecipeList();
  2118. break;
  2119. }
  2120. case OP_BuyPlayerHouseMsg: {
  2121. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  2122. //DumpPacket(app);
  2123. int64 bank_money = GetPlayer()->GetBankCoinsPlat();
  2124. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  2125. if (packet) {
  2126. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2127. int64 house_id = 0;
  2128. if(GetVersion() <= 561) {
  2129. house_id = packet->getType_int32_ByName("house_id");
  2130. }
  2131. else {
  2132. house_id = packet->getType_int64_ByName("house_id");
  2133. }
  2134. HouseZone* hz = world.GetHouseZone(house_id);
  2135. if (hz) {
  2136. bool got_bank_money = BankHasCoin(hz->cost_coin);
  2137. int8 disable_alignment_req = rule_manager.GetGlobalRule(R_Player, DisableHouseAlignmentRequirement)->GetInt8();
  2138. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  2139. if (houses.size() > 24)
  2140. {
  2141. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  2142. safe_delete(packet);
  2143. break;
  2144. }
  2145. if(disable_alignment_req && hz->alignment > 0 && hz->alignment != GetPlayer()->GetAlignment())
  2146. {
  2147. std::string req = "You must be of ";
  2148. if (hz->alignment == 1)
  2149. req.append("Good");
  2150. else
  2151. req.append("Evil");
  2152. req.append(" alignment to purchase this house");
  2153. SimpleMessage(CHANNEL_COLOR_YELLOW, req.c_str());
  2154. safe_delete(packet);
  2155. break;
  2156. }
  2157. int32 status_req = hz->cost_status;
  2158. int32 available_status = player->GetInfoStruct()->get_status_points();
  2159. if (status_req <= available_status && (!hz->cost_coin || (hz->cost_coin && player->RemoveCoins(hz->cost_coin))))
  2160. {
  2161. player->GetInfoStruct()->subtract_status_points(status_req);
  2162. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id, false, false);
  2163. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  2164. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  2165. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  2166. //ClientPacketFunctions::SendHousingList(this);
  2167. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  2168. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2169. PlaySound("coin_cha_ching");
  2170. }
  2171. else if (status_req <= available_status && got_bank_money == 1) {
  2172. player->GetInfoStruct()->subtract_status_points(status_req);
  2173. bool bankwithdrawl = BankWithdrawalNoBanker(hz->cost_coin);
  2174. //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
  2175. if (bankwithdrawl == 0) {
  2176. PlaySound("buy_failed");
  2177. SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
  2178. safe_delete(packet);
  2179. break;
  2180. }
  2181. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id, false, false);
  2182. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  2183. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  2184. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  2185. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  2186. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2187. PlaySound("coin_cha_ching");
  2188. }
  2189. else
  2190. {
  2191. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  2192. PlaySound("buy_failed");
  2193. }
  2194. }
  2195. }
  2196. }
  2197. safe_delete(packet);
  2198. break;
  2199. }
  2200. case OP_EnterHouseMsg: {
  2201. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  2202. //DumpPacket(app);
  2203. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  2204. if (packet) {
  2205. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2206. PlayerHouse* ph = nullptr;
  2207. HouseZone* hz = nullptr;
  2208. int64 house_id = 0;
  2209. int32 spawn_index = 0;
  2210. if(GetVersion() <= 561) {
  2211. spawn_index = packet->getType_int32_ByName("house_id");
  2212. }
  2213. else {
  2214. house_id = packet->getType_int64_ByName("house_id");
  2215. }
  2216. ZoneServer* house = GetHouseZoneServer(spawn_index, house_id);
  2217. if (house) {
  2218. Zone(house, true);
  2219. }
  2220. }
  2221. }
  2222. safe_delete(packet);
  2223. break;
  2224. }
  2225. case OP_PayHouseUpkeepMsg: {
  2226. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  2227. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  2228. if (packet) {
  2229. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2230. int64 house_id = 0;
  2231. if(GetVersion() <= 561) {
  2232. house_id = packet->getType_int32_ByName("house_id");
  2233. }
  2234. else {
  2235. house_id = packet->getType_int64_ByName("house_id");
  2236. }
  2237. HouseZone* hz = nullptr;
  2238. PlayerHouse* ph = world.GetPlayerHouse(this, GetVersion() <= 561 ? house_id : 0, GetVersion() > 561 ? house_id : 0, &hz);
  2239. if (ph)
  2240. {
  2241. if (!hz)
  2242. {
  2243. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  2244. safe_delete(packet);
  2245. break;
  2246. }
  2247. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  2248. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  2249. {
  2250. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  2251. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  2252. {
  2253. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  2254. PlaySound("buy_failed");
  2255. safe_delete(packet);
  2256. break;
  2257. }
  2258. }
  2259. bool escrowChange = false;
  2260. int64 statusReq = hz->upkeep_status;
  2261. int64 tmpRecoverStatus = 0;
  2262. if(ph->escrow_status && statusReq >= ph->escrow_status )
  2263. {
  2264. escrowChange = true;
  2265. tmpRecoverStatus = ph->escrow_status;
  2266. statusReq -= ph->escrow_status;
  2267. ph->escrow_status = 0;
  2268. }
  2269. else if (ph->escrow_status && statusReq && statusReq <= ph->escrow_status)
  2270. {
  2271. escrowChange = true;
  2272. ph->escrow_status -= statusReq;
  2273. tmpRecoverStatus = statusReq;
  2274. statusReq = 0;
  2275. }
  2276. int64 coinReq = hz->upkeep_coin;
  2277. int64 tmpRecoverCoins = 0;
  2278. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  2279. {
  2280. escrowChange = true;
  2281. tmpRecoverCoins = ph->escrow_coins;
  2282. coinReq -= ph->escrow_coins;
  2283. ph->escrow_coins = 0;
  2284. }
  2285. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  2286. {
  2287. escrowChange = true;
  2288. // more than enough in escrow, subtract and make our cost 0!
  2289. ph->escrow_coins -= coinReq;
  2290. tmpRecoverCoins = coinReq;
  2291. coinReq = 0;
  2292. }
  2293. int32 available_status_points = player->GetInfoStruct()->get_status_points();
  2294. if(!statusReq || (statusReq && statusReq <= available_status_points))
  2295. {
  2296. if(coinReq && player->RemoveCoins(coinReq))
  2297. coinReq = 0;
  2298. if(!coinReq && statusReq && player->GetInfoStruct()->subtract_status_points(statusReq))
  2299. statusReq = 0;
  2300. }
  2301. bool got_bank_money = BankHasCoin(hz->upkeep_coin);
  2302. if (!coinReq && !statusReq) // TODO: Need option to take from bank if player does not have enough coin on them
  2303. {
  2304. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2305. if (escrowChange)
  2306. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2307. ph->upkeep_due = upkeep_due;
  2308. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2309. //ClientPacketFunctions::SendHousingList(this);
  2310. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2311. PlaySound("coin_cha_ching");
  2312. }
  2313. else if (!statusReq && got_bank_money == 1) {
  2314. bool bankwithdrawl = BankWithdrawalNoBanker(hz->upkeep_coin);
  2315. //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
  2316. if (bankwithdrawl == 0) {
  2317. PlaySound("buy_failed");
  2318. SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
  2319. safe_delete(packet);
  2320. break;
  2321. }
  2322. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2323. if (escrowChange)
  2324. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2325. ph->upkeep_due = upkeep_due;
  2326. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2327. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 561 ? house_id : this->GetPlayer()->GetID());
  2328. PlaySound("coin_cha_ching");
  2329. }
  2330. else
  2331. {
  2332. // recover the escrow we were going to use but could not spend due to lack of funds
  2333. if (tmpRecoverCoins)
  2334. ph->escrow_coins += tmpRecoverCoins;
  2335. if(tmpRecoverStatus)
  2336. ph->escrow_status += tmpRecoverStatus;
  2337. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money or status to pay for upkeep.");
  2338. PlaySound("buy_failed");
  2339. }
  2340. }
  2341. else
  2342. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", house_id);
  2343. }
  2344. }
  2345. safe_delete(packet);
  2346. break;
  2347. }
  2348. case OP_ExitHouseMsg: {
  2349. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  2350. int32 instance_id = GetCurrentZone()->GetInstanceID();
  2351. if (instance_id > 0) {
  2352. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  2353. if (ph) {
  2354. HouseZone* hz = world.GetHouseZone(ph->house_id);
  2355. if (hz) {
  2356. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  2357. // determine if this is an instanced zone that already exists
  2358. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  2359. if (instance_zone || new_zone) {
  2360. GetPlayer()->SetX(hz->exit_x);
  2361. GetPlayer()->SetY(hz->exit_y);
  2362. GetPlayer()->SetZ(hz->exit_z);
  2363. GetPlayer()->SetHeading(hz->exit_heading);
  2364. if (instance_zone)
  2365. Zone(instance_zone->GetInstanceID(), false, true);
  2366. else
  2367. Zone(new_zone, false);
  2368. }
  2369. }
  2370. }
  2371. }
  2372. break;
  2373. }
  2374. case OP_QuestJournalWaypointMsg: {
  2375. //DumpPacket(app);
  2376. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  2377. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  2378. if (packet) {
  2379. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2380. if(GetVersion() <= 561) {
  2381. int32 quest_id = packet->getType_int32_ByName("quest_id");
  2382. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2383. if (player->player_quests.count(quest_id) > 0 && player->player_quests[quest_id]) {
  2384. if(player->player_quests[quest_id]->GetTracked())
  2385. player->player_quests[quest_id]->SetTracked(false);
  2386. else
  2387. player->player_quests[quest_id]->SetTracked(true);
  2388. player->player_quests[quest_id]->SetSaveNeeded(true);
  2389. }
  2390. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2391. }
  2392. else {
  2393. int32 quests = packet->getType_int32_ByName("num_quests");
  2394. if (quests > 100) // just picking a number higher than max allowed
  2395. {
  2396. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  2397. break;
  2398. }
  2399. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  2400. for (int32 i = 0; i < quests; i++) {
  2401. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  2402. if (id == 0)
  2403. continue;
  2404. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  2405. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  2406. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2407. if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
  2408. player->player_quests[id]->SetTracked(tracked);
  2409. player->player_quests[id]->SetSaveNeeded(true);
  2410. }
  2411. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2412. }
  2413. }
  2414. }
  2415. safe_delete(packet);
  2416. }
  2417. break;
  2418. }
  2419. case OP_PaperdollImage: {
  2420. /* PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  2421. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2422. //First check if this is a new image... delete an existing partial image if one exists
  2423. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  2424. if (packet_index == 0) {
  2425. safe_delete_array(incoming_paperdoll.image_bytes);
  2426. incoming_paperdoll.last_received_packet_index = 0;
  2427. incoming_paperdoll.current_size_bytes = 0;
  2428. }
  2429. //return if this packet is not the one we are expecting...
  2430. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  2431. safe_delete(packet);
  2432. break;
  2433. }
  2434. //Check how many packets we're supposed to be receiving for this/these images
  2435. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  2436. //Check the image type, if this is a new type in the same series of packets we have a new image
  2437. int8 img_type = packet->getType_int8_ByName("image_type");
  2438. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  2439. //We have a new image. Save the old data and clear before continuing
  2440. SavePlayerImages();
  2441. }
  2442. incoming_paperdoll.image_type = img_type;
  2443. //Get the size of the image data in this packet
  2444. sint64 image_size = packet->getType_int32_ByName("imageSize");
  2445. if (image_size <= 0 || image_size > 1048576) {
  2446. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  2447. safe_delete(packet);
  2448. break;
  2449. }
  2450. //Create a new array
  2451. int32 new_image_size = image_size;
  2452. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  2453. if (incoming_paperdoll.image_bytes) {
  2454. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  2455. safe_delete_array(incoming_paperdoll.image_bytes);
  2456. }
  2457. //variable i should be the index in the packet of the first PNG file byte
  2458. vector<DataStruct*>* d_structs = packet->getStructs();
  2459. vector<DataStruct*>::iterator itr;
  2460. int32 i = 0;
  2461. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  2462. DataStruct* ds = (*itr);
  2463. if (strcmp(ds->GetName(), "pngData_0") != 0)
  2464. i += ds->GetDataSizeInBytes();
  2465. else
  2466. break;
  2467. }
  2468. //Return if this packet is bad and we would read out of bounds
  2469. if (app->size - i < new_image_size) {
  2470. safe_delete(packet);
  2471. safe_delete_array(new_image);
  2472. break;
  2473. }
  2474. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  2475. memcpy(tmp, app->pBuffer + i, new_image_size);
  2476. incoming_paperdoll.current_size_bytes += new_image_size;
  2477. incoming_paperdoll.image_bytes = new_image;
  2478. //Check if this is the last packet we're expecting for this image. Create a final image if so
  2479. if (incoming_paperdoll.image_num_packets == 1 ||
  2480. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  2481. SavePlayerImages();
  2482. }
  2483. incoming_paperdoll.last_received_packet_index = packet_index;
  2484. }
  2485. safe_delete(packet);
  2486. */
  2487. break;
  2488. }
  2489. case OP_ReadyForTakeOffMsg:
  2490. {
  2491. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  2492. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  2493. if (GetPendingFlightPath() > 0) {
  2494. if (index != -1) {
  2495. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  2496. if (packet) {
  2497. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  2498. packet->setDataByName("path_id", index);
  2499. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  2500. QueuePacket(packet->serialize());
  2501. safe_delete(packet);
  2502. on_auto_mount = true;
  2503. }
  2504. }
  2505. else {
  2506. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2507. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2508. EndAutoMount();
  2509. }
  2510. SetPendingFlightPath(0);
  2511. }
  2512. else
  2513. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  2514. break;
  2515. }
  2516. case OP_EarlyLandingRequestMsg:
  2517. {
  2518. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  2519. EndAutoMount();
  2520. break;
  2521. }
  2522. case OP_SubmitCharCust:
  2523. {
  2524. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  2525. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  2526. if (packet && packet->LoadPacketData(app->pBuffer, app->size, GetVersion() <= 561 ? false : true)) {
  2527. int8 type = packet->getType_int8_ByName("type");
  2528. if (type == 0) {
  2529. /*if (player->custNPC) {
  2530. player->custNPCTarget->CustomizeAppearance(packet);
  2531. current_zone->SendSpawnChanges(player->custNPCTarget);
  2532. }
  2533. else {*/
  2534. player->CustomizeAppearance(packet);
  2535. current_zone->SendSpawnChanges(player);
  2536. //}
  2537. }
  2538. }
  2539. safe_delete(packet);
  2540. /*
  2541. if (player->custNPC) {
  2542. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2543. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2544. if (player->custNPCTarget->IsBot())
  2545. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2546. player->custNPC = false;
  2547. player->custNPCTarget = 0;
  2548. player->changed = true;
  2549. player->info_changed = true;
  2550. current_zone->SendSpawnChanges(player, this);
  2551. }*/
  2552. break;
  2553. }
  2554. default: {
  2555. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2556. const char* name = app->GetOpcodeName();
  2557. if (name)
  2558. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2559. else
  2560. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2561. // keeping this around for debugging purposes
  2562. //DumpPacket(app);
  2563. }
  2564. }
  2565. if (!eqs || !eqs->CheckActive()) {
  2566. return false;
  2567. }
  2568. return ret;
  2569. }
  2570. bool Client::HandleLootItem(Spawn* entity, Item* item, Spawn* target, bool overrideLootRestrictions) {
  2571. if (!item) {
  2572. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2573. return false;
  2574. }
  2575. int32 conflictItemList = 0, conflictequipmentList = 0, conflictAppearanceEquipmentList = 0;
  2576. int16 lore_stack_count = 0;
  2577. Player* lootingPlayer = player;
  2578. Client* lootingClient = this;
  2579. if (target != nullptr && target != lootingPlayer && target->IsPlayer()) {
  2580. lootingPlayer = (Player*)target;
  2581. lootingClient = lootingPlayer->GetClient();
  2582. }
  2583. // needs to only be checked before expiration of loot restrictions
  2584. if (entity && !overrideLootRestrictions) {
  2585. if (entity->GetLootGroupID() > 0 && (!lootingPlayer->GetGroupMemberInfo() || lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID())) {
  2586. 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());
  2587. return false;
  2588. }
  2589. if (entity->GetLootMethod() != GroupLootMethod::METHOD_FFA) {
  2590. switch (entity->GetLootMethod()) {
  2591. case GroupLootMethod::METHOD_LEADER: {
  2592. if (entity->GetLootGroupID() > 0 && (!lootingPlayer->GetGroupMemberInfo() || (lootingPlayer->GetGroupMemberInfo() && (lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID() || !lootingPlayer->GetGroupMemberInfo()->leader)))) {
  2593. 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);
  2594. return false;
  2595. }
  2596. break;
  2597. }
  2598. case GroupLootMethod::METHOD_LOTTO:
  2599. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2600. if (entity->IsLootTimerRunning()) {
  2601. 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);
  2602. return false;
  2603. }
  2604. break;
  2605. }
  2606. }
  2607. }
  2608. }
  2609. if (((conflictItemList = lootingPlayer->item_list.CheckSlotConflict(item, true, true, &lore_stack_count)) == LORE ||
  2610. (conflictequipmentList = lootingPlayer->equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE ||
  2611. (conflictAppearanceEquipmentList = lootingPlayer->appearance_equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE) && !item->CheckFlag(STACK_LORE)) {
  2612. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to lore conflict.", item->name.c_str());
  2613. return false;
  2614. }
  2615. else if (conflictItemList == STACK_LORE || conflictequipmentList == STACK_LORE || conflictAppearanceEquipmentList == STACK_LORE) {
  2616. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to stack lore conflict.", item->name.c_str());
  2617. return false;
  2618. }
  2619. if (lootingPlayer->item_list.HasFreeSlot() || lootingPlayer->item_list.CanStack(item)) {
  2620. if (lootingPlayer->item_list.AssignItemToFreeSlot(item)) {
  2621. if (item->CheckFlag2(HEIRLOOM)) { // TODO: RAID Support
  2622. GroupMemberInfo* gmi = lootingClient->GetPlayer()->GetGroupMemberInfo();
  2623. if (gmi && gmi->group_id)
  2624. {
  2625. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  2626. if (group)
  2627. {
  2628. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  2629. deque<GroupMemberInfo*>* members = group->GetMembers();
  2630. if (members) {
  2631. for (int8 i = 0; i < members->size(); i++) {
  2632. Entity* member = members->at(i)->member;
  2633. if (!member)
  2634. continue;
  2635. if ((member->GetZone() != lootingClient->GetPlayer()->GetZone()))
  2636. continue;
  2637. if (member->IsPlayer()) {
  2638. item->grouped_char_ids.insert(std::make_pair(((Player*)member)->GetCharacterID(), true));
  2639. item->save_needed = true;
  2640. }
  2641. }
  2642. }
  2643. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  2644. }
  2645. }
  2646. }
  2647. int8 type = CHANNEL_LOOT;
  2648. if (entity) {
  2649. lootingClient->Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2650. }
  2651. else {
  2652. lootingClient->Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2653. }
  2654. Guild* guild = lootingPlayer->GetGuild();
  2655. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2656. char adjective[32];
  2657. int8 type;
  2658. memset(adjective, 0, sizeof(adjective));
  2659. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2660. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2661. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2662. }
  2663. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2664. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2665. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2666. }
  2667. else {
  2668. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2669. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2670. }
  2671. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2672. guild->SendMessageToGuild(type, "%s has looted the %s %s", lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2673. }
  2674. if (item->GetItemScript() && lua_interface)
  2675. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, lootingPlayer);
  2676. lootingClient->CheckPlayerQuestsItemUpdate(item);
  2677. if (GetVersion() <= 561) {
  2678. EQ2Packet* outapp = lootingPlayer->SendInventoryUpdate(GetVersion());
  2679. if (outapp)
  2680. lootingClient->QueuePacket(outapp);
  2681. }
  2682. return true;
  2683. }
  2684. else
  2685. lootingClient->SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2686. }
  2687. else
  2688. lootingClient->SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2689. return false;
  2690. }
  2691. bool Client::HandleLootItemByID(Spawn* entity, int32 item_id, Spawn* target) {
  2692. if (!entity) {
  2693. return false;
  2694. }
  2695. Item* item = entity->LootItem(item_id);
  2696. bool success = false;
  2697. success = HandleLootItem(entity, item, target);
  2698. if (!success)
  2699. entity->AddLootItem(item);
  2700. return success;
  2701. }
  2702. void Client::HandleLootItemRequestPacket(EQApplicationPacket* app) {
  2703. PacketStruct* packet = configReader.getStruct("WS_LootItem", GetVersion());
  2704. if (packet) {
  2705. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  2706. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2707. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2708. int32 target_id = packet->getType_int32_ByName("target_id");
  2709. int8 button_clicked = packet->getType_int8_ByName("button_clicked");
  2710. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2711. if(!spawn) {
  2712. safe_delete(packet);
  2713. return;
  2714. }
  2715. Item* item = nullptr;
  2716. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2717. if (items) {
  2718. int32 items_looted = 0;
  2719. int32 item_id = packet->getType_int32_ByName("item_id_0");
  2720. for (int32 i = 0; i < items->size(); i++) {
  2721. Item* master_item = items->at(i);
  2722. if (master_item && (loot_all || master_item->details.item_id == item_id)) {
  2723. item = new Item(master_item);
  2724. if (item) {
  2725. loot_all = HandleLootItem(0, item);
  2726. if (loot_all) {
  2727. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2728. if (GetVersion() <= 561) {
  2729. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2730. if (outapp)
  2731. QueuePacket(outapp);
  2732. }
  2733. if(master_item->details.item_id == item_id) {
  2734. break;
  2735. }
  2736. }
  2737. }
  2738. if (!loot_all)
  2739. break;
  2740. }
  2741. }
  2742. if(((loot_all && !item_id) || (loot_all && item_id && items->size() == 1)) || items->size() < 1) {
  2743. CloseLoot(loot_id);
  2744. }
  2745. else {
  2746. vector<Item*>* items2 = player->GetPendingLootItems(loot_id);
  2747. SendLootResponsePacket(spawn->GetLootCoins(), items2, spawn, true);
  2748. safe_delete(items2);
  2749. }
  2750. safe_delete(items);
  2751. safe_delete(packet);
  2752. return;
  2753. }
  2754. spawn->LockLoot();
  2755. bool unlockedLoot = false;
  2756. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2757. if (loot_all) {
  2758. switch (spawn->GetLootMethod()) {
  2759. case GroupLootMethod::METHOD_LOTTO: {
  2760. spawn->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
  2761. break;
  2762. }
  2763. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2764. spawn->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
  2765. }
  2766. default: {
  2767. if (!unlockedLoot) {
  2768. spawn->UnlockLoot();
  2769. unlockedLoot = true;
  2770. }
  2771. int32 item_id = 0;
  2772. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2773. loot_all = HandleLootItemByID(spawn, item_id, GetPlayer());
  2774. }
  2775. break;
  2776. }
  2777. }
  2778. spawn->UnlockLoot();
  2779. if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
  2780. CloseLoot(loot_id);
  2781. }
  2782. }
  2783. else {
  2784. int8 item_count = packet->getType_int8_ByName("item_count");
  2785. for (int8 cur = 0; cur < item_count; cur++) {
  2786. char item_field_name[64];
  2787. snprintf(item_field_name, 64, "item_id_%u", cur);
  2788. int32 item_id = packet->getType_int32_ByName(item_field_name);
  2789. Spawn* target = this->GetPlayer();
  2790. if (target_id != 0xFFFFFFFF && GetPlayer()->GetGroupMemberInfo()) {
  2791. Spawn* destTarget = GetPlayer()->GetSpawnWithPlayerID(target_id);
  2792. if (destTarget && (!destTarget->IsPlayer() || !world.GetGroupManager()->IsInGroup(GetPlayer()->GetGroupMemberInfo()->group_id, ((Player*)destTarget)))) {
  2793. SimpleMessage(CHANNEL_COMMAND_TEXT, "HACKS!!");
  2794. safe_delete(packet);
  2795. spawn->UnlockLoot();
  2796. return;
  2797. }
  2798. target = destTarget;
  2799. }
  2800. bool breakLoopAllLooted = false;
  2801. switch (spawn->GetLootMethod()) {
  2802. case GroupLootMethod::METHOD_LOTTO: {
  2803. spawn->AddLottoItemRequest(item_id, GetPlayer()->GetID());
  2804. break;
  2805. }
  2806. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2807. if (button_clicked == 3) { // decline
  2808. break;
  2809. }
  2810. if (GetVersion() <= 561) {
  2811. button_clicked = 1; // selecting is need
  2812. }
  2813. spawn->AddNeedGreedItemRequest(item_id, GetPlayer()->GetID(), (button_clicked == 1));
  2814. break;
  2815. }
  2816. default: {
  2817. if (!unlockedLoot) {
  2818. spawn->UnlockLoot();
  2819. unlockedLoot = true;
  2820. }
  2821. if (!loot_all) {
  2822. HandleLootItemByID(spawn, item_id, target);
  2823. }
  2824. else {
  2825. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2826. loot_all = HandleLootItemByID(spawn, item_id, target);
  2827. }
  2828. breakLoopAllLooted = true;
  2829. }
  2830. break;
  2831. }
  2832. }
  2833. if (breakLoopAllLooted) {
  2834. break;
  2835. }
  2836. }
  2837. if (!unlockedLoot) {
  2838. spawn->UnlockLoot();
  2839. }
  2840. if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO ||
  2841. (spawn->GetLootMethod() == GroupLootMethod::METHOD_NEED_BEFORE_GREED && item_count >= spawn->GetLootCount())) {
  2842. CloseLoot(loot_id);
  2843. }
  2844. }
  2845. if (GetVersion() > 561) {
  2846. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2847. if (outapp)
  2848. QueuePacket(outapp);
  2849. }
  2850. if (spawn->GetLootMethod() != GroupLootMethod::METHOD_LOTTO && spawn->GetLootMethod() != GroupLootMethod::METHOD_NEED_BEFORE_GREED) {
  2851. LootSpawnRequest(spawn);
  2852. }
  2853. else {
  2854. spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  2855. }
  2856. if (!spawn->HasLoot()) {
  2857. CloseLoot(loot_id);
  2858. if (spawn->IsNPC())
  2859. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2860. }
  2861. }
  2862. else {
  2863. spawn->UnlockLoot();
  2864. if (!spawn) {
  2865. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2866. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2867. }
  2868. else
  2869. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2870. }
  2871. }
  2872. safe_delete(packet);
  2873. }
  2874. }
  2875. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2876. PacketStruct* request = 0;
  2877. // cout << "Request: \n";
  2878. // DumpPacket(app);
  2879. switch (app->pBuffer[0]) {
  2880. case 0: { //items
  2881. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2882. if (request) {
  2883. if(request->LoadPacketData(app->pBuffer, app->size)) {
  2884. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2885. if (!item)
  2886. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2887. if (item) {
  2888. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2889. if (response) {
  2890. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2891. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2892. response->setSmallStringByName("name", item->name.c_str());
  2893. EQ2Packet* app2 = response->serialize();
  2894. //DumpPacket(app2);
  2895. QueuePacket(app2);
  2896. safe_delete(response);
  2897. }
  2898. }
  2899. }
  2900. safe_delete(request);
  2901. }
  2902. break;
  2903. }
  2904. case 2: {//spells
  2905. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2906. if (request) {
  2907. if(request->LoadPacketData(app->pBuffer, app->size)) {
  2908. int32 id = request->getType_int32_ByName("id");
  2909. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2910. Spell* spell = master_spell_list.GetSpell(id, tier);
  2911. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2912. if (response) {
  2913. response->setDataByName("request_type", 2);
  2914. response->setDataByName("unique_id", tier);
  2915. response->setDataByName("id", id);
  2916. if (spell)
  2917. response->setSmallStringByName("name", spell->GetName());
  2918. else
  2919. response->setSmallStringByName("name", "Unknown Spell");
  2920. EQ2Packet* app2 = response->serialize();
  2921. // DumpPacket(app2);
  2922. QueuePacket(app2);
  2923. safe_delete(response);
  2924. }
  2925. }
  2926. safe_delete(request);
  2927. }
  2928. break;
  2929. }
  2930. default: {
  2931. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2932. }
  2933. }
  2934. safe_delete(request);
  2935. }
  2936. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2937. PacketStruct* request = 0;
  2938. if (!app || app->size == 0)
  2939. return;
  2940. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2941. int8 type = app->pBuffer[0];
  2942. //DumpPacket(app->pBuffer,app->size);
  2943. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2944. if (version <= 373) {
  2945. if (type == 1)
  2946. type = 4;
  2947. else if (type == 2)
  2948. type = 5;
  2949. }
  2950. if (type == 3) {
  2951. Spell* spell = 0;
  2952. bool trait_display;
  2953. request = configReader.getStruct((GetVersion() <= 373) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  2954. if (!request) {
  2955. return;
  2956. }
  2957. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2958. safe_delete(request);
  2959. return;
  2960. }
  2961. int32 id = request->getType_int32_ByName("id");
  2962. int32 tier = request->getType_int32_ByName("tier");
  2963. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2964. if(GetVersion() > 373 && GetVersion() <= 561) {
  2965. trait_tier = request->getType_int32_ByName("unique_id");
  2966. }
  2967. bool display = true;
  2968. if (version <= 373 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2969. display = false;
  2970. else if (version <= 561)
  2971. display = request->getType_int8_ByName("display");
  2972. else if (version > 561)
  2973. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  2974. LogWrite(CCLIENT__DEBUG, 5, "Client", "Client::HandleExamineInfoRequest from %s: Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)",GetPlayer()->GetName(),type,tier,trait_tier,id);
  2975. if (trait_tier != 0xFFFFFFFF) {
  2976. spell = master_spell_list.GetSpell(id, trait_tier);
  2977. if (!spell) {
  2978. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2979. }
  2980. trait_display = true;
  2981. }
  2982. else {
  2983. spell = master_spell_list.GetSpell(id, tier);
  2984. trait_display = false;
  2985. }
  2986. // if we can't find it on the master spell list, see if it is a custom spell
  2987. if (!spell)
  2988. {
  2989. lua_interface->FindCustomSpellLock();
  2990. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2991. if (tmpSpell)
  2992. spell = tmpSpell->spell;
  2993. lua_interface->FindCustomSpellUnlock();
  2994. }
  2995. if(!spell) { // fix ui timeout for classic, isle of refuge, dof, kos clients
  2996. int8 playerTier = GetPlayer()->GetSpellTier(id);
  2997. spell = master_spell_list.GetSpell(id, playerTier);
  2998. LogWrite(CCLIENT__WARNING, 0, "Client", "Client::HandleExamineInfoRequest from %s: Failed to find tier 1 spell. Last resort try to get the spell from the player book, spell %u, tier %u", GetPlayer()->GetName(),id,playerTier);
  2999. }
  3000. if (spell && !CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
  3001. if (!spell->IsCopiedSpell())
  3002. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3003. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  3004. //DumpPacket(app);
  3005. QueuePacket(app);
  3006. }
  3007. else if(spell && GetVersion() <=561 && CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
  3008. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display, GetVersion() <= 561 ? true : false);
  3009. //DumpPacket(app);
  3010. QueuePacket(app);
  3011. }
  3012. else {
  3013. LogWrite(CCLIENT__ERROR, 0, "Client", "Client::HandleExamineInfoRequest from %s: Failed to successfully send Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)",GetPlayer()->GetName(),type,tier,trait_tier,id);
  3014. }
  3015. }
  3016. else if (type == 0) {
  3017. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  3018. if (!request) {
  3019. return;
  3020. }
  3021. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3022. safe_delete(request);
  3023. return;
  3024. }
  3025. int32 id = request->getType_int32_ByName("id");
  3026. Item* item = 0;
  3027. // translate from unique id to spawn id for houses
  3028. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  3029. bool wasSpawn = false;
  3030. if (spawn)
  3031. {
  3032. item = master_item_list.GetItem(spawn->GetPickupItemID());
  3033. if (item)
  3034. {
  3035. wasSpawn = true;
  3036. item = new Item(item);
  3037. item->details.unique_id = spawn->GetPickupUniqueItemID();
  3038. }
  3039. }
  3040. if (!item)
  3041. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  3042. if (!item)
  3043. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  3044. if (!item)
  3045. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(id);
  3046. if (!item)
  3047. item = master_item_list.GetItem(id);
  3048. if (item) {// && sent_item_details.count(id) == 0){
  3049. MItemDetails.writelock(__FUNCTION__, __LINE__);
  3050. sent_item_details[id] = true;
  3051. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  3052. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  3053. QueuePacket(app);
  3054. if (wasSpawn)
  3055. delete item;
  3056. }
  3057. else {
  3058. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  3059. DumpPacket(app);
  3060. }
  3061. }
  3062. else if (type == 1) {
  3063. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  3064. if (!request) {
  3065. return;
  3066. }
  3067. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3068. safe_delete(request);
  3069. return;
  3070. }
  3071. int32 id = request->getType_int32_ByName("id");
  3072. int32 unique_id = request->getType_int32_ByName("unique_id");
  3073. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  3074. if (!item)
  3075. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  3076. if (!item)
  3077. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(unique_id);
  3078. if (!item)
  3079. item = master_item_list.GetItem(id);
  3080. if (item) {
  3081. MItemDetails.writelock(__FUNCTION__, __LINE__);
  3082. sent_item_details[id] = true;
  3083. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  3084. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  3085. QueuePacket(app);
  3086. }
  3087. else {
  3088. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  3089. DumpPacket(app);
  3090. }
  3091. }
  3092. else if (type == 2) {
  3093. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  3094. if (!request) {
  3095. return;
  3096. }
  3097. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3098. safe_delete(request);
  3099. return;
  3100. }
  3101. int32 id = request->getType_int32_ByName("item_id");
  3102. LogWrite(CCLIENT__DEBUG, 5, "Client", "Client::HandleExamineInfoRequest from %s: Found Type: (%i) Item ID: (%u)",GetPlayer()->GetName(),type,id);
  3103. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  3104. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  3105. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  3106. //int32 unique_id = request->getType_int32_ByName("unique_id");
  3107. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  3108. //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);
  3109. Item* item = master_item_list.GetItem(id);
  3110. if (item) {
  3111. //only display popup for non merchant links
  3112. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, GetVersion() > 561 ? true : false);
  3113. QueuePacket(app);
  3114. }
  3115. else {
  3116. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  3117. DumpPacket(app);
  3118. }
  3119. }
  3120. else if (type == 4) { //spell effect
  3121. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  3122. if (!request) {
  3123. return;
  3124. }
  3125. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3126. safe_delete(request);
  3127. return;
  3128. }
  3129. int32 id = request->getType_int32_ByName("id");
  3130. int16 display = request->getType_int8_ByName("partial_info");
  3131. SpellEffects* effect = player->GetSpellEffect(id);
  3132. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  3133. if (effect) {
  3134. LogWrite(CCLIENT__DEBUG, 5, "Client", "Client::HandleExamineInfoRequest from %s: Found Type: (%i) Item ID: (%u)",GetPlayer()->GetName(),type,id);
  3135. int8 tier = effect->tier;
  3136. Spell* spell = master_spell_list.GetSpell(id, tier);
  3137. // if we can't find it on the master spell list, see if it is a custom spell
  3138. if (!spell)
  3139. {
  3140. lua_interface->FindCustomSpellLock();
  3141. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  3142. EQ2Packet* pack = 0;
  3143. if (tmpSpell)
  3144. spell = tmpSpell->spell;
  3145. lua_interface->FindCustomSpellUnlock();
  3146. }
  3147. if (spell && (version <= 561 || !CountSentSpell(id, tier))) { // fix DoF and KoS clients UI Timeout
  3148. if (!spell->IsCopiedSpell())
  3149. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3150. int8 type = 0;
  3151. if (version <= 373)
  3152. type = 1;
  3153. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  3154. //DumpPacket(app);
  3155. QueuePacket(app);
  3156. }
  3157. }
  3158. else {
  3159. LogWrite(CCLIENT__ERROR, 0, "Client", "Client::HandleExamineInfoRequest from %s: Cannot Find Type: (%i) Item ID: (%u)",GetPlayer()->GetName(),type,id);
  3160. }
  3161. }
  3162. else if (type == 5) { // recipe info
  3163. request = configReader.getStruct((GetVersion() <= 373) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  3164. if (!request)
  3165. return;
  3166. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3167. safe_delete(request);
  3168. return;
  3169. }
  3170. int32 id = 0;
  3171. if(GetVersion() < 546) {
  3172. id = request->getType_int32_ByName("id");
  3173. }
  3174. else if(GetVersion() <= 561) {
  3175. id = request->getType_int32_ByName("unique_id");
  3176. }
  3177. else {
  3178. id = request->getType_int32_ByName("unknown_id");
  3179. }
  3180. Recipe* recipe = master_recipe_list.GetRecipe(id);
  3181. if (recipe) {
  3182. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  3183. //DumpPacket(app);
  3184. QueuePacket(app);
  3185. }
  3186. }
  3187. else if (type == 6) { // AA spell info
  3188. Spell* spell = 0;
  3189. //Spell* spell2 = 0;
  3190. //AltAdvanceData* data = 0;
  3191. request = configReader.getStruct((GetVersion() <= 373) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  3192. if (!request)
  3193. return;
  3194. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3195. safe_delete(request);
  3196. return;
  3197. }
  3198. int32 id = request->getType_int32_ByName("id");
  3199. int32 tier = GetPlayer()->GetSpellTier(id);
  3200. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  3201. //data = master_aa_list.GetAltAdvancement(id);
  3202. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  3203. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  3204. spell = master_spell_list.GetSpell(id, tier);
  3205. if (!spell)
  3206. spell = master_spell_list.GetSpell(id, 1);
  3207. if (!spell)
  3208. {
  3209. lua_interface->FindCustomSpellLock();
  3210. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  3211. if (tmpSpell)
  3212. spell = tmpSpell->spell;
  3213. lua_interface->FindCustomSpellUnlock();
  3214. }
  3215. if (!spell)
  3216. {
  3217. LogWrite(CCLIENT__ERROR, 0, "Client", "WORLD", "Client::HandleExamineInfoRequest from %s: FAILED Examine Info Request-> Spell ID: %u, tier: %i", GetPlayer()->GetName(), id, tier);
  3218. return;
  3219. }
  3220. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  3221. if (!spell->IsCopiedSpell())
  3222. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3223. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  3224. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  3225. if(GetVersion() > 561) {
  3226. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  3227. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  3228. //DumpPacket(app);
  3229. QueuePacket(app);
  3230. }
  3231. //}
  3232. }
  3233. else {
  3234. LogWrite(CCLIENT__ERROR, 0, "World", "Client::HandleExamineInfoRequest from %s: Unknown examine request: %i", GetPlayer()->GetName(), (int)type);
  3235. DumpPacket(app);
  3236. }
  3237. safe_delete(request);
  3238. }
  3239. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  3240. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  3241. if (request) {
  3242. if(request->LoadPacketData(app->pBuffer, app->size)) {
  3243. int32 id = request->getType_int32_ByName("id");
  3244. int32 bar = request->getType_int32_ByName("hotbar_number");
  3245. int32 slot = request->getType_int32_ByName("hotkey_slot");
  3246. int32 type = request->getType_int32_ByName("type");
  3247. int8 tier = request->getType_int32_ByName("unique_id");
  3248. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  3249. Spell* spell = 0;
  3250. if (type == 0xFFFFFFFF)
  3251. GetPlayer()->RemoveQuickbarItem(bar, slot);
  3252. else {
  3253. if (type == QUICKBAR_NORMAL)
  3254. spell = master_spell_list.GetSpell(id, tier);
  3255. if (spell)
  3256. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  3257. else
  3258. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  3259. }
  3260. }
  3261. safe_delete(request);
  3262. }
  3263. }
  3264. bool Client::Process(bool zone_process) {
  3265. bool ret = true;
  3266. // EQS can become null if player is linkdead, we want to always be able to process the camp/linkdead timers when active
  3267. if ((camp_timer && camp_timer->Check()) || (linkdead_timer && linkdead_timer->Check())) {
  3268. ResetSendMail();
  3269. if(getConnection())
  3270. getConnection()->SendDisconnect(false);
  3271. safe_delete(camp_timer);
  3272. if(linkdead_timer) {
  3273. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player %s triggered linkdead timer, disconnecting", GetPlayer()->GetName());
  3274. // we remove the linkdead status and force a camp out immediately
  3275. if((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0) {
  3276. GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() - ACTIVITY_STATUS_LINKDEAD);
  3277. }
  3278. if ((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0) {
  3279. GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  3280. }
  3281. }
  3282. safe_delete(linkdead_timer);
  3283. ret = false;
  3284. }
  3285. if (!eqs) {
  3286. return false;
  3287. }
  3288. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  3289. return true;
  3290. }
  3291. switch(new_client_login) {
  3292. case NewLoginState::LOGIN_SEND: {
  3293. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  3294. SendLoginInfo();
  3295. new_client_login = NewLoginState::LOGIN_NONE;
  3296. break;
  3297. }
  3298. case NewLoginState::LOGIN_INITIAL_LOAD: {
  3299. bool isDBActive = database.IsActiveQuery(GetCharacterID());
  3300. // wait for starting skills/spells to load and reload from DB.
  3301. if(!isDBActive) {
  3302. if (GetPlayer()->GetInfoStruct()->get_reload_player_spells()) {
  3303. database.LoadCharacterSpells(GetCharacterID(), GetPlayer());
  3304. GetPlayer()->GetInfoStruct()->set_reload_player_spells(0);
  3305. }
  3306. new_client_login = NewLoginState::LOGIN_SEND;
  3307. }
  3308. break;
  3309. }
  3310. case NewLoginState::LOGIN_ALLOWED: {
  3311. int32 count = 0;
  3312. if(!GetPlayer()->IsReturningFromLD())
  3313. {
  3314. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  3315. count = database.LoadCharacterSkills(GetCharacterID(), player);
  3316. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
  3317. count = database.LoadCharacterSpells(GetCharacterID(), player);
  3318. }
  3319. else
  3320. {
  3321. LogWrite(CCLIENT__INFO, 0, "Client", "Player is returning from linkdead status (Player does not need reload) thus skipping database loading for '%s'...", player->GetName());
  3322. }
  3323. // get the latest character starting skills / spells, may have been updated after character creation
  3324. if(GetPlayer()->GetInfoStruct()->get_first_world_login()) {
  3325. world.SyncCharacterAbilities(this);
  3326. Query query;
  3327. query.AddQueryAsync(GetCharacterID(), &database, Q_UPDATE, "UPDATE characters set first_world_login = 0 where id=%u", GetCharacterID());
  3328. GetPlayer()->GetInfoStruct()->set_first_world_login(0);
  3329. }
  3330. new_client_login = NewLoginState::LOGIN_INITIAL_LOAD;
  3331. break;
  3332. }
  3333. case NewLoginState::LOGIN_DELAYED: {
  3334. if(!delay_msg_timer.Enabled() || delay_msg_timer.Check()) {
  3335. LogWrite(CCLIENT__INFO, 0, "Client", "Wait for zone %s to load for new client %s...", GetCurrentZone()->GetZoneName(), GetPlayer()->GetName());
  3336. delay_msg_timer.Start(1000, true);
  3337. }
  3338. if(!GetCurrentZone()->IsLoading()) {
  3339. new_client_login = NewLoginState::LOGIN_ALLOWED;
  3340. }
  3341. return true;
  3342. break;
  3343. }
  3344. }
  3345. delay_msg_timer.Disable();
  3346. sockaddr_in to;
  3347. memset((char*)&to, 0, sizeof(to));
  3348. to.sin_family = AF_INET;
  3349. to.sin_port = port;
  3350. to.sin_addr.s_addr = ip;
  3351. /************ Get all packets from packet manager out queue and process them ************/
  3352. EQApplicationPacket* app = 0;
  3353. if (eqs && !eqs->CheckActive()) {
  3354. num_active_failures++;
  3355. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  3356. if (num_active_failures > 100) {
  3357. return false;
  3358. }
  3359. return true;
  3360. }
  3361. while (ret && eqs && (app = eqs->PopPacket())) {
  3362. ret = HandlePacket(app);
  3363. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  3364. delete app;
  3365. }
  3366. if (GetCurrentZone() && !GetCurrentZone()->IsLoading() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  3367. //database.LoadCharacterActiveSpells(player);
  3368. player->UnlockAllSpells(true);
  3369. should_load_spells = false;
  3370. }
  3371. if(spawn_removal_timer.Check() && GetPlayer()) {
  3372. GetPlayer()->ProcessSpawnRangeUpdates();
  3373. GetPlayer()->CheckSpawnStateQueue();
  3374. }
  3375. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  3376. {
  3377. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  3378. return false;
  3379. }
  3380. if (quest_updates) {
  3381. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  3382. ProcessQuestUpdates();
  3383. }
  3384. int32 queue_timer_delay = rule_manager.GetGlobalRule(R_Client, QuestQueueTimer)->GetInt32();
  3385. if(queue_timer_delay < 10) {
  3386. queue_timer_delay = 10;
  3387. }
  3388. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - queue_timer_delay)) {
  3389. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  3390. CheckQuestQueue();
  3391. }
  3392. MSaveSpellStateMutex.lock();
  3393. if(save_spell_state_timer.Check())
  3394. {
  3395. save_spell_state_timer.Disable();
  3396. GetPlayer()->SaveSpellEffects();
  3397. }
  3398. MSaveSpellStateMutex.unlock();
  3399. if (temp_placement_timer.Check()) {
  3400. if(GetTempPlacementSpawn() && GetPlayer()->WasSentSpawn(GetTempPlacementSpawn()->GetID()) && !hasSentTempPlacementSpawn) {
  3401. SendMoveObjectMode(GetTempPlacementSpawn(), 0);
  3402. hasSentTempPlacementSpawn = true;
  3403. temp_placement_timer.Disable();
  3404. }
  3405. }
  3406. if (pos_update.Check())
  3407. {
  3408. ProcessStateCommands();
  3409. GetPlayer()->ResetMentorship(); // check if we need to asynchronously reset mentorship
  3410. if(GetPlayer()->GetRegionMap())
  3411. GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3412. if(!player_pos_changed && IsReadyForUpdates() && player_pos_timer < Timer::GetCurrentTime2() && enabled_player_pos_timer) {
  3413. if(version > 373) {
  3414. GetPlayer()->info_changed = true;
  3415. GetPlayer()->vis_changed = true;
  3416. GetPlayer()->position_changed = true;
  3417. GetPlayer()->changed = true;
  3418. GetPlayer()->AddChangedZoneSpawn();
  3419. }
  3420. player_pos_timer = Timer::GetCurrentTime2()+5000;
  3421. enabled_player_pos_timer = false;
  3422. }
  3423. if(player_pos_changed && IsReadyForUpdates()) {
  3424. player_pos_timer = Timer::GetCurrentTime2()+500;
  3425. enabled_player_pos_timer = true;
  3426. if(!underworld_cooldown_timer.Enabled() || (underworld_cooldown_timer.Enabled() && underworld_cooldown_timer.Check())) {
  3427. bool underworld = false;
  3428. if(rule_manager.GetGlobalRule(R_Zone, UseMapUnderworldCoords)->GetBool()) {
  3429. if(GetCurrentZone()->GetUnderWorld() != -1000000.0f) {
  3430. if(GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld())
  3431. underworld = true;
  3432. }
  3433. else if(GetPlayer()->GetMap() && GetPlayer()->GetMap()->GetMinY() != 9999999.0f && GetPlayer()->GetY() < (GetPlayer()->GetMap()->GetMinY() + rule_manager.GetGlobalRule(R_Zone, MapUnderworldCoordOffset)->GetFloat())) {
  3434. underworld = true;
  3435. }
  3436. }
  3437. else if(GetPlayer()->GetMap() && GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld()) {
  3438. underworld = true;
  3439. }
  3440. if(underworld) {
  3441. player->SetX(GetCurrentZone()->GetSafeX());
  3442. player->SetY(GetCurrentZone()->GetSafeY());
  3443. player->SetZ(GetCurrentZone()->GetSafeZ());
  3444. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3445. EQ2Packet* app = GetPlayer()->Move(player->GetX(), player->GetY(), player->GetZ(), GetVersion(), player->GetHeading());
  3446. if(app){
  3447. QueuePacket(app);
  3448. }
  3449. SimpleMessage(CHANNEL_COLOR_RED, "You have been teleported to a safe location in the zone, because you appeared to have fallen through the world.");
  3450. }
  3451. underworld_cooldown_timer.Start();
  3452. }
  3453. //GetPlayer()->CalculateLocation();
  3454. client_list.CheckPlayersInvisStatus(this);
  3455. player_pos_changed = false;
  3456. GetCurrentZone()->CheckTransporters(this);
  3457. if(GetPlayer()->GetRegionMap())
  3458. {
  3459. GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3460. }
  3461. }
  3462. else if (IsReadyForUpdates() && GetPlayer()->GetRegionMap()) {
  3463. GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3464. }
  3465. }
  3466. if (lua_interface && lua_debug && lua_debug_timer.Check())
  3467. lua_interface->UpdateDebugClients(this);
  3468. if (quest_pos_timer.Check())
  3469. CheckPlayerQuestsLocationUpdate();
  3470. if (player->GetSkills()->HasSkillUpdates()) {
  3471. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  3472. if (skills) {
  3473. Skill* skill = 0;
  3474. vector<Skill*>::iterator itr;
  3475. for (itr = skills->begin(); itr != skills->end(); itr++) {
  3476. skill = *itr;
  3477. SkillChanged(skill, skill->previous_val, skill->current_val);
  3478. }
  3479. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  3480. if (app) QueuePacket(app);
  3481. safe_delete(skills);
  3482. }
  3483. }
  3484. m_resurrect.writelock(__FUNCTION__, __LINE__);
  3485. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  3486. safe_delete(current_rez.expire_timer);
  3487. current_rez.expire_timer = 0;
  3488. current_rez.active = false;
  3489. current_rez.caster = 0;
  3490. current_rez.crit = false;
  3491. current_rez.crit_mod = 0;
  3492. current_rez.expire_timer = 0;
  3493. current_rez.heal_name = "";
  3494. current_rez.hp_perc = 0;
  3495. current_rez.mp_perc = 0;
  3496. current_rez.no_calcs = false;
  3497. current_rez.range = 0;
  3498. current_rez.should_delete = false;
  3499. current_rez.spell_name = "";
  3500. current_rez.spell_visual = 0;
  3501. current_rez.subspell = 0;
  3502. }
  3503. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  3504. // Quest timers
  3505. Quest* failed_step = 0;
  3506. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  3507. if (quest_timers.size() > 0) {
  3508. vector<int32>::iterator itr;
  3509. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  3510. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  3511. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  3512. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  3513. Quest* quest = player_quests->at(*itr);
  3514. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  3515. failed_step = quest;
  3516. break;
  3517. }
  3518. }
  3519. else {
  3520. itr = quest_timers.erase(itr);
  3521. break;
  3522. }
  3523. }
  3524. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  3525. }
  3526. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  3527. if (failed_step)
  3528. failed_step->StepFailed(failed_step->GetTimerStep());
  3529. if (player->ControlFlagsChanged())
  3530. player->SendControlFlagUpdates(this);
  3531. if (!eqs || (eqs && !eqs->CheckActive()))
  3532. ret = false;
  3533. // redundant to client disconnect
  3534. // if(!ret)
  3535. // Save();
  3536. return ret;
  3537. }
  3538. ClientList::ClientList() {
  3539. MClients.SetName("ClientList::MClients");
  3540. }
  3541. ClientList::~ClientList() {
  3542. }
  3543. void ClientList::ReloadQuests() {
  3544. list<Client*>::iterator client_iter;
  3545. Client* client = 0;
  3546. MClients.readlock(__FUNCTION__, __LINE__);
  3547. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3548. client = *client_iter;
  3549. if (client)
  3550. client->ReloadQuests();
  3551. }
  3552. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3553. }
  3554. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  3555. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  3556. return;
  3557. list<Client*>::iterator client_iter;
  3558. Client* client = 0;
  3559. MClients.readlock(__FUNCTION__, __LINE__);
  3560. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3561. client = *client_iter;
  3562. if (client == owner || client->GetPlayer() == NULL)
  3563. continue;
  3564. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  3565. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  3566. }
  3567. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3568. }
  3569. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  3570. list<Client*>::iterator client_iter;
  3571. Client* client = 0;
  3572. MClients.readlock(__FUNCTION__, __LINE__);
  3573. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3574. client = *client_iter;
  3575. if (!client->GetPlayer())
  3576. continue;
  3577. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  3578. }
  3579. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3580. }
  3581. int32 ClientList::Count() {
  3582. return client_list.size();
  3583. }
  3584. void ClientList::Add(Client* client) {
  3585. MClients.writelock(__FUNCTION__, __LINE__);
  3586. client_list.push_back(client);
  3587. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3588. }
  3589. Client* ClientList::FindByAccountID(int32 account_id) {
  3590. list<Client*>::iterator client_iter;
  3591. Client* client = 0;
  3592. Client* ret = 0;
  3593. MClients.readlock(__FUNCTION__, __LINE__);
  3594. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3595. client = *client_iter;
  3596. if (client->GetAccountID() == account_id) {
  3597. ret = client;
  3598. break;
  3599. }
  3600. }
  3601. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3602. return ret;
  3603. }
  3604. Client* ClientList::FindByName(char* charName) {
  3605. list<Client*>::iterator client_iter;
  3606. Client* client = 0;
  3607. Client* ret = 0;
  3608. MClients.readlock(__FUNCTION__, __LINE__);
  3609. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3610. client = *client_iter;
  3611. if (!client || !client->GetPlayer())
  3612. continue;
  3613. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  3614. ret = client;
  3615. break;
  3616. }
  3617. }
  3618. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3619. return ret;
  3620. }
  3621. Client* ClientList::Get(int32 ip, int16 port) {
  3622. list<Client*>::iterator client_iter;
  3623. Client* client = 0;
  3624. Client* ret = 0;
  3625. MClients.readlock(__FUNCTION__, __LINE__);
  3626. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3627. client = *client_iter;
  3628. if (client->GetIP() == ip && client->GetPort() == port) {
  3629. ret = client;
  3630. break;
  3631. }
  3632. }
  3633. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3634. return ret;
  3635. }
  3636. void ClientList::Process() {
  3637. list<Client*>::iterator client_iter;
  3638. list<Client*>::iterator erase_iter;
  3639. Client* client = 0;
  3640. MClients.readlock(__FUNCTION__, __LINE__);
  3641. erase_iter = client_list.end();
  3642. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3643. client = *client_iter;
  3644. // have a sanity check because the client list can sometimes obtain null client pointers
  3645. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  3646. erase_iter = client_iter;
  3647. break;
  3648. }
  3649. }
  3650. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3651. if (erase_iter != client_list.end()) {
  3652. client = *erase_iter;
  3653. MClients.writelock(__FUNCTION__, __LINE__);
  3654. client_list.erase(erase_iter);
  3655. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3656. if (client && !client->remove_from_list) {
  3657. struct in_addr in;
  3658. in.s_addr = client->GetIP();
  3659. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  3660. safe_delete(client);
  3661. }
  3662. }
  3663. }
  3664. void ClientList::RemoveConnection(EQStream* eqs) {
  3665. Client* client;
  3666. if (eqs) {
  3667. list<Client*>::iterator client_iter;
  3668. MClients.readlock(__FUNCTION__, __LINE__);
  3669. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3670. client = *client_iter;
  3671. if (client->getConnection() == eqs)
  3672. client->Disconnect(true);
  3673. }
  3674. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3675. }
  3676. }
  3677. bool ClientList::ContainsStream(EQStream* eqs) {
  3678. if (!eqs) {
  3679. return false;
  3680. }
  3681. list<Client*>::iterator client_iter;
  3682. bool ret = false;
  3683. MClients.readlock(__FUNCTION__, __LINE__);
  3684. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3685. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  3686. ret = true;
  3687. break;
  3688. }
  3689. }
  3690. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3691. return ret;
  3692. }
  3693. void ClientList::Remove(Client* client, bool remove_data) {
  3694. client->remove_from_list = true;
  3695. if (remove_data) {
  3696. safe_delete(client);
  3697. }
  3698. }
  3699. void Client::SetCurrentZone(ZoneServer* zone) {
  3700. current_zone = zone;
  3701. if(player) {
  3702. player->SetZone(zone, GetVersion());
  3703. }
  3704. }
  3705. void Client::SetCurrentZone(int32 id) {
  3706. if (current_zone) {
  3707. //current_zone->GetCombat()->RemoveHate(player);
  3708. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3709. }
  3710. SetCurrentZone(zone_list.Get(id));
  3711. }
  3712. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  3713. if (current_zone) {
  3714. //current_zone->GetCombat()->RemoveHate(player);
  3715. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3716. }
  3717. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  3718. }
  3719. ZoneServer* Client::GetCurrentZone() {
  3720. return current_zone;
  3721. }
  3722. int8 Client::GetMessageChannelColor(int8 channel_type) {
  3723. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  3724. if (channel_type == CHANNEL_LOOT)
  3725. return CHANNEL_COLOR_NEW_LOOT;
  3726. }
  3727. else if (GetVersion() >= 973) {
  3728. if (channel_type == CHANNEL_LOOT)
  3729. return CHANNEL_COLOR_NEWEST_LOOT;
  3730. }
  3731. if (GetVersion() <= 283) {
  3732. if (channel_type <=12)
  3733. return channel_type;
  3734. switch (channel_type) {
  3735. case CHANNEL_GROUP_CHAT:
  3736. case CHANNEL_GROUP_SAY:
  3737. case CHANNEL_RAID_SAY:
  3738. case CHANNEL_GUILD_CHAT:
  3739. case CHANNEL_GUILD_SAY:
  3740. case CHANNEL_OFFICER_SAY:
  3741. case CHANNEL_GUILD_MOTD:
  3742. return channel_type - 1;
  3743. case CHANNEL_PRIVATE_CHAT:
  3744. case CHANNEL_NONPLAYER_TELL:
  3745. return channel_type - 5;
  3746. case CHANNEL_PRIVATE_TELL:
  3747. case CHANNEL_TELL_FROM_CS:
  3748. return channel_type - 6;
  3749. case CHANNEL_CHAT_CHANNEL_TEXT:
  3750. case CHANNEL_OUT_OF_CHARACTER:
  3751. case CHANNEL_AUCTION:
  3752. case CHANNEL_CUSTOM_CHANNEL:
  3753. case CHANNEL_CHARACTER_TEXT:
  3754. case CHANNEL_REWARD:
  3755. case CHANNEL_DEATH:
  3756. case CHANNEL_PET_CHAT:
  3757. case CHANNEL_SKILL:
  3758. return channel_type - 7;
  3759. case CHANNEL_SPELLS:
  3760. case CHANNEL_YOU_CAST:
  3761. case CHANNEL_YOU_FAIL:
  3762. return channel_type - 8;
  3763. case CHANNEL_FRIENDLY_CAST:
  3764. case CHANNEL_FRIENDLY_FAIL:
  3765. case CHANNEL_OTHER_CAST:
  3766. case CHANNEL_OTHER_FAIL:
  3767. case CHANNEL_HOSTILE_CAST:
  3768. case CHANNEL_HOSTILE_FAIL:
  3769. case CHANNEL_WORN_OFF:
  3770. case CHANNEL_SPELLS_OTHER:
  3771. return channel_type - 9;
  3772. case CHANNEL_COMBAT:
  3773. return channel_type - 15;
  3774. case CHANNEL_HEROIC_OPPORTUNITY:
  3775. case CHANNEL_NON_MELEE_DAMAGE:
  3776. case CHANNEL_DAMAGE_SHIELD:
  3777. return channel_type - 16;
  3778. case CHANNEL_MELEE_COMBAT:
  3779. case CHANNEL_WARNINGS:
  3780. case CHANNEL_YOU_HIT:
  3781. case CHANNEL_YOU_MISS:
  3782. case CHANNEL_ATTACKER_HITS:
  3783. case CHANNEL_ATTACKER_MISSES:
  3784. return channel_type - 18;
  3785. case CHANNEL_OTHER_HIT:
  3786. case CHANNEL_OTHER_MISSES:
  3787. case CHANNEL_CRITICAL_HIT:
  3788. return channel_type - 22;
  3789. case CHANNEL_OTHER:
  3790. case CHANNEL_MONEY_SPLIT:
  3791. case CHANNEL_LOOT:
  3792. return channel_type - 30;
  3793. case CHANNEL_COMMAND_TEXT:
  3794. case CHANNEL_BROADCAST:
  3795. case CHANNEL_WHO:
  3796. case CHANNEL_COMMANDS:
  3797. case CHANNEL_MERCHANT:
  3798. case CHANNEL_MERCHANT_BUY_SELL:
  3799. case CHANNEL_CONSIDER_MESSAGE:
  3800. case CHANNEL_CON_MINUS_2:
  3801. case CHANNEL_CON_MINUS_1:
  3802. case CHANNEL_CON_0:
  3803. case CHANNEL_CON_1:
  3804. case CHANNEL_CON_2:
  3805. return channel_type - 31;
  3806. default: {
  3807. return CHANNEL_DEFAULT;
  3808. }
  3809. }
  3810. }
  3811. else if (GetVersion() <= 373) {
  3812. if (channel_type <=18)
  3813. return channel_type;
  3814. switch (channel_type) {
  3815. case CHANNEL_PRIVATE_CHAT:
  3816. case CHANNEL_NONPLAYER_TELL:
  3817. return 22;
  3818. case CHANNEL_PRIVATE_TELL:
  3819. case CHANNEL_TELL_FROM_CS:
  3820. return 23;
  3821. case CHANNEL_CHAT_CHANNEL_TEXT:
  3822. case CHANNEL_OUT_OF_CHARACTER:
  3823. case CHANNEL_CUSTOM_CHANNEL:
  3824. case CHANNEL_CHARACTER_TEXT:
  3825. case CHANNEL_REWARD:
  3826. case CHANNEL_DEATH:
  3827. case CHANNEL_PET_CHAT:
  3828. case CHANNEL_SKILL:
  3829. return 26;
  3830. case CHANNEL_AUCTION:
  3831. return 27;
  3832. case CHANNEL_SPELLS:
  3833. case CHANNEL_YOU_CAST:
  3834. case CHANNEL_YOU_FAIL:
  3835. return channel_type - 8;
  3836. case CHANNEL_FRIENDLY_CAST:
  3837. case CHANNEL_FRIENDLY_FAIL:
  3838. case CHANNEL_OTHER_CAST:
  3839. case CHANNEL_OTHER_FAIL:
  3840. case CHANNEL_HOSTILE_CAST:
  3841. case CHANNEL_HOSTILE_FAIL:
  3842. case CHANNEL_WORN_OFF:
  3843. case CHANNEL_SPELLS_OTHER:
  3844. return channel_type - 9;
  3845. case CHANNEL_COMBAT:
  3846. return channel_type - 15;
  3847. case CHANNEL_HEROIC_OPPORTUNITY:
  3848. case CHANNEL_NON_MELEE_DAMAGE:
  3849. case CHANNEL_DAMAGE_SHIELD:
  3850. return channel_type - 16;
  3851. case CHANNEL_MELEE_COMBAT:
  3852. case CHANNEL_WARNINGS:
  3853. case CHANNEL_YOU_HIT:
  3854. case CHANNEL_YOU_MISS:
  3855. case CHANNEL_ATTACKER_HITS:
  3856. case CHANNEL_ATTACKER_MISSES:
  3857. return channel_type - 18;
  3858. case CHANNEL_OTHER_HIT:
  3859. case CHANNEL_OTHER_MISSES:
  3860. case CHANNEL_CRITICAL_HIT:
  3861. return channel_type - 22;
  3862. case CHANNEL_OTHER:
  3863. case CHANNEL_MONEY_SPLIT:
  3864. case CHANNEL_LOOT:
  3865. return channel_type - 30;
  3866. case CHANNEL_COMMAND_TEXT:
  3867. case CHANNEL_BROADCAST:
  3868. case CHANNEL_WHO:
  3869. case CHANNEL_COMMANDS:
  3870. case CHANNEL_MERCHANT:
  3871. case CHANNEL_MERCHANT_BUY_SELL:
  3872. case CHANNEL_CONSIDER_MESSAGE:
  3873. case CHANNEL_CON_MINUS_2:
  3874. case CHANNEL_CON_MINUS_1:
  3875. case CHANNEL_CON_0:
  3876. case CHANNEL_CON_1:
  3877. case CHANNEL_CON_2:
  3878. return 68;
  3879. default: {
  3880. return CHANNEL_DEFAULT;
  3881. }
  3882. }
  3883. }
  3884. else if (GetVersion() <= 561) {
  3885. if (channel_type < 20)
  3886. return channel_type;
  3887. switch (channel_type) {
  3888. case CHANNEL_GUILD_MOTD:
  3889. case CHANNEL_GUILD_MEMBER_ONLINE:
  3890. case CHANNEL_GUILD_EVENT:
  3891. return channel_type + 1;
  3892. case CHANNEL_PRIVATE_CHAT:
  3893. case CHANNEL_NONPLAYER_TELL:
  3894. return channel_type - 1;
  3895. case CHANNEL_PRIVATE_TELL:
  3896. case CHANNEL_TELL_FROM_CS:
  3897. case CHANNEL_ARENA:
  3898. case CHANNEL_CHAT_CHANNEL_TEXT:
  3899. case CHANNEL_OUT_OF_CHARACTER:
  3900. case CHANNEL_AUCTION:
  3901. case CHANNEL_CUSTOM_CHANNEL:
  3902. case CHANNEL_CHARACTER_TEXT:
  3903. case CHANNEL_REWARD:
  3904. case CHANNEL_DEATH:
  3905. case CHANNEL_PET_CHAT:
  3906. case CHANNEL_SKILL:
  3907. case CHANNEL_FACTION:
  3908. case CHANNEL_SPELLS:
  3909. case CHANNEL_YOU_CAST:
  3910. case CHANNEL_YOU_FAIL:
  3911. return channel_type - 2;
  3912. case CHANNEL_FRIENDLY_CAST:
  3913. case CHANNEL_FRIENDLY_FAIL:
  3914. case CHANNEL_OTHER_CAST:
  3915. case CHANNEL_OTHER_FAIL:
  3916. case CHANNEL_HOSTILE_CAST:
  3917. case CHANNEL_HOSTILE_FAIL:
  3918. case CHANNEL_WORN_OFF:
  3919. case CHANNEL_SPELLS_OTHER:
  3920. case CHANNEL_HEAL_SPELLS:
  3921. case CHANNEL_HEALS:
  3922. case CHANNEL_FRIENDLY_HEALS:
  3923. case CHANNEL_OTHER_HEALS:
  3924. case CHANNEL_HOSTILE_HEALS:
  3925. return channel_type - 3;
  3926. case CHANNEL_COMBAT:
  3927. case CHANNEL_GENERAL_COMBAT:
  3928. case CHANNEL_HEROIC_OPPORTUNITY:
  3929. case CHANNEL_NON_MELEE_DAMAGE:
  3930. case CHANNEL_DAMAGE_SHIELD:
  3931. case CHANNEL_WARD:
  3932. return channel_type - 4;
  3933. case CHANNEL_MELEE_COMBAT:
  3934. case CHANNEL_WARNINGS:
  3935. case CHANNEL_YOU_HIT:
  3936. case CHANNEL_YOU_MISS:
  3937. case CHANNEL_ATTACKER_HITS:
  3938. case CHANNEL_ATTACKER_MISSES:
  3939. case CHANNEL_YOUR_PET_HITS:
  3940. case CHANNEL_YOUR_PET_MISSES:
  3941. case CHANNEL_ATTACKER_HITS_PET:
  3942. case CHANNEL_ATTACKER_MISSES_PET:
  3943. case CHANNEL_OTHER_HIT:
  3944. case CHANNEL_OTHER_MISSES:
  3945. return channel_type - 5;
  3946. case CHANNEL_OTHER:
  3947. case CHANNEL_MONEY_SPLIT:
  3948. case CHANNEL_LOOT:
  3949. return channel_type - 14;
  3950. case CHANNEL_COMMAND_TEXT:
  3951. case CHANNEL_BROADCAST:
  3952. case CHANNEL_WHO:
  3953. case CHANNEL_COMMANDS:
  3954. case CHANNEL_MERCHANT:
  3955. case CHANNEL_MERCHANT_BUY_SELL:
  3956. case CHANNEL_CONSIDER_MESSAGE:
  3957. case CHANNEL_CON_MINUS_2:
  3958. case CHANNEL_CON_MINUS_1:
  3959. case CHANNEL_CON_0:
  3960. case CHANNEL_CON_1:
  3961. case CHANNEL_CON_2:
  3962. case CHANNEL_TRADESKILLS:
  3963. case CHANNEL_HARVESTING:
  3964. case CHANNEL_HARVESTING_WARNINGS:
  3965. return channel_type - 15;
  3966. default: {
  3967. return CHANNEL_DEFAULT;
  3968. }
  3969. }
  3970. }
  3971. else {
  3972. switch (channel_type) {
  3973. default: {
  3974. return channel_type;
  3975. }
  3976. }
  3977. }
  3978. return channel_type;
  3979. }
  3980. void Client::HandleTellMessage(Client* from, const char* message, const char* to, int32 current_language_id) {
  3981. if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  3982. return;
  3983. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  3984. if (packet) {
  3985. packet->setDataByName("from", from->GetPlayer()->GetName());
  3986. packet->setDataByName("to", to);
  3987. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  3988. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  3989. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  3990. packet->setDataByName("unknown2", 1, 1);
  3991. packet->setDataByName("show_bubble", 1);
  3992. if (current_language_id == 0 || GetPlayer()->HasLanguage(current_language_id)) {
  3993. packet->setDataByName("understood", 1);
  3994. }
  3995. packet->setDataByName("time", 2);
  3996. packet->setDataByName("language", current_language_id);
  3997. packet->setMediumStringByName("message", message);
  3998. EQ2Packet* outpacket = packet->serialize();
  3999. QueuePacket(outpacket);
  4000. safe_delete(packet);
  4001. }
  4002. }
  4003. void Client::SimpleMessage(int8 color, const char* message) {
  4004. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  4005. if (command_packet) {
  4006. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  4007. command_packet->setMediumStringByName("text", message);
  4008. command_packet->setDataByName("unknown02", 0x00ff);
  4009. EQ2Packet* outapp = command_packet->serialize();
  4010. QueuePacket(outapp);
  4011. safe_delete(command_packet);
  4012. }
  4013. }
  4014. void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
  4015. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  4016. if (packet) {
  4017. int8 xxx = spell->GetSpellData()->is_aa;
  4018. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  4019. packet->setDataByName("spell_id", spell->GetSpellID());
  4020. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  4021. packet->setDataByName("spell_name", spell->GetName());
  4022. if(add_silently)
  4023. packet->setDataByName("add_silently", 1);
  4024. if(add_to_hotbar)
  4025. packet->setDataByName("add_to_hotbar", 1);
  4026. packet->setDataByName("unknown", xxx);
  4027. packet->setDataByName("display_spell_tier", 1);
  4028. packet->setDataByName("unknown3", 1);
  4029. packet->setDataByName("tier", spell->GetSpellTier());
  4030. packet->setDataByName("icon", spell->GetSpellIcon());
  4031. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  4032. packet->setDataByName("unknown5", 0xFFFFFFFF);
  4033. //packet->PrintPacket();
  4034. EQ2Packet* outapp = packet->serialize();
  4035. //DumpPacket(outapp);
  4036. QueuePacket(outapp);
  4037. safe_delete(packet);
  4038. }
  4039. }
  4040. void Client::Message(int8 type, const char* message, ...) {
  4041. va_list argptr;
  4042. char buffer[4096];
  4043. va_start(argptr, message);
  4044. vsnprintf(buffer, sizeof(buffer), message, argptr);
  4045. va_end(argptr);
  4046. SimpleMessage(type, buffer);
  4047. }
  4048. void Client::Disconnect(bool send_disconnect)
  4049. {
  4050. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  4051. this->Save();
  4052. this->GetPlayer()->WritePlayerStatistics();
  4053. SetConnected(false);
  4054. if (send_disconnect && getConnection())
  4055. getConnection()->SendDisconnect(true);
  4056. eqs = 0;
  4057. }
  4058. bool Client::Summon(const char* search_name) {
  4059. Spawn* target = 0;
  4060. if (search_name || GetPlayer()->GetTarget()) {
  4061. Client* search_client = 0;
  4062. if (search_name) {
  4063. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  4064. if (target && target->IsPlayer())
  4065. search_client = target->GetClient();
  4066. if (!target) {
  4067. search_client = zone_list.GetClientByCharName(string(search_name));
  4068. if (search_client)
  4069. target = search_client->GetPlayer();
  4070. }
  4071. }
  4072. else
  4073. target = GetPlayer()->GetTarget();
  4074. if (target && target != GetPlayer()) {
  4075. target->SetX(GetPlayer()->GetX());
  4076. target->SetY(GetPlayer()->GetY());
  4077. target->SetZ(GetPlayer()->GetZ());
  4078. target->SetHeading(GetPlayer()->GetHeading());
  4079. if (!target->IsPlayer()) {
  4080. target->SetSpawnOrigX(target->GetX());
  4081. target->SetSpawnOrigY(target->GetY());
  4082. target->SetSpawnOrigZ(target->GetZ());
  4083. target->SetSpawnOrigHeading(target->GetHeading());
  4084. }
  4085. target->SetLocation(GetPlayer()->GetLocation());
  4086. if(target->IsNPC()) {
  4087. ((NPC*)target)->HaltMovement();
  4088. }
  4089. }
  4090. else if (target)
  4091. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  4092. if (search_client && search_client != this) {
  4093. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  4094. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  4095. if (search_client->GetCurrentZone() != GetCurrentZone())
  4096. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  4097. else {
  4098. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  4099. if (app)
  4100. search_client->QueuePacket(app);
  4101. }
  4102. }
  4103. }
  4104. if (!target)
  4105. return false;
  4106. else
  4107. return true;
  4108. }
  4109. std::string Client::IdentifyInstanceLockout(int32 zoneID, bool displayClient) {
  4110. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  4111. if(instanceType < 1)
  4112. return std::string("");
  4113. ZoneServer* instance_zone = nullptr;
  4114. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  4115. if (data) {
  4116. // If lockout instances check to see if we are locked out
  4117. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  4118. int32 time = 0;
  4119. // Check success timer
  4120. if (data->last_success_timestamp > 0) {
  4121. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  4122. // Timer has not expired yet can't re enter
  4123. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  4124. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  4125. }
  4126. }
  4127. // Check failure timer
  4128. if (data->last_failure_timestamp > 0) {
  4129. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  4130. // Timer has not expired yet
  4131. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  4132. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  4133. }
  4134. }
  4135. // Time > 0 then we are locked out, make the message and send it and return true
  4136. if (time > 0) {
  4137. string time_msg = "";
  4138. int16 hour;
  4139. int8 min;
  4140. int8 sec;
  4141. hour = time / 3600;
  4142. time = time % 3600;
  4143. min = time / 60;
  4144. time = time % 60;
  4145. sec = time;
  4146. if (hour > 0) {
  4147. char temp[10];
  4148. snprintf(temp, 9," %i", hour);
  4149. time_msg.append(temp);
  4150. time_msg.append(" hour");
  4151. time_msg.append((hour > 1) ? "s" : "");
  4152. }
  4153. if (min > 0) {
  4154. char temp[5];
  4155. snprintf(temp, 4," %i", min);
  4156. time_msg.append(temp);
  4157. time_msg.append(" minute");
  4158. time_msg.append((min > 1) ? "s" : "");
  4159. }
  4160. // Only add seconds if minutes and hours are 0
  4161. if (hour == 0 && min == 0 && sec > 0) {
  4162. char temp[5];
  4163. snprintf(temp, 4," %i", sec);
  4164. time_msg.append(temp);
  4165. time_msg.append(" second");
  4166. time_msg.append((sec > 1) ? "s" : "");
  4167. }
  4168. if(displayClient)
  4169. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  4170. return time_msg;
  4171. }
  4172. }
  4173. }
  4174. return std::string("");
  4175. }
  4176. ZoneServer* Client::IdentifyInstance(int32 zoneID) {
  4177. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  4178. if(instanceType < 1)
  4179. return nullptr;
  4180. ZoneServer* instance_zone = nullptr;
  4181. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  4182. if (data) {
  4183. std::string lockoutTime = IdentifyInstanceLockout(zoneID);
  4184. // If lockout instances check to see if we are locked out
  4185. if (lockoutTime.length() > 0) {
  4186. return nullptr;
  4187. }
  4188. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  4189. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID, false, false);
  4190. // 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
  4191. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  4192. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  4193. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  4194. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  4195. }
  4196. else
  4197. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  4198. data->instance_id = instance_zone->GetInstanceID();
  4199. }
  4200. }
  4201. return instance_zone;
  4202. }
  4203. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  4204. ZoneServer* instance_zone = NULL;
  4205. int8 instanceType = 0;
  4206. // determine if this is a group instanced zone that already exists
  4207. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  4208. if (instance_zone != NULL)
  4209. Zone(instance_zone->GetInstanceID(), zone_coords_valid);
  4210. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  4211. {
  4212. // best to check if we already have our own instance!
  4213. if((instance_zone = IdentifyInstance(zoneID)) == nullptr)
  4214. {
  4215. switch (instanceType)
  4216. {
  4217. case SOLO_LOCKOUT_INSTANCE:
  4218. case GROUP_LOCKOUT_INSTANCE:
  4219. case RAID_LOCKOUT_INSTANCE:
  4220. {
  4221. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4222. if (instance_zone) {
  4223. // 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
  4224. // so delete `instances` entry for the zone when it shuts down.
  4225. 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());
  4226. if (db_id > 0)
  4227. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  4228. }
  4229. break;
  4230. }
  4231. case SOLO_PERSIST_INSTANCE:
  4232. case GROUP_PERSIST_INSTANCE:
  4233. case RAID_PERSIST_INSTANCE:
  4234. {
  4235. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4236. if (instance_zone) {
  4237. 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());
  4238. if (db_id > 0)
  4239. 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()));
  4240. }
  4241. break;
  4242. }
  4243. case PUBLIC_INSTANCE:
  4244. case TRADESKILL_INSTANCE:
  4245. {
  4246. // if its public/tradeskill, look for a public already setup
  4247. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  4248. if (instance_zone) {
  4249. // Check the current population against the max population, if greater or equal start a new version
  4250. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  4251. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4252. }
  4253. else
  4254. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4255. break;
  4256. }
  4257. case PERSONAL_HOUSE_INSTANCE:
  4258. case GUILD_HOUSE_INSTANCE:
  4259. {
  4260. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  4261. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  4262. // with the OP_EnterHouseMsg opcode
  4263. break;
  4264. }
  4265. case QUEST_INSTANCE:
  4266. {
  4267. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4268. break;
  4269. /*
  4270. 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`;
  4271. */
  4272. }
  4273. default:
  4274. {
  4275. // NONE
  4276. }
  4277. }
  4278. }
  4279. if (instance_zone != NULL)
  4280. Zone(instance_zone, zone_coords_valid);
  4281. }
  4282. if (instance_zone != NULL)
  4283. return true;
  4284. else
  4285. return false;
  4286. }
  4287. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  4288. Spawn* target = 0;
  4289. if (search_name || GetPlayer()->GetTarget()) {
  4290. Client* search_client = 0;
  4291. if (search_name) {
  4292. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  4293. if (!target) {
  4294. search_client = zone_list.GetClientByCharName(search_name);
  4295. if (search_client)
  4296. target = search_client->GetPlayer();
  4297. }
  4298. if (target)
  4299. GetPlayer()->SetTarget(target);
  4300. }
  4301. else
  4302. target = GetPlayer()->GetTarget();
  4303. float y = (target != nullptr) ? target->GetY() : 0.0f;
  4304. if(target && target->GetMap() != GetPlayer()->GetMap()) {
  4305. auto loc = glm::vec3(target->GetX(), target->GetZ(), target->GetY());
  4306. y = GetPlayer()->FindBestZ(loc, nullptr);
  4307. }
  4308. if (target && target != GetPlayer()) {
  4309. GetPlayer()->SetX(target->GetX());
  4310. GetPlayer()->SetY(y);
  4311. GetPlayer()->SetZ(target->GetZ());
  4312. GetPlayer()->SetHeading(target->GetHeading());
  4313. GetPlayer()->SetLocation(target->GetLocation());
  4314. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  4315. }
  4316. else if (target)
  4317. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  4318. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  4319. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  4320. else if (target) {
  4321. EQ2Packet* app = GetPlayer()->Move(target->GetX(), y, target->GetZ(), GetVersion(), (target->GetHeading() + 180.0f));
  4322. if (app)
  4323. QueuePacket(app);
  4324. }
  4325. }
  4326. if (!target)
  4327. return false;
  4328. else
  4329. return true;
  4330. }
  4331. bool Client::CheckZoneAccess(const char* zoneName) {
  4332. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  4333. ZoneServer* zone = zone_list.Get(zoneName, false, false, false);
  4334. // JA: implemented /zone lock|unlock commands (2012.07.28)
  4335. if (zone && zone->GetZoneLockState())
  4336. {
  4337. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  4338. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  4339. return false;
  4340. }
  4341. sint16 zoneMinStatus = 0;
  4342. int16 zoneMinLevel = 0;
  4343. int16 zoneMaxLevel = 0;
  4344. int16 zoneMinVersion = 0;
  4345. if (!zone)
  4346. {
  4347. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  4348. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  4349. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  4350. return true;
  4351. }
  4352. }
  4353. else
  4354. {
  4355. zoneMinStatus = zone->GetMinimumStatus();
  4356. zoneMinLevel = zone->GetMinimumLevel();
  4357. zoneMaxLevel = zone->GetMaximumLevel();
  4358. zoneMinVersion = zone->GetMinimumVersion();
  4359. }
  4360. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  4361. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  4362. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  4363. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  4364. {
  4365. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  4366. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  4367. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  4368. return false;
  4369. }
  4370. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  4371. {
  4372. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  4373. {
  4374. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  4375. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  4376. return false;
  4377. }
  4378. }
  4379. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  4380. {
  4381. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  4382. {
  4383. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  4384. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  4385. return false;
  4386. }
  4387. }
  4388. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  4389. {
  4390. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  4391. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  4392. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  4393. {
  4394. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  4395. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  4396. return false;
  4397. }
  4398. }
  4399. return true;
  4400. }
  4401. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID, bool is_spell) {
  4402. Zone(zone_list.GetByInstanceID(instanceid, 0, false, true), set_coords, is_spell);
  4403. }
  4404. void Client::Zone(ZoneServer* new_zone, bool set_coords, bool is_spell) {
  4405. if (!new_zone) {
  4406. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  4407. return;
  4408. }
  4409. if(GetVersion() == 373 && GetAdminStatus() == 0) {
  4410. if(strncasecmp(new_zone->GetZoneFile(),"boat_06p_tutorial02",19) && strncasecmp(new_zone->GetZoneFile(),"tutorial_island02",17)
  4411. && strncasecmp(new_zone->GetZoneFile(),"tutorial_island02_epic",22)) { // accounts for 01 and 02 zones
  4412. SimpleMessage(CHANNEL_COLOR_RED, "This client does not currently support beyond the boat tutorial (farjourneyfreeport) or island of refuge (islerefuge1)");
  4413. return;
  4414. }
  4415. }
  4416. else if(GetVersion() < 546 && GetVersion() > 561) {
  4417. if(strncasecmp(new_zone->GetZoneFile(),"design_path_script",18) == 0) {
  4418. SimpleMessage(CHANNEL_COLOR_RED, "This zone is only available for KoS and earlier clients.");
  4419. return;
  4420. }
  4421. }
  4422. client_zoning = true;
  4423. zoning_id = new_zone->GetZoneID();
  4424. zoning_instance_id = new_zone->GetInstanceID();
  4425. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  4426. player->SetResurrecting(true);
  4427. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  4428. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  4429. SaveSpells();
  4430. ResetSendMail();
  4431. // Remove players pet from zone if there is one
  4432. ((Entity*)player)->DismissAllPets();
  4433. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  4434. GetCurrentZone()->RemoveSpawn(player, false, true, true, true, !is_spell);
  4435. GetPlayer()->DeleteSpellEffects(true);
  4436. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  4437. SetZoningDestination(new_zone);
  4438. SetCurrentZone(new_zone);
  4439. if (player->GetGroupMemberInfo())
  4440. {
  4441. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  4442. player->UpdateGroupMemberInfo();
  4443. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  4444. }
  4445. // block out the member info for the group
  4446. TempRemoveGroup();
  4447. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  4448. if (set_coords)
  4449. {
  4450. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  4451. __FUNCTION__,
  4452. GetCurrentZone()->GetSafeX(),
  4453. GetCurrentZone()->GetSafeY(),
  4454. GetCurrentZone()->GetSafeZ(),
  4455. GetCurrentZone()->GetSafeHeading(),
  4456. new_zone->GetZoneName()
  4457. );
  4458. player->SetX(GetCurrentZone()->GetSafeX());
  4459. player->SetY(GetCurrentZone()->GetSafeY());
  4460. player->SetZ(GetCurrentZone()->GetSafeZ());
  4461. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  4462. SetZoningCoords(GetCurrentZone()->GetSafeX(), GetCurrentZone()->GetSafeY(),
  4463. GetCurrentZone()->GetSafeZ(), GetCurrentZone()->GetSafeHeading());
  4464. }
  4465. else {
  4466. ResetZoningCoords();
  4467. }
  4468. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  4469. Save();
  4470. char* new_zone_ip = 0;
  4471. if (IsPrivateAddress(this->GetIP()) && strlen(net.GetInternalWorldAddress()) > 0)
  4472. new_zone_ip = net.GetInternalWorldAddress();
  4473. else
  4474. new_zone_ip = net.GetWorldAddress();
  4475. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  4476. int32 key = Timer::GetUnixTimeStamp();
  4477. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  4478. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  4479. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  4480. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  4481. if (version > 373) {
  4482. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  4483. if (packet)
  4484. {
  4485. QueuePacket(packet->serialize());
  4486. safe_delete(packet);
  4487. }
  4488. }
  4489. }
  4490. void Client::Zone(const char* new_zone, bool set_coords, bool is_spell)
  4491. {
  4492. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  4493. Zone(zone_list.Get(new_zone), set_coords, is_spell);
  4494. }
  4495. float Client::DistanceFrom(Client* client) {
  4496. float ret = 0;
  4497. if (client && client != this) {
  4498. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  4499. ret = sqrt(ret);
  4500. }
  4501. return ret;
  4502. }
  4503. void Client::DetermineCharacterUpdates() {
  4504. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  4505. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  4506. cdu->account_id = GetAccountID();
  4507. cdu->char_id = GetCharacterID();
  4508. int32 timestamp = Timer::GetUnixTimeStamp();
  4509. int8 flag = GetTimeStampFlag();
  4510. if (flag & LEVEL_UPDATE_FLAG)
  4511. {
  4512. cdu->update_field = LEVEL_UPDATE_FLAG;
  4513. cdu->update_data = player->GetLevel();
  4514. loginserver.SendPacket(outpack);
  4515. }
  4516. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  4517. if (flag & CLASS_UPDATE_FLAG)
  4518. {
  4519. cdu->update_field = CLASS_UPDATE_FLAG;
  4520. cdu->update_data = player->GetAdventureClass();
  4521. loginserver.SendPacket(outpack);
  4522. }
  4523. if (flag & GENDER_UPDATE_FLAG)
  4524. {
  4525. cdu->update_field = GENDER_UPDATE_FLAG;
  4526. cdu->update_data = player->GetGender();
  4527. loginserver.SendPacket(outpack);
  4528. }
  4529. if (flag & DELETE_UPDATE_FLAG) {
  4530. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4531. }
  4532. safe_delete(outpack); // Zone, armor and name use a different structure
  4533. if (flag & RACE_UPDATE_FLAG)
  4534. {
  4535. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  4536. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  4537. ru->account_id = GetAccountID();
  4538. ru->char_id = GetCharacterID();
  4539. ru->race = player->GetRace();
  4540. ru->model_type = player->GetModelType();
  4541. loginserver.SendPacket(outpack);
  4542. safe_delete(outpack);
  4543. }
  4544. if (flag & ZONE_UPDATE_FLAG) {
  4545. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  4546. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  4547. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  4548. czu->account_id = GetAccountID();
  4549. czu->char_id = GetCharacterID();
  4550. czu->zone_id = GetCurrentZone()->GetZoneID();
  4551. const char* zone_file = GetCurrentZone()->GetZoneFile();
  4552. czu->zone_length = strlen(zone_file);
  4553. if (czu->zone_length > 64)
  4554. czu->zone_length = 64;
  4555. strncpy(czu->new_zone, zone_file, czu->zone_length);
  4556. loginserver.SendPacket(outpack);
  4557. safe_delete(outpack);
  4558. }
  4559. if (flag & ARMOR_UPDATE_FLAG) {
  4560. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4561. }
  4562. if (flag & NAME_UPDATE_FLAG) {
  4563. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4564. }
  4565. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  4566. }
  4567. void Client::Save() {
  4568. if (GetCharacterID() == 0 || IsSaveDisabled())
  4569. return;
  4570. if (current_zone) {
  4571. DetermineCharacterUpdates();
  4572. UpdateCharacterInstances();
  4573. this->SetLastSavedTimeStamp(Timer::GetCurrentTime2());
  4574. database.Save(this);
  4575. if (GetPlayer()->UpdateQuickbarNeeded()) {
  4576. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  4577. GetPlayer()->ResetQuickbarNeeded();
  4578. }
  4579. database.SaveItems(this);
  4580. database.SaveBuyBacks(this);
  4581. GetPlayer()->SaveHistory();
  4582. GetPlayer()->SaveLUAHistory();
  4583. MSaveSpellStateMutex.lock();
  4584. GetPlayer()->SaveSpellEffects();
  4585. MSaveSpellStateMutex.unlock();
  4586. }
  4587. }
  4588. void Client::UpdateCharacterInstances() {
  4589. if (GetPlayer() != NULL)
  4590. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  4591. /*if ( GetPlayer() != NULL )
  4592. {
  4593. // determine the last timestamp then get a new one, determine the difference in the timestamp
  4594. // to use for applying the update to each instances timer
  4595. int32 lastSaveTS = GetLastSavedTimeStamp();
  4596. int32 newSaveTS = Timer::GetUnixTimeStamp();
  4597. int32 diffTS = newSaveTS - lastSaveTS;
  4598. // update instance timers
  4599. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  4600. // update with the new timestamp and save the db
  4601. this->SetLastSavedTimeStamp(newSaveTS);
  4602. }*/
  4603. }
  4604. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  4605. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  4606. if (packet) {
  4607. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  4608. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  4609. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  4610. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  4611. vector<EntityCommand*> commands;
  4612. vector<EntityCommand*> delete_commands;
  4613. if (out && spawn) {
  4614. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  4615. {
  4616. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  4617. if (!spawn->primary_command_list[i]->default_allow_list)
  4618. {
  4619. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4620. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  4621. continue;
  4622. }
  4623. else
  4624. {
  4625. // default is allow list, only deny if added to the list as deny (false itr second)
  4626. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4627. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  4628. continue;
  4629. }
  4630. commands.push_back(spawn->primary_command_list[i]);
  4631. }
  4632. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  4633. commands.push_back(spawn->secondary_command_list[i]);
  4634. if (spawn->IsPlayer()) {
  4635. if (player->IsFriend(spawn->GetName()))
  4636. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  4637. else
  4638. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  4639. if (player->IsIgnored(spawn->GetName()))
  4640. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  4641. else
  4642. {
  4643. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  4644. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  4645. }
  4646. if (((Player*)spawn)->GetGroupMemberInfo()) {
  4647. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  4648. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  4649. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  4650. }
  4651. if(spawn->IsPlayer() && player->GetGroupMemberInfo() && !player->GetGroupMemberInfo()->mentor_target_char_id)
  4652. delete_commands.push_back(player->CreateEntityCommand("Mentor", 10000, "mentor", "", 0, 0));
  4653. else if(spawn->IsPlayer() && player->GetGroupMemberInfo() && player->GetGroupMemberInfo()->mentor_target_char_id == ((Player*)spawn)->GetCharacterID())
  4654. delete_commands.push_back(player->CreateEntityCommand("Stop Mentoring", 10000, "unmentor", "", 0, 0));
  4655. }
  4656. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  4657. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  4658. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  4659. }
  4660. out->setDataByName("spawn_id", spawn_id);
  4661. out->setArrayLengthByName("num_verbs", commands.size());
  4662. for (int32 i = 0; i < commands.size(); i++) {
  4663. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  4664. out->setArrayDataByName("distance", commands[i]->distance, i);
  4665. if (commands[i]->error_text.length() == 0)
  4666. out->setArrayAddToPacketByName("error", false, i);
  4667. else {
  4668. out->setArrayDataByName("display_error", 1, i);
  4669. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  4670. }
  4671. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  4672. }
  4673. EQ2Packet* outapp = out->serialize();
  4674. //DumpPacket(outapp);
  4675. QueuePacket(outapp);
  4676. safe_delete(out);
  4677. for (int32 i = 0; i < delete_commands.size(); i++) {
  4678. safe_delete(delete_commands[i]);
  4679. }
  4680. }
  4681. }
  4682. safe_delete(packet);
  4683. }
  4684. }
  4685. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  4686. if (previous_value != new_value) {
  4687. 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);
  4688. char tmp[200] = { 0 };
  4689. 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);
  4690. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  4691. }
  4692. }
  4693. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  4694. {
  4695. /* JA notes on the unknown:
  4696. 2 = ding glimmer
  4697. 16 = Achievement Unlocked
  4698. 6 no longer does anything
  4699. */
  4700. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  4701. if (packet) {
  4702. packet->setDataByName("unknown", unknown);
  4703. packet->setMediumStringByName("text", text);
  4704. if (type && strlen(type) > 0)
  4705. packet->setMediumStringByName("message_type", type);
  4706. packet->setDataByName("size", size);
  4707. packet->setDataByName("red", red);
  4708. packet->setDataByName("green", green);
  4709. packet->setDataByName("blue", blue);
  4710. QueuePacket(packet->serialize());
  4711. safe_delete(packet);
  4712. }
  4713. }
  4714. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  4715. if (new_level < 1) {
  4716. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4717. return;
  4718. }
  4719. if (player->GetLevel() != new_level) {
  4720. player->SetLevel(new_level);
  4721. if (player->GetGroupMemberInfo()) {
  4722. player->UpdateGroupMemberInfo();
  4723. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4724. }
  4725. }
  4726. if (new_level > old_level) {
  4727. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  4728. }
  4729. if (player->GetPet()) {
  4730. NPC* pet = (NPC*)player->GetPet();
  4731. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  4732. pet->SetLevel(new_level);
  4733. pet->UpdateWeapons();
  4734. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4735. if (command_packet) {
  4736. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  4737. command_packet->setDataByName("anim_type", 1753);
  4738. QueuePacket(command_packet->serialize());
  4739. safe_delete(command_packet);
  4740. }
  4741. }
  4742. }
  4743. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4744. if (level_update) {
  4745. level_update->setDataByName("old_level", old_level);
  4746. level_update->setDataByName("new_level", new_level);
  4747. QueuePacket(level_update->serialize());
  4748. safe_delete(level_update);
  4749. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  4750. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  4751. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  4752. }
  4753. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4754. if (command_packet) {
  4755. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  4756. command_packet->setDataByName("anim_type", 1753);
  4757. QueuePacket(command_packet->serialize());
  4758. safe_delete(command_packet);
  4759. }
  4760. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  4761. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  4762. SendNewAdventureSpells();
  4763. GetPlayer()->GetInfoStruct()->set_level(new_level);
  4764. GetPlayer()->UpdateWeapons();
  4765. // GetPlayer()->SetLevel(new_level);
  4766. 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__);
  4767. GetPlayer()->CalculatePlayerHPPower();
  4768. GetPlayer()->CalculateBonuses();
  4769. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  4770. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  4771. /*InfoStruct* info = player->GetInfoStruct();
  4772. info->set_agi_base(new_level * 2 + 15);
  4773. info->set_intel_base(new_level * 2 + 15);
  4774. info->set_wis_base(new_level * 2 + 15);
  4775. info->set_str_base(new_level * 2 + 15);
  4776. info->set_sta_base(new_level * 2 + 15);
  4777. info->set_cold_base((int16)(new_level * 1.5 + 10));
  4778. info->set_heat_base((int16)(new_level * 1.5 + 10));
  4779. info->set_disease_base((int16)(new_level * 1.5 + 10));
  4780. info->set_mental_base((int16)(new_level * 1.5 + 10));
  4781. info->set_magic_base((int16)(new_level * 1.5 + 10));
  4782. info->set_divine_base((int16)(new_level * 1.5 + 10));
  4783. info->set_poison_base((int16)(new_level * 1.5 + 10));
  4784. GetPlayer()->GetInfoStruct()->set_poison_base((int16)(new_level * 1.5 + 10));*/
  4785. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4786. GetPlayer()->SetCharSheetChanged(true);
  4787. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  4788. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4789. int16 new_skill_cap = 5 * new_level;
  4790. PlayerSkillList* player_skills = player->GetSkills();
  4791. player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
  4792. player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
  4793. if(rule_manager.GetGlobalRule(R_Player, AutoSkillUpBaseSkills)->GetBool()) {
  4794. //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
  4795. player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
  4796. player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
  4797. }
  4798. player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
  4799. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
  4800. if(rule_manager.GetGlobalRule(R_Player, AutoSkillUpBaseSkills)->GetBool()) {
  4801. //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
  4802. player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
  4803. player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
  4804. }
  4805. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  4806. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  4807. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  4808. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  4809. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPONRY, new_skill_cap);
  4810. if (new_level > player->GetTSLevel())
  4811. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  4812. //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
  4813. if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
  4814. player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
  4815. if (player_skills->HasSkill(SKILL_ID_FISTS))
  4816. player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
  4817. if (player_skills->HasSkill(SKILL_ID_DESTROYING))
  4818. player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
  4819. if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
  4820. player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
  4821. Guild* guild = GetPlayer()->GetGuild();
  4822. if (guild) {
  4823. int8 event_type = 0;
  4824. if (new_level < 10)
  4825. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  4826. else if (new_level == 10)
  4827. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  4828. else if (new_level >= 11 && new_level < 20)
  4829. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  4830. else if (new_level == 20)
  4831. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  4832. else if (new_level >= 21 && new_level < 30)
  4833. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  4834. else if (new_level == 30)
  4835. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  4836. else if (new_level >= 31 && new_level < 40)
  4837. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  4838. else if (new_level == 40)
  4839. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  4840. else if (new_level >= 41 && new_level < 50)
  4841. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  4842. else if (new_level == 50)
  4843. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  4844. else if (new_level >= 51 && new_level < 60)
  4845. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  4846. else if (new_level == 60)
  4847. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  4848. else if (new_level >= 61 && new_level < 70)
  4849. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  4850. else if (new_level == 70)
  4851. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  4852. else if (new_level >= 71 && new_level < 80)
  4853. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  4854. else if (new_level == 80)
  4855. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  4856. 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());
  4857. 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());
  4858. guild->UpdateGuildMemberInfo(GetPlayer());
  4859. guild->SendGuildMember(GetPlayer());
  4860. guild->SendGuildMemberList();
  4861. }
  4862. // Need to send the trait list every time the players level changes
  4863. // Also need to force the char sheet update or else there can be a large delay from when you level
  4864. // to when you are actually able to select traits.
  4865. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4866. GetPlayer()->need_trait_update = true;
  4867. if (version > 561) {
  4868. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4869. master_aa_list.DisplayAA(this, 0, 0);
  4870. }
  4871. else
  4872. master_trait_list.ChooseNextTrait(this);
  4873. if (GetPlayer()->SpawnedBots.size() > 0) {
  4874. map<int32, int32>::iterator itr;
  4875. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  4876. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  4877. if (bot && bot->IsBot())
  4878. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  4879. }
  4880. }
  4881. if (GetPlayer()->GetHP() < GetPlayer()->GetTotalHP() || GetPlayer()->GetPower() < GetPlayer()->GetTotalPower())
  4882. GetPlayer()->GetZone()->AddDamagedSpawn(GetPlayer());
  4883. }
  4884. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  4885. if (new_level < 1) {
  4886. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4887. return;
  4888. }
  4889. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  4890. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  4891. return;
  4892. }
  4893. if (new_level > old_level)
  4894. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  4895. if (player->GetTSLevel() != new_level) {
  4896. player->SetTSLevel(new_level);
  4897. if (player->GetGroupMemberInfo()) {
  4898. player->UpdateGroupMemberInfo();
  4899. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4900. }
  4901. }
  4902. // Only tradeskill skills should increace, and then only those related to your class
  4903. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4904. if (level_update) {
  4905. level_update->setDataByName("old_level", old_level);
  4906. level_update->setDataByName("new_level", new_level);
  4907. level_update->setDataByName("type", 1);
  4908. QueuePacket(level_update->serialize());
  4909. safe_delete(level_update);
  4910. }
  4911. // provide new spells upon levelling
  4912. SendNewTradeskillSpells();
  4913. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4914. if (command_packet) {
  4915. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  4916. command_packet->setDataByName("anim_type", 1753);
  4917. QueuePacket(command_packet->serialize());
  4918. safe_delete(command_packet);
  4919. }
  4920. GetPlayer()->GetInfoStruct()->set_tradeskill_level(new_level);
  4921. GetPlayer()->SetTSLevel(new_level);
  4922. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4923. GetPlayer()->SetCharSheetChanged(true);
  4924. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  4925. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4926. PlayerSkillList* player_skills = player->GetSkills();
  4927. int16 specialize_skill_cap = new_level * 5;
  4928. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  4929. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  4930. int8 ts_class = player->GetTradeskillClass();
  4931. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  4932. int32 skill_id_1, skill_id_2, skill_id_3;
  4933. switch (base_ts_class) {
  4934. case ARTISAN:
  4935. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4936. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4937. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4938. break;
  4939. case OUTFITTER:
  4940. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4941. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4942. skill_id_1 = SKILL_ID_TAILORING;
  4943. skill_id_2 = SKILL_ID_METALSHAPING;
  4944. skill_id_3 = SKILL_ID_METALWORKING;
  4945. if (ts_class == TAILOR) {
  4946. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4947. skill_id_1 = 0;
  4948. }
  4949. else if (ts_class == ARMORER) {
  4950. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4951. skill_id_2 = 0;
  4952. }
  4953. else if (ts_class == WEAPONSMITH) {
  4954. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4955. skill_id_3 = 0;
  4956. }
  4957. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4958. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4959. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4960. break;
  4961. case SCHOLAR:
  4962. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4963. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4964. skill_id_1 = SKILL_ID_SCRIBING;
  4965. skill_id_2 = SKILL_ID_CHEMISTRY;
  4966. skill_id_3 = SKILL_ID_ARTIFICING;
  4967. if (ts_class == SAGE) {
  4968. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4969. skill_id_1 = 0;
  4970. }
  4971. else if (ts_class == ALCHEMIST) {
  4972. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4973. skill_id_2 = 0;
  4974. }
  4975. else if (ts_class == JEWELER) {
  4976. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4977. skill_id_3 = 0;
  4978. }
  4979. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4980. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4981. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4982. break;
  4983. case CRAFTSMAN:
  4984. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4985. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4986. skill_id_1 = SKILL_ID_ARTISTRY;
  4987. skill_id_2 = SKILL_ID_FLETCHING;
  4988. skill_id_3 = SKILL_ID_SCULPTING;
  4989. if (ts_class == PROVISIONER) {
  4990. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4991. skill_id_1 = 0;
  4992. }
  4993. else if (ts_class == WOODWORKER) {
  4994. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4995. skill_id_2 = 0;
  4996. }
  4997. else if (ts_class == CARPENTER) {
  4998. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4999. skill_id_3 = 0;
  5000. }
  5001. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  5002. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  5003. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  5004. break;
  5005. default:
  5006. break;
  5007. }
  5008. if (new_level > player->GetAdventureClass())
  5009. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  5010. Guild* guild = GetPlayer()->GetGuild();
  5011. if (guild) {
  5012. int8 event_type = 0;
  5013. if (new_level < 10)
  5014. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  5015. else if (new_level == 10)
  5016. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  5017. else if (new_level >= 11 && new_level < 20)
  5018. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  5019. else if (new_level == 20)
  5020. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  5021. else if (new_level >= 21 && new_level < 30)
  5022. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  5023. else if (new_level == 30)
  5024. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  5025. else if (new_level >= 31 && new_level < 40)
  5026. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  5027. else if (new_level == 40)
  5028. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  5029. else if (new_level >= 41 && new_level < 50)
  5030. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  5031. else if (new_level == 50)
  5032. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  5033. else if (new_level >= 51 && new_level < 60)
  5034. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  5035. else if (new_level == 60)
  5036. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  5037. else if (new_level >= 61 && new_level < 70)
  5038. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  5039. else if (new_level == 70)
  5040. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  5041. else if (new_level >= 71 && new_level < 80)
  5042. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  5043. else if (new_level == 80)
  5044. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  5045. 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());
  5046. 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());
  5047. guild->UpdateGuildMemberInfo(GetPlayer());
  5048. guild->SendGuildMember(GetPlayer());
  5049. guild->SendGuildMemberList();
  5050. }
  5051. // Need to send the trait list every time the players level changes
  5052. // Also need to force the char sheet update or else there can be a large delay from when you level
  5053. // to when you are actually able to select traits.
  5054. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  5055. QueuePacket(master_trait_list.GetTraitListPacket(this));
  5056. }
  5057. void Client::CloseLoot(int32 spawn_id) {
  5058. if (GetVersion() > 561) {
  5059. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  5060. if (packet) {
  5061. packet->setDataByName("window_id", 4);
  5062. EQ2Packet* outapp = packet->serialize();
  5063. if (outapp) {
  5064. //DumpPacket(outapp);
  5065. QueuePacket(outapp);
  5066. }
  5067. safe_delete(packet);
  5068. }
  5069. }
  5070. if(spawn_id > 0){
  5071. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  5072. if (packet) {
  5073. packet->setDataByName("spawn_id", spawn_id);
  5074. EQ2Packet* outapp = packet->serialize();
  5075. if (outapp)
  5076. QueuePacket(outapp);
  5077. safe_delete(packet);
  5078. }
  5079. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  5080. if(spawn) {
  5081. spawn->CloseLoot(GetPlayer());
  5082. }
  5083. }
  5084. }
  5085. string Client::GetCoinMessage(int32 total_coins) {
  5086. if (total_coins == 0) {
  5087. return " 0 Copper";
  5088. }
  5089. char tmp[64] = { 0 };
  5090. string message = "";
  5091. int32 val = 0;
  5092. if (total_coins >= 1000000) {
  5093. val = total_coins / 1000000;
  5094. total_coins -= 1000000 * val;
  5095. sprintf(tmp, " %u Platinum", val);
  5096. message.append(tmp);
  5097. memset(tmp, 0, 64);
  5098. }
  5099. if (total_coins >= 10000) {
  5100. val = total_coins / 10000;
  5101. total_coins -= 10000 * val;
  5102. sprintf(tmp, " %u Gold", val);
  5103. message.append(tmp);
  5104. memset(tmp, 0, 64);
  5105. }
  5106. if (total_coins >= 100) {
  5107. val = total_coins / 100;
  5108. total_coins -= 100 * val;
  5109. sprintf(tmp, " %u Silver", val);
  5110. message.append(tmp);
  5111. memset(tmp, 0, 64);
  5112. }
  5113. if (total_coins > 0) {
  5114. sprintf(tmp, " %u Copper", (int32)total_coins);
  5115. message.append(tmp);
  5116. }
  5117. return message;
  5118. }
  5119. void Client::SendLootResponsePacket(int32 total_coins, vector<Item*>* items, Spawn* entity, bool ignore_loot_tier) {
  5120. if (!entity) {
  5121. CloseLoot(0);
  5122. return;
  5123. }
  5124. if (total_coins > 0) {
  5125. player->AddCoins(total_coins);
  5126. //PlaySound("coin_cha_ching");
  5127. string message = "";
  5128. if (entity->GetHP() == 0) {
  5129. message = "You loot ";
  5130. entity->SetLootCoins(0, false);
  5131. }
  5132. else
  5133. message = "You receive ";
  5134. message.append(GetCoinMessage(total_coins));
  5135. if (entity->GetHP() == 0)
  5136. message.append(" from the corpse of ").append(entity->GetName());
  5137. int8 type = CHANNEL_LOOT;
  5138. SimpleMessage(type, message.c_str());
  5139. }
  5140. entity->StartLootTimer(GetPlayer());
  5141. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  5142. if (packet) {
  5143. entity->AddSpawnLootWindowCompleted(GetPlayer()->GetID(), false);
  5144. vector<Item*>::iterator itr;
  5145. int32 packet_size = 0;
  5146. EQ2Packet* outapp = 0;
  5147. uchar* data = 0;
  5148. vector<Item*> send_items;
  5149. if (items && items->size() > 0) {
  5150. for (int i = 0; i < items->size(); i++) {
  5151. Item* item = (*items)[i];
  5152. if (entity->GetLootMethod() > GroupLootMethod::METHOD_FFA && !ignore_loot_tier) {
  5153. bool skipItem = entity->IsItemInLootTier(item);
  5154. if (!skipItem) {
  5155. send_items.push_back(item);
  5156. }
  5157. }
  5158. else {
  5159. send_items.push_back(item);
  5160. }
  5161. }
  5162. }
  5163. if (GetVersion() >= 374) {
  5164. if (GetVersion() > 561) {
  5165. if (send_items.size() > 0) {
  5166. packet->setDataByName("loot_count", send_items.size());
  5167. packet->setDataByName("display", 1);
  5168. }
  5169. packet->setDataByName("loot_type", entity->GetLootMethod());
  5170. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000);
  5171. packet->setDataByName("loot_id", entity->GetID());
  5172. EQ2Packet* tmpPacket = packet->serialize();
  5173. packet_size += tmpPacket->size;
  5174. if (send_items.size() > 0) {
  5175. data = new uchar[send_items.size() * 1000 + packet_size];
  5176. memset(data, 0, send_items.size() * 1000 + packet_size);
  5177. }
  5178. else {
  5179. data = new uchar[packet_size];
  5180. memset(data, 0, packet_size);
  5181. }
  5182. uchar* ptr = data;
  5183. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  5184. ptr += tmpPacket->size;
  5185. safe_delete(tmpPacket);
  5186. Item* item = 0;
  5187. if (send_items.size() > 0) {
  5188. for (itr = send_items.begin(); itr != send_items.end(); itr++) {
  5189. item = *itr;
  5190. memcpy(ptr, &item->details.item_id, sizeof(int32));
  5191. ptr += sizeof(int32);
  5192. packet_size += sizeof(int32);
  5193. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  5194. int8 offset = 0;
  5195. if (GetVersion() >= 1188) {
  5196. offset = 13;
  5197. }
  5198. else if (GetVersion() >= 860) {
  5199. offset = 11;
  5200. }
  5201. else if (GetVersion() <= 561) {
  5202. offset = 19;
  5203. }
  5204. else {
  5205. offset = 10;
  5206. }
  5207. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  5208. ptr += tmpPacket->size - offset;
  5209. packet_size += tmpPacket->size - offset;
  5210. safe_delete(tmpPacket);
  5211. }
  5212. }
  5213. packet_size -= sizeof(int32);
  5214. memcpy(data, &packet_size, sizeof(int32));
  5215. packet_size += sizeof(int32);
  5216. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  5217. }
  5218. else {
  5219. if (send_items.size() > 0) {
  5220. packet->setArrayLengthByName("loot_count", send_items.size());
  5221. Item* item = 0;
  5222. if (send_items.size() > 0) {
  5223. int i = 0;
  5224. for (itr = send_items.begin(); itr != send_items.end(); itr++) {
  5225. item = *itr;
  5226. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  5227. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  5228. i++;
  5229. }
  5230. }
  5231. packet->setDataByName("display", 1);
  5232. }
  5233. packet->setDataByName("loot_type", entity->GetLootMethod()); // normal
  5234. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000); // 60 seconds
  5235. packet->setDataByName("spawn_id", entity->GetID());
  5236. outapp = packet->serialize();
  5237. }
  5238. }
  5239. else {
  5240. if (send_items.size() > 0) {
  5241. packet->setArrayLengthByName("loot_count", send_items.size());
  5242. for (int i = 0; i < send_items.size(); i++) {
  5243. Item* item = (send_items)[i];
  5244. packet->setArrayDataByName("name", item->name.c_str(), i);
  5245. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5246. packet->setArrayDataByName("count", item->details.count, i);
  5247. packet->setArrayDataByName("icon", item->GetIcon(GetVersion()), i);
  5248. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  5249. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  5250. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  5251. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  5252. else
  5253. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  5254. }
  5255. }
  5256. packet->setDataByName("display", 1);
  5257. packet->setDataByName("loot_type", entity->GetLootMethod()); // normal
  5258. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000); // 60 seconds
  5259. packet->setDataByName("object_id", entity->GetID());
  5260. outapp = packet->serialize();
  5261. }
  5262. if (outapp) {
  5263. QueuePacket(outapp);
  5264. }
  5265. safe_delete_array(data);
  5266. safe_delete(packet);
  5267. if (!items || items->size() == 0)
  5268. CloseLoot(entity->GetID());
  5269. }
  5270. }
  5271. bool Client::LootSpawnByMethod(Spawn* entity) {
  5272. bool sentLoot = false;
  5273. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  5274. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  5275. if (gmi && gmi->group_id)
  5276. {
  5277. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  5278. if (group)
  5279. {
  5280. int8 auto_split_coin = group->GetGroupOptions()->auto_split;
  5281. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  5282. deque<GroupMemberInfo*>* members = group->GetMembers();
  5283. int32 split_coin_per_player = 0;
  5284. int32 coins_remain_after_split = entity->GetLootCoins();
  5285. int32 total_coins = entity->GetLootCoins();
  5286. if (auto_split_coin) {
  5287. int8 members_in_zone = 0;
  5288. for (int8 i = 0; i < members->size(); i++) {
  5289. Entity* member = members->at(i)->member;
  5290. if (!member || !member->IsPlayer())
  5291. continue;
  5292. if (member->GetZone() != GetPlayer()->GetZone())
  5293. continue;
  5294. members_in_zone++;
  5295. }
  5296. if (members_in_zone < 1) // this should not happen, but divide by zero checked
  5297. members_in_zone = 0;
  5298. split_coin_per_player = entity->GetLootCoins() / members_in_zone;
  5299. coins_remain_after_split = entity->GetLootCoins() - (split_coin_per_player * members_in_zone);
  5300. entity->SetLootCoins(0, false);
  5301. }
  5302. 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);
  5303. bool startWithLooter = true;
  5304. for (int8 i = 0; i < members->size(); i++) {
  5305. Entity* member = members->at(i)->member;
  5306. if (!member || !member->IsPlayer())
  5307. continue;
  5308. if (member->GetZone() != GetPlayer()->GetZone())
  5309. continue;
  5310. // this will make sure we properly send the loot window to the initial requester if there is no item rarity matches
  5311. if (startWithLooter && member != GetPlayer())
  5312. continue;
  5313. else if (!startWithLooter && member == GetPlayer())
  5314. continue;
  5315. else if (startWithLooter) {
  5316. i = 0;
  5317. startWithLooter = false;
  5318. }
  5319. if (auto_split_coin && (split_coin_per_player + coins_remain_after_split) > 0) {
  5320. player->AddCoins(split_coin_per_player + coins_remain_after_split);
  5321. if (((Player*)member)->GetClient()) {
  5322. ((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());
  5323. }
  5324. if (coins_remain_after_split > 0) // overflow of coin division went to the first player
  5325. coins_remain_after_split = 0;
  5326. }
  5327. switch (entity->GetLootMethod()) {
  5328. case GroupLootMethod::METHOD_LOTTO:
  5329. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  5330. if (((Player*)member)->GetClient()) {
  5331. switch (member->GetInfoStruct()->get_group_auto_loot_method()) {
  5332. case 1: { // lotto, need
  5333. if (entity->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
  5334. entity->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
  5335. }
  5336. else { // *need* before greed
  5337. entity->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
  5338. }
  5339. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5340. // if it already exists we have to override the setting
  5341. entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  5342. break;
  5343. }
  5344. case 2: { // decline
  5345. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5346. // if it already exists we have to override the setting
  5347. entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  5348. break;
  5349. }
  5350. default: { // presume 0 or higher than 2
  5351. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity, true);
  5352. break;
  5353. }
  5354. }
  5355. sentLoot = true;
  5356. }
  5357. break;
  5358. }
  5359. case GroupLootMethod::METHOD_ROUND_ROBIN: {
  5360. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5361. sentLoot = true;
  5362. break;
  5363. }
  5364. case GroupLootMethod::METHOD_LEADER: {
  5365. if (member->GetGroupMemberInfo()->leader)
  5366. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
  5367. break;
  5368. }
  5369. case GroupLootMethod::METHOD_FFA: {
  5370. if(member == GetPlayer()) {
  5371. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
  5372. }
  5373. break;
  5374. }
  5375. }
  5376. }
  5377. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5378. }
  5379. }
  5380. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  5381. return sentLoot;
  5382. }
  5383. void Client::LootSpawnRequest(Spawn* entity, bool attemptDisarm) {
  5384. bool lootAllowed = false;
  5385. bool sentLoot = false;
  5386. std::vector<int32> item_list;
  5387. if (entity->IsNPC()) {
  5388. entity->LockLoot();
  5389. lootAllowed = ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer());
  5390. entity->UnlockLoot();
  5391. if (lootAllowed) {
  5392. OpenChest(entity, attemptDisarm);
  5393. }
  5394. else {
  5395. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  5396. return;
  5397. }
  5398. entity->LockLoot();
  5399. if (((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  5400. lootAllowed = true;
  5401. if ((sentLoot = LootSpawnByMethod(entity))) {
  5402. entity->GetLootItemsList(&item_list);
  5403. }
  5404. else {
  5405. SendLootResponsePacket(entity->GetLootCoins(), entity->GetLootItems(), entity);
  5406. }
  5407. }
  5408. entity->UnlockLoot();
  5409. if (lootAllowed) {
  5410. entity->DistributeGroupLoot_RoundRobin(&item_list, true);
  5411. }
  5412. }
  5413. }
  5414. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  5415. {
  5416. if (!entity)
  5417. return;
  5418. int8 chest_difficulty = 0;
  5419. int32 state = 0;
  5420. // Check for the chest and set the action state
  5421. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  5422. string modelName;
  5423. if (entity->GetModelType() == 4034) {
  5424. // small chest, open with copper coins
  5425. // does not include traps, however can be disarmed
  5426. chest_difficulty = 1;
  5427. state = 11899;
  5428. modelName.append("Small Chest");
  5429. }
  5430. else if (entity->GetModelType() == 5864) {
  5431. // treasure chest, open with silver coins
  5432. chest_difficulty = 2;
  5433. state = 11901;
  5434. modelName.append("Treasure Chest");
  5435. }
  5436. else if (entity->GetModelType() == 5865) {
  5437. // ornate chest, open with gold coins
  5438. chest_difficulty = 3;
  5439. state = 11900;
  5440. modelName.append("Ornate Chest");
  5441. }
  5442. else if (entity->GetModelType() == 4015) {
  5443. // exquisite chest, open with gold coins and jewels as well as a glow effect
  5444. chest_difficulty = 5;
  5445. state = 11898;
  5446. modelName.append("Exquisite Chest");
  5447. }
  5448. bool firstChestOpen = false;
  5449. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  5450. {
  5451. ChestTrap::ChestTrapInfo nextTrap;
  5452. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  5453. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  5454. firstChestOpen = true;
  5455. entity->SetTrapTriggered(true, state);
  5456. if (ret)
  5457. {
  5458. if (disarmSkill && attemptDisarm)
  5459. {
  5460. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  5461. {
  5462. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  5463. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  5464. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  5465. }
  5466. else
  5467. {
  5468. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  5469. }
  5470. // despite fail/succeed we should always try to increase skill if disarm is available
  5471. GetPlayer()->GetSkillByName("Disarm Trap", true);
  5472. }
  5473. else // no disarm skill, always fail
  5474. {
  5475. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  5476. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  5477. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  5478. }
  5479. }
  5480. }
  5481. else if (!entity->HasTrapTriggered())
  5482. {
  5483. firstChestOpen = true;
  5484. entity->SetTrapTriggered(true, state);
  5485. }
  5486. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  5487. // for those in range the SendStateCommand will cause it to animate open.
  5488. // players not currently in radius will have it queued with client->QueueStateCommand when SendSpawn takes place
  5489. if (firstChestOpen)
  5490. GetCurrentZone()->SendStateCommand(entity, state);
  5491. }
  5492. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  5493. {
  5494. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  5495. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  5496. if (source == NULL)
  5497. source = (Entity*)GetPlayer();
  5498. if (spell)
  5499. {
  5500. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  5501. if (gmi && gmi->group_id)
  5502. {
  5503. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  5504. if (group)
  5505. {
  5506. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  5507. deque<GroupMemberInfo*>* members = group->GetMembers();
  5508. for (int8 i = 0; i < members->size(); i++) {
  5509. Entity* member = members->at(i)->member;
  5510. if(!member)
  5511. continue;
  5512. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  5513. continue;
  5514. // if we have a radius provided then check if the group member is outside the radius or not
  5515. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  5516. continue;
  5517. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  5518. }
  5519. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5520. }
  5521. }
  5522. else
  5523. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  5524. }
  5525. }
  5526. Spawn* Client::GetBanker() {
  5527. return banker;
  5528. }
  5529. void Client::SetBanker(Spawn* in_banker) {
  5530. banker = in_banker;
  5531. }
  5532. void Client::Bank(Spawn* banker, bool cancel) {
  5533. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  5534. if (!cancel)
  5535. SetBanker(banker);
  5536. else
  5537. SetBanker(0);
  5538. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  5539. if (packet) {
  5540. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  5541. int64 coins = GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + GetPlayer()->GetInfoStruct()->get_bank_coin_silver() * 100 +
  5542. GetPlayer()->GetInfoStruct()->get_bank_coin_gold() * 10000 + (int64)GetPlayer()->GetInfoStruct()->get_bank_coin_plat() * 1000000;
  5543. int32 coins1, coins2;
  5544. coins1 = ((int32*)&coins)[0];
  5545. coins2 = ((int32*)&coins)[1];
  5546. packet->setDataByName("bank_coins", coins1);
  5547. packet->setDataByName("bank_coins2", coins2);
  5548. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->get_coin_copper());
  5549. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->get_coin_silver());
  5550. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->get_coin_gold());
  5551. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->get_coin_plat());
  5552. if (!cancel)
  5553. packet->setDataByName("display", 1);
  5554. QueuePacket(packet->serialize());
  5555. safe_delete(packet);
  5556. }
  5557. }
  5558. }
  5559. bool Client::BankHasCoin(int64 amount){
  5560. int32 tmp = 0;
  5561. if(amount <= 0)
  5562. return 0;
  5563. //plat
  5564. if (amount >= 1000000) {
  5565. tmp = amount / 1000000;
  5566. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5567. if(bank_coins_plat >= tmp)
  5568. return 1;
  5569. }
  5570. //gold
  5571. if (amount >= 10000) {
  5572. tmp = amount / 10000;
  5573. int32 bank_coins_gold = GetPlayer()->GetBankCoinsGold();
  5574. if(bank_coins_gold >= tmp)
  5575. return 1;
  5576. }
  5577. //silver
  5578. if (amount >= 100) {
  5579. tmp = amount / 100;
  5580. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5581. if(bank_coins_silver >= tmp)
  5582. return 1;
  5583. }
  5584. //copper
  5585. if (amount > 0) {
  5586. int32 bank_coins_copper = GetPlayer()->GetBankCoinsCopper();
  5587. if(bank_coins_copper >= amount)
  5588. return 1;
  5589. }
  5590. return 0;
  5591. }
  5592. bool Client::BankWithdrawalNoBanker(int64 amount) {
  5593. bool cheater = false;
  5594. if (amount > 0) {
  5595. string withdrawal = "";
  5596. char withdrawal_data[512] = { 0 };
  5597. int32 tmp = 0;
  5598. if (amount >= 1000000) {
  5599. tmp = amount / 1000000;
  5600. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5601. if (tmp > bank_coins_plat)
  5602. cheater = true;
  5603. else {
  5604. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  5605. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  5606. amount -= (int64)tmp * 1000000;
  5607. sprintf(withdrawal_data, "%u Platinum ", tmp);
  5608. withdrawal.append(withdrawal_data);
  5609. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5610. }
  5611. }
  5612. if (!cheater && amount >= 10000) {
  5613. tmp = amount / 10000;
  5614. if (tmp > GetPlayer()->GetBankCoinsGold())
  5615. cheater = true;
  5616. else {
  5617. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  5618. bank_coins_gold -= tmp;
  5619. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  5620. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  5621. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  5622. }
  5623. else
  5624. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  5625. amount -= tmp * 10000;
  5626. sprintf(withdrawal_data, "%u Gold ", tmp);
  5627. withdrawal.append(withdrawal_data);
  5628. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5629. }
  5630. }
  5631. if (!cheater && amount >= 100) {
  5632. tmp = amount / 100;
  5633. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5634. if (tmp > bank_coins_silver)
  5635. cheater = true;
  5636. else {
  5637. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  5638. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  5639. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  5640. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  5641. }
  5642. else
  5643. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  5644. amount -= tmp * 100;
  5645. sprintf(withdrawal_data, "%u Silver ", tmp);
  5646. withdrawal.append(withdrawal_data);
  5647. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5648. }
  5649. }
  5650. if (!cheater) {
  5651. if (amount > 0) {
  5652. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  5653. withdrawal.append(withdrawal_data);
  5654. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  5655. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  5656. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  5657. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  5658. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  5659. }
  5660. else
  5661. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  5662. }
  5663. if (withdrawal.length() > 0) {
  5664. withdrawal.append("withdrawn ");
  5665. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5666. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5667. withdrawal.append(withdrawal_data);
  5668. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  5669. return 1;
  5670. }
  5671. }
  5672. else
  5673. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5674. return 0;
  5675. }
  5676. return 0;
  5677. }
  5678. void Client::BankWithdrawal(int64 amount) {
  5679. bool cheater = false;
  5680. if (GetBanker() && amount > 0) {
  5681. string withdrawal = "";
  5682. char withdrawal_data[512] = { 0 };
  5683. int32 tmp = 0;
  5684. if (amount >= 1000000) {
  5685. tmp = amount / 1000000;
  5686. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5687. if (tmp > bank_coins_plat)
  5688. cheater = true;
  5689. else {
  5690. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  5691. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  5692. amount -= (int64)tmp * 1000000;
  5693. sprintf(withdrawal_data, "%u Platinum ", tmp);
  5694. withdrawal.append(withdrawal_data);
  5695. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5696. }
  5697. }
  5698. if (!cheater && amount >= 10000) {
  5699. tmp = amount / 10000;
  5700. if (tmp > GetPlayer()->GetBankCoinsGold())
  5701. cheater = true;
  5702. else {
  5703. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  5704. bank_coins_gold -= tmp;
  5705. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  5706. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  5707. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  5708. }
  5709. else
  5710. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  5711. amount -= tmp * 10000;
  5712. sprintf(withdrawal_data, "%u Gold ", tmp);
  5713. withdrawal.append(withdrawal_data);
  5714. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5715. }
  5716. }
  5717. if (!cheater && amount >= 100) {
  5718. tmp = amount / 100;
  5719. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5720. if (tmp > bank_coins_silver)
  5721. cheater = true;
  5722. else {
  5723. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  5724. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  5725. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  5726. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  5727. }
  5728. else
  5729. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  5730. amount -= tmp * 100;
  5731. sprintf(withdrawal_data, "%u Silver ", tmp);
  5732. withdrawal.append(withdrawal_data);
  5733. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5734. }
  5735. }
  5736. if (!cheater) {
  5737. if (amount > 0) {
  5738. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  5739. withdrawal.append(withdrawal_data);
  5740. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  5741. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  5742. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  5743. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  5744. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  5745. }
  5746. else
  5747. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  5748. }
  5749. if (withdrawal.length() > 0) {
  5750. withdrawal.append("withdrawn ");
  5751. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5752. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5753. withdrawal.append(withdrawal_data);
  5754. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  5755. }
  5756. }
  5757. else
  5758. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5759. player->SetCharSheetChanged(true);
  5760. Bank(banker);
  5761. }
  5762. }
  5763. void Client::BankDeposit(int64 amount) {
  5764. bool cheater = false;
  5765. if (GetBanker() && amount > 0) {
  5766. int32 tmp = 0;
  5767. char deposit_data[512] = { 0 };
  5768. string deposit = "";
  5769. if (amount >= 1000000) {
  5770. tmp = amount / 1000000;
  5771. if (tmp > GetPlayer()->GetCoinsPlat())
  5772. cheater = true;
  5773. else {
  5774. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(tmp);
  5775. GetPlayer()->GetInfoStruct()->set_coin_plat(GetPlayer()->GetInfoStruct()->get_coin_plat() - tmp);
  5776. amount -= (int64)tmp * 1000000;
  5777. sprintf(deposit_data, "%u Platinum ", tmp);
  5778. deposit.append(deposit_data);
  5779. memset(deposit_data, 0, sizeof(deposit_data));
  5780. }
  5781. }
  5782. if (!cheater && amount >= 10000) {
  5783. tmp = amount / 10000;
  5784. if (tmp > GetPlayer()->GetCoinsGold())
  5785. cheater = true;
  5786. else {
  5787. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) > 100) {
  5788. GetPlayer()->GetInfoStruct()->set_bank_coin_gold((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) - 100);
  5789. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(1);
  5790. }
  5791. else
  5792. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(tmp);
  5793. GetPlayer()->GetInfoStruct()->set_coin_gold(GetPlayer()->GetInfoStruct()->get_coin_gold() - tmp);
  5794. amount -= tmp * 10000;
  5795. sprintf(deposit_data, "%u Gold ", tmp);
  5796. deposit.append(deposit_data);
  5797. memset(deposit_data, 0, sizeof(deposit_data));
  5798. }
  5799. }
  5800. if (!cheater && amount >= 100) {
  5801. tmp = amount / 100;
  5802. if (tmp > GetPlayer()->GetCoinsSilver())
  5803. cheater = true;
  5804. else {
  5805. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) > 100) {
  5806. GetPlayer()->GetInfoStruct()->set_bank_coin_silver((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) - 100);
  5807. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(1);
  5808. }
  5809. else
  5810. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(tmp);
  5811. GetPlayer()->GetInfoStruct()->set_coin_silver(GetPlayer()->GetInfoStruct()->get_coin_silver() - tmp);
  5812. amount -= tmp * 100;
  5813. sprintf(deposit_data, "%u Silver ", tmp);
  5814. deposit.append(deposit_data);
  5815. memset(deposit_data, 0, sizeof(deposit_data));
  5816. }
  5817. }
  5818. if (!cheater) {
  5819. if (amount > 0) {
  5820. sprintf(deposit_data, "%u Copper ", (int32)amount);
  5821. deposit.append(deposit_data);
  5822. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) > 100) {
  5823. GetPlayer()->GetInfoStruct()->set_bank_coin_copper((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) - 100);
  5824. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(1);
  5825. }
  5826. else
  5827. GetPlayer()->GetInfoStruct()->add_bank_coin_copper(amount);
  5828. GetPlayer()->GetInfoStruct()->set_coin_copper(GetPlayer()->GetInfoStruct()->get_coin_copper() - amount);
  5829. }
  5830. if (deposit.length() > 0) {
  5831. deposit.append("deposited ");
  5832. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5833. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5834. deposit.append(deposit_data);
  5835. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  5836. }
  5837. }
  5838. else
  5839. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5840. player->SetCharSheetChanged(true);
  5841. Bank(banker);
  5842. }
  5843. }
  5844. void Client::AddPendingQuestAcceptReward(Quest* quest)
  5845. {
  5846. std::unique_lock lock(MPendingQuestAccept);
  5847. pending_quest_accept.push_back(quest->GetQuestID());
  5848. }
  5849. void Client::AddPendingQuestReward(Quest* quest, bool update, bool is_temporary, std::string description) {
  5850. QueueQuestReward(quest->GetQuestID(), is_temporary, false, false, (is_temporary ? quest->GetCoinTmpReward() : 0),
  5851. (is_temporary ? quest->GetStatusTmpReward() : 0), description, false, 0);
  5852. quest_updates = update;
  5853. if(quest_updates) {
  5854. SaveQuestRewardData(true);
  5855. }
  5856. }
  5857. 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) {
  5858. if(HasQuestRewardQueued(quest_id, is_temporary, is_collection))
  5859. return;
  5860. QuestRewardData* data = new QuestRewardData;
  5861. data->quest_id = quest_id;
  5862. data->is_temporary = is_temporary;
  5863. data->is_collection = is_collection;
  5864. data->has_displayed = has_displayed;
  5865. data->tmp_coin = tmp_coin;
  5866. data->tmp_status = tmp_status;
  5867. data->description = std::string(description);
  5868. data->db_saved = db_saved;
  5869. data->db_index = index;
  5870. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5871. quest_pending_reward.push_back(data);
  5872. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5873. }
  5874. bool Client::HasQuestRewardQueued(int32 quest_id, bool is_temporary, bool is_collection) {
  5875. bool success = false;
  5876. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5877. if (quest_pending_reward.size() > 0) {
  5878. vector<QuestRewardData*>::iterator itr;
  5879. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  5880. int32 questID = (*itr)->quest_id;
  5881. bool temporary = (*itr)->is_temporary;
  5882. bool collection = (*itr)->is_collection;
  5883. if( questID == quest_id && is_temporary == temporary && is_collection == collection ) {
  5884. success = true;
  5885. break;
  5886. }
  5887. }
  5888. }
  5889. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5890. return success;
  5891. }
  5892. void Client::RemoveQueuedQuestReward() {
  5893. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5894. if(quest_pending_reward.size() > 0) {
  5895. QuestRewardData* data = quest_pending_reward.at(0);
  5896. if(data->db_saved) {
  5897. Query query;
  5898. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_rewards where char_id = %u and indexed = %u", GetCharacterID(), data->db_index);
  5899. if(data->is_temporary && data->quest_id) {
  5900. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_temporary_rewards where char_id = %u and quest_id = %u", GetCharacterID(), data->quest_id);
  5901. }
  5902. }
  5903. quest_pending_reward.erase(quest_pending_reward.begin());
  5904. }
  5905. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5906. SaveQuestRewardData(true);
  5907. }
  5908. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  5909. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5910. quest_pending_updates[quest_id][step_id] = progress;
  5911. quest_updates = true;
  5912. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5913. }
  5914. void Client::ProcessQuestUpdates() {
  5915. if(!IsReadyForUpdates())
  5916. return;
  5917. if (quest_pending_updates.size() > 0) {
  5918. map<int32, map<int32, int32> > tmp_quest_updates;
  5919. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5920. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  5921. quest_pending_updates.clear();
  5922. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5923. map<int32, map<int32, int32> >::iterator quest_itr;
  5924. map<int32, int32>::iterator step_itr;
  5925. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  5926. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  5927. if (step_itr->second == 0xFFFFFFFF) {
  5928. SetStepComplete(quest_itr->first, step_itr->first);
  5929. player->SendQuestRequiredSpawns(quest_itr->first);
  5930. }
  5931. else
  5932. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  5933. }
  5934. }
  5935. }
  5936. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5937. if (quest_pending_reward.size() > 0) {
  5938. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5939. // only able to display one reward at a time
  5940. if(GetPlayer()->IsActiveReward())
  5941. return;
  5942. Query query;
  5943. vector<QuestRewardData*>::iterator itr;
  5944. vector<QuestRewardData*> tmp_quest_rewards;
  5945. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5946. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.begin()+1);
  5947. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5948. bool delete_first = false;
  5949. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end();) {
  5950. int32 questID = (*itr)->quest_id;
  5951. if((*itr)->is_collection && GetPlayer()->GetPendingCollectionReward()) {
  5952. DisplayCollectionComplete(GetPlayer()->GetPendingCollectionReward());
  5953. GetPlayer()->SetActiveReward(true);
  5954. (*itr)->has_displayed = true;
  5955. UpdateCharacterRewardData((*itr));
  5956. break;
  5957. }
  5958. else if(questID > 0 && GetPlayer()->UpdateQuestReward(questID, (*itr))) {
  5959. (*itr)->has_displayed = true;
  5960. UpdateCharacterRewardData((*itr));
  5961. // only able to display one reward at a time
  5962. break;
  5963. } else {
  5964. delete_first = true;
  5965. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, deleting quest id from tmp_quest_rewards.", questID, GetPlayer()->GetName());
  5966. break;
  5967. }
  5968. }
  5969. if(delete_first) {
  5970. RemoveQueuedQuestReward();
  5971. }
  5972. } else {
  5973. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5974. }
  5975. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5976. if (quest_pending_reward.size() > 0) {
  5977. quest_updates = true;
  5978. }
  5979. else {
  5980. quest_updates = false;
  5981. }
  5982. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5983. }
  5984. void Client::CheckQuestQueue() {
  5985. MQuestQueue.writelock();
  5986. last_update_time = 0;
  5987. vector<QueuedQuest*>::iterator itr;
  5988. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  5989. if(!GetPlayer()->SendQuestStepUpdate((*itr)->quest_id, (*itr)->step, (*itr)->display_quest_helper)) {
  5990. LogWrite(CCLIENT__ERROR, 0, "Client", "Queued Quest ID %u missing for Player %s, cannot send quest step update.", (*itr)->quest_id, GetPlayer()->GetName());
  5991. }
  5992. safe_delete((*itr));
  5993. }
  5994. quest_queue.clear();
  5995. MQuestQueue.releasewritelock();
  5996. }
  5997. void Client::SetStepComplete(int32 quest_id, int32 step) {
  5998. Quest* quest = player->SetStepComplete(quest_id, step);
  5999. if (quest) {
  6000. SendQuestUpdate(quest);
  6001. GetCurrentZone()->SendQuestUpdates(this);
  6002. }
  6003. }
  6004. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  6005. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  6006. if (quest) {
  6007. SendQuestUpdate(quest);
  6008. GetCurrentZone()->SendQuestUpdates(this);
  6009. }
  6010. }
  6011. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  6012. bool hadUpdates = false;
  6013. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  6014. if (quest_updates) {
  6015. for (int32 i = 0; i < quest_updates->size(); i++)
  6016. {
  6017. SendQuestUpdate(quest_updates->at(i));
  6018. hadUpdates = true;
  6019. }
  6020. }
  6021. safe_delete(quest_updates);
  6022. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  6023. if (quest_failures) {
  6024. for (int32 i = 0; i < quest_failures->size(); i++)
  6025. {
  6026. SendQuestFailure(quest_failures->at(i));
  6027. hadUpdates = true;
  6028. }
  6029. }
  6030. safe_delete(quest_failures);
  6031. if (hadUpdates)
  6032. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  6033. }
  6034. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  6035. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  6036. if (quest_updates) {
  6037. for (int32 i = 0; i < quest_updates->size(); i++)
  6038. SendQuestUpdate(quest_updates->at(i));
  6039. GetCurrentZone()->SendQuestUpdates(this);
  6040. }
  6041. safe_delete(quest_updates);
  6042. }
  6043. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  6044. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  6045. if (quest_updates) {
  6046. for (int32 i = 0; i < quest_updates->size(); i++)
  6047. SendQuestUpdate(quest_updates->at(i));
  6048. }
  6049. safe_delete(quest_updates);
  6050. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  6051. if (quest_failures) {
  6052. for (int32 i = 0; i < quest_failures->size(); i++)
  6053. SendQuestFailure(quest_failures->at(i));
  6054. }
  6055. safe_delete(quest_failures);
  6056. }
  6057. void Client::CheckPlayerQuestsLocationUpdate() {
  6058. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  6059. if (quest_updates) {
  6060. for (int32 i = 0; i < quest_updates->size(); i++)
  6061. SendQuestUpdate(quest_updates->at(i));
  6062. }
  6063. safe_delete(quest_updates);
  6064. }
  6065. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  6066. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  6067. if (quest_updates) {
  6068. for (int32 i = 0; i < quest_updates->size(); i++)
  6069. SendQuestUpdate(quest_updates->at(i));
  6070. }
  6071. safe_delete(quest_updates);
  6072. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  6073. if (quest_failures) {
  6074. for (int32 i = 0; i < quest_failures->size(); i++)
  6075. SendQuestFailure(quest_failures->at(i));
  6076. }
  6077. safe_delete(quest_failures);
  6078. }
  6079. void Client::AddPendingQuest(Quest* quest, bool forced) {
  6080. if (version <= 372 || forced) { //this client doesn't ask if you want the quest, so auto accept
  6081. MPendingQuestAccept.lock();
  6082. player->pending_quests[quest->GetQuestID()] = quest;
  6083. MPendingQuestAccept.unlock();
  6084. AcceptQuest(quest->GetQuestID());
  6085. }
  6086. else {
  6087. MPendingQuestAccept.lock();
  6088. player->pending_quests[quest->GetQuestID()] = quest;
  6089. MPendingQuestAccept.unlock();
  6090. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  6091. //DumpPacket(outapp);
  6092. QueuePacket(outapp);
  6093. }
  6094. }
  6095. void Client::AcceptQuest(int32 quest_id) {
  6096. MPendingQuestAccept.lock_shared();
  6097. if (player->pending_quests.count(quest_id) > 0) {
  6098. Quest* quest = player->pending_quests[quest_id];
  6099. if(quest) {
  6100. MPendingQuestAccept.unlock_shared();
  6101. MPendingQuestAccept.lock();
  6102. player->pending_quests.erase(quest->GetQuestID());
  6103. MPendingQuestAccept.unlock();
  6104. AddPlayerQuest(quest);
  6105. GetCurrentZone()->SendQuestUpdates(this);
  6106. GetPlayer()->UpdateQuestCompleteCount(quest_id);
  6107. return; // already unlocked mutex
  6108. }
  6109. }
  6110. MPendingQuestAccept.unlock_shared();
  6111. }
  6112. void Client::RemovePendingQuest(int32 quest_id) {
  6113. bool send_updates = false;
  6114. MPendingQuestAccept.lock_shared();
  6115. if (player->pending_quests.count(quest_id) > 0) {
  6116. Quest* quest = player->pending_quests[quest_id];
  6117. MPendingQuestAccept.unlock_shared();
  6118. MPendingQuestAccept.lock();
  6119. player->pending_quests.erase(quest_id);
  6120. MPendingQuestAccept.unlock();
  6121. if(lua_interface) {
  6122. lua_interface->CallQuestFunction(quest, "Declined", GetPlayer());
  6123. lua_interface->SetLuaUserDataStale(quest);
  6124. }
  6125. safe_delete(quest);
  6126. send_updates = true;
  6127. }
  6128. else {
  6129. MPendingQuestAccept.unlock_shared();
  6130. }
  6131. if(send_updates) {
  6132. GetCurrentZone()->SendQuestUpdates(this);
  6133. }
  6134. }
  6135. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  6136. if (!quest || !progress) {
  6137. return;
  6138. }
  6139. map<int32, int32>::iterator itr;
  6140. QuestStep* step = 0;
  6141. for (itr = progress->begin(); itr != progress->end(); itr++) {
  6142. step = quest->GetQuestStep(itr->first);
  6143. if (step && itr->second > 0) {
  6144. step->SetStepProgress(itr->second);
  6145. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  6146. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  6147. }
  6148. }
  6149. if (lua_interface && step)
  6150. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  6151. else if(!step) {
  6152. LogWrite(QUEST__ERROR, 0, "Client", "Missing step for quest %s (ID %u), cannot CallQuestFunction for CurrentStep", quest->GetName(), quest->GetQuestID());
  6153. }
  6154. }
  6155. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  6156. bool lockCleared = false;
  6157. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  6158. if (player->player_quests.count(quest->GetQuestID()) > 0 && player->player_quests[quest->GetQuestID()]) {
  6159. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  6160. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  6161. int32 questID = quest->GetQuestID();
  6162. lockCleared = true;
  6163. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6164. RemovePlayerQuest(questID, false, false);
  6165. }
  6166. player->player_quests[quest->GetQuestID()] = quest;
  6167. if(!lockCleared)
  6168. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6169. quest->SetPlayer(player);
  6170. quest->SetSaveNeeded(true);
  6171. current_quest_id = quest->GetQuestID();
  6172. if (send_packets && quest->GetQuestGiver() > 0)
  6173. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  6174. if (lua_interface && call_accepted)
  6175. lua_interface->CallQuestFunction(quest, "Accepted", player);
  6176. if (send_packets) {
  6177. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6178. //SendQuestJournal();
  6179. SendQuestJournalUpdate(quest);
  6180. // sent twice to match live
  6181. quest->SetTracked(false);
  6182. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  6183. quest->SetTracked(true);
  6184. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  6185. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  6186. }
  6187. //This isn't during a load screen, so update spawns with required quests
  6188. if (call_accepted)
  6189. player->SendQuestRequiredSpawns(quest->GetQuestID());
  6190. }
  6191. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  6192. if (current_quest_id == id)
  6193. current_quest_id = 0;
  6194. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  6195. if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
  6196. if (delete_quest) {
  6197. player->player_quests[id]->SetDeleted(true);
  6198. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  6199. }
  6200. int32 quest_giver = player->player_quests[id]->GetQuestGiver();
  6201. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6202. if (send_update && quest_giver > 0)
  6203. GetCurrentZone()->SendSpawnChangesByDBID(quest_giver, this, false, true);
  6204. if (send_update) {
  6205. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6206. SendQuestJournal(false, 0, true);
  6207. }
  6208. player->RemoveQuest(id, delete_quest);
  6209. if (send_update) {
  6210. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6211. SendQuestJournal(false, 0, true);
  6212. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  6213. }
  6214. }
  6215. else {
  6216. // if we don't have any quests to count then release the write lock
  6217. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6218. }
  6219. }
  6220. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  6221. if (quest) {
  6222. QuestStep* quest_step = quest->GetQuestStep(step);
  6223. if (quest_step) {
  6224. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  6225. quest_step->WasUpdated(false);
  6226. }
  6227. }
  6228. }
  6229. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  6230. QueuedQuest* item = new QueuedQuest;
  6231. item->quest_id = quest->GetQuestID();
  6232. item->step = step;
  6233. item->display_quest_helper = display_quest_helper;
  6234. MQuestQueue.writelock();
  6235. quest_queue.push_back(item);
  6236. last_update_time = Timer::GetCurrentTime2();
  6237. MQuestQueue.releasewritelock();
  6238. }
  6239. void Client::SendQuestFailure(Quest* quest) {
  6240. vector<QuestStep*>* failures = quest->GetQuestFailures();
  6241. if (failures) {
  6242. QuestStep* step = 0;
  6243. for (int32 i = 0; i < failures->size(); i++) {
  6244. step = failures->at(i);
  6245. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  6246. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6247. SendQuestJournal(false, 0, true);
  6248. }
  6249. failures->clear();
  6250. }
  6251. }
  6252. void Client::SendQuestUpdate(Quest* quest) {
  6253. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  6254. if (updates) {
  6255. QuestStep* step = 0;
  6256. bool updated = false;
  6257. for (int32 i = 0; i < updates->size(); i++) {
  6258. step = updates->at(i);
  6259. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  6260. {
  6261. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  6262. SendQuestUpdateStep(quest, step->GetStepID());
  6263. updated = true;
  6264. }
  6265. if (step->WasUpdated()) {
  6266. // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
  6267. SendQuestJournal(false, 0, true);
  6268. if(!updated)
  6269. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  6270. updated = true;
  6271. }
  6272. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6273. }
  6274. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  6275. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  6276. SendQuestJournalUpdate(quest, true);
  6277. }
  6278. if (quest->GetCompleted()) {
  6279. if (quest->GetQuestReturnNPC() > 0)
  6280. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  6281. if (quest->GetCompletedFlag())
  6282. quest->SetCompletedFlag(false);
  6283. }
  6284. updates->clear();
  6285. }
  6286. }
  6287. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  6288. if (!client)
  6289. client = this;
  6290. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  6291. if (packet) {
  6292. EQ2Packet* outapp = packet->serialize();
  6293. //DumpPacket(outapp);
  6294. client->QueuePacket(outapp);
  6295. safe_delete(packet);
  6296. }
  6297. }
  6298. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  6299. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  6300. if (packet) {
  6301. QueuePacket(packet->serialize());
  6302. safe_delete(packet);
  6303. }
  6304. }
  6305. void Client::ReloadQuests() {
  6306. vector<int32> ids = player->GetQuestIDs();
  6307. Quest* quest = 0;
  6308. for (int32 i = 0; i < ids.size(); i++) {
  6309. quest = master_quest_list.GetQuest(ids[i]);
  6310. if (quest)
  6311. AddPlayerQuest(quest, false);
  6312. else
  6313. RemovePlayerQuest(ids[i]);
  6314. }
  6315. }
  6316. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  6317. std::unique_lock lock(MPendingQuestAccept);
  6318. bool found_quest = false;
  6319. vector<int32>::iterator itr;
  6320. int32 questID = 0;
  6321. Quest* quest = nullptr;
  6322. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end();) {
  6323. questID = *itr;
  6324. bool quest_exists = false;
  6325. quest = GetPlayer()->PendingQuestAcceptance(questID, item_id, &quest_exists);
  6326. if(!quest_exists) {
  6327. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, removing quest id from pending_quest_accept.", questID, GetPlayer()->GetName());
  6328. itr = pending_quest_accept.erase(itr);
  6329. quest = nullptr;
  6330. continue;
  6331. }
  6332. else if (quest) {
  6333. pending_quest_accept.erase(itr);
  6334. break;
  6335. }
  6336. itr++;
  6337. }
  6338. return quest;
  6339. }
  6340. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  6341. int8 num_slots_needed = 0;
  6342. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  6343. Item* master_item = 0;
  6344. if (item_id > 0) {
  6345. num_slots_needed++;
  6346. master_item = master_item_list.GetItem(item_id);
  6347. }
  6348. int32 totalItems = 0;
  6349. vector<Item*>* items = 0;
  6350. vector<Item*>* tmpItems = 0;
  6351. bool isTempState = quest->GetQuestTemporaryState();
  6352. if(isTempState)
  6353. {
  6354. tmpItems = quest->GetTmpRewardItems();
  6355. if (tmpItems && tmpItems->size() > 0)
  6356. {
  6357. num_slots_needed += tmpItems->size();
  6358. totalItems += tmpItems->size();
  6359. }
  6360. }
  6361. else
  6362. {
  6363. items = quest->GetRewardItems();
  6364. if (items && items->size() > 0)
  6365. {
  6366. num_slots_needed += items->size();
  6367. totalItems += items->size();
  6368. }
  6369. }
  6370. RemoveQueuedQuestReward();
  6371. GetPlayer()->SetActiveReward(false);
  6372. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= totalItems)) {
  6373. if (master_item)
  6374. AddItem(item_id);
  6375. if (tmpItems && tmpItems->size() > 0) {
  6376. for (int32 i = 0; i < tmpItems->size(); i++)
  6377. AddItem(new Item(tmpItems->at(i)));
  6378. }
  6379. if (items && items->size() > 0) {
  6380. for (int32 i = 0; i < items->size(); i++)
  6381. AddItem(new Item(items->at(i)));
  6382. }
  6383. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6384. if (outapp)
  6385. QueuePacket(outapp);
  6386. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  6387. map<int32, sint32>::iterator itr;
  6388. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  6389. int32 faction_id = itr->first;
  6390. sint32 amount = itr->second;
  6391. if (amount > 0)
  6392. player->GetFactions()->IncreaseFaction(faction_id, amount);
  6393. else
  6394. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  6395. }
  6396. if(quest->GetQuestTemporaryState())
  6397. {
  6398. int64 total_coins = quest->GetCoinTmpReward();
  6399. if (total_coins > 0)
  6400. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  6401. player->GetInfoStruct()->add_status_points(quest->GetStatusTmpReward());
  6402. }
  6403. else {
  6404. player->GetInfoStruct()->add_status_points(quest->GetStatusPoints());
  6405. }
  6406. quest->SetQuestTemporaryState(false);
  6407. player->SetCharSheetChanged(true);
  6408. }
  6409. else {
  6410. GetPlayer()->SetActiveReward(true);
  6411. AddPendingQuestAcceptReward(quest);
  6412. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  6413. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  6414. }
  6415. }
  6416. 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) {
  6417. 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))) {
  6418. /*if (quest)
  6419. text = quest->GetName();
  6420. else*/
  6421. return;//nothing to give
  6422. }
  6423. GetPlayer()->ClearPendingSelectableItemRewards(0, true);
  6424. GetPlayer()->ClearPendingItemRewards();
  6425. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  6426. if (packet2) {
  6427. int32 source_id = 0;
  6428. if (quest)
  6429. source_id = quest->GetQuestID();
  6430. int64 rewarded_coin = 0;
  6431. if (quest) {
  6432. if (quest->GetCoinsReward() > 0) {
  6433. if (quest->GetCoinsRewardMax() > 0)
  6434. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  6435. else
  6436. rewarded_coin = quest->GetCoinsReward();
  6437. }
  6438. quest->SetGeneratedCoin(rewarded_coin);
  6439. }
  6440. if (rewarded_coin > coin)
  6441. coin = rewarded_coin;
  6442. 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
  6443. if (coin > 0) {
  6444. player->AddCoins(coin);
  6445. PlaySound("coin_cha_ching");
  6446. }
  6447. }
  6448. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  6449. packet2->setSubstructDataByName("reward_data", "reward", header);
  6450. packet2->setSubstructDataByName("reward_data", "max_coin", coin);
  6451. if (player->GetGuild() && !was_displayed) {
  6452. 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
  6453. player->GetInfoStruct()->add_status_points(status_points);
  6454. player->SetCharSheetChanged(true);
  6455. }
  6456. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  6457. }
  6458. if(text)
  6459. packet2->setSubstructDataByName("reward_data", "text", text);
  6460. std::vector<Item*> items;
  6461. quest->GetTmpRewardItemsByID(&items);
  6462. if(rewards || items.size() > 0){
  6463. int32 item_count = items.size();
  6464. item_count += rewards ? rewards->size() : 0;
  6465. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
  6466. int i = 0;
  6467. if(rewards) {
  6468. for (i = 0; i < rewards->size(); i++) {
  6469. Item* item = rewards->at(i);
  6470. if (item) {
  6471. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  6472. packet2->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  6473. }
  6474. 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
  6475. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  6476. }
  6477. }
  6478. for (int j = 0; j < items.size(); j++) {
  6479. Item* item = items.at(j);
  6480. if (item) {
  6481. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  6482. packet2->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  6483. }
  6484. 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
  6485. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  6486. i++;
  6487. }
  6488. }
  6489. if (selectable_rewards) {
  6490. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  6491. for (int i = 0; i < selectable_rewards->size(); i++) {
  6492. Item* item = selectable_rewards->at(i);
  6493. if (item) {
  6494. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  6495. packet2->setItemArrayDataByName("select_item", item, player, i, 0, GetClientItemPacketOffset());
  6496. 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
  6497. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  6498. }
  6499. }
  6500. }
  6501. if (factions) {
  6502. map<int32, sint32>::iterator itr;
  6503. map<Faction*, signed int> factions_map;
  6504. for (itr = factions->begin(); itr != factions->end(); itr++) {
  6505. Faction* faction = master_faction_list.GetFaction(itr->first);
  6506. if (faction)
  6507. factions_map[faction] = itr->second;
  6508. }
  6509. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  6510. map<Faction*, signed int>::iterator faction_itr;
  6511. int8 i = 0;
  6512. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  6513. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  6514. sint32 amount = faction_itr->second;
  6515. packet2->setArrayDataByName("amount", amount, i);
  6516. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6517. if (amount > 0)
  6518. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  6519. else
  6520. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  6521. }
  6522. i++;
  6523. }
  6524. }
  6525. QueuePacket(packet2->serialize());
  6526. safe_delete(packet2);
  6527. }
  6528. }
  6529. void Client::PopulateQuestRewardItems(vector <Item*>* items, PacketStruct* packet,
  6530. std::string num_rewards_str, std::string reward_id_str, std::string item_str) {
  6531. if(!items || !packet)
  6532. return;
  6533. if (items) {
  6534. int32 total_item_count = 0;
  6535. for(int s=0;s<items->size();s++) {
  6536. Item* tmpItem = items->at(s);
  6537. if(tmpItem) {
  6538. if(tmpItem->details.count > 1) {
  6539. total_item_count += tmpItem->details.count;
  6540. }
  6541. else {
  6542. total_item_count += 1;
  6543. }
  6544. }
  6545. }
  6546. packet->setArrayLengthByName(num_rewards_str.c_str(), total_item_count);
  6547. int16 count = 0;
  6548. int16 pos = 0;
  6549. for (int32 i = 0; i < items->size();) {
  6550. packet->setArrayDataByName(reward_id_str.c_str(), items->at(i)->details.item_id, pos);
  6551. if (version < 860)
  6552. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, GetClientItemPacketOffset());
  6553. else if (version < 1193)
  6554. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos);
  6555. else
  6556. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, 2);
  6557. pos++;
  6558. if(count >= items->at(i)->details.count-1) {
  6559. count = 0;
  6560. }
  6561. else if(items->at(i)->details.count > 1) {
  6562. count++;
  6563. continue;
  6564. }
  6565. i++;
  6566. }
  6567. }
  6568. }
  6569. void Client::DisplayQuestComplete(Quest* quest, bool tempReward, std::string customDescription, bool was_displayed) {
  6570. if (!quest)
  6571. return;
  6572. if (GetVersion() <= 561) {
  6573. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints(), tempReward ? customDescription.c_str() : quest->GetCompletedDescription(), was_displayed);
  6574. return;
  6575. }
  6576. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  6577. if (packet) {
  6578. packet->setDataByName("title", "Quest Reward!");
  6579. packet->setDataByName("name", quest->GetName());
  6580. if(tempReward)
  6581. {
  6582. packet->setDataByName("description", customDescription.c_str());
  6583. }
  6584. else
  6585. packet->setDataByName("description", quest->GetCompletedDescription());
  6586. packet->setDataByName("level", quest->GetLevel());
  6587. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  6588. int8 difficulty = 0;
  6589. if ((string)quest->GetType() == "Tradeskill")
  6590. difficulty = player->GetTSArrowColor(quest->GetLevel());
  6591. else
  6592. difficulty = player->GetArrowColor(quest->GetLevel());
  6593. packet->setDataByName("difficulty", difficulty);
  6594. if(tempReward)
  6595. {
  6596. packet->setDataByName("max_coin", quest->GetCoinTmpReward());
  6597. packet->setDataByName("min_coin", quest->GetCoinTmpReward());
  6598. packet->setDataByName("status_points", quest->GetStatusPoints());
  6599. }
  6600. else
  6601. {
  6602. int64 rewarded_coin = 0;
  6603. if (quest->GetCoinsReward() > 0) {
  6604. if (quest->GetCoinsRewardMax() > 0)
  6605. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  6606. else
  6607. rewarded_coin = quest->GetCoinsReward();
  6608. }
  6609. quest->SetGeneratedCoin(rewarded_coin);
  6610. packet->setDataByName("max_coin", rewarded_coin);
  6611. packet->setDataByName("min_coin", rewarded_coin);
  6612. packet->setDataByName("status_points", quest->GetStatusPoints());
  6613. }
  6614. if(tempReward) {
  6615. PopulateQuestRewardItems(quest->GetTmpRewardItems(), packet);
  6616. }
  6617. else
  6618. {
  6619. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  6620. PopulateQuestRewardItems(quest->GetRewardItems(), packet);
  6621. PopulateQuestRewardItems(quest->GetSelectableRewardItems(), packet, std::string("num_select_rewards"),
  6622. std::string("select_reward_id"), std::string("select_item"));
  6623. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  6624. if (reward_factions && reward_factions->size() > 0) {
  6625. packet->setArrayLengthByName("num_factions", reward_factions->size());
  6626. map<int32, sint32>::iterator itr;
  6627. int16 index = 0;
  6628. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  6629. int32 faction_id = itr->first;
  6630. sint32 amount = itr->second;
  6631. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  6632. if (faction_name) {
  6633. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  6634. packet->setArrayDataByName("amount", amount, index);
  6635. }
  6636. index++;
  6637. }
  6638. }
  6639. }
  6640. EQ2Packet* outapp = packet->serialize();
  6641. // DumpPacket(outapp);
  6642. QueuePacket(outapp);
  6643. safe_delete(packet);
  6644. }
  6645. }
  6646. void Client::DisplayRandomizeFeatures(int32 flags) {
  6647. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  6648. if (flags > 0) {
  6649. if (flags & RANDOMIZE_GENDER)
  6650. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  6651. if (flags & RANDOMIZE_RACE)
  6652. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  6653. if (flags & RANDOMIZE_MODEL_TYPE)
  6654. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  6655. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  6656. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  6657. if (flags & RANDOMIZE_HAIR_TYPE)
  6658. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  6659. if (flags & RANDOMIZE_WING_TYPE)
  6660. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  6661. if (flags & RANDOMIZE_CHEEK_TYPE)
  6662. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  6663. if (flags & RANDOMIZE_CHIN_TYPE)
  6664. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  6665. if (flags & RANDOMIZE_EAR_TYPE)
  6666. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  6667. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  6668. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  6669. if (flags & RANDOMIZE_EYE_TYPE)
  6670. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  6671. if (flags & RANDOMIZE_LIP_TYPE)
  6672. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  6673. if (flags & RANDOMIZE_NOSE_TYPE)
  6674. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  6675. if (flags & RANDOMIZE_EYE_COLOR)
  6676. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  6677. if (flags & RANDOMIZE_HAIR_COLOR1)
  6678. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  6679. if (flags & RANDOMIZE_HAIR_COLOR2)
  6680. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  6681. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  6682. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  6683. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  6684. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  6685. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  6686. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  6687. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  6688. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  6689. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  6690. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  6691. if (flags & RANDOMIZE_SKIN_COLOR)
  6692. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  6693. if (flags & RANDOMIZE_WING_COLOR1)
  6694. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  6695. if (flags & RANDOMIZE_WING_COLOR2)
  6696. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  6697. }
  6698. else
  6699. {
  6700. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  6701. }
  6702. }
  6703. void Client::GiveQuestReward(Quest* quest, bool has_displayed) {
  6704. current_quest_id = 0;
  6705. if(!quest->GetQuestTemporaryState() && !has_displayed)
  6706. {
  6707. quest->IncrementCompleteCount();
  6708. player->AddCompletedQuest(quest);
  6709. }
  6710. AddPendingQuestAcceptReward(quest);
  6711. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  6712. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6713. SendQuestJournal();
  6714. if(quest->GetQuestTemporaryState()) {
  6715. return;
  6716. }
  6717. if(!has_displayed) {
  6718. if (quest->GetExpReward() > 0) {
  6719. int32 xp = quest->GetExpReward();
  6720. player->AddXP(xp);
  6721. }
  6722. if (quest->GetTSExpReward() > 0) {
  6723. int8 ts_level = player->GetTSLevel();
  6724. int32 xp = quest->GetTSExpReward();
  6725. if (player->AddTSXP(xp)) {
  6726. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  6727. if (player->GetTSLevel() != ts_level)
  6728. ChangeTSLevel(ts_level, player->GetTSLevel());
  6729. player->SetCharSheetChanged(true);
  6730. }
  6731. }
  6732. int64 total_coins = quest->GetGeneratedCoin();
  6733. if (total_coins > 0)
  6734. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  6735. player->RemoveQuest(quest->GetQuestID(), false);
  6736. }
  6737. if (quest->GetQuestGiver() > 0)
  6738. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  6739. if(!has_displayed) {
  6740. RemovePlayerQuest(quest->GetQuestID(), true, false);
  6741. }
  6742. }
  6743. 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) {
  6744. std::unique_lock lock(MConversation);
  6745. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  6746. if (packet) {
  6747. packet->setDataByName("conversation_id", conversation_id);
  6748. packet->setDataByName("text", text);
  6749. packet->setDataByName("language", language); // default 0
  6750. packet->setDataByName("enable_blue_ui", 0); // default 0
  6751. packet->setDataByName("can_close", can_close); // default 1
  6752. conversation_map[conversation_id].clear();
  6753. if (conversations) {
  6754. packet->setArrayLengthByName("num_responses", conversations->size());
  6755. for (int32 i = 0; i < conversations->size(); i++) {
  6756. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  6757. if (conversations->at(i).function.length() > 0)
  6758. conversation_map[conversation_id][i] = conversations->at(i).function;
  6759. }
  6760. }
  6761. packet->setDataByName("spawn_id", spawn_id);
  6762. if (mp3) {
  6763. packet->setDataByName("voice", mp3);
  6764. packet->setDataByName("key1", key1);
  6765. packet->setDataByName("key2", key2);
  6766. }
  6767. QueuePacket(packet->serialize());
  6768. safe_delete(packet);
  6769. }
  6770. }
  6771. 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) {
  6772. if (!item || !text || !conversations || conversations->size() == 0) {
  6773. return;
  6774. }
  6775. int32 conversation_id = GetConversationID(0, item);
  6776. if (conversation_id == 0) {
  6777. next_conversation_id++;
  6778. conversation_id = next_conversation_id;
  6779. }
  6780. MConversation.lock();
  6781. conversation_items[conversation_id] = item;
  6782. MConversation.unlock();
  6783. if (type == 4)
  6784. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  6785. else
  6786. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  6787. }
  6788. 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) {
  6789. if (!src || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  6790. return;
  6791. }
  6792. int32 conversation_id = GetConversationID(src, 0);
  6793. if (conversation_id == 0) {
  6794. next_conversation_id++;
  6795. conversation_id = next_conversation_id;
  6796. }
  6797. MConversation.lock();
  6798. conversation_spawns[conversation_id] = src->GetID();
  6799. MConversation.unlock();
  6800. /* Spawns can start two different types of conversations.
  6801. * Type 1: The chat type with bubbles.
  6802. * Type 2: The dialog type with the blue box. */
  6803. if (type == 1)
  6804. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(src), conversations, text, mp3, key1, key2, language, can_close);
  6805. else if (type == 2)
  6806. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  6807. else //if (type == 3)
  6808. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  6809. }
  6810. void Client::CloseDialog(int32 conversation_id) {
  6811. std::unique_lock lock(MConversation);
  6812. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  6813. if (packet) {
  6814. packet->setDataByName("conversation_id", conversation_id);
  6815. QueuePacket(packet->serialize());
  6816. safe_delete(packet);
  6817. }
  6818. std::map<int32, Item*>::iterator itr;
  6819. while((itr = conversation_items.find(conversation_id)) != conversation_items.end())
  6820. {
  6821. conversation_items.erase(itr);
  6822. }
  6823. std::map<int32, int32>::iterator itr2 = conversation_spawns.find(conversation_id);
  6824. while((itr2 = conversation_spawns.find(conversation_id)) != conversation_spawns.end())
  6825. {
  6826. conversation_spawns.erase(itr2);
  6827. }
  6828. }
  6829. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  6830. std::shared_lock lock(MConversation);
  6831. int32 conversation_id = 0;
  6832. if (spawn) {
  6833. map<int32, int32>::iterator itr;
  6834. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  6835. if (itr->second == spawn->GetID()) {
  6836. conversation_id = itr->first;
  6837. break;
  6838. }
  6839. }
  6840. }
  6841. else if (item) {
  6842. map<int32, Item*>::iterator itr;
  6843. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  6844. if (itr->second == item) {
  6845. conversation_id = itr->first;
  6846. break;
  6847. }
  6848. }
  6849. }
  6850. return conversation_id;
  6851. }
  6852. Spawn* Client::GetCombineSpawn() {
  6853. return combine_spawn;
  6854. }
  6855. bool Client::ShouldTarget() {
  6856. return should_target;
  6857. }
  6858. void Client::TargetSpawn(Spawn* spawn) {
  6859. should_target = false;
  6860. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  6861. if (packet) {
  6862. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  6863. QueuePacket(packet->serialize());
  6864. safe_delete(packet);
  6865. }
  6866. GetPlayer()->SetTarget(spawn);
  6867. GetPlayer()->info_changed = true;
  6868. GetPlayer()->changed = true;
  6869. GetPlayer()->AddChangedZoneSpawn();
  6870. }
  6871. void Client::CombineSpawns(float radius, Spawn* spawn) {
  6872. combine_spawn = spawn;
  6873. spawn->RemoveSpawnFromGroup(true);
  6874. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  6875. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  6876. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6877. should_target = true;
  6878. }
  6879. void Client::AddCombineSpawn(Spawn* spawn) {
  6880. if (combine_spawn && combine_spawn != spawn && spawn) {
  6881. combine_spawn->AddSpawnToGroup(spawn);
  6882. spawn->AddSpawnToGroup(combine_spawn);
  6883. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6884. }
  6885. else if (spawn)
  6886. combine_spawn = spawn;
  6887. should_target = true;
  6888. }
  6889. void Client::RemoveCombineSpawn(Spawn* spawn) {
  6890. if (combine_spawn && spawn)
  6891. spawn->RemoveSpawnFromGroup();
  6892. if (combine_spawn == spawn)
  6893. combine_spawn->RemoveSpawnFromGroup(true);
  6894. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6895. if (combine_spawn == spawn)
  6896. combine_spawn = 0;
  6897. }
  6898. void Client::SaveCombineSpawns(const char* name) {
  6899. if (!combine_spawn) {
  6900. return;
  6901. }
  6902. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  6903. if (!spawns) {
  6904. return;
  6905. }
  6906. int32 count = spawns->size();
  6907. int32 spawnLocationID = 0;
  6908. if (count == 1)
  6909. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  6910. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  6911. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  6912. // we remove the spawn inside SaveCombinedSpawnLocation
  6913. //GetCurrentZone()->RemoveSpawn(combine_spawn);
  6914. }
  6915. else
  6916. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  6917. safe_delete(spawns);
  6918. combine_spawn = 0;
  6919. }
  6920. bool Client::AddItem(int32 item_id, int16 quantity, AddItemType type) {
  6921. Item* master_item = master_item_list.GetItem(item_id);
  6922. Item* item = 0;
  6923. if (master_item)
  6924. item = new Item(master_item);
  6925. if (item) {
  6926. if (quantity > 0)
  6927. item->details.count = quantity;
  6928. return AddItem(item, nullptr, type);
  6929. }
  6930. else
  6931. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6932. return false;
  6933. }
  6934. bool Client::AddItem(Item* item, bool* item_deleted, AddItemType type) {
  6935. if (!item) {
  6936. return false;
  6937. }
  6938. if (player->AddItem(item, type)) {
  6939. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6940. if (outapp) {
  6941. //DumpPacket(outapp);
  6942. QueuePacket(outapp);
  6943. //resend bag desc with new item name added
  6944. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  6945. if (outapp) {
  6946. //DumpPacket(outapp);
  6947. QueuePacket(outapp);
  6948. }
  6949. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6950. DumpPacket(app);
  6951. client->QueuePacket(app);
  6952. */
  6953. }
  6954. CheckPlayerQuestsItemUpdate(item);
  6955. if (item->GetItemScript() && lua_interface)
  6956. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6957. }
  6958. else {
  6959. lua_interface->SetLuaUserDataStale(item);
  6960. // likely lore conflict
  6961. if(item_deleted)
  6962. *item_deleted = true;
  6963. return false;
  6964. }
  6965. return true;
  6966. }
  6967. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  6968. Item* master_item = master_item_list.GetItem(item_id);
  6969. Item* item = 0;
  6970. if (master_item)
  6971. item = new Item(master_item);
  6972. if (item) {
  6973. if (quantity > 0)
  6974. item->details.count = quantity;
  6975. return AddItemToBank(item);
  6976. }
  6977. else
  6978. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6979. return false;
  6980. }
  6981. bool Client::AddItemToBank(Item* item) {
  6982. if (!item) {
  6983. return false;
  6984. }
  6985. if (player->AddItemToBank(item)) {
  6986. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6987. if (outapp) {
  6988. QueuePacket(outapp);
  6989. //resend bag desc with new item name added
  6990. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  6991. if (outapp)
  6992. QueuePacket(outapp);
  6993. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6994. DumpPacket(app);
  6995. client->QueuePacket(app);
  6996. */
  6997. }
  6998. CheckPlayerQuestsItemUpdate(item);
  6999. if (item->GetItemScript() && lua_interface)
  7000. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  7001. }
  7002. else {
  7003. lua_interface->SetLuaUserDataStale(item);
  7004. // likely lore conflict
  7005. safe_delete(item);
  7006. return false;
  7007. }
  7008. return true;
  7009. }
  7010. void Client::UnequipItem(int16 index, sint32 bag_id, int8 to_slot, int8 appearance_equip) {
  7011. vector<EQ2Packet*> packets = GetPlayer()->UnequipItem(index, bag_id, to_slot, GetVersion(), appearance_equip);
  7012. EQ2Packet* outapp = 0;
  7013. for(int32 i=0;i<packets.size();i++)
  7014. {
  7015. outapp = packets[i];
  7016. if(outapp)
  7017. QueuePacket(outapp);
  7018. }
  7019. GetPlayer()->UpdateWeapons();
  7020. EQ2Packet* characterSheetPackets = GetPlayer()->GetPlayerInfo()->serialize(GetVersion());
  7021. QueuePacket(characterSheetPackets);
  7022. }
  7023. bool Client::RemoveItem(Item* item, int16 quantity, bool force_override_no_delete) {
  7024. EQ2Packet* outapp;
  7025. bool delete_item = false;
  7026. assert(item);
  7027. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  7028. item->details.count -= quantity;
  7029. item->save_needed = true;
  7030. }
  7031. else {
  7032. database.DeleteItem(character_id, item, 0);
  7033. player->GetPlayerItemList()->RemoveItem(item, false);
  7034. delete_item = true;
  7035. }
  7036. if(force_override_no_delete)
  7037. delete_item = false;
  7038. if ((outapp = player->SendInventoryUpdate(version))) {
  7039. QueuePacket(outapp);
  7040. if (item->GetItemScript() && lua_interface)
  7041. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  7042. if (delete_item)
  7043. {
  7044. PurgeItem(item);
  7045. lua_interface->SetLuaUserDataStale(item);
  7046. safe_delete(item);
  7047. }
  7048. GetPlayer()->CalculateApplyWeight();
  7049. return true;
  7050. }
  7051. return false;
  7052. }
  7053. void Client::SetLuaDebugClient(bool val) {
  7054. if (val)
  7055. lua_debug_timer.Start();
  7056. lua_debug = val;
  7057. if (lua_interface && !val) {
  7058. lua_interface->RemoveDebugClients(this);
  7059. lua_debug_timer.Disable();
  7060. }
  7061. }
  7062. void Client::SetMerchantTransaction(Spawn* spawn) {
  7063. merchant_transaction = spawn;
  7064. }
  7065. Spawn* Client::GetMerchantTransaction() {
  7066. return merchant_transaction;
  7067. }
  7068. void Client::SetMailTransaction(Spawn* spawn) {
  7069. ResetSendMail(spawn ? false : true);
  7070. MMailWindowMutex.lock();
  7071. mail_transaction = spawn;
  7072. MMailWindowMutex.unlock();
  7073. }
  7074. Spawn* Client::GetMailTransaction() {
  7075. return mail_transaction;
  7076. }
  7077. void Client::PlaySound(const char* name) {
  7078. if (name) {
  7079. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  7080. if (packet) {
  7081. packet->setMediumStringByName("name", name);
  7082. QueuePacket(packet->serialize());
  7083. safe_delete(packet);
  7084. }
  7085. }
  7086. }
  7087. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  7088. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  7089. if(multiplier){
  7090. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  7091. float diff_low = faction_val - multiplier->faction_min;
  7092. if(diff_low < 0)
  7093. diff_low*=-1;
  7094. float total_diff = multiplier->faction_max - multiplier->faction_min;
  7095. if(total_diff < 0)
  7096. total_diff*=-1;
  7097. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  7098. float total1 = (diff_low/total_diff);
  7099. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  7100. return final_buy_multiplier;
  7101. }*/
  7102. return 1;
  7103. }
  7104. float Client::CalculateSellMultiplier(int32 merchant_id) {
  7105. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  7106. if(multiplier){
  7107. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  7108. float diff_low = faction_val - multiplier->faction_min;
  7109. if(diff_low < 0)
  7110. diff_low*=-1;
  7111. float total_diff = multiplier->faction_max - multiplier->faction_min;
  7112. if(total_diff < 0)
  7113. total_diff*=-1;
  7114. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  7115. float total1 = (diff_low/total_diff);
  7116. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  7117. return final_sell_multiplier;
  7118. }*/
  7119. return 1;
  7120. }
  7121. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  7122. Spawn* spawn = GetMerchantTransaction();
  7123. Guild* guild = GetPlayer()->GetGuild();
  7124. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY)) &&
  7125. spawn->IsClientInMerchantLevelRange(this)) {
  7126. int32 total_sell_price = 0;
  7127. int32 total_status_sell_price = 0; //for status
  7128. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7129. int32 sell_price = 0;
  7130. int32 status_sell_price = 0; //for status
  7131. Item* master_item = master_item_list.GetItem(item_id);
  7132. Item* item = 0;
  7133. if (unique_id == 0)
  7134. item = player->item_list.GetItemFromID(item_id, quantity);
  7135. else
  7136. item = player->item_list.GetItemFromUniqueID(unique_id);
  7137. if (!item)
  7138. item = player->item_list.GetItemFromID(item_id);
  7139. if (item && master_item) {
  7140. if(item->details.item_locked || item->details.equip_slot_id)
  7141. {
  7142. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell the item in use.");
  7143. return;
  7144. }
  7145. else if(item->CheckFlag(NO_VALUE))
  7146. {
  7147. SimpleMessage(CHANNEL_COLOR_RED, "This item has no value.");
  7148. return;
  7149. }
  7150. else if (item->IsBag())
  7151. {
  7152. int32 bagitemcount = player->GetPlayerItemList()->GetItemCountInBag(item);
  7153. if (bagitemcount > 0) {
  7154. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell a bag with items inside it.");
  7155. return;
  7156. }
  7157. }
  7158. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  7159. if (sell_price > item->sell_price)
  7160. sell_price = item->sell_price;
  7161. if (quantity > item->details.count)
  7162. quantity = item->details.count;
  7163. total_sell_price = sell_price * quantity;
  7164. //------------------------------For Selling Status Items
  7165. status_sell_price = (int32)(master_item->sell_status * multiplier);
  7166. if (status_sell_price > item->sell_status)
  7167. status_sell_price = item->sell_status;
  7168. if (quantity > item->details.count)
  7169. quantity = item->details.count;
  7170. total_status_sell_price = status_sell_price * quantity;
  7171. if(total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  7172. total_status_sell_price = 0;
  7173. player->GetInfoStruct()->add_status_points(total_status_sell_price);
  7174. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  7175. if (player->GetGuild() && guild->GetLevel() < guildMaxLevel) {
  7176. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  7177. guild->SendGuildMemberList();
  7178. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  7179. }
  7180. if (quantity > 1)
  7181. {
  7182. if(total_status_sell_price)
  7183. 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);
  7184. else
  7185. 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());
  7186. }
  7187. else
  7188. {
  7189. if(total_status_sell_price)
  7190. 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);
  7191. else
  7192. 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());
  7193. }
  7194. player->AddCoins(total_sell_price);
  7195. if(!item->no_buy_back && (total_status_sell_price == 0 || (total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))))
  7196. AddBuyBack(unique_id, item_id, quantity, sell_price);
  7197. if (quantity >= item->details.count) {
  7198. database.DeleteItem(GetCharacterID(), item, 0);
  7199. player->item_list.RemoveItem(item, true);
  7200. }
  7201. else {
  7202. item->details.count -= quantity;
  7203. item->save_needed = true;
  7204. }
  7205. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  7206. if (outapp)
  7207. QueuePacket(outapp);
  7208. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  7209. SendBuyBackList();
  7210. }
  7211. }
  7212. }
  7213. void Client::BuyBack(int32 item_id, int16 quantity) {
  7214. Spawn* spawn = GetMerchantTransaction();
  7215. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK)) &&
  7216. spawn->IsClientInMerchantLevelRange(this)) {
  7217. deque<BuyBackItem*>::iterator itr;
  7218. BuyBackItem* buyback = 0;
  7219. BuyBackItem* closest = 0;
  7220. MBuyBack.readlock(__FUNCTION__, __LINE__);
  7221. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  7222. buyback = *itr;
  7223. if (buyback->unique_id == item_id) {
  7224. closest = buyback;
  7225. quantity = buyback->quantity;
  7226. break;
  7227. }
  7228. }
  7229. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  7230. if (closest) {
  7231. Item* item = 0;
  7232. Item* master_item = master_item_list.GetItem(closest->item_id);
  7233. if (master_item) {
  7234. item = new Item(master_item);
  7235. if (closest->quantity >= quantity)
  7236. item->details.count = quantity;
  7237. else
  7238. item->details.count = closest->quantity;
  7239. }
  7240. bool itemDeleted = false;
  7241. bool itemAdded = false;
  7242. sint64 dispFlags = 0;
  7243. if (item && item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buyback_display_flags", item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  7244. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  7245. else if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  7246. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  7247. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  7248. bool removed = false;
  7249. if (closest->quantity == quantity) {
  7250. MBuyBack.writelock(__FUNCTION__, __LINE__);
  7251. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  7252. if (*itr == closest) {
  7253. buy_back_items.erase(itr);
  7254. removed = true;
  7255. break;
  7256. }
  7257. }
  7258. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  7259. }
  7260. else {
  7261. closest->quantity -= quantity;
  7262. closest->save_needed = true;
  7263. }
  7264. itemAdded = AddItem(item, &itemDeleted);
  7265. if (removed) {
  7266. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  7267. safe_delete(closest);
  7268. }
  7269. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  7270. SendBuyBackList();
  7271. }
  7272. else
  7273. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  7274. if(!itemAdded && !itemDeleted) {
  7275. lua_interface->SetLuaUserDataStale(item);
  7276. safe_delete(item);
  7277. }
  7278. }
  7279. }
  7280. }
  7281. void Client::BuyItem(int32 item_id, int16 quantity) {
  7282. // Get the merchant we are buying from
  7283. Spawn* spawn = GetMerchantTransaction();
  7284. // Make sure the spawn has a merchant list
  7285. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7286. int32 total_buy_price = 0;
  7287. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7288. int32 sell_price = 0;
  7289. Item* master_item = master_item_list.GetItem(item_id);
  7290. Item* item = 0;
  7291. int16 total_available = 0;
  7292. vector<MerchantItemInfo>* temp;
  7293. vector<MerchantItemInfo>::iterator itr;
  7294. MerchantItemInfo* ItemInfo = 0;
  7295. temp = world.GetMerchantList(spawn->GetMerchantID());
  7296. for (itr = temp->begin(); itr != temp->end(); itr++) {
  7297. if ((*itr).item_id == item_id) {
  7298. ItemInfo = &(*itr);
  7299. break;
  7300. }
  7301. }
  7302. if (master_item && ItemInfo) {
  7303. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  7304. quantity = 1;
  7305. total_available = 0xFFFF;
  7306. sell_price = master_item->sell_price;
  7307. }
  7308. else {
  7309. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  7310. sell_price = (int32)(master_item->sell_price * multiplier);
  7311. if (quantity > total_available)
  7312. quantity = total_available;
  7313. }
  7314. sint64 dispFlags = 0;
  7315. 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))
  7316. {
  7317. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  7318. return;
  7319. }
  7320. if(quantity < 1)
  7321. {
  7322. SimpleMessage(CHANNEL_COLOR_RED, "Merchant does not have item for purchase (quantity < 1).");
  7323. return;
  7324. }
  7325. total_buy_price = sell_price * quantity;
  7326. item = new Item(master_item);
  7327. item->details.count = quantity;
  7328. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  7329. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  7330. lua_interface->SetLuaUserDataStale(item);
  7331. safe_delete(item);
  7332. }
  7333. else {
  7334. // Price not set in the merchant_inventory table, use the old method
  7335. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  7336. if (player->RemoveCoins(total_buy_price)) {
  7337. item->SetMaxSellValue(sell_price);
  7338. if (quantity > 1)
  7339. 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());
  7340. else
  7341. 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());
  7342. bool itemDeleted = false;
  7343. AddItem(item, &itemDeleted);
  7344. if(!itemDeleted) {
  7345. CheckPlayerQuestsItemUpdate(item);
  7346. if (item && total_available < 0xFF) {
  7347. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  7348. SendBuyMerchantList();
  7349. }
  7350. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  7351. PlayLotto(total_buy_price, item->details.item_id);
  7352. }
  7353. }
  7354. else {
  7355. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7356. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7357. PlaySound("buy_failed");
  7358. }
  7359. }
  7360. else {
  7361. // Price set in merchant_inventory table
  7362. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  7363. // TODO: need to add support for station cash
  7364. if (player->GetInfoStruct()->get_status_points() >= (ItemInfo->price_status * quantity) && player->HasCoins(ItemInfo->price_coins * quantity)) {
  7365. // Check items
  7366. int16 item_quantity = 0;
  7367. // Default these to true in case price_item_id or price_item2_id was never set
  7368. bool hasItem1 = true;
  7369. bool hasItem2 = true;
  7370. Item* tempItem1 = 0;
  7371. Item* tempItem2 = 0;
  7372. if (ItemInfo->price_item_id != 0) {
  7373. // Same item for whatever reason lets add the quantities together
  7374. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  7375. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  7376. else
  7377. item_quantity = ItemInfo->price_item_qty;
  7378. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  7379. if (tempItem1) {
  7380. if (tempItem1->details.count < item_quantity)
  7381. hasItem1 = false;
  7382. }
  7383. else {
  7384. hasItem1 = false;
  7385. }
  7386. }
  7387. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  7388. // as item1 and we already checked for it so we can skip this check
  7389. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  7390. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  7391. if (tempItem2) {
  7392. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  7393. hasItem2 = false;
  7394. }
  7395. else {
  7396. hasItem2 = false;
  7397. }
  7398. }
  7399. // if we have every thing then remove the price and give the item
  7400. if (hasItem1 && hasItem2) {
  7401. player->GetInfoStruct()->set_status_points(player->GetInfoStruct()->get_status_points() - (ItemInfo->price_status * quantity));
  7402. // TODO: station cash
  7403. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  7404. // so there is no need to send it more then that one time
  7405. if (tempItem1) {
  7406. if (tempItem1->details.count > item_quantity) {
  7407. tempItem1->details.count -= item_quantity;
  7408. tempItem1->save_needed = true;
  7409. }
  7410. else {
  7411. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  7412. player->item_list.DestroyItem(tempItem1->details.index);
  7413. }
  7414. }
  7415. if (tempItem2) {
  7416. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  7417. tempItem2->details.count -= ItemInfo->price_item2_qty;
  7418. tempItem2->save_needed = true;
  7419. }
  7420. else {
  7421. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  7422. player->item_list.DestroyItem(tempItem2->details.index);
  7423. }
  7424. }
  7425. // 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
  7426. player->RemoveCoins(ItemInfo->price_coins * quantity);
  7427. item->SetMaxSellValue(sell_price);
  7428. if (quantity > 1)
  7429. 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());
  7430. else
  7431. 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());
  7432. bool itemDeleted = false;
  7433. AddItem(item, &itemDeleted);
  7434. if(!itemDeleted) {
  7435. CheckPlayerQuestsItemUpdate(item);
  7436. if (item && total_available < 0xFF) {
  7437. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  7438. SendBuyMerchantList();
  7439. }
  7440. SendSellMerchantList();
  7441. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  7442. PlayLotto(total_buy_price, item->details.item_id);
  7443. }
  7444. }
  7445. else {
  7446. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7447. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7448. PlaySound("buy_failed");
  7449. }
  7450. }
  7451. else {
  7452. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7453. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7454. PlaySound("buy_failed");
  7455. }
  7456. }
  7457. }
  7458. }
  7459. }
  7460. }
  7461. void Client::RepairItem(int32 item_id) {
  7462. Spawn* spawn = GetMerchantTransaction();
  7463. if (spawn) {
  7464. Item* item = player->item_list.GetItemFromID(item_id);
  7465. if (!item)
  7466. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  7467. if (item) {
  7468. if(item->CheckFlag2(NO_REPAIR)) {
  7469. Message(CHANNEL_MERCHANT, "The mender was unable to repair your items.");
  7470. PlaySound("buy_failed");
  7471. }
  7472. else {
  7473. int32 repair_cost = item->CalculateRepairCost();
  7474. if (player->RemoveCoins((int32)repair_cost)) {
  7475. item->generic_info.condition = 100;
  7476. item->save_needed = true;
  7477. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  7478. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  7479. QueuePacket(item->serialize(version, false, player));
  7480. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  7481. PlaySound("coin_cha_ching");
  7482. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  7483. SendRepairList();
  7484. }
  7485. else {
  7486. string popup_text = "You do not have enough coin to repair ";
  7487. string popup_item = item->CreateItemLink(GetVersion()).c_str();
  7488. popup_text.append(popup_item);
  7489. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7490. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  7491. PlaySound("buy_failed");
  7492. }
  7493. }
  7494. }
  7495. }
  7496. }
  7497. void Client::RepairAllItems() {
  7498. Spawn* spawn = GetMerchantTransaction();
  7499. if (spawn) {
  7500. vector<Item*>* repairable_items = GetRepairableItems();
  7501. if (repairable_items && repairable_items->size() > 0) {
  7502. vector<Item*>::iterator itr;
  7503. int64 total_cost = 0;
  7504. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  7505. total_cost += (*itr)->CalculateRepairCost();
  7506. if (player->RemoveCoins((int32)total_cost)) {
  7507. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  7508. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  7509. Item* item = *itr;
  7510. if (item) {
  7511. item->generic_info.condition = 100;
  7512. item->save_needed = true;
  7513. QueuePacket(item->serialize(version, false, player));
  7514. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  7515. }
  7516. }
  7517. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  7518. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  7519. PlaySound("coin_cha_ching");
  7520. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  7521. SendRepairList();
  7522. }
  7523. else {
  7524. string popup_text = "You do not have enough coin to repair all of your items. ";
  7525. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7526. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  7527. PlaySound("buy_failed");
  7528. }
  7529. }
  7530. safe_delete(repairable_items);
  7531. }
  7532. }
  7533. void Client::SendAchievementsList()
  7534. {
  7535. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  7536. map<int32, Achievement *>::iterator itr;
  7537. Achievement *achievement;
  7538. vector<AchievementRequirements *> *requirements = 0;
  7539. vector<AchievementRequirements *>::iterator itr2;
  7540. AchievementRequirements *requirement;
  7541. vector<AchievementRewards *> *rewards = 0;
  7542. vector<AchievementRewards *>::iterator itr3;
  7543. AchievementRewards *reward;
  7544. PacketStruct *packet;
  7545. int16 i = 0;
  7546. int16 j = 0;
  7547. int16 k = 0;
  7548. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  7549. return;
  7550. }
  7551. packet->setArrayLengthByName("num_achievements" , achievements->size());
  7552. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  7553. achievement = itr->second;
  7554. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  7555. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  7556. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  7557. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  7558. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  7559. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  7560. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  7561. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  7562. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  7563. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  7564. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  7565. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  7566. requirements = achievement->GetRequirements();
  7567. rewards = achievement->GetRewards();
  7568. j = 0;
  7569. k = 0;
  7570. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  7571. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  7572. requirement = *itr2;
  7573. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  7574. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  7575. j++;
  7576. }
  7577. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  7578. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  7579. reward = *itr3;
  7580. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  7581. k++;
  7582. }
  7583. i++;
  7584. }
  7585. //packet->PrintPacket();
  7586. EQ2Packet* data = packet->serialize();
  7587. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  7588. safe_delete(packet);
  7589. safe_delete(data);
  7590. //DumpPacket(app);
  7591. QueuePacket(app);*/
  7592. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  7593. SendAchievementUpdate(true);
  7594. }
  7595. void Client::SendAchievementUpdate(bool first_login) {
  7596. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  7597. map<int32, AchievementUpdate*>::iterator itr;
  7598. AchievementUpdate* update;
  7599. vector<AchievementUpdateItems*>* update_items = 0;
  7600. vector<AchievementUpdateItems*>::iterator itr2;
  7601. AchievementUpdateItems* update_item;
  7602. int16 i = 0;
  7603. int16 j = 0;
  7604. PacketStruct* packet;
  7605. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  7606. return;
  7607. }
  7608. packet->setDataByName("unknown1", first_login ? 1 : 0);
  7609. packet->setArrayLengthByName("num_achievements", updates->size());
  7610. for (itr = updates->begin(); itr != updates->end(); itr++) {
  7611. update = itr->second;
  7612. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  7613. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  7614. update_items = update->GetUpdateItems();
  7615. j = 0;
  7616. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  7617. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  7618. update_item = *itr2;
  7619. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  7620. j++;
  7621. }
  7622. i++;
  7623. }
  7624. //packet->PrintPacket();
  7625. EQ2Packet* data = packet->serialize();
  7626. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  7627. safe_delete(packet);
  7628. safe_delete(data);
  7629. //DumpPacket(app);
  7630. QueuePacket(app);
  7631. }
  7632. void Client::SendBuyMerchantList(bool sell) {
  7633. Spawn* spawn = GetMerchantTransaction();
  7634. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7635. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  7636. if (items) {
  7637. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7638. if (packet) {
  7639. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7640. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7641. packet->setArrayLengthByName("num_items", items->size());
  7642. vector<MerchantItemInfo>::iterator itr;
  7643. sint8 item_difficulty = 0;
  7644. int32 sell_price = 0;
  7645. int i = 0;
  7646. int tmp_level = 0;
  7647. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  7648. MerchantItemInfo ItemInfo = *itr;
  7649. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  7650. if (!item)
  7651. continue;
  7652. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7653. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7654. packet->setArrayDataByName("stack_size", item->stack_count, i);
  7655. packet->setArrayDataByName("icon", item->GetIcon(GetVersion()), i);
  7656. if (item->generic_info.adventure_default_level > 0)
  7657. tmp_level = item->generic_info.adventure_default_level;
  7658. else
  7659. tmp_level = item->generic_info.tradeskill_default_level;
  7660. packet->setArrayDataByName("level", tmp_level, i);
  7661. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7662. packet->setArrayDataByName("tier", item->details.tier, i);
  7663. }
  7664. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7665. item_difficulty = player->GetArrowColor(tmp_level);
  7666. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7667. item_difficulty = ARROW_COLOR_WHITE;
  7668. sint64 overrideValue = 0;
  7669. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  7670. item_difficulty = (sint8)overrideValue;
  7671. item_difficulty -= 6;
  7672. if (item_difficulty < 0)
  7673. item_difficulty *= -1;
  7674. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7675. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  7676. packet->setArrayDataByName("unknown5", 255, i);
  7677. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  7678. sint64 dispFlags = 0;
  7679. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buy_display_flags", item, player, nullptr, &dispFlags))
  7680. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  7681. std::string overrideValueStr;
  7682. // 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)
  7683. if (GetVersion() >= 546 && item->GetItemScript() && lua_interface && lua_interface->RunItemScriptWithReturnString(item->GetItemScript(), "item_description", item, player, &overrideValueStr))
  7684. packet->setArrayDataByName("description", overrideValueStr.c_str(), i);
  7685. // If no price set in the merchant_inventory table then use the old method
  7686. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  7687. sell_price = (int32)(item->sell_price * multiplier);
  7688. packet->setArrayDataByName("price", sell_price, i);
  7689. }
  7690. else {
  7691. int8 count = 0;
  7692. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  7693. count++;
  7694. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  7695. count++;
  7696. if (count != 0) {
  7697. packet->setSubArrayLengthByName("num_tokens", count, i);
  7698. int8 index = 0;
  7699. Item* token = 0;
  7700. if (ItemInfo.price_item_id != 0) {
  7701. token = master_item_list.GetItem(ItemInfo.price_item_id);
  7702. if (item) {
  7703. packet->setSubArrayDataByName("token_icon", token->GetIcon(GetVersion()), i, index);
  7704. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  7705. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  7706. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  7707. }
  7708. token = 0;
  7709. index++;
  7710. }
  7711. if (ItemInfo.price_item2_id != 0) {
  7712. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  7713. if (item) {
  7714. packet->setSubArrayDataByName("token_icon", token->GetIcon(GetVersion()), i, index);
  7715. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  7716. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  7717. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  7718. }
  7719. }
  7720. }
  7721. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  7722. packet->setArrayDataByName("status2", ItemInfo.price_status, i);
  7723. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  7724. }
  7725. }
  7726. if (GetVersion() < 561) {
  7727. //buy is 0 so dont need to set it
  7728. if (sell)
  7729. packet->setDataByName("type", 1);
  7730. }
  7731. else if (GetVersion() == 561) {
  7732. packet->setDataByName("type", 2);
  7733. }
  7734. else {
  7735. if (sell)
  7736. packet->setDataByName("type", 130);
  7737. else
  7738. packet->setDataByName("type", 2);
  7739. }
  7740. EQ2Packet* outapp = packet->serialize();
  7741. QueuePacket(outapp);
  7742. safe_delete(packet);
  7743. }
  7744. safe_delete(items);
  7745. }
  7746. else {
  7747. // Need to send an empty packet in the event there is no item list, otherwise the
  7748. // last item list sent to the player will show for this merchant
  7749. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7750. if (packet) {
  7751. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7752. if (GetVersion() <= 561) {
  7753. //buy is 0 so dont need to set it
  7754. if (sell)
  7755. packet->setDataByName("type", 1);
  7756. }
  7757. else {
  7758. if (sell)
  7759. packet->setDataByName("type", 130);
  7760. else
  7761. packet->setDataByName("type", 2);
  7762. }
  7763. EQ2Packet* outapp = packet->serialize();
  7764. QueuePacket(outapp);
  7765. safe_delete(packet);
  7766. }
  7767. }
  7768. }
  7769. }
  7770. void Client::SendSellMerchantList(bool sell) {
  7771. Spawn* spawn = GetMerchantTransaction();
  7772. if (!spawn || (spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) || (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  7773. return;
  7774. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7775. map<int32, Item*>* items = player->GetItemList();
  7776. if (items) {
  7777. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7778. if (packet) {
  7779. vector<Item*> sellable_items;
  7780. map<int32, Item*>::iterator test_itr;
  7781. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  7782. bool isbagwithitems = false;
  7783. 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))
  7784. isbagwithitems = true;
  7785. 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))
  7786. sellable_items.push_back(test_itr->second);
  7787. }
  7788. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7789. packet->setArrayLengthByName("num_items", sellable_items.size());
  7790. vector<Item*>::iterator itr;
  7791. Item* item = 0;
  7792. sint8 item_difficulty = 0;
  7793. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  7794. int32 sell_price = 0;
  7795. Item* master_item = 0;
  7796. int i = 0;
  7797. int tmp_level = 0;
  7798. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  7799. item = *itr;
  7800. master_item = master_item_list.GetItem(item->details.item_id);
  7801. if (master_item)
  7802. sell_price = (int32)(master_item->sell_price * multiplier);
  7803. else
  7804. sell_price = 0;
  7805. if (sell_price > item->sell_price)
  7806. sell_price = item->sell_price;
  7807. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7808. string thename = item->name;
  7809. packet->setArrayDataByName("price", sell_price, i);
  7810. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  7811. int8 dispFlags = 0;
  7812. // only city merchants allow selling for status
  7813. if(item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT))
  7814. {
  7815. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  7816. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  7817. if (GetPlayer()->GetGuild() && GetPlayer()->GetGuild()->GetLevel() >= guildMaxLevel) {
  7818. dispFlags += DISPLAY_FLAG_NO_GUILD_STATUS;
  7819. }
  7820. }
  7821. if(item->no_buy_back || (item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  7822. {
  7823. if(GetVersion() < 1188)
  7824. 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
  7825. else
  7826. dispFlags += DISPLAY_FLAG_NO_BUYBACK;
  7827. }
  7828. if(item->no_sale)
  7829. dispFlags += DISPLAY_FLAG_NOT_FOR_SALE;
  7830. packet->setArrayDataByName("display_flags", dispFlags, i);
  7831. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7832. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  7833. packet->setArrayDataByName("stack_size", item->details.count, i);
  7834. packet->setArrayDataByName("icon", item->GetIcon(GetVersion()), i);
  7835. if (item->generic_info.adventure_default_level > 0)
  7836. tmp_level = item->generic_info.adventure_default_level;
  7837. else
  7838. tmp_level = item->generic_info.tradeskill_default_level;
  7839. packet->setArrayDataByName("level", item->details.recommended_level, i);
  7840. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7841. packet->setArrayDataByName("tier", item->details.tier, i);
  7842. }
  7843. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7844. item_difficulty = player->GetArrowColor(tmp_level);
  7845. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7846. item_difficulty = ARROW_COLOR_WHITE;
  7847. sint64 overrideValue = 0;
  7848. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  7849. item_difficulty = (sint8)overrideValue;
  7850. item_difficulty -= 6;
  7851. if (item_difficulty < 0)
  7852. item_difficulty *= -1;
  7853. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7854. if (item->details.count == 1)
  7855. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7856. else
  7857. packet->setArrayDataByName("quantity", item->details.count, i);
  7858. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7859. if (GetVersion() <= 1096)
  7860. packet->setArrayDataByName("description", item->description.c_str(), i);
  7861. }
  7862. if (GetVersion() < 561) {
  7863. packet->setDataByName("type", 1);
  7864. }
  7865. else if(GetVersion() == 561) {
  7866. packet->setDataByName("type", 1);
  7867. }
  7868. else {
  7869. if (sell)
  7870. packet->setDataByName("type", 129);
  7871. else
  7872. packet->setDataByName("type", 1);
  7873. }
  7874. packet->setDataByName("unknown8a", 16256, 6);
  7875. packet->setDataByName("unknown8a", 16256, 10);
  7876. //packet->PrintPacket();
  7877. EQ2Packet* outapp = packet->serialize();
  7878. //DumpPacket(outapp);
  7879. QueuePacket(outapp);
  7880. safe_delete(packet);
  7881. }
  7882. safe_delete(items);
  7883. }
  7884. }
  7885. }
  7886. void Client::SendBuyBackList(bool sell) {
  7887. if (GetVersion() <= 561) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  7888. return;
  7889. Spawn* spawn = GetMerchantTransaction();
  7890. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7891. deque<BuyBackItem*>::iterator itr;
  7892. int i = 0;
  7893. Item* master_item = 0;
  7894. BuyBackItem* buyback = 0;
  7895. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7896. if (packet) {
  7897. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7898. packet->setArrayLengthByName("num_items", buy_back_items.size());
  7899. sint8 item_difficulty = 0;
  7900. MBuyBack.readlock(__FUNCTION__, __LINE__);
  7901. int tmp_level = 0;
  7902. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  7903. buyback = *itr;
  7904. master_item = master_item_list.GetItem(buyback->item_id);
  7905. if (master_item) {
  7906. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  7907. packet->setArrayDataByName("price", buyback->price, i);
  7908. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  7909. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  7910. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  7911. packet->setArrayDataByName("icon", master_item->GetIcon(GetVersion()), i);
  7912. if (master_item->generic_info.adventure_default_level > 0)
  7913. tmp_level = master_item->generic_info.adventure_default_level;
  7914. else
  7915. tmp_level = master_item->generic_info.tradeskill_default_level;
  7916. packet->setArrayDataByName("level", tmp_level, i);
  7917. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7918. packet->setArrayDataByName("tier", master_item->details.tier, i);
  7919. }
  7920. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  7921. item_difficulty = player->GetArrowColor(tmp_level);
  7922. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7923. item_difficulty = ARROW_COLOR_WHITE;
  7924. sint64 overrideValue = 0;
  7925. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "item_difficulty", master_item, player, nullptr, &overrideValue))
  7926. item_difficulty = (sint8)overrideValue;
  7927. item_difficulty -= 6;
  7928. if (item_difficulty < 0)
  7929. item_difficulty *= -1;
  7930. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7931. sint64 dispFlags = 0;
  7932. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buyback_display_flags", master_item, player, nullptr, &dispFlags))
  7933. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  7934. if (buyback->quantity == 1)
  7935. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7936. else
  7937. packet->setArrayDataByName("quantity", buyback->quantity, i);
  7938. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  7939. if (GetVersion() <= 1096)
  7940. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  7941. }
  7942. }
  7943. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  7944. if (sell)
  7945. packet->setDataByName("type", 640);
  7946. else
  7947. packet->setDataByName("type", 512);
  7948. EQ2Packet* outapp = packet->serialize();
  7949. // DumpPacket(outapp);
  7950. QueuePacket(outapp);
  7951. safe_delete(packet);
  7952. }
  7953. }
  7954. }
  7955. void Client::SendRepairList() {
  7956. Spawn* spawn = GetMerchantTransaction();
  7957. if (spawn) {
  7958. vector<Item*>* repairable_items = GetRepairableItems();
  7959. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7960. if (packet) {
  7961. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7962. packet->setArrayLengthByName("num_items", repairable_items->size());
  7963. Item* item = 0;
  7964. sint8 item_difficulty = 0;
  7965. int32 i = 0;
  7966. vector<Item*>::iterator itr;
  7967. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  7968. item = *itr;
  7969. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7970. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  7971. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7972. packet->setArrayDataByName("stack_size", item->details.count, i);
  7973. packet->setArrayDataByName("icon", item->GetIcon(GetVersion()), i);
  7974. /*if (item->generic_info.adventure_default_level > 0)
  7975. tmp_level = item->generic_info.adventure_default_level;
  7976. else
  7977. tmp_level = item->generic_info.tradeskill_default_level;
  7978. packet->setArrayDataByName("level", tmp_level, i);*/
  7979. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  7980. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7981. packet->setArrayDataByName("tier", item->details.tier, i);
  7982. }
  7983. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7984. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7985. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7986. item_difficulty = ARROW_COLOR_WHITE;
  7987. item_difficulty -= 6;
  7988. if (item_difficulty < 0)
  7989. item_difficulty *= -1;
  7990. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7991. if (item->details.count == 1)
  7992. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7993. else
  7994. packet->setArrayDataByName("quantity", item->details.count, i);
  7995. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7996. if (GetVersion() <= 1096)
  7997. packet->setArrayDataByName("description", item->description.c_str(), i);
  7998. }
  7999. if (GetVersion() <= 561) {
  8000. packet->setDataByName("type", 112);
  8001. }
  8002. else {
  8003. packet->setDataByName("type", 96);
  8004. }
  8005. EQ2Packet* outapp = packet->serialize();
  8006. //DumpPacket(outapp);
  8007. QueuePacket(outapp);
  8008. /*if (GetVersion() <= 561) {
  8009. packet->setDataByName("type", 16);
  8010. EQ2Packet* outapp2 = packet->serialize();
  8011. QueuePacket(outapp2);
  8012. }*/
  8013. safe_delete(packet);
  8014. }
  8015. safe_delete(repairable_items);
  8016. }
  8017. }
  8018. void Client::ShowLottoWindow() {
  8019. if(GetVersion() <= 373) {
  8020. SimpleMessage(CHANNEL_COLOR_RED, "This client does not support the gambler UI, only Desert of Flames or later client.");
  8021. return;
  8022. }
  8023. Spawn* spawn = GetMerchantTransaction();
  8024. if (spawn) {
  8025. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  8026. if (!item_id)
  8027. {
  8028. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  8029. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  8030. return;
  8031. }
  8032. else if (item_id == 0)
  8033. {
  8034. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  8035. return;
  8036. }
  8037. Item* item = master_item_list.GetItem(item_id);
  8038. if (!item) {
  8039. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  8040. return;
  8041. }
  8042. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  8043. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  8044. if (packet) {
  8045. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  8046. packet->setArrayLengthByName("num_items", 1);
  8047. packet->setArrayDataByName("item_name", item->name.c_str());
  8048. packet->setArrayDataByName("price", item->sell_price);
  8049. packet->setArrayDataByName("item_id", item->details.item_id);
  8050. packet->setArrayDataByName("stack_size", item->details.count);
  8051. packet->setArrayDataByName("icon", item->GetIcon(GetVersion()));
  8052. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  8053. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  8054. packet->setArrayDataByName("tier", item->details.tier);
  8055. }
  8056. packet->setArrayDataByName("item_id2", item->details.item_id);
  8057. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  8058. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  8059. item_difficulty = ARROW_COLOR_WHITE;
  8060. item_difficulty -= 6;
  8061. if (item_difficulty < 0)
  8062. item_difficulty *= -1;
  8063. packet->setArrayDataByName("item_difficulty", item_difficulty);
  8064. //if(item->details.count == 1)
  8065. packet->setArrayDataByName("quantity", 0xFFFF);
  8066. //else
  8067. // packet->setArrayDataByName("quantity", item->details.count);
  8068. packet->setArrayDataByName("stack_size2", item->details.count);
  8069. packet->setArrayDataByName("description", item->description.c_str());
  8070. if (GetVersion() <= 546) {
  8071. packet->setDataByName("type", 128);
  8072. }
  8073. else {
  8074. packet->setDataByName("type", 0x00000102);
  8075. }
  8076. QueuePacket(packet->serialize());
  8077. safe_delete(packet);
  8078. }
  8079. }
  8080. }
  8081. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  8082. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  8083. if (packet) {
  8084. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  8085. int32 rolls[6] = { 0 };
  8086. int32 lottery_digits[6] = { 0 };
  8087. int8 num_matches = 0;
  8088. int64 jackpot = 0;
  8089. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  8090. if (!item) {
  8091. return;
  8092. }
  8093. database.DeleteItem(GetCharacterID(), item, 0);
  8094. GetPlayer()->item_list.RemoveItem(item, true);
  8095. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  8096. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  8097. if (!winning_numbers) {
  8098. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  8099. variables.AddVariable(winning_numbers);
  8100. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  8101. }
  8102. if (strlen(winning_numbers->GetValue()) != 12) {
  8103. winning_numbers->SetValue("231205182236");
  8104. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  8105. }
  8106. try {
  8107. for (int32 i = 0; i < 12; i += 2) {
  8108. char num[4];
  8109. strncpy(num, winning_numbers->GetValue() + i, 2);
  8110. lottery_digits[i / 2] = atoi(num);
  8111. }
  8112. }
  8113. catch (...) {
  8114. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  8115. return;
  8116. }
  8117. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  8118. if (!jackpot_var) {
  8119. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  8120. variables.AddVariable(jackpot_var);
  8121. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  8122. }
  8123. try {
  8124. jackpot = atoul(jackpot_var->GetValue());
  8125. if (jackpot < 10000)
  8126. jackpot = 10000;
  8127. }
  8128. catch (...) {
  8129. jackpot = 10000;
  8130. }
  8131. char new_jackpot[128] = { 0 };
  8132. sprintf(new_jackpot, "%llu", jackpot + price);
  8133. jackpot_var->SetValue(new_jackpot);
  8134. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  8135. world.PickRandomLottoDigits(rolls);
  8136. packet->setDataByName("roll_digit1", rolls[0]);
  8137. packet->setDataByName("roll_digit2", rolls[1]);
  8138. packet->setDataByName("roll_digit3", rolls[2]);
  8139. packet->setDataByName("roll_digit4", rolls[3]);
  8140. packet->setDataByName("roll_digit5", rolls[4]);
  8141. packet->setDataByName("roll_digit6", rolls[5]);
  8142. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  8143. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  8144. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  8145. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  8146. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  8147. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  8148. QueuePacket(packet->serialize());
  8149. safe_delete(packet);
  8150. for (int32 i = 0; i < 6; i++) {
  8151. for (int32 j = 0; j < 6; j++) {
  8152. if (rolls[i] == lottery_digits[j]) {
  8153. num_matches++;
  8154. break;
  8155. }
  8156. }
  8157. }
  8158. char new_jackpot_str[16];
  8159. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  8160. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  8161. if (num_matches == 6) {
  8162. world.PickRandomLottoDigits(lottery_digits);
  8163. for (int32 i = 0; i < 12; i += 2)
  8164. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  8165. winning_numbers->SetValue(new_jackpot_str);
  8166. jackpot_var->SetValue("10000");
  8167. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  8168. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  8169. }
  8170. }
  8171. }
  8172. void Client::SendGuildCreateWindow() {
  8173. if (GetVersion() <= 561) {
  8174. SimpleMessage(0, "Not implemented on this client...yet?");
  8175. }
  8176. else {
  8177. Spawn* spawn = GetPlayer()->GetTarget();
  8178. if (spawn) {
  8179. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  8180. if (packet) {
  8181. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  8182. packet->setArrayLengthByName("num_items", 0);
  8183. packet->setDataByName("type", 0x00008000);
  8184. QueuePacket(packet->serialize());
  8185. safe_delete(packet);
  8186. }
  8187. }
  8188. }
  8189. }
  8190. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  8191. BuyBackItem* item = new BuyBackItem;
  8192. item->item_id = item_id;
  8193. item->unique_id = unique_id;
  8194. item->price = price;
  8195. item->quantity = quantity;
  8196. item->save_needed = save_needed;
  8197. MBuyBack.writelock(__FUNCTION__, __LINE__);
  8198. buy_back_items.push_back(item);
  8199. if (buy_back_items.size() > 10) {
  8200. safe_delete(buy_back_items.front());
  8201. buy_back_items.pop_front();
  8202. }
  8203. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  8204. }
  8205. deque<BuyBackItem*>* Client::GetBuyBacks() {
  8206. return &buy_back_items;
  8207. }
  8208. vector<Item*>* Client::GetRepairableItems() {
  8209. vector<Item*>* repairable_items = new vector<Item*>;
  8210. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  8211. map<int32, Item*>* items = player->GetItemList();
  8212. if (equipped_items && equipped_items->size() > 0) {
  8213. for (int32 i = 0; i < equipped_items->size(); i++) {
  8214. Item* item = equipped_items->at(i);
  8215. if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
  8216. repairable_items->push_back(item);
  8217. }
  8218. }
  8219. if (items && items->size() > 0) {
  8220. map<int32, Item*>::iterator itr;
  8221. for (itr = items->begin(); itr != items->end(); itr++) {
  8222. Item* item = itr->second;
  8223. if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
  8224. repairable_items->push_back(item);
  8225. }
  8226. }
  8227. safe_delete(equipped_items);
  8228. safe_delete(items);
  8229. return repairable_items;
  8230. }
  8231. vector<Item*>* Client::GetItemsByEffectType(ItemEffectType type, ItemEffectType type2) {
  8232. if(type == NO_EFFECT_TYPE)
  8233. return nullptr;
  8234. vector<Item*>* return_items = new vector<Item*>;
  8235. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  8236. map<int32, Item*>* items = player->GetItemList();
  8237. if (equipped_items && equipped_items->size() > 0) {
  8238. for (int32 i = 0; i < equipped_items->size(); i++) {
  8239. Item* item = equipped_items->at(i);
  8240. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  8241. return_items->push_back(item);
  8242. }
  8243. }
  8244. if (items && items->size() > 0) {
  8245. map<int32, Item*>::iterator itr;
  8246. for (itr = items->begin(); itr != items->end(); itr++) {
  8247. Item* item = itr->second;
  8248. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  8249. return_items->push_back(item);
  8250. }
  8251. }
  8252. safe_delete(equipped_items);
  8253. safe_delete(items);
  8254. return return_items;
  8255. }
  8256. void Client::SendMailList() {
  8257. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  8258. if (kiosk_id > 0) {
  8259. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  8260. if (p) {
  8261. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  8262. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  8263. int32 i = 0;
  8264. p->setDataByName("kiosk_id", kiosk_id);
  8265. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  8266. while (itr.Next()) {
  8267. Mail* mail = itr->second;
  8268. p->setArrayDataByName("mail_id", mail->mail_id, i);
  8269. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  8270. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  8271. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  8272. p->setArrayDataByName("already_read", mail->already_read, i);
  8273. if(mail->expire_time)
  8274. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  8275. else
  8276. p->setArrayDataByName("mail_deletion", 0, i);
  8277. p->setArrayDataByName("mail_type", mail->mail_type, i);
  8278. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  8279. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  8280. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  8281. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  8282. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  8283. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  8284. //p->setArrayDataByName("unknown2", 0, i);
  8285. bool successItemAdd = false;
  8286. if(mail->stack || mail->char_item_id)
  8287. {
  8288. Item* item = master_item_list.GetItem(mail->char_item_id);
  8289. if(item)
  8290. {
  8291. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  8292. if (version < 860)
  8293. p->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  8294. else if (version < 1193)
  8295. p->setItemArrayDataByName("item", item, player, i);
  8296. else
  8297. p->setItemArrayDataByName("item", item, player, i, 0, 2);
  8298. successItemAdd = true;
  8299. }
  8300. }
  8301. if(!successItemAdd)
  8302. {
  8303. p->setArrayDataByName("end_tag2", GetItemPacketType(GetVersion()), i);
  8304. p->setArrayDataByName("end_tag3", 0xFF, i);
  8305. }
  8306. i++;
  8307. }
  8308. // GMs send mail for free!
  8309. if (GetAdminStatus() > 0)
  8310. {
  8311. p->setDataByName("postage_cost", 0);
  8312. p->setDataByName("attachment_cost", 0);
  8313. }
  8314. else
  8315. {
  8316. p->setDataByName("postage_cost", 10);
  8317. p->setDataByName("attachment_cost", 50);
  8318. }
  8319. p->setDataByName("unknown3", 0x01F4);
  8320. p->setDataByName("unknown4", 0x01000000);
  8321. EQ2Packet* pack = p->serialize();
  8322. //DumpPacket(pack);
  8323. QueuePacket(pack);
  8324. safe_delete(p);
  8325. }
  8326. }
  8327. else
  8328. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8329. }
  8330. void Client::DisplayMailMessage(int32 mail_id) {
  8331. Mail* mail = player->GetMail(mail_id);
  8332. if (mail) {
  8333. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  8334. if (kiosk_id > 0) {
  8335. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8336. if (update) {
  8337. update->setDataByName("action", 0x03);
  8338. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  8339. update->setDataByName("packetsubtype", 0xFF);
  8340. QueuePacket(update->serialize());
  8341. safe_delete(update);
  8342. }
  8343. if(!mail->already_read) {
  8344. mail->already_read = true;
  8345. SendMailList();
  8346. }
  8347. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  8348. if (packet) {
  8349. packet->setDataByName("kiosk_id", kiosk_id);
  8350. packet->setDataByName("mail_id", mail->mail_id);
  8351. packet->setDataByName("player_to_id", mail->player_to_id);
  8352. packet->setDataByName("player_from", mail->player_from.c_str());
  8353. packet->setDataByName("subject", mail->subject.c_str());
  8354. packet->setDataByName("mail_body", mail->mail_body.c_str());
  8355. packet->setDataByName("unknown1", 1);
  8356. packet->setDataByName("unknown2", 0);
  8357. packet->setDataByName("lock_report_button", 1);
  8358. packet->setDataByName("unknown3", 0xFFFFFFFF);
  8359. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  8360. packet->setDataByName("coin_copper", mail->coin_copper);
  8361. packet->setDataByName("coin_silver", mail->coin_silver);
  8362. packet->setDataByName("coin_gold", mail->coin_gold);
  8363. packet->setDataByName("coin_plat", mail->coin_plat);
  8364. if(mail->stack || mail->char_item_id)
  8365. {
  8366. Item* item = master_item_list.GetItem(mail->char_item_id);
  8367. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  8368. if (version < 860)
  8369. packet->setItemByName("item", item, player, 0, version <= 373 ? -2 : -1);
  8370. else if (version < 1193)
  8371. packet->setItemByName("item", item, player, 0, 0);
  8372. else
  8373. packet->setItemByName("item", item, player, 0, 2);
  8374. }
  8375. else
  8376. {
  8377. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8378. packet->setDataByName("end_tag3", 0xFF);
  8379. }
  8380. mail->save_needed = true;
  8381. EQ2Packet* pack = packet->serialize();
  8382. QueuePacket(pack);
  8383. safe_delete(packet);
  8384. // trying to update this causes the window not to open
  8385. //SendMailList();
  8386. }
  8387. }
  8388. else
  8389. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8390. }
  8391. }
  8392. /* 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
  8393. packet back to the client before the mail actually sent. */
  8394. void Client::HandleSentMail(EQApplicationPacket* app) {
  8395. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  8396. if (packet) {
  8397. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  8398. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  8399. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  8400. vector<int32>* ids = 0;
  8401. MMailWindowMutex.lock();
  8402. if (reply_packet) {
  8403. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  8404. if (player_to.length() == 0)
  8405. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  8406. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  8407. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  8408. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  8409. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  8410. else {
  8411. if (GetAdminStatus() > 200 && player_to.compare("<all>") == 0) {
  8412. if (mail_window.char_item_id == 0 && (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat) == 0)
  8413. ids = database.GetAllPlayerIDs();
  8414. else
  8415. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  8416. }
  8417. else {
  8418. ids = new vector<int32>;
  8419. ids->push_back(database.GetCharacterID(player_to.c_str()));
  8420. }
  8421. if (ids) {
  8422. for (int32 i = 0; i < ids->size(); i++) {
  8423. int32 player_to_id = ids->at(i);
  8424. if (player_to_id > 0) {
  8425. reply_type = MAIL_SEND_RESULT_SUCCESS;
  8426. Mail* mail = new Mail;
  8427. mail->mail_id = 0;
  8428. mail->player_to_id = player_to_id;
  8429. mail->player_from = string(GetPlayer()->GetName());
  8430. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  8431. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  8432. mail->already_read = 0;
  8433. mail->mail_type = MAIL_TYPE_REGULAR;
  8434. mail->coin_copper = mail_window.coin_copper;
  8435. mail->coin_silver = mail_window.coin_silver;
  8436. mail->coin_gold = mail_window.coin_gold;
  8437. mail->coin_plat = mail_window.coin_plat;
  8438. mail->char_item_id = mail_window.char_item_id;
  8439. mail->stack = mail_window.stack;
  8440. // GM's send mail for free!
  8441. if (GetAdminStatus() > 0)
  8442. {
  8443. mail->postage_cost = 0;
  8444. mail->attachment_cost = 0;
  8445. }
  8446. else
  8447. {
  8448. mail->postage_cost = 10;
  8449. mail->attachment_cost = 50;
  8450. }
  8451. mail->time_sent = Timer::GetUnixTimeStamp();
  8452. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  8453. mail->save_needed = false;
  8454. database.SavePlayerMail(mail);
  8455. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  8456. if (to_client) {
  8457. to_client->GetPlayer()->AddMail(mail);
  8458. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You have unread mail in your mailbox.");
  8459. string popup_text = "You have unread mail!";
  8460. to_client->SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  8461. }
  8462. else {
  8463. // don't need the pointer the client doesn't exist currently
  8464. safe_delete(mail);
  8465. }
  8466. ResetSendMail(false, false);
  8467. }
  8468. else
  8469. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  8470. }
  8471. }
  8472. }
  8473. string players_to = "";
  8474. if (ids) {
  8475. for (int32 i = 0; i < ids->size(); i++) {
  8476. if (ids->at(i) != 0)
  8477. players_to.append(database.GetCharacterName(ids->at(i)));
  8478. if (i < (ids->size() - 1))
  8479. players_to.append(", ");
  8480. }
  8481. }
  8482. reply_packet->setDataByName("player_to", players_to.c_str());
  8483. reply_packet->setDataByName("reply_type", reply_type);
  8484. QueuePacket(reply_packet->serialize());
  8485. safe_delete(reply_packet);
  8486. safe_delete(ids);
  8487. }
  8488. MMailWindowMutex.unlock();
  8489. }
  8490. safe_delete(packet);
  8491. }
  8492. }
  8493. void Client::DeleteMail(int32 mail_id, bool from_database) {
  8494. player->DeleteMail(mail_id, from_database);
  8495. }
  8496. bool Client::AddMailItem(Item* item)
  8497. {
  8498. if(item && (item->CheckFlag(LORE) || item->CheckFlag(STACK_LORE))) {
  8499. Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "Lore items cannot be mailed.");
  8500. return false;
  8501. }
  8502. bool ret = false;
  8503. if (GetMailTransaction()) {
  8504. MMailWindowMutex.lock();
  8505. if(mail_window.char_item_id == 0)
  8506. {
  8507. mail_window.item = item;
  8508. mail_window.char_item_id = item->details.item_id;
  8509. mail_window.stack = item->details.count;
  8510. ret = true;
  8511. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8512. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8513. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8514. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8515. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8516. if(item)
  8517. {
  8518. packet->setDataByName("stack", mail_window.stack);
  8519. item->stack_count = mail_window.stack;
  8520. if (version < 860)
  8521. packet->setItemByName("item", item, player, 0, version <= 373 ? -2 : -1);
  8522. else if (version < 1193)
  8523. packet->setItemByName("item", item, player, 0, 0);
  8524. else
  8525. packet->setItemByName("item", item, player, 0, 2);
  8526. }
  8527. else
  8528. {
  8529. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8530. packet->setDataByName("end_tag3", 0xFF);
  8531. }
  8532. QueuePacket(packet->serialize());
  8533. }
  8534. MMailWindowMutex.unlock();
  8535. }
  8536. return ret;
  8537. }
  8538. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  8539. bool ret = false;
  8540. if (GetMailTransaction()) {
  8541. MMailWindowMutex.lock();
  8542. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8543. if (packet) {
  8544. if (copper > 0) {
  8545. if (player->RemoveCoins(copper)) {
  8546. mail_window.coin_copper += copper;
  8547. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  8548. ret = true;
  8549. }
  8550. }
  8551. else if (silver > 0) {
  8552. if (player->RemoveCoins(silver * 100)) {
  8553. mail_window.coin_silver += silver;
  8554. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  8555. ret = true;
  8556. }
  8557. }
  8558. else if (gold > 0) {
  8559. if (player->RemoveCoins(gold * 10000)) {
  8560. mail_window.coin_gold += gold;
  8561. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  8562. ret = true;
  8563. }
  8564. }
  8565. else if (plat > 0) {
  8566. if (player->RemoveCoins(plat * 1000000)) {
  8567. mail_window.coin_plat += plat;
  8568. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  8569. ret = true;
  8570. }
  8571. }
  8572. if (ret) {
  8573. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8574. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8575. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8576. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8577. Item* item = master_item_list.GetItem(mail_window.char_item_id);
  8578. if(item)
  8579. {
  8580. packet->setDataByName("stack", mail_window.stack);
  8581. item->stack_count = mail_window.stack;
  8582. if (version < 860)
  8583. packet->setItemByName("item", item, player, 0, version <= 373 ? -2 : -1);
  8584. else if (version < 1193)
  8585. packet->setItemByName("item", item, player, 0, 0);
  8586. else
  8587. packet->setItemByName("item", item, player, 0, 2);
  8588. }
  8589. else
  8590. {
  8591. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8592. packet->setDataByName("end_tag3", 0xFF);
  8593. }
  8594. //packet->PrintPacket();
  8595. QueuePacket(packet->serialize());
  8596. }
  8597. else
  8598. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  8599. safe_delete(packet);
  8600. }
  8601. MMailWindowMutex.unlock();
  8602. }
  8603. else
  8604. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8605. return ret;
  8606. }
  8607. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  8608. bool ret = false;
  8609. if (GetMailTransaction()) {
  8610. MMailWindowMutex.lock();
  8611. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8612. if (packet) {
  8613. if (copper > 0) {
  8614. player->AddCoins(copper);
  8615. mail_window.coin_copper -= copper;
  8616. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  8617. ret = true;
  8618. }
  8619. else if (silver > 0) {
  8620. player->AddCoins(silver * 100);
  8621. mail_window.coin_silver -= silver;
  8622. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  8623. ret = true;
  8624. }
  8625. else if (gold > 0) {
  8626. player->AddCoins(gold * 10000);
  8627. mail_window.coin_gold -= gold;
  8628. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  8629. ret = true;
  8630. }
  8631. else if (plat > 0) {
  8632. player->AddCoins(plat * 1000000);
  8633. mail_window.coin_plat -= plat;
  8634. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  8635. ret = true;
  8636. }
  8637. if (ret) {
  8638. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8639. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8640. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8641. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8642. packet->setDataByName("stack", 0);
  8643. packet->setDataByName("packettype", 0x2BFE);
  8644. packet->setDataByName("packetsubtype", 0xFF);
  8645. packet->setDataByName("unknown2", 0);
  8646. QueuePacket(packet->serialize());
  8647. }
  8648. safe_delete(packet);
  8649. }
  8650. MMailWindowMutex.unlock();
  8651. }
  8652. else
  8653. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8654. return ret;
  8655. }
  8656. void Client::TakeMailAttachments(int32 mail_id) {
  8657. if (GetMailTransaction()) {
  8658. Mail* mail = player->GetMail(mail_id);
  8659. if (mail) {
  8660. int64 amount = 0;
  8661. if (mail->coin_copper > 0) {
  8662. amount += mail->coin_copper;
  8663. mail->coin_copper = 0;
  8664. }
  8665. if (mail->coin_silver > 0) {
  8666. amount += mail->coin_silver * 100;
  8667. mail->coin_silver = 0;
  8668. }
  8669. if (mail->coin_gold > 0) {
  8670. amount += mail->coin_gold * 10000;
  8671. mail->coin_gold = 0;
  8672. }
  8673. if (mail->coin_plat > 0) {
  8674. amount += mail->coin_plat * 1000000;
  8675. mail->coin_plat = 0;
  8676. }
  8677. if (mail->char_item_id > 0) {
  8678. AddItem(mail->char_item_id, mail->stack);
  8679. mail->char_item_id = 0;
  8680. mail->stack = 0;
  8681. }
  8682. /* 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
  8683. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  8684. find it in any packet logs.*/
  8685. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8686. if (packet) {
  8687. packet->setDataByName("unknown", 0x03);
  8688. packet->setDataByName("coin_copper", mail->coin_copper);
  8689. packet->setDataByName("coin_silver", mail->coin_silver);
  8690. packet->setDataByName("coin_gold", mail->coin_gold);
  8691. packet->setDataByName("coin_plat", mail->coin_plat);
  8692. packet->setDataByName("stack", 0);
  8693. packet->setDataByName("packettype", 0x2BFE);
  8694. packet->setDataByName("packetsubtype", 0xFF);
  8695. packet->setDataByName("unknown2", 0);
  8696. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  8697. DumpPacket(packet->serialize());
  8698. QueuePacket(packet->serialize());
  8699. safe_delete(packet);
  8700. }*/
  8701. database.SavePlayerMail(mail);
  8702. if (amount > 0)
  8703. player->AddCoins(amount);
  8704. SendMailList();
  8705. }
  8706. }
  8707. else
  8708. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8709. }
  8710. void Client::ResetSendMail(bool cancel, bool needslock) {
  8711. if(cancel && mail_transaction)
  8712. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  8713. if(needslock)
  8714. MMailWindowMutex.lock();
  8715. if(cancel)
  8716. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  8717. if(!cancel)
  8718. mail_transaction = 0;
  8719. mail_window.coin_copper = 0;
  8720. mail_window.coin_silver = 0;
  8721. mail_window.coin_gold = 0;
  8722. mail_window.coin_plat = 0;
  8723. mail_window.char_item_id = 0;
  8724. mail_window.stack = 0;
  8725. if(mail_window.item){
  8726. if(cancel)
  8727. AddItem(mail_window.item);
  8728. else
  8729. safe_delete(mail_window.item);
  8730. }
  8731. mail_window.item = nullptr;
  8732. if(needslock)
  8733. MMailWindowMutex.unlock();
  8734. }
  8735. bool Client::GateAllowed() {
  8736. ZoneServer* zone = GetCurrentZone();
  8737. if (zone){
  8738. bool cangate = zone->GetCanGate();
  8739. return cangate;
  8740. }
  8741. return false;
  8742. }
  8743. bool Client::BindAllowed() {
  8744. ZoneServer* zone = GetCurrentZone();
  8745. if (zone){
  8746. bool canbind = zone->GetCanBind();
  8747. return canbind;
  8748. }
  8749. return false;
  8750. }
  8751. bool Client::Bind() {
  8752. int canbind = BindAllowed();
  8753. if(canbind == 0) {
  8754. Message(CHANNEL_MERCHANT, "You cannot bind at this location.");
  8755. return false;
  8756. }
  8757. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  8758. player->GetPlayerInfo()->SetBindX(player->GetX());
  8759. player->GetPlayerInfo()->SetBindY(player->GetY());
  8760. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  8761. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  8762. Message(CHANNEL_MERCHANT, "Your spirit has been bound to this location.");
  8763. return true;
  8764. }
  8765. bool Client::Gate(bool is_spell) {
  8766. if (player->GetPlayerInfo()->GetBindZoneID() == 0) {
  8767. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells. You have no bind location set.");
  8768. return false;
  8769. }
  8770. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  8771. if (zone) {
  8772. int cangate = GateAllowed();
  8773. if(cangate == 0) {
  8774. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells in this zone.");
  8775. return false;
  8776. }
  8777. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  8778. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  8779. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  8780. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  8781. Zone(zone, false, is_spell);
  8782. return true;
  8783. }
  8784. return false;
  8785. }
  8786. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id, bool is_spell) {
  8787. if (!destinations || !spawn) {
  8788. return;
  8789. }
  8790. bool has_map = false;
  8791. if (transport_id > 0)
  8792. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  8793. transport_spawn = spawn;
  8794. vector<TransportDestination*> transport_list;
  8795. vector<TransportDestination*>::iterator itr;
  8796. TransportDestination* destination = 0;
  8797. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  8798. destination = *itr;
  8799. 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)))
  8800. transport_list.push_back(destination);
  8801. }
  8802. if (transport_list.size() == 0 && destination) {
  8803. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  8804. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  8805. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  8806. else
  8807. {
  8808. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  8809. if (app)
  8810. QueuePacket(app);
  8811. }
  8812. }
  8813. else {
  8814. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  8815. // determine if this is an instanced zone that already exists
  8816. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  8817. if (instance_zone || new_zone) {
  8818. GetPlayer()->SetX(destination->destination_x);
  8819. GetPlayer()->SetY(destination->destination_y);
  8820. GetPlayer()->SetZ(destination->destination_z);
  8821. GetPlayer()->SetHeading(destination->destination_heading);
  8822. if (instance_zone)
  8823. Zone(instance_zone->GetInstanceID(), false, true, is_spell);
  8824. else
  8825. Zone(new_zone, false, is_spell);
  8826. }
  8827. }
  8828. if (destination->message.length() > 0)
  8829. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  8830. }
  8831. else if (transport_list.size() > 0) {
  8832. if (!spawn->IsSoundsDisabled())
  8833. PlaySound("mariner_bell");
  8834. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  8835. if (packet) {
  8836. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  8837. // Put all the destinations the player can go in a new vector
  8838. vector<TransportDestination*> destinations;
  8839. for (int32 i = 0; i < transport_list.size(); i++) {
  8840. destination = transport_list.at(i);
  8841. // Check min level
  8842. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  8843. continue;
  8844. // Check max level
  8845. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  8846. continue;
  8847. // Check quest complete
  8848. if (destination->req_quest_complete > 0 && GetPlayer()->HasQuestBeenCompleted(destination->req_quest_complete) == 0)
  8849. continue;
  8850. // Check req quest and step
  8851. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  8852. continue;
  8853. // 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
  8854. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  8855. packet->setDataByName("current_zone", destination->display_name.c_str());
  8856. packet->setDataByName("current_map_x", destination->map_x);
  8857. packet->setDataByName("current_map_y", destination->map_y);
  8858. }
  8859. else {
  8860. destinations.push_back(destination);
  8861. }
  8862. }
  8863. // Use the new vector to create the packet
  8864. destination = 0;
  8865. packet->setArrayLengthByName("num_destinations", destinations.size());
  8866. for (int32 i = 0; i < destinations.size(); i++) {
  8867. destination = destinations.at(i);
  8868. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  8869. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  8870. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  8871. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  8872. packet->setArrayDataByName("cost", destination->cost, i);
  8873. if (has_map) {
  8874. packet->setArrayDataByName("map_x", destination->map_x, i);
  8875. packet->setArrayDataByName("map_y", destination->map_y, i);
  8876. }
  8877. }
  8878. if (has_map)
  8879. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  8880. EQ2Packet* app = packet->serialize();
  8881. //DumpPacket(app);
  8882. if (destinations.size() > 0)
  8883. QueuePacket(app);
  8884. safe_delete(packet);
  8885. }
  8886. }
  8887. }
  8888. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  8889. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  8890. if (packet) {
  8891. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  8892. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  8893. int32 unique_id = packet->getType_int32_ByName("unique_id");
  8894. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  8895. int32 cost = packet->getType_int32_ByName("cost");
  8896. vector<TransportDestination*> destinations;
  8897. TransportDestination* destination = 0;
  8898. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  8899. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  8900. vector<TransportDestination*>::iterator itr;
  8901. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  8902. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  8903. destination = *itr;
  8904. break;
  8905. }
  8906. }
  8907. SetTemporaryTransportID(0);
  8908. if (!destination)
  8909. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  8910. else {
  8911. if (cost == 0 || player->RemoveCoins(cost)) {
  8912. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  8913. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  8914. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  8915. else
  8916. {
  8917. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  8918. if (outapp)
  8919. QueuePacket(outapp);
  8920. }
  8921. }
  8922. else {
  8923. GetPlayer()->SetX(destination->destination_x);
  8924. GetPlayer()->SetY(destination->destination_y);
  8925. GetPlayer()->SetZ(destination->destination_z);
  8926. GetPlayer()->SetHeading(destination->destination_heading);
  8927. // Test if where we're going is an Instanced zone
  8928. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  8929. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  8930. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  8931. Zone(new_zone, false);
  8932. }
  8933. }
  8934. if (destination->message.length() > 0)
  8935. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  8936. }
  8937. else
  8938. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  8939. }
  8940. }
  8941. safe_delete(packet);
  8942. }
  8943. }
  8944. void Client::SendNewSpells(int8 class_id) {
  8945. if (class_id > 0) {
  8946. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  8947. AddSendNewSpells(spells);
  8948. safe_delete(spells);
  8949. }
  8950. }
  8951. void Client::SendNewTSSpells(int8 class_id) {
  8952. if (class_id > 0) {
  8953. vector<Spell*>* spells = master_spell_list.GetSpellListByTradeskillClass(class_id, player->GetLevel(), 1);
  8954. AddSendNewSpells(spells);
  8955. safe_delete(spells);
  8956. }
  8957. }
  8958. void Client::AddSendNewSpells(vector<Spell*>* spells) {
  8959. Spell* spell = 0;
  8960. bool send_updates = false;
  8961. vector<Spell*>::iterator itr;
  8962. for (itr = spells->begin(); itr != spells->end(); itr++) {
  8963. spell = *itr;
  8964. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  8965. send_updates = true;
  8966. SendSpellUpdate(spell);
  8967. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  8968. player->UnlockSpell(spell);
  8969. }
  8970. }
  8971. if (send_updates) {
  8972. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  8973. if (outapp)
  8974. QueuePacket(outapp);
  8975. }
  8976. }
  8977. void Client::SetItemSearch(vector<Item*>* items) {
  8978. if (items) {
  8979. safe_delete(search_items);
  8980. search_items = items;
  8981. }
  8982. }
  8983. vector<Item*>* Client::GetSearchItems() {
  8984. return search_items;
  8985. }
  8986. void Client::SearchStore(int32 page) {
  8987. if (search_items) {
  8988. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  8989. if (packet) {
  8990. int32 x = page * 8;
  8991. if (search_items->size() > 8) {
  8992. if ((search_items->size() - x) > 8)
  8993. packet->setArrayLengthByName("num_items", 8);
  8994. else
  8995. packet->setArrayLengthByName("num_items", search_items->size() - x);
  8996. }
  8997. else
  8998. packet->setArrayLengthByName("num_items", search_items->size());
  8999. if (search_items->size() > 0) {
  9000. packet->setArrayLengthByName("num_sellers", 1);
  9001. packet->setArrayDataByName("seller_seller_id", 1);
  9002. packet->setDataByName("per_page", 8);
  9003. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  9004. packet->setDataByName("page", page);
  9005. Item* item = 0;
  9006. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  9007. for (int32 i = 0; i < limit; i++, x++) {
  9008. if (x >= search_items->size())
  9009. break;
  9010. item = search_items->at(x);
  9011. std::string teststr("test ");
  9012. teststr.append(std::to_string(i));
  9013. packet->setArrayDataByName("string_one", teststr.c_str(), i);
  9014. packet->setArrayDataByName("string_two", "testtwo", i);
  9015. packet->setArrayDataByName("seller_name", "EQ2EMuDev", i);
  9016. packet->setArrayDataByName("item_id", item->details.item_id, i);
  9017. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  9018. packet->setArrayDataByName("icon", item->GetIcon(GetVersion()), i);
  9019. //packet->setArrayDataByName("unknown2b", i, i);
  9020. packet->setArrayDataByName("item_seller_id", 1, i);
  9021. if (item->stack_count == 0)
  9022. packet->setArrayDataByName("quantity", 1, i);
  9023. else
  9024. packet->setArrayDataByName("quantity", item->stack_count, i);
  9025. packet->setArrayDataByName("stack_size", item->stack_count, i);
  9026. packet->setArrayDataByName("sell_price", item->sell_price, i);
  9027. std::string tmpStr("");
  9028. tmpStr.append(item->name.c_str());
  9029. tmpStr.append(" (");
  9030. tmpStr.append(std::to_string(item->details.item_id));
  9031. tmpStr.append(")");
  9032. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  9033. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  9034. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  9035. }
  9036. }
  9037. EQ2Packet* outapp = packet->serialize();
  9038. //DumpPacket(outapp);
  9039. QueuePacket(outapp);
  9040. safe_delete(packet);
  9041. }
  9042. }
  9043. }
  9044. void Client::SetReadyForUpdates() {
  9045. if (!ready_for_updates) {
  9046. database.loadCharacterProperties(this);
  9047. SendDefaultGroupOptions();
  9048. }
  9049. ready_for_updates = true;
  9050. if(GetVersion() <= 561) {
  9051. SendRecipeList();
  9052. }
  9053. }
  9054. void Client::SetReadyForSpawns(bool val) {
  9055. ready_for_spawns = val;
  9056. if (GetPlayer()->GetActivityStatus() > 0) {
  9057. GetPlayer()->SetActivityStatus(0);
  9058. if (GetPlayer()->GetGroupMemberInfo()) {
  9059. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  9060. }
  9061. }
  9062. GetPlayer()->SetActiveReward(false);
  9063. zone_list.CheckFriendZoned(this);
  9064. }
  9065. void Client::SendChatRelationship(int8 type, const char* name) {
  9066. if (!name) {
  9067. return;
  9068. }
  9069. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  9070. if (packet) {
  9071. packet->setDataByName("account_id", GetAccountID());
  9072. packet->setDataByName("type", type);
  9073. packet->setArrayLengthByName("num_names", 1);
  9074. packet->setArrayDataByName("name", name);
  9075. if (type == 0) {
  9076. Client* client = zone_list.GetClientByCharName(name);
  9077. if (client) {
  9078. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  9079. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  9080. }
  9081. }
  9082. QueuePacket(packet->serialize());
  9083. safe_delete(packet);
  9084. }
  9085. }
  9086. void Client::SendFriendList() {
  9087. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  9088. if (packet) {
  9089. packet->setDataByName("account_id", GetAccountID());
  9090. map<string, int8>::iterator itr;
  9091. map<string, int8>* friends = player->GetFriends();
  9092. if (friends && friends->size() > 0) {
  9093. Client* client = 0;
  9094. vector<string> names;
  9095. for (itr = friends->begin(); itr != friends->end(); itr++) {
  9096. if (itr->second == 2)
  9097. continue;
  9098. names.push_back(itr->first);
  9099. }
  9100. packet->setArrayLengthByName("num_names", names.size());
  9101. for (int32 i = 0; i < names.size(); i++) {
  9102. client = zone_list.GetClientByCharName(names[i]);
  9103. packet->setArrayDataByName("name", names[i].c_str(), i);
  9104. if (client) {
  9105. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  9106. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  9107. }
  9108. }
  9109. }
  9110. QueuePacket(packet->serialize());
  9111. safe_delete(packet);
  9112. }
  9113. }
  9114. void Client::SendIgnoreList() {
  9115. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  9116. if (packet) {
  9117. packet->setDataByName("account_id", GetAccountID());
  9118. packet->setDataByName("type", 2);
  9119. map<string, int8>::iterator itr;
  9120. map<string, int8>* ignored = player->GetIgnoredPlayers();
  9121. if (ignored && ignored->size() > 0) {
  9122. vector<string> names;
  9123. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  9124. if (itr->second == 2)
  9125. continue;
  9126. names.push_back(itr->first);
  9127. }
  9128. packet->setArrayLengthByName("num_names", names.size());
  9129. for (int32 i = 0; i < names.size(); i++)
  9130. packet->setArrayDataByName("name", names[i].c_str(), i);
  9131. }
  9132. QueuePacket(packet->serialize());
  9133. safe_delete(packet);
  9134. }
  9135. }
  9136. void Client::AddWaypoint(string name, int8 type) {
  9137. waypoint_id++;
  9138. WaypointInfo info;
  9139. info.id = waypoint_id;
  9140. info.type = type;
  9141. waypoints[name] = info;
  9142. }
  9143. void Client::SendWaypoints() {
  9144. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  9145. if (packet) {
  9146. packet->setArrayLengthByName("num_updates", waypoints.size());
  9147. map<string, WaypointInfo>::iterator itr;
  9148. int16 i = 0;
  9149. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  9150. packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
  9151. packet->setArrayDataByName("waypoint_category", itr->second.type, i);
  9152. packet->setArrayDataByName("spawn_id", itr->second.id, i);
  9153. i++;
  9154. }
  9155. packet->setDataByName("unknown", 0xFFFFFFFF);
  9156. QueuePacket(packet->serialize());
  9157. safe_delete(packet);
  9158. }
  9159. }
  9160. void Client::SelectWaypoint(int32 id) {
  9161. string found_name = "";
  9162. map<string, WaypointInfo>::iterator itr;
  9163. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  9164. if (itr->second.id == id) {
  9165. found_name = itr->first;
  9166. break;
  9167. }
  9168. }
  9169. if (found_name.length() > 0) {
  9170. Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
  9171. ShowPathToTarget(spawn);
  9172. }
  9173. }
  9174. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  9175. if (waypoint_name) {
  9176. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  9177. if (packet) {
  9178. packet->setArrayLengthByName("num_updates", 1);
  9179. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  9180. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  9181. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  9182. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  9183. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  9184. packet->setDataByName("unknown", 0xFFFFFFFF);
  9185. QueuePacket(packet->serialize());
  9186. safe_delete(packet);
  9187. }
  9188. }
  9189. }
  9190. void Client::ClearWaypoint() {
  9191. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  9192. if (packet) {
  9193. QueuePacket(packet->serialize());
  9194. safe_delete(packet);
  9195. }
  9196. }
  9197. bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
  9198. if (current_zone->pathing) {
  9199. if (GetPlayer()->GetMap()) {
  9200. if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
  9201. return false;
  9202. if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
  9203. return false;
  9204. auto loc = glm::vec3(x, z, y);
  9205. float new_z = GetPlayer()->FindBestZ(loc, nullptr);
  9206. if (new_z != BEST_Z_INVALID) //this is actually y
  9207. y = new_z;
  9208. }
  9209. bool partial = false;
  9210. bool stuck = false;
  9211. PathfinderOptions opts;
  9212. opts.smooth_path = true;
  9213. opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
  9214. opts.offset = y_offset + 1.0f;
  9215. opts.flags = PathingNotDisabled ^ PathingZoneLine;
  9216. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  9217. if (packet) {
  9218. auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
  9219. packet->setArrayLengthByName("num_points", path.size());
  9220. int i = 0;
  9221. for (auto& node : path)
  9222. {
  9223. packet->setArrayDataByName("x", node.pos.x, i);
  9224. packet->setArrayDataByName("y", node.pos.z, i);
  9225. packet->setArrayDataByName("z", node.pos.y, i);
  9226. packet->setDataByName("waypoint_x", x);
  9227. packet->setDataByName("waypoint_y", y);
  9228. packet->setDataByName("waypoint_z", z);
  9229. i++;
  9230. }
  9231. if (i > 0)
  9232. QueuePacket(packet->serialize());
  9233. safe_delete(packet);
  9234. return (i > 0);
  9235. }
  9236. }
  9237. return false;
  9238. }
  9239. bool Client::ShowPathToTarget(Spawn* spawn) {
  9240. if (spawn) {
  9241. return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
  9242. }
  9243. return false;
  9244. }
  9245. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  9246. if (waypoint_name) {
  9247. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  9248. if (packet) {
  9249. packet->setArrayLengthByName("num_points", 1);
  9250. packet->setArrayDataByName("x", x, 0);
  9251. packet->setArrayDataByName("y", y, 0);
  9252. packet->setArrayDataByName("z", z, 0);
  9253. packet->setDataByName("waypoint_x", x);
  9254. packet->setDataByName("waypoint_y", y);
  9255. packet->setDataByName("waypoint_z", z);
  9256. packet->setDataByName("waypoint_name", waypoint_name);
  9257. packet->setDataByName("unknown", 0);
  9258. QueuePacket(packet->serialize());
  9259. safe_delete(packet);
  9260. }
  9261. }
  9262. }
  9263. void Client::InspectPlayer(Player* player_to_inspect) {
  9264. int source_pvp_alignment = GetPlayer()->GetPVPAlignment();
  9265. int target_pvp_alignment = player_to_inspect->GetPVPAlignment();
  9266. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  9267. if(pvp_allowed == true){
  9268. if(source_pvp_alignment != target_pvp_alignment){
  9269. Message(CHANNEL_COLOR_RED, "You can not inspect players of different alignments.");
  9270. return;
  9271. }
  9272. }
  9273. if (player_to_inspect && player_to_inspect->GetClient()) {
  9274. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  9275. if (packet) {
  9276. packet->setDataByName("unknown", 0);
  9277. packet->setSmallStringByName("name", player_to_inspect->GetName());
  9278. packet->setDataByName("race", player_to_inspect->GetRace());
  9279. packet->setDataByName("gender", player_to_inspect->GetGender());
  9280. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  9281. int16 effective_level = player_to_inspect->GetInfoStruct()->get_effective_level() != 0 ? player_to_inspect->GetInfoStruct()->get_effective_level() : player_to_inspect->GetLevel();
  9282. packet->setDataByName("adventure_level_effective", effective_level);
  9283. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  9284. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  9285. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  9286. packet->setDataByName("health", player_to_inspect->GetHP());
  9287. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  9288. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  9289. packet->setDataByName("power", player_to_inspect->GetPower());
  9290. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  9291. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  9292. packet->setDataByName("mitigation", player_to_inspect->GetInfoStruct()->get_cur_mitigation());
  9293. packet->setDataByName("unknown1", 0);
  9294. packet->setDataByName("avoidance", player_to_inspect->GetInfoStruct()->get_avoidance_display()*10.0f);
  9295. packet->setDataByName("unknown2", 0);
  9296. packet->setDataByName("mitigation_percentage", 0);
  9297. packet->setDataByName("strength", player_to_inspect->GetStr());
  9298. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  9299. packet->setDataByName("stamina", player_to_inspect->GetSta());
  9300. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  9301. packet->setDataByName("agility", player_to_inspect->GetAgi());
  9302. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  9303. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  9304. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  9305. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  9306. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  9307. packet->setDataByName("unknown4", 0);
  9308. packet->setDataByName("unknown5", 0);
  9309. packet->setDataByName("unknown6", 0);
  9310. packet->setDataByName("unknown7", 0);
  9311. packet->setDataByName("unknown8", 0);
  9312. packet->setDataByName("unknown9", 0);
  9313. packet->setDataByName("unknown10", 0);
  9314. packet->setDataByName("unknown11", 0);
  9315. packet->setDataByName("unknown12", 0);
  9316. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  9317. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  9318. packet->setDataByName("heat_resist_percentage", 0);
  9319. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  9320. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  9321. packet->setDataByName("cold_resist_percentage", 0);
  9322. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  9323. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  9324. packet->setDataByName("magic_resist_percentage", 0);
  9325. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  9326. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  9327. packet->setDataByName("mental_resist_percentage", 0);
  9328. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  9329. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  9330. packet->setDataByName("divine_resist_percentage", 0);
  9331. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  9332. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  9333. packet->setDataByName("disease_resist_percentage", 0);
  9334. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  9335. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  9336. packet->setDataByName("poison_resist_percentage", 0);
  9337. packet->setArrayLengthByName("num_chars", 0x01FF);
  9338. string biography = player_to_inspect->GetBiography();
  9339. for (size_t i = 0; i < biography.length(); i++)
  9340. packet->setArrayDataByName("biography_char", biography[i], i);
  9341. if(GetVersion() <= 373) {
  9342. for(int32 s=0;s<20;s++) {
  9343. int32 slot = s;
  9344. char item_slot_name[64], item_slot_name_appearance[64];
  9345. _snprintf(item_slot_name,64,"slot_%u",slot);
  9346. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, GetVersion()));
  9347. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 7, true, true, true);
  9348. }
  9349. }
  9350. else if(GetVersion() <= 561) {
  9351. for(int32 s=0;s<22;s++) {
  9352. int32 slot = s;
  9353. char item_slot_name[64], item_slot_name_appearance[64];
  9354. _snprintf(item_slot_name,64,"slot_%u",slot);
  9355. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, GetVersion()));
  9356. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 5, true, true);
  9357. }
  9358. }
  9359. else {
  9360. for(int32 s=0;s<NUM_SLOTS;s++) {
  9361. int32 slot = s*2;
  9362. char item_slot_name[64], item_slot_name_appearance[64];
  9363. _snprintf(item_slot_name,64,"slot_%u",slot);
  9364. int32 slot_appearance = (s*2)+1;
  9365. _snprintf(item_slot_name_appearance,64,"slot_%u",slot_appearance);
  9366. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, player_to_inspect->GetClient()->GetVersion()));
  9367. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 13, false, true);
  9368. if(s <= EQ2_FEET_SLOT || s == EQ2_RANGE_SLOT || s == EQ2_CLOAK_SLOT) {
  9369. pw = player_to_inspect->GetAppearanceEquipmentList()->GetItem(s);
  9370. packet->setItemByName(item_slot_name_appearance, pw, this->GetPlayer(), 0, 13, false, true);
  9371. }
  9372. else {
  9373. packet->setItemByName(item_slot_name_appearance, nullptr, this->GetPlayer(), 0, 13, false, true);
  9374. }
  9375. }
  9376. }
  9377. QueuePacket(packet->serialize());
  9378. safe_delete(packet);
  9379. }
  9380. }
  9381. }
  9382. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  9383. pending_guild_invite.guild = guild;
  9384. pending_guild_invite.invited_by = invited_by;
  9385. }
  9386. void Client::ShowClaimWindow() {
  9387. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  9388. if (packet) {
  9389. int16 loaded = database.CountCharClaimItems(GetCharacterID());
  9390. vector<ClaimItems> claim = database.LoadCharacterClaimItems(GetCharacterID());
  9391. int32 account_age = database.GetAccountAge(GetAccountID());
  9392. //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.
  9393. if (loaded == 0 || claim.empty()) {
  9394. Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
  9395. return;
  9396. }
  9397. packet->setArrayLengthByName("num_claim_items", loaded);
  9398. int j = 0; //use this to track skipped vet items.
  9399. for (int i = 0; i < claim.size(); i++)
  9400. {
  9401. if (j == claim.size()) {
  9402. Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
  9403. return;
  9404. }
  9405. Item* item = master_item_list.GetItem(claim[i].item_id);
  9406. int16 claimed = 0;
  9407. if (claim[i].curr_claim < claim[i].max_claim) {
  9408. claimed = claim[i].max_claim - claim[i].curr_claim;
  9409. }
  9410. else {
  9411. claimed = 0;
  9412. }
  9413. //dont display vet rewards until they reach the age required
  9414. if (account_age < claim[i].vet_reward_time) {
  9415. j++;
  9416. continue;
  9417. }
  9418. packet->setArrayDataByName("id", i, i);
  9419. packet->setArrayDataByName("not_yet_claimed", 1, i);
  9420. packet->setArrayDataByName("num_remaining", claim[i].curr_claim, i);
  9421. packet->setArrayDataByName("one_per_character", claim[i].one_per_char, i);
  9422. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  9423. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  9424. packet->setArrayDataByName("text", "If you ever see this text, let a developer know!", i); //I've not seen this!
  9425. //packet->setArrayDataByName("category", "Scott's Shit", i); //devn00b: not using so commenting out, leaving in case we ever do implement categories.
  9426. packet->setArrayDataByName("icon", item->GetIcon(GetVersion()), i);
  9427. packet->setArrayDataByName("item_id", item->details.item_id, i);
  9428. j++;
  9429. }
  9430. }
  9431. packet->setDataByName("unknown3", 1);
  9432. QueuePacket(packet->serialize());
  9433. safe_delete(packet);
  9434. }
  9435. void Client::ShowGuildSearchWindow() {
  9436. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  9437. if (packet) {
  9438. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  9439. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  9440. packet->setArrayLengthByName("num_guilds", guilds->size());
  9441. int32 i = 0;
  9442. while (itr.Next()) {
  9443. Guild* guild = itr.second;
  9444. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  9445. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  9446. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  9447. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  9448. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  9449. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  9450. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  9451. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  9452. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  9453. packet->setArrayDataByName("unknown7", 0x02, i);
  9454. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  9455. i++;
  9456. }
  9457. QueuePacket(packet->serialize());
  9458. safe_delete(packet);
  9459. }
  9460. }
  9461. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  9462. PacketStruct* packet;
  9463. vector<int8>* slot_data;
  9464. vector<int8>::iterator itr;
  9465. int32 slots = 0;
  9466. assert(item);
  9467. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  9468. return;
  9469. }
  9470. slot_data = &item->slot_data;
  9471. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  9472. if (version >= 1188)
  9473. slots = *itr;
  9474. else
  9475. slots += (int8)pow(2.0, *itr);
  9476. }
  9477. packet->setDataByName("slot", slots);
  9478. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  9479. if (slots == 2) {
  9480. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  9481. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  9482. }
  9483. else {
  9484. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  9485. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  9486. }
  9487. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  9488. if (slots == 4) {
  9489. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  9490. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  9491. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  9492. }
  9493. else if (slots == 7) {
  9494. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  9495. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  9496. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  9497. }
  9498. else {
  9499. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  9500. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  9501. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  9502. }
  9503. packet->setDataByName("icon", item->GetIcon(GetVersion()));
  9504. packet->setDataByName("item_id", item->details.item_id);
  9505. packet->setDataByName("item_crc", crc);
  9506. packet->setDataByName("unknown2", 0xFFFFFFFF);
  9507. packet->setDataByName("unknown4", 0xFFFFFFFF);
  9508. packet->setDataByName("unknown5", 0xFF, 9);
  9509. packet->setDataByName("unknown5", 0xFF, 10);
  9510. QueuePacket(packet->serialize());
  9511. safe_delete(packet);
  9512. }
  9513. void Client::SendCollectionList() {
  9514. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  9515. map<int32, Collection*>::iterator itr;
  9516. vector<struct CollectionItem*>* collection_items;
  9517. Collection* collection;
  9518. struct CollectionItem* collection_item;
  9519. PacketStruct* packet = 0;
  9520. int16 i = 0, j;
  9521. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  9522. return;
  9523. packet->setArrayLengthByName("num_collections", collections->size());
  9524. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9525. collection = itr->second;
  9526. collection_items = collection->GetCollectionItems();
  9527. packet->setArrayDataByName("unknown", 1, i);
  9528. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  9529. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  9530. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  9531. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  9532. packet->setArrayDataByName("level", collection->GetLevel(), i);
  9533. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  9534. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  9535. for (j = 0; j < collection_items->size(); j++) {
  9536. collection_item = collection_items->at(j);
  9537. Item* item = master_item_list.GetItem(collection_item->item);
  9538. if (item) {
  9539. packet->setSubArrayDataByName("item_icon", item->GetIcon(GetVersion()), i, j);
  9540. if (version < 955)
  9541. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  9542. else
  9543. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  9544. }
  9545. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  9546. }
  9547. i++;
  9548. }
  9549. packet->setDataByName("new_collection_flag", 1);
  9550. QueuePacket(packet->serialize());
  9551. safe_delete(packet);
  9552. }
  9553. bool Client::SendCollectionsForItem(Item* item) {
  9554. map<int32, Collection*> collections_to_send;
  9555. map<int32, Collection*>* collections;
  9556. map<int32, Collection*>::iterator itr;
  9557. vector<struct CollectionItem*>* collection_items;
  9558. Collection* collection;
  9559. struct CollectionItem* collection_item;
  9560. PacketStruct* packet;
  9561. int16 i;
  9562. assert(item);
  9563. /* get any collections required by this item that the player already has */
  9564. collections = player->GetCollectionList()->GetCollections();
  9565. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9566. collection = itr->second;
  9567. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  9568. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  9569. collections_to_send[collection->GetID()] = collection;
  9570. }
  9571. }
  9572. /* get any collections required by this item that the player does not have and send it to the client */
  9573. collections = master_collection_list.GetCollections();
  9574. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9575. collection = itr->second;
  9576. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  9577. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  9578. return false;
  9579. }
  9580. packet->setArrayLengthByName("num_collections", 1);
  9581. packet->setArrayDataByName("unknown", 1, 0);
  9582. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  9583. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  9584. packet->setArrayDataByName("completed", 0, 0);
  9585. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  9586. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  9587. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  9588. packet->setArrayDataByName("unknown3", 0x28, 0);
  9589. collection_items = collection->GetCollectionItems();
  9590. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  9591. for (i = 0; i < collection_items->size(); i++) {
  9592. collection_item = collection_items->at(i);
  9593. Item* item2 = master_item_list.GetItem(collection_item->item);
  9594. if (item2) {
  9595. packet->setSubArrayDataByName("item_icon", item2->GetIcon(GetVersion()), 0, i);
  9596. if (version < 955)
  9597. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  9598. else
  9599. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  9600. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  9601. }
  9602. }
  9603. packet->setDataByName("new_collection_flag", 0);
  9604. QueuePacket(packet->serialize());
  9605. safe_delete(packet);
  9606. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  9607. collections_to_send[collection->GetID()] = collection;
  9608. }
  9609. }
  9610. /* send the client a list of collections that should be filtered for this item */
  9611. if (collections_to_send.size() > 0) {
  9612. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  9613. return false;
  9614. }
  9615. i = 0;
  9616. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  9617. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  9618. collection = itr->second;
  9619. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  9620. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  9621. i++;
  9622. }
  9623. packet->setDataByName("item_icon", item->GetIcon(GetVersion()));
  9624. packet->setDataByName("item_name", item->name.c_str());
  9625. packet->setDataByName("item_id", item->details.item_id);
  9626. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  9627. QueuePacket(packet->serialize());
  9628. safe_delete(packet);
  9629. }
  9630. return collections_to_send.size() > 0;
  9631. }
  9632. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  9633. Collection* collection;
  9634. struct CollectionItem* collection_item;
  9635. PacketStruct* packet;
  9636. char tmp[200] = { 0 };
  9637. assert(item);
  9638. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  9639. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  9640. /* get the item struct that represents the item for this collection */
  9641. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  9642. SendCollectionList();
  9643. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  9644. return;
  9645. }
  9646. /* sanity check */
  9647. if (collection_item->found) {
  9648. SendCollectionList();
  9649. 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());
  9650. return;
  9651. }
  9652. }
  9653. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  9654. collection = new Collection(collection);
  9655. /* get the item struct that represents the item for this collection */
  9656. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  9657. SendCollectionList();
  9658. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  9659. safe_delete(collection);
  9660. return;
  9661. }
  9662. /* add the new collection to the player's collection list */
  9663. if (!player->GetCollectionList()->AddCollection(collection)) {
  9664. SendCollectionList();
  9665. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  9666. safe_delete(collection);
  9667. return;
  9668. }
  9669. }
  9670. else {
  9671. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  9672. return;
  9673. }
  9674. collection_item->found = 1;
  9675. collection->SetSaveNeeded(true);
  9676. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  9677. SendCollectionList();
  9678. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  9679. return;
  9680. }
  9681. packet->setDataByName("collection_id", collection_id);
  9682. packet->setDataByName("collection_item_num", collection_item->index);
  9683. packet->setDataByName("add", 1);
  9684. QueuePacket(packet->serialize());
  9685. Item* item2 = master_item_list.GetItem(collection_item->item);
  9686. if (item2) {
  9687. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  9688. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  9689. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  9690. }
  9691. safe_delete(packet);
  9692. RemoveItem(item, 1);
  9693. SendCollectionList();
  9694. }
  9695. void Client::DisplayCollectionComplete(Collection* collection) {
  9696. vector<struct CollectionRewardItem*>* reward_items;
  9697. vector<struct CollectionRewardItem*>* selectable_reward_items;
  9698. struct CollectionRewardItem* reward_item;
  9699. PacketStruct* packet;
  9700. int32 i;
  9701. assert(collection);
  9702. reward_items = collection->GetRewardItems();
  9703. selectable_reward_items = collection->GetSelectableRewardItems();
  9704. if (GetVersion() <= 561) {
  9705. int32 source_id = collection->GetID();
  9706. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  9707. if (packet2) {
  9708. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  9709. packet2->setSubstructDataByName("reward_data", "reward", "Quest Reward!");
  9710. packet2->setSubstructDataByName("reward_data", "max_coin", collection->GetRewardCoin());
  9711. packet2->setSubstructDataByName("reward_data", "exp_bonus", collection->GetRewardXP());
  9712. if(reward_items){
  9713. int32 item_count = reward_items->size();
  9714. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
  9715. i = 0;
  9716. if(reward_items) {
  9717. for (i = 0; i < reward_items->size(); i++) {
  9718. Item* item = reward_items->at(i)->item;
  9719. if (item) {
  9720. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  9721. packet2->setItemArrayDataByName("item", item, player, i, 0, GetClientItemPacketOffset());
  9722. }
  9723. }
  9724. }
  9725. }
  9726. if (selectable_reward_items) {
  9727. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_reward_items->size());
  9728. for (i = 0; i < selectable_reward_items->size(); i++) {
  9729. Item* item = selectable_reward_items->at(i)->item;
  9730. if (item) {
  9731. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  9732. packet2->setItemArrayDataByName("select_item", item, player, i, 0, GetClientItemPacketOffset());
  9733. }
  9734. }
  9735. }
  9736. }
  9737. EQ2Packet* app = packet2->serialize();
  9738. QueuePacket(app);
  9739. safe_delete(packet2);
  9740. return;
  9741. }
  9742. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  9743. return;
  9744. }
  9745. packet->setDataByName("title", "Quest Reward!");
  9746. packet->setDataByName("name", collection->GetName());
  9747. packet->setDataByName("description", collection->GetCategory());
  9748. packet->setDataByName("level", collection->GetLevel());
  9749. packet->setDataByName("max_coin", collection->GetRewardCoin());
  9750. packet->setDataByName("min_coin", collection->GetRewardCoin());
  9751. //packet->setDataByName("status_points", quest->GetStatusPoints());
  9752. packet->setArrayLengthByName("num_rewards", reward_items->size());
  9753. for (i = 0; i < reward_items->size(); i++) {
  9754. reward_item = reward_items->at(i);
  9755. if(!reward_item->item)
  9756. {
  9757. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9758. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9759. continue;
  9760. }
  9761. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  9762. if (version < 860)
  9763. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, GetClientItemPacketOffset());
  9764. else if (version < 1193)
  9765. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  9766. else
  9767. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  9768. }
  9769. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  9770. for (i = 0; i < selectable_reward_items->size(); i++) {
  9771. reward_item = selectable_reward_items->at(i);
  9772. if(!reward_item->item)
  9773. {
  9774. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9775. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9776. continue;
  9777. }
  9778. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  9779. if (version < 860)
  9780. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, GetClientItemPacketOffset());
  9781. else if (version < 1193)
  9782. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  9783. else
  9784. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  9785. }
  9786. QueuePacket(packet->serialize());
  9787. safe_delete(packet);
  9788. }
  9789. void Client::HandInCollections() {
  9790. map<int32, Collection*>* collections;
  9791. map<int32, Collection*>::iterator itr;
  9792. Collection* collection;
  9793. /* only show 1 collection reward dialog at a time */
  9794. if (player->GetPendingCollectionReward()) {
  9795. return;
  9796. }
  9797. collections = player->GetCollectionList()->GetCollections();
  9798. /* 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
  9799. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  9800. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9801. collection = itr->second;
  9802. if (collection->GetIsReadyToTurnIn()) {
  9803. player->SetPendingCollectionReward(collection);
  9804. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  9805. QuestRewardData* data = new QuestRewardData;
  9806. data->quest_id = 0;
  9807. data->is_temporary = false;
  9808. data->description = std::string("");
  9809. data->is_collection = true;
  9810. data->has_displayed = false;
  9811. data->tmp_coin = 0;
  9812. data->tmp_status = 0;
  9813. data->db_saved = false;
  9814. data->db_index = 0;
  9815. quest_pending_reward.push_back(data);
  9816. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  9817. quest_updates = true;
  9818. break;
  9819. }
  9820. }
  9821. if(quest_updates) {
  9822. SaveQuestRewardData(true);
  9823. }
  9824. }
  9825. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  9826. vector<struct CollectionRewardItem*>* reward_items;
  9827. vector<struct CollectionRewardItem*>::iterator itr;
  9828. struct CollectionRewardItem* reward_item;
  9829. int16 num_slots_needed;
  9830. int16 num_slots;
  9831. assert(collection);
  9832. reward_items = collection->GetRewardItems();
  9833. num_slots_needed = (int16)reward_items->size();
  9834. if (selectable_item_id > 0)
  9835. num_slots_needed++;
  9836. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  9837. if (num_slots < num_slots_needed) {
  9838. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  9839. DisplayCollectionComplete(collection);
  9840. return;
  9841. }
  9842. /* add manditory items */
  9843. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  9844. reward_item = *itr;
  9845. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  9846. }
  9847. /* find and add the selectable item if there's one */
  9848. if (selectable_item_id > 0) {
  9849. reward_items = collection->GetSelectableRewardItems();
  9850. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  9851. reward_item = *itr;
  9852. if (reward_item->item->details.item_id == selectable_item_id) {
  9853. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  9854. break;
  9855. }
  9856. }
  9857. }
  9858. if (collection->GetRewardXP() > 0) {
  9859. player->AddXP((int32)collection->GetRewardXP());
  9860. }
  9861. if (collection->GetRewardCoin() > 0) {
  9862. player->AddCoins(collection->GetRewardCoin());
  9863. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  9864. }
  9865. collection->SetCompleted(true);
  9866. //update achievements for completeing collection here
  9867. collection->SetSaveNeeded(true);
  9868. SendCollectionList();
  9869. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  9870. player->SetPendingCollectionReward(0);
  9871. RemoveQueuedQuestReward();
  9872. GetPlayer()->SetActiveReward(false);
  9873. HandInCollections();
  9874. GetPlayer()->GetZone()->SendSubSpawnUpdates(SUBSPAWN_TYPES::COLLECTOR);
  9875. }
  9876. void Client::SendRecipeList() {
  9877. if(GetRecipeListSent()) {
  9878. return;
  9879. }
  9880. PacketStruct* packet = 0;
  9881. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  9882. map<int32, Recipe*>::iterator itr;
  9883. int16 i = 0;
  9884. Recipe* recipe;
  9885. if(version <= 561) {
  9886. PacketStruct* packet = 0;
  9887. if (!(packet = configReader.getStruct("WS_UpdateRecipeBook", GetVersion()))) {
  9888. return;
  9889. }
  9890. packet->setArrayLengthByName("recipe_count", recipes->size());
  9891. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9892. recipe = itr->second;
  9893. int32 recipe_id = recipe->GetID();
  9894. packet->setArrayDataByName("recipe_id", recipe_id, i);
  9895. packet->setArrayDataByName("recipe_data_crc", GetRecipeCRC(recipe), i);
  9896. packet->setArrayDataByName("unknown", 0x7005BE3, i); //0x7005BE3
  9897. i++;
  9898. }
  9899. EQ2Packet* ret = packet->serializeCountPacket(GetVersion(), 0, nullptr, nullptr);
  9900. QueuePacket(ret);
  9901. safe_delete(packet);
  9902. SetRecipeListSent(true);
  9903. return;
  9904. }
  9905. else if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  9906. return;
  9907. }
  9908. int8 level = player->GetTSLevel();
  9909. int index = 0;
  9910. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9911. recipe = itr->second;
  9912. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  9913. if (res != devices.end())
  9914. index = res - devices.begin();
  9915. else
  9916. devices.push_back(recipe->GetDevice());
  9917. }
  9918. packet->setDataByName("command_type", 0);
  9919. packet->setArrayLengthByName("num_recipes", recipes->size());
  9920. int stringsize = 0;
  9921. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9922. recipe = itr->second;
  9923. int32 myid = recipe->GetID();
  9924. int8 rlevel = recipe->GetLevel();
  9925. int8 even = level - level * .05 + .5;
  9926. int8 easymin = level - level * .25 + .5;
  9927. int8 veasymin = level - level * .35 + .5;
  9928. if (rlevel > level )
  9929. packet->setArrayDataByName("tier", 4, i);
  9930. else if ((rlevel <= level) & (rlevel >= even))
  9931. packet->setArrayDataByName("tier", 3, i);
  9932. else if ((rlevel <= even) & (rlevel >= easymin))
  9933. packet->setArrayDataByName("tier", 2, i);
  9934. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  9935. packet->setArrayDataByName("tier", 1, i);
  9936. else if ((rlevel <= veasymin) & (rlevel >= 0))
  9937. packet->setArrayDataByName("tier", 0, i);
  9938. if (rlevel == 2)
  9939. int xxx = 1;
  9940. packet->setArrayDataByName("recipe_id", myid, i);
  9941. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  9942. packet->setArrayDataByName("unknown1", recipe->GetLevel(), i);
  9943. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  9944. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  9945. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  9946. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  9947. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  9948. if (recipe_device != devices.end())
  9949. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), i);
  9950. else
  9951. {//TODO error should never get here
  9952. }
  9953. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  9954. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  9955. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  9956. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  9957. i++;
  9958. }
  9959. //packet->PrintPacket();
  9960. EQ2Packet* pack = packet->serialize();
  9961. QueuePacket(pack);
  9962. safe_delete(packet);
  9963. SetRecipeListSent(true);
  9964. }
  9965. void Client::ShowRecipeBook() {
  9966. PacketStruct* packet = 0;
  9967. Spawn* target = 0;
  9968. int index = 0;
  9969. if (!(target = player->GetTarget())) {
  9970. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  9971. return;
  9972. }
  9973. if (!target->IsObject() || !((Object*)target)->GetDeviceID()) {
  9974. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  9975. return;
  9976. }
  9977. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  9978. return;
  9979. }
  9980. packet->setDataByName("device", target->GetName());
  9981. packet->setDataByName("unknown1", 1);
  9982. auto res = std::find(devices.begin(), devices.end(), target->GetName());
  9983. if (res != devices.end()){
  9984. index = res - devices.begin();
  9985. int32 deviceID = 0;
  9986. deviceID |= 1UL << index;
  9987. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  9988. packet->setDataByName("unknown2", devices.size());
  9989. packet->setDataByName("unknown3", deviceID);
  9990. }
  9991. else
  9992. packet->setDataByName("unknown2", devices.size());
  9993. QueuePacket(packet->serialize());
  9994. safe_delete(packet);
  9995. }
  9996. void Client::SendTitleUpdate() {
  9997. // must call release read lock before leaving function on GetPlayerTitles
  9998. vector<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  9999. vector<Title*>::iterator itr;
  10000. Title* title;
  10001. sint32 i = 0;
  10002. sint32 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  10003. sint32 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  10004. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  10005. if (packet) {
  10006. packet->setArrayLengthByName("num_titles", titles->size());
  10007. for (itr = titles->begin(); itr != titles->end(); itr++) {
  10008. title = *itr;
  10009. packet->setArrayDataByName("title", title->GetName(), i);
  10010. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  10011. i++;
  10012. }
  10013. packet->setDataByName("current_prefix", prefix_index);
  10014. packet->setDataByName("current_suffix", suffix_index);
  10015. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  10016. #if EQDEBUG >= 9
  10017. packet->PrintPacket();
  10018. #endif
  10019. QueuePacket(packet->serialize());
  10020. safe_delete(packet);
  10021. SendUpdateTitles(prefix_index, suffix_index);
  10022. }
  10023. player->GetPlayerTitles()->ReleaseReadLock();
  10024. }
  10025. void Client::SendUpdateTitles(sint32 prefix, sint32 suffix) {
  10026. Title* suffix_title = 0;
  10027. Title* prefix_title = 0;
  10028. if (suffix != -1) {
  10029. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  10030. if(suffix_title)
  10031. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  10032. }
  10033. else
  10034. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  10035. if (prefix != -1) {
  10036. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  10037. if(prefix_title)
  10038. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  10039. }
  10040. else
  10041. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  10042. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  10043. }
  10044. void Client::SendLanguagesUpdate(int32 id, bool setlang) {
  10045. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  10046. list<Language*>::iterator itr;
  10047. Language* language;
  10048. int32 i = 0;
  10049. if(setlang==1){
  10050. GetPlayer()->SetCurrentLanguage(id);
  10051. }
  10052. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  10053. if (packet) {
  10054. packet->setArrayLengthByName("num_languages", languages->size());
  10055. for (itr = languages->begin(); itr != languages->end(); itr++) {
  10056. language = *itr;
  10057. packet->setArrayDataByName("language_id", language->GetID(), i);
  10058. i++;
  10059. }
  10060. packet->setDataByName("current_language", id);
  10061. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  10062. #if EQDEBUG >= 9
  10063. packet->PrintPacket();
  10064. #endif
  10065. QueuePacket(packet->serialize());
  10066. safe_delete(packet);
  10067. }
  10068. }
  10069. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  10070. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  10071. if (packet) {
  10072. if (pet_name)
  10073. packet->setDataByName("pet_name", pet_name);
  10074. if (player->GetInfoStruct()->get_pet_behavior() & 1)
  10075. packet->setDataByName("protect_master", 1);
  10076. if (player->GetInfoStruct()->get_pet_behavior() & 2)
  10077. packet->setDataByName("protect_self", 1);
  10078. if (player->GetInfoStruct()->get_pet_movement() == 2)
  10079. packet->setDataByName("stay_follow_toggle", 1);
  10080. packet->setDataByName("pet_type", type);
  10081. QueuePacket(packet->serialize());
  10082. }
  10083. safe_delete(packet);
  10084. }
  10085. bool Client::IsCrafting() {
  10086. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  10087. }
  10088. void Client::SendBiography() {
  10089. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  10090. if (packet) {
  10091. char biography[512];
  10092. if(player->GetInfoStruct()->get_biography().size() < 1)
  10093. {
  10094. safe_delete(packet);
  10095. return;
  10096. }
  10097. else
  10098. {
  10099. int16 size = player->GetInfoStruct()->get_biography().size();
  10100. if(size>511)
  10101. size = 511;
  10102. strncpy(biography, player->GetInfoStruct()->get_biography().c_str(), player->GetInfoStruct()->get_biography().size());
  10103. biography[player->GetInfoStruct()->get_biography().size()] = '\0';
  10104. }
  10105. packet->setDataByName("biography", biography);
  10106. QueuePacket(packet->serialize());
  10107. }
  10108. safe_delete(packet);
  10109. }
  10110. PendingResurrection* Client::GetCurrentRez() {
  10111. return &current_rez;
  10112. }
  10113. Mutex* Client::GetResurrectMutex() {
  10114. return &m_resurrect;
  10115. }
  10116. void Client::SendResurrectionWindow() {
  10117. Spawn* caster = current_rez.caster;
  10118. if (!caster || !player)
  10119. return;
  10120. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  10121. if (!packet)
  10122. return;
  10123. char* tmp = new char[512];
  10124. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  10125. packet->setMediumStringByName("text", tmp);
  10126. packet->setMediumStringByName("accept_text", "Yes");
  10127. packet->setMediumStringByName("cancel_text", "No");
  10128. sprintf(tmp, "accept_resurrection %u", player->GetID());
  10129. packet->setMediumStringByName("accept_command", tmp);
  10130. sprintf(tmp, "decline_resurrection %u", player->GetID());
  10131. packet->setMediumStringByName("cancel_command", tmp);
  10132. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  10133. QueuePacket(packet->serialize());
  10134. safe_delete(packet);
  10135. safe_delete_array(tmp);
  10136. }
  10137. void Client::AcceptResurrection() {
  10138. Spawn* caster = current_rez.caster;
  10139. if (!player || !caster)
  10140. return;
  10141. if (player->Alive())
  10142. return;
  10143. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  10144. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  10145. SendResurrectionWindow();
  10146. return;
  10147. }
  10148. player->GetZone()->ResurrectSpawn(player, this);
  10149. current_rez.should_delete = true;
  10150. }
  10151. void Client::SetPendingLastName(string last_name) {
  10152. pending_last_name = new string;
  10153. pending_last_name->assign(last_name);
  10154. }
  10155. string* Client::GetPendingLastName() {
  10156. return pending_last_name;
  10157. }
  10158. void Client::RemovePendingLastName() {
  10159. safe_delete(pending_last_name);
  10160. }
  10161. void Client::SendLastNameConfirmation() {
  10162. if (!pending_last_name)
  10163. return;
  10164. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  10165. if (packet) {
  10166. char* text = new char[128];
  10167. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  10168. packet->setDataByName("text", text);
  10169. packet->setDataByName("accept_text", "Yes");
  10170. packet->setDataByName("accept_command", "confirmedlastname");
  10171. packet->setDataByName("cancel_text", "No");
  10172. packet->setDataByName("max_length", 50);
  10173. packet->setDataByName("unknown4", 1);
  10174. packet->setDataByName("unknown5", 1);
  10175. QueuePacket(packet->serialize());
  10176. safe_delete(packet);
  10177. safe_delete_array(text);
  10178. }
  10179. }
  10180. void Client::AddQuestTimer(int32 quest_id) {
  10181. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  10182. quest_timers.push_back(quest_id);
  10183. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  10184. }
  10185. void Client::RemoveQuestTimer(int32 quest_id) {
  10186. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  10187. vector<int32>::iterator itr;
  10188. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  10189. if ((*itr) == quest_id) {
  10190. quest_timers.erase(itr);
  10191. break;
  10192. }
  10193. }
  10194. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  10195. }
  10196. void Client::SavePlayerImages() {
  10197. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  10198. // Save the paperdoll image if the server allows it
  10199. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  10200. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  10201. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  10202. // Save the head shot if the server allows it
  10203. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  10204. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  10205. // Send the head shot to the login server
  10206. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  10207. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  10208. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  10209. memset(packet->pBuffer, 0, size);
  10210. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  10211. pic->account_id = GetAccountID();
  10212. pic->char_id = GetCharacterID();
  10213. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  10214. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  10215. loginserver.SendPacket(packet);
  10216. safe_delete(packet);
  10217. }
  10218. }
  10219. safe_delete_array(incoming_paperdoll.image_bytes);
  10220. incoming_paperdoll.current_size_bytes = 0;
  10221. }
  10222. void Client::EndAutoMount() {
  10223. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  10224. if (packet) {
  10225. packet->setDataByName("parameter1", 128);
  10226. packet->setDataByName("parameter2", 64);
  10227. packet->setDataByName("value", 1);
  10228. QueuePacket(packet->serialize());
  10229. safe_delete(packet);
  10230. }
  10231. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  10232. if (packet) {
  10233. packet->setDataByName("parameter3", 4);
  10234. packet->setDataByName("parameter5", 2);
  10235. packet->setDataByName("value", 0);
  10236. QueuePacket(packet->serialize());
  10237. safe_delete(packet);
  10238. }
  10239. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  10240. if (packet) {
  10241. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  10242. QueuePacket(packet->serialize());
  10243. safe_delete(packet);
  10244. }
  10245. on_auto_mount = false;
  10246. player->SetMount(((Player*)player)->GetTempMount());
  10247. EQ2_Color mount_color = player->GetTempMountColor();
  10248. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  10249. player->SetMountColor(&mount_color);
  10250. player->SetMountSaddleColor(&saddle_color);
  10251. player->SetTempMount(0);
  10252. }
  10253. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  10254. const char* spawn_script = spawn->GetSpawnScript();
  10255. bool should_use_spawn = true;
  10256. if (spawn_script) {
  10257. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  10258. if (state) {
  10259. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  10260. if (state_mutex)
  10261. state_mutex->writelock(__FUNCTION__, __LINE__);
  10262. lua_getglobal(state, "can_use_command");
  10263. if (lua_isfunction(state, lua_gettop(state))) {
  10264. lua_interface->SetSpawnValue(state, spawn);
  10265. lua_interface->SetSpawnValue(state, GetPlayer());
  10266. lua_interface->SetStringValue(state, command ? command : "");
  10267. if (lua_pcall(state, 3, 1, 0) == 0) {
  10268. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  10269. }
  10270. }
  10271. lua_interface->ResetFunctionStack(state);
  10272. if (state_mutex)
  10273. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  10274. }
  10275. }
  10276. return should_use_spawn;
  10277. }
  10278. bool Client::IsCurrentTransmuteID(int32 req_id) {
  10279. return req_id == transmuteID;
  10280. }
  10281. void Client::SetTransmuteID(int32 trans_id) {
  10282. transmuteID = trans_id;
  10283. }
  10284. int32 Client::GetTransmuteID() {
  10285. return transmuteID;
  10286. }
  10287. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  10288. {
  10289. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  10290. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  10291. if (zar)
  10292. {
  10293. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  10294. if (database.IsActiveQuery(charID))
  10295. {
  10296. delayedLogin = true;
  10297. delayedAccountID = account_id;
  10298. delayedAccessKey = access_code;
  10299. delayTimer.Start(500);
  10300. 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);
  10301. return true;
  10302. }
  10303. delayedLogin = false;
  10304. delayTimer.Disable();
  10305. firstlogin = zar->isFirstLogin();
  10306. SetReadyForSpawns(false);
  10307. ready_for_updates = false;
  10308. 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);
  10309. Client* client = zone_list.GetClientByCharName(zar->GetCharacterName());
  10310. if (client || database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  10311. GetPlayer()->CalculateOfflineDebtRecovery(GetLastSavedTimeStamp());
  10312. GetPlayer()->vis_changed = false;
  10313. GetPlayer()->info_changed = false;
  10314. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  10315. if (pvp_allowed)
  10316. this->GetPlayer()->SetAttackable(1);
  10317. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  10318. if (client) {
  10319. if (client->getConnection())
  10320. client->getConnection()->SendDisconnect(true);
  10321. bool restore_ld_success = false;
  10322. if (client->GetCurrentZone() && !client->IsZoning()) {
  10323. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  10324. if (client->GetVersion() == version) {
  10325. client->DisableSave();
  10326. client->ReplaceGroupClient(this);
  10327. Player* current_player = GetPlayer();
  10328. SetPlayer(client->GetPlayer());
  10329. GetPlayer()->SetClient(this);
  10330. GetPlayer()->SetReturningFromLD(true);
  10331. SetCharacterID(client->GetCharacterID());
  10332. SetAccountID(client->GetAccountID());
  10333. SetAdminStatus(client->GetAdminStatus());
  10334. SetCurrentZone(GetPlayer()->GetZone());
  10335. client->SetPlayer(current_player);
  10336. GetPlayer()->ResetSavedSpawns();
  10337. restore_ld_success = true;
  10338. char tmpldname[128];
  10339. snprintf(tmpldname, 128, "%s Linkdead",GetPlayer()->GetName());
  10340. client->GetPlayer()->SetName(tmpldname, false);
  10341. }
  10342. ZoneServer* tmpZone = client->GetCurrentZone();
  10343. tmpZone->RemoveClientImmediately(client);
  10344. }
  10345. if(!restore_ld_success && !database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  10346. LogWrite(ZONE__ERROR, 0, "Zone", "Error reloading LD character and loading DB character: %s", player->GetName());
  10347. ClientPacketFunctions::SendLoginDenied(this);
  10348. Disconnect();
  10349. return false;
  10350. }
  10351. }
  10352. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  10353. if (!GetCurrentZone()) {
  10354. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  10355. ClientPacketFunctions::SendLoginDenied(this);
  10356. Disconnect();
  10357. return false;
  10358. }
  10359. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  10360. getConnection()->SetClientVersion(version);
  10361. GetCurrentZone()->SetSpawnStructs(this);
  10362. connected_to_zone = true;
  10363. client_list.Remove(this); //remove from master client list
  10364. GetCurrentZone()->AddClient(this); //add to zones client list
  10365. zone_list.AddClientToMap(player->GetName(), this);
  10366. // 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.
  10367. if(GetCurrentZone()->IsLoading()) {
  10368. new_client_login = NewLoginState::LOGIN_DELAYED;
  10369. }
  10370. else {
  10371. new_client_login = NewLoginState::LOGIN_ALLOWED;
  10372. }
  10373. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  10374. if (zone_script && lua_interface)
  10375. lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
  10376. }
  10377. else {
  10378. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  10379. version = 0;
  10380. ClientPacketFunctions::SendLoginDenied(this);
  10381. Disconnect();
  10382. return false;
  10383. }
  10384. }
  10385. else {
  10386. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  10387. ClientPacketFunctions::SendLoginDenied(this);
  10388. Disconnect();
  10389. return false;
  10390. }
  10391. zone_auth.RemoveAuth(zar);
  10392. }
  10393. else
  10394. {
  10395. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  10396. Disconnect();
  10397. return false;
  10398. }
  10399. return true;
  10400. }
  10401. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  10402. if (!IsReadyForUpdates())
  10403. return;
  10404. map<int32, SpawnData> info_changes;
  10405. map<int32, SpawnData> pos_changes;
  10406. map<int32, SpawnData> vis_changes;
  10407. map<int32, SpawnData> empty_changes;
  10408. int32 info_size = 0;
  10409. int32 pos_size = 0;
  10410. int32 vis_size = 0;
  10411. int count = 0;
  10412. for (const auto& spawn : spawns) {
  10413. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  10414. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()))
  10415. continue;
  10416. if(GetPlayer() == spawn && GetVersion() <= 284) { // stopped self client/player warping in the EQ2 release disc (Beta), don't send yourself in bulk spawn updates
  10417. continue;
  10418. }
  10419. int16 tmp_info_size = 0;
  10420. int16 tmp_pos_size = 0;
  10421. int16 tmp_vis_size = 0;
  10422. if (spawn->vis_changed)
  10423. {
  10424. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
  10425. if (vis_change) {
  10426. SpawnData data;
  10427. data.spawn = spawn;
  10428. data.data = vis_change;
  10429. data.size = tmp_vis_size;
  10430. map<int32, SpawnData> tmp_vis_changes;
  10431. tmp_vis_changes[index] = data;
  10432. map<int32, SpawnData> tmp_info_changes;
  10433. map<int32, SpawnData> tmp_pos_changes;
  10434. if (spawn->info_changed) {
  10435. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
  10436. if (info_change) {
  10437. SpawnData data;
  10438. data.spawn = spawn;
  10439. data.data = info_change;
  10440. data.size = tmp_info_size;
  10441. tmp_info_changes[index] = data;
  10442. }
  10443. }
  10444. if (spawn->position_changed) {
  10445. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
  10446. if (pos_change) {
  10447. SpawnData data;
  10448. data.spawn = spawn;
  10449. data.data = pos_change;
  10450. data.size = tmp_pos_size;
  10451. tmp_pos_changes[index] = data;
  10452. }
  10453. }
  10454. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  10455. for (auto& kv : tmp_info_changes) {
  10456. safe_delete_array(kv.second.data);
  10457. }
  10458. for (auto& kv : tmp_pos_changes) {
  10459. safe_delete_array(kv.second.data);
  10460. }
  10461. for (auto& kv : tmp_vis_changes) {
  10462. safe_delete_array(kv.second.data);
  10463. }
  10464. continue;
  10465. }
  10466. }
  10467. if (spawn->info_changed) {
  10468. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
  10469. if (info_change) {
  10470. SpawnData data;
  10471. data.spawn = spawn;
  10472. data.data = info_change;
  10473. data.size = tmp_info_size;
  10474. info_size += tmp_info_size;
  10475. info_changes[index] = data;
  10476. }
  10477. count++;
  10478. }
  10479. if (spawn->position_changed) {
  10480. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
  10481. if (pos_change) {
  10482. SpawnData data;
  10483. data.spawn = spawn;
  10484. data.data = pos_change;
  10485. data.size = tmp_pos_size;
  10486. pos_size += tmp_pos_size;
  10487. pos_changes[index] = data;
  10488. }
  10489. count++;
  10490. }
  10491. if (spawn->vis_changed) {
  10492. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
  10493. if (vis_change) {
  10494. SpawnData data;
  10495. data.spawn = spawn;
  10496. data.data = vis_change;
  10497. data.size = tmp_vis_size;
  10498. vis_size += tmp_vis_size;
  10499. vis_changes[index] = data;
  10500. }
  10501. count++;
  10502. }
  10503. }
  10504. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  10505. return;
  10506. }
  10507. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  10508. for (auto& kv : info_changes) {
  10509. safe_delete_array(kv.second.data);
  10510. }
  10511. for (auto& kv : pos_changes) {
  10512. safe_delete_array(kv.second.data);
  10513. }
  10514. for (auto& kv : vis_changes) {
  10515. safe_delete_array(kv.second.data);
  10516. }
  10517. }
  10518. 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)
  10519. {
  10520. static const int8 oversized = 255;
  10521. int16 opcode_val = 0;
  10522. if (EQOpcodeManager.count(GetOpcodeVersion(version)) != 0) {
  10523. opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  10524. }
  10525. int32 size = info_size + pos_size + vis_size + 8;
  10526. size += CheckOverLoadSize(info_size);
  10527. size += CheckOverLoadSize(pos_size);
  10528. size += CheckOverLoadSize(vis_size);
  10529. if (version <= 373 && size >= 255) {//1 byte to 3 for overloaded val
  10530. size += 2;
  10531. }
  10532. else if (version >= 374)
  10533. size += 3;
  10534. uchar* tmp = new uchar[size];
  10535. uchar* ptr = tmp;
  10536. memset(tmp, 0, size);
  10537. if (version <= 373) {
  10538. if (size >= 255) {
  10539. size -= 3;
  10540. memcpy(ptr, &oversized, sizeof(int8));
  10541. ptr += sizeof(int8);
  10542. memcpy(ptr, &size, sizeof(int16));
  10543. ptr += sizeof(int16);
  10544. size += 3;
  10545. }
  10546. else {
  10547. size -= 1;
  10548. memcpy(ptr, &size, sizeof(int8));
  10549. ptr += sizeof(int8);
  10550. size += 1;
  10551. }
  10552. }
  10553. else {
  10554. size -= 4;
  10555. memcpy(ptr, &size, sizeof(int32));
  10556. ptr += sizeof(int32);
  10557. size += 4;
  10558. }
  10559. memcpy(ptr, &oversized, sizeof(int8));
  10560. ptr += sizeof(int8);
  10561. memcpy(ptr, &opcode_val, sizeof(int16));
  10562. ptr += sizeof(int16);
  10563. int32 current_time = Timer::GetCurrentTime2();
  10564. memcpy(ptr, &current_time, sizeof(int32));
  10565. ptr += sizeof(int32);
  10566. ptr += DoOverLoad(info_size, ptr);
  10567. for (const auto& kv : info_changes) {
  10568. auto info = kv.second;
  10569. memcpy(ptr, info.data, info.size);
  10570. ptr += info.size;
  10571. }
  10572. ptr += DoOverLoad(pos_size, ptr);
  10573. for (const auto& kv : pos_changes) {
  10574. auto pos = kv.second;
  10575. memcpy(ptr, pos.data, pos.size);
  10576. ptr += pos.size;
  10577. }
  10578. ptr += DoOverLoad(vis_size, ptr);
  10579. for (const auto& kv : vis_changes) {
  10580. auto vis = kv.second;
  10581. memcpy(ptr, vis.data, vis.size);
  10582. ptr += vis.size;
  10583. }
  10584. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  10585. if (packet) {
  10586. /*char blah[64];
  10587. snprintf(blah, 64, "Sending %i", current_time);
  10588. SimpleMessage(4, blah);*/
  10589. QueuePacket(packet);
  10590. }
  10591. delete[] tmp;
  10592. }
  10593. void Client::SendHailCommand(Spawn* spawn)
  10594. {
  10595. // hardcoded 'hail' entity commands
  10596. switch (spawn->secondary_command_list_id)
  10597. {
  10598. case 9:
  10599. case 1262:
  10600. case 1265:
  10601. case 1267:
  10602. {
  10603. EQ2_16BitString* command = new EQ2_16BitString();
  10604. command->data = "";
  10605. command->size = 0;
  10606. commands.Process(COMMAND_HAIL, command, this, spawn);
  10607. safe_delete(command);
  10608. break;
  10609. }
  10610. }
  10611. }
  10612. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  10613. {
  10614. if (GetPlayer()->WasSentSpawn(spawn->GetID())) {
  10615. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  10616. if (packet) {
  10617. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  10618. packet->setMediumStringByName("command_name", command);
  10619. packet->setDataByName("distance", distance);
  10620. QueuePacket(packet->serialize());
  10621. safe_delete(packet);
  10622. }
  10623. }
  10624. }
  10625. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  10626. {
  10627. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  10628. return false;
  10629. if (command == "house_spawn_examine")
  10630. {
  10631. uint32 itemID = spawn->GetPickupItemID();
  10632. if (itemID)
  10633. {
  10634. Item* item = master_item_list.GetItem(itemID);
  10635. if (item)
  10636. {
  10637. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  10638. //DumpPacket(app);
  10639. QueuePacket(app);
  10640. }
  10641. }
  10642. return true;
  10643. }
  10644. return false;
  10645. }
  10646. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  10647. {
  10648. if (GetTempPlacementSpawn())
  10649. {
  10650. Spawn* tmp = GetTempPlacementSpawn();
  10651. int32 spawn_group_id = database.GetNextSpawnLocation();
  10652. tmp->SetSpawnLocationID(spawn_group_id);
  10653. float newHeading = place_object->getType_float_ByName("heading") + 180;
  10654. int32 spawnDBID = 0;
  10655. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  10656. {
  10657. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  10658. tmp->SetDatabaseID(spawnDBID);
  10659. }
  10660. else
  10661. {
  10662. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  10663. if (spawnDBID)
  10664. {
  10665. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  10666. tmp->SetDatabaseID(spawnDBID);
  10667. }
  10668. }
  10669. tmp->SetX(place_object->getType_float_ByName("x"));
  10670. tmp->SetY(place_object->getType_float_ByName("y"));
  10671. tmp->SetZ(place_object->getType_float_ByName("z"));
  10672. tmp->SetHeading(newHeading);
  10673. tmp->SetSpawnOrigX(tmp->GetX());
  10674. tmp->SetSpawnOrigY(tmp->GetY());
  10675. tmp->SetSpawnOrigZ(tmp->GetZ());
  10676. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  10677. database.SaveSpawnInfo(tmp);
  10678. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  10679. if (!spawnDBID)
  10680. {
  10681. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  10682. // we need to copy as to not delete the ZoneServer object_list entry this on house item pickup
  10683. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), ((Object*)tmp)->Copy());
  10684. }
  10685. return true;
  10686. }
  10687. return false;
  10688. }
  10689. bool Client::PopulateHouseSpawnFinalize()
  10690. {
  10691. if (GetTempPlacementSpawn())
  10692. {
  10693. Spawn* tmp = GetTempPlacementSpawn();
  10694. GetCurrentZone()->AddSpawn(tmp);
  10695. GetCurrentZone()->SendSpawnChanges(tmp, this);
  10696. SetTempPlacementSpawn(nullptr);
  10697. int32 uniqueID = GetPlacementUniqueItemID();
  10698. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  10699. tmp->SetPickupItemID(uniqueItem->details.item_id);
  10700. tmp->SetPickupUniqueItemID(uniqueID);
  10701. if (uniqueItem)
  10702. {
  10703. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  10704. {
  10705. Query query;
  10706. 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);
  10707. }
  10708. if(uniqueItem->GetItemScript() &&
  10709. lua_interface->RunItemScript(uniqueItem->GetItemScript(), "placed", uniqueItem, GetPlayer(), tmp))
  10710. {
  10711. uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  10712. }
  10713. if(uniqueItem) {
  10714. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  10715. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  10716. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  10717. }
  10718. SetPlacementUniqueItemID(0);
  10719. }
  10720. return true;
  10721. }
  10722. return false;
  10723. }
  10724. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  10725. {
  10726. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  10727. packet->setDataByName("placement_mode", placementMode);
  10728. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  10729. packet->setDataByName("model_type", spawn->GetModelType());
  10730. packet->setDataByName("unknown", 1); //size
  10731. packet->setDataByName("unknown2", 1); //size 2
  10732. packet->setDataByName("unknown2", .5, 1); //size 3
  10733. packet->setDataByName("unknown2", 3, 2);
  10734. packet->setDataByName("unknown2", unknown2_3, 3);
  10735. packet->setDataByName("max_distance", 500);
  10736. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  10737. QueuePacket(packet->serialize());
  10738. safe_delete(packet);
  10739. }
  10740. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  10741. {
  10742. SetPendingFlightPath(path_id);
  10743. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  10744. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  10745. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  10746. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  10747. if (packet) {
  10748. QueuePacket(packet->serialize());
  10749. safe_delete(packet);
  10750. }
  10751. if (mount_id)
  10752. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  10753. }
  10754. void Client::SendShowBook(Spawn* sender, string title, int8 language, int8 num_pages, ...)
  10755. {
  10756. if (!sender)
  10757. {
  10758. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  10759. return;
  10760. }
  10761. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  10762. if (!packet) {
  10763. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  10764. return;
  10765. }
  10766. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  10767. packet->setDataByName("book_title", title.c_str());
  10768. packet->setDataByName("book_type", "simple");
  10769. packet->setDataByName("unknown2", 1);
  10770. if(language > 0 && !GetPlayer()->HasLanguage(language))
  10771. packet->setDataByName("language", language);
  10772. if (GetVersion() > 561)
  10773. packet->setDataByName("unknown5", 1, 4);
  10774. packet->setArrayLengthByName("num_pages", num_pages);
  10775. va_list args;
  10776. va_start(args, num_pages);
  10777. std::string endString("");
  10778. for (int8 p = 0; p < num_pages; p++)
  10779. {
  10780. std::string page = va_arg(args, string);
  10781. switch (GetVersion())
  10782. {
  10783. // release client
  10784. case 283:
  10785. case 373: // trial isle client
  10786. {
  10787. endString.append(page);
  10788. break;
  10789. }
  10790. // DoF trial
  10791. case 546:
  10792. case 561:
  10793. {
  10794. if (p == 0)
  10795. packet->setDataByName("cover_page", page.c_str());
  10796. else
  10797. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  10798. break;
  10799. }
  10800. // all other clients
  10801. default:
  10802. {
  10803. packet->setArrayDataByName("page_text", page.c_str(), p);
  10804. break;
  10805. }
  10806. }
  10807. }
  10808. if (GetVersion() <= 373)
  10809. {
  10810. packet->setDataByName("page_text", endString.c_str());
  10811. }
  10812. va_end(args);
  10813. QueuePacket(packet->serialize());
  10814. safe_delete(packet);
  10815. }
  10816. void Client::SendShowBook(Spawn* sender, string title, int8 language, vector<Item::BookPage*> pages)
  10817. {
  10818. if (!sender)
  10819. {
  10820. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  10821. return;
  10822. }
  10823. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  10824. if (!packet) {
  10825. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  10826. return;
  10827. }
  10828. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  10829. packet->setDataByName("book_title", title.c_str());
  10830. packet->setDataByName("book_type", "simple");
  10831. packet->setDataByName("unknown2", 1);
  10832. if(language > 0 && !GetPlayer()->HasLanguage(language))
  10833. packet->setDataByName("language", language);
  10834. if (GetVersion() > 561)
  10835. packet->setDataByName("unknown5", 1, 4);
  10836. packet->setArrayLengthByName("num_pages", pages.size());
  10837. std::string endString("");
  10838. for (int8 p = 0; p < pages.size(); p++)
  10839. {
  10840. Item::BookPage* page = pages[p];
  10841. std::string pageText = string(page->page_text.data);
  10842. switch (GetVersion())
  10843. {
  10844. // release client
  10845. case 283:
  10846. case 373: // trial isle client
  10847. {
  10848. endString.append(pageText);
  10849. break;
  10850. }
  10851. // DoF trial
  10852. case 546:
  10853. case 561:
  10854. {
  10855. if (p == 0)
  10856. packet->setDataByName("cover_page", pageText.c_str());
  10857. else
  10858. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  10859. break;
  10860. }
  10861. // all other clients
  10862. default:
  10863. {
  10864. int8 valign = int8(page->valign);
  10865. int8 halign = int8(page->halign);
  10866. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  10867. packet->setArrayDataByName("page_text_valign", valign, p);
  10868. packet->setArrayDataByName("page_text_halign", halign, p);
  10869. break;
  10870. }
  10871. }
  10872. }
  10873. if (GetVersion() == 283)
  10874. {
  10875. packet->setDataByName("page_text", endString.c_str());
  10876. }
  10877. QueuePacket(packet->serialize());
  10878. safe_delete(packet);
  10879. }
  10880. void Client::ReplaceGroupClient(Client* new_client)
  10881. {
  10882. if (this->GetPlayer()->GetGroupMemberInfo())
  10883. {
  10884. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  10885. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  10886. if(group)
  10887. {
  10888. group->MGroupMembers.writelock();
  10889. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  10890. this->GetPlayer()->GetGroupMemberInfo()->client = new_client;
  10891. this->GetPlayer()->GetGroupMemberInfo()->member = GetPlayer();
  10892. group->MGroupMembers.releasewritelock();
  10893. }
  10894. else
  10895. {
  10896. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10897. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10898. this->GetPlayer()->SetGroupMemberInfo(0);
  10899. }
  10900. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  10901. }
  10902. }
  10903. void Client::TempRemoveGroup()
  10904. {
  10905. if (this->GetPlayer()->GetGroupMemberInfo())
  10906. {
  10907. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  10908. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  10909. if(group)
  10910. {
  10911. group->MGroupMembers.writelock();
  10912. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  10913. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10914. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10915. this->GetPlayer()->SetGroupMemberInfo(0);
  10916. group->MGroupMembers.releasewritelock();
  10917. group->RemoveClientReference(this);
  10918. }
  10919. else
  10920. {
  10921. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10922. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10923. this->GetPlayer()->SetGroupMemberInfo(0);
  10924. }
  10925. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  10926. }
  10927. }
  10928. void Client::CreateMail(int32 charID, std::string fromName, std::string subjectName, std::string mailBody,
  10929. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  10930. {
  10931. Mail mail;
  10932. mail.mail_id = 0;
  10933. mail.already_read = 0;
  10934. mail.postage_cost = 0;
  10935. mail.attachment_cost = 0;
  10936. mail.save_needed = 1;
  10937. //uhh...mail has std::strings so
  10938. //memset(&mail,0,sizeof(Mail));
  10939. mail.player_to_id = charID;
  10940. mail.player_from = fromName;
  10941. mail.subject = subjectName;
  10942. mail.mail_body = mailBody;
  10943. mail.mail_type = mailType;
  10944. mail.coin_copper = copper;
  10945. mail.coin_silver = silver;
  10946. mail.coin_gold = gold;
  10947. mail.coin_plat = platinum;
  10948. mail.char_item_id = item_id;
  10949. mail.stack = stack_size;
  10950. mail.time_sent = time_sent;
  10951. mail.expire_time = expire_time;
  10952. database.SavePlayerMail(&mail);
  10953. }
  10954. void Client::CreateAndUpdateMail(std::string fromName, std::string subjectName, std::string mailBody,
  10955. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  10956. {
  10957. Mail* mail = new Mail();
  10958. mail->player_to_id = GetCharacterID();
  10959. mail->player_from = fromName;
  10960. mail->subject = subjectName;
  10961. mail->mail_body = mailBody;
  10962. mail->mail_type = mailType;
  10963. mail->coin_copper = copper;
  10964. mail->coin_silver = silver;
  10965. mail->coin_gold = gold;
  10966. mail->coin_plat = platinum;
  10967. mail->char_item_id = item_id;
  10968. mail->stack = stack_size;
  10969. mail->time_sent = time_sent;
  10970. mail->expire_time = expire_time;
  10971. mail->postage_cost = 0;
  10972. mail->save_needed = 1;
  10973. mail->already_read = 0;
  10974. database.SavePlayerMail(mail);
  10975. GetPlayer()->AddMail(mail);
  10976. }
  10977. void Client::SendEquipOrInvUpdateBySlot(int8 slot)
  10978. {
  10979. if(slot < NUM_SLOTS)
  10980. {
  10981. EQ2Packet* app = GetPlayer()->GetEquipmentList()->serialize(GetVersion(), GetPlayer());
  10982. if (app)
  10983. QueuePacket(app);
  10984. }
  10985. else
  10986. {
  10987. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  10988. if (outapp)
  10989. QueuePacket(outapp);
  10990. }
  10991. }
  10992. void Client::QueueStateCommand(int32 spawn_player_id, int32 state)
  10993. {
  10994. if(spawn_player_id < 1)
  10995. return;
  10996. MQueueStateCmds.writelock();
  10997. queued_state_commands.insert(make_pair(spawn_player_id, state));
  10998. MQueueStateCmds.releasewritelock();
  10999. }
  11000. void Client::ProcessStateCommands()
  11001. {
  11002. if(!IsReadyForUpdates())
  11003. return;
  11004. MQueueStateCmds.writelock();
  11005. map<int32, int32>::iterator itr = queued_state_commands.begin();
  11006. for(; itr != queued_state_commands.end(); itr++)
  11007. ClientPacketFunctions::SendStateCommand(this, itr->first, itr->second);
  11008. queued_state_commands.clear();
  11009. MQueueStateCmds.releasewritelock();
  11010. }
  11011. void Client::PurgeItem(Item* item)
  11012. {
  11013. std::unique_lock lock(MConversation);
  11014. map<int32, Item*>::iterator itr;
  11015. for(itr = conversation_items.begin(); itr != conversation_items.end(); itr++)
  11016. {
  11017. if ( itr->second == item )
  11018. {
  11019. conversation_items.erase(itr);
  11020. break;
  11021. }
  11022. }
  11023. }
  11024. void Client::ConsumeFoodDrink(Item* item, int32 slot)
  11025. {
  11026. if(GetPlayer()->StopSaveSpellEffects())
  11027. return;
  11028. if(item) {
  11029. LogWrite(MISC__INFO, 1, "Command", "ItemID: %u, ItemName: %s ItemCount: %i ", item->details.item_id, item->name.c_str(), item->details.count);
  11030. if(item->GetItemScript() && lua_interface){
  11031. lua_interface->RunItemScript(item->GetItemScript(), "cast", item, GetPlayer());
  11032. if (slot == 22) {
  11033. Message(CHANNEL_NARRATIVE, "You eat a %s.", item->name.c_str());
  11034. GetPlayer()->SetActiveFoodUniqueID(item->details.unique_id);
  11035. }
  11036. else {
  11037. Message(CHANNEL_NARRATIVE, "You drink a %s.", item->name.c_str());
  11038. GetPlayer()->SetActiveDrinkUniqueID(item->details.unique_id);
  11039. }
  11040. }
  11041. else {
  11042. Message(CHANNEL_NARRATIVE, "SERVER BUG! Item Script not assigned for consuming '%s'.", item->name.c_str());
  11043. return;
  11044. }
  11045. if (item->details.count > 1) {
  11046. item->details.count -= 1;
  11047. item->save_needed = true;
  11048. }
  11049. else {
  11050. database.DeleteItem(GetPlayer()->GetCharacterID(), item, "EQUIPPED");
  11051. GetPlayer()->GetEquipmentList()->RemoveItem(slot, true);
  11052. }
  11053. GetPlayer()->SetCharSheetChanged(true);
  11054. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  11055. if(GetVersion() <= 373) {
  11056. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  11057. QueuePacket(outapp);
  11058. }
  11059. }
  11060. }
  11061. void Client::AwardCoins(int64 total_coins, std::string reason)
  11062. {
  11063. if (total_coins > 0) {
  11064. player->AddCoins(total_coins);
  11065. PlaySound("coin_cha_ching");
  11066. char tmp[64] = { 0 };
  11067. string message = "You receive ";
  11068. int32 val = 0;
  11069. if (total_coins >= 1000000) {
  11070. val = total_coins / 1000000;
  11071. total_coins -= 1000000 * val;
  11072. sprintf(tmp, "%u Platinum ", val);
  11073. message.append(tmp);
  11074. memset(tmp, 0, 64);
  11075. }
  11076. if (total_coins >= 10000) {
  11077. val = total_coins / 10000;
  11078. total_coins -= 10000 * val;
  11079. sprintf(tmp, "%u Gold ", val);
  11080. message.append(tmp);
  11081. memset(tmp, 0, 64);
  11082. }
  11083. if (total_coins >= 100) {
  11084. val = total_coins / 100;
  11085. total_coins -= 100 * val;
  11086. sprintf(tmp, "%u Silver ", val);
  11087. message.append(tmp);
  11088. memset(tmp, 0, 64);
  11089. }
  11090. if (total_coins > 0) {
  11091. sprintf(tmp, "%u Copper ", (int32)total_coins);
  11092. message.append(tmp);
  11093. }
  11094. message.append(reason);
  11095. int8 type = CHANNEL_LOOT;
  11096. SimpleMessage(type, message.c_str());
  11097. }
  11098. }
  11099. void Client::TriggerSpellSave()
  11100. {
  11101. int32 interval = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateWaitInterval)->GetInt32();
  11102. // default to not have some bogus value in the rule
  11103. if(interval < 1)
  11104. interval = 100;
  11105. MSaveSpellStateMutex.lock();
  11106. if(!save_spell_state_timer.Enabled())
  11107. {
  11108. save_spell_state_time_bucket = 0;
  11109. save_spell_state_timer.Start(interval, true);
  11110. }
  11111. else
  11112. {
  11113. int32 elapsed_time = save_spell_state_timer.GetElapsedTime();
  11114. save_spell_state_time_bucket += elapsed_time;
  11115. int32 save_wait_cap = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateCap)->GetInt32();
  11116. // default to not have some bogus value in the rule
  11117. if(save_wait_cap < interval)
  11118. save_wait_cap = interval+1;
  11119. if(save_spell_state_time_bucket >= save_wait_cap)
  11120. {
  11121. save_spell_state_timer.Trigger();
  11122. }
  11123. }
  11124. MSaveSpellStateMutex.unlock();
  11125. }
  11126. void Client::UpdateSentSpellList() {
  11127. MSpellDetails.readlock(__FUNCTION__, __LINE__);
  11128. std::map<int32, int32>::iterator itr;
  11129. for(itr = sent_spell_details.begin(); itr != sent_spell_details.end(); itr++) {
  11130. Spell* spell = master_spell_list.GetSpell(itr->first, itr->second);
  11131. EQ2Packet* app = spell->SerializeSpell(this, false, false);
  11132. QueuePacket(app);
  11133. }
  11134. MSpellDetails.releasereadlock(__FUNCTION__, __LINE__);
  11135. }
  11136. void Client::SetTempPlacementSpawn(Spawn* tmp) {
  11137. tempPlacementSpawn = tmp;
  11138. hasSentTempPlacementSpawn = false;
  11139. if(tempPlacementSpawn)
  11140. temp_placement_timer.Start();
  11141. else
  11142. temp_placement_timer.Disable();
  11143. }
  11144. void Client::SetPlayer(Player* new_player) {
  11145. if (player && player != new_player)
  11146. zone_list.RemoveClientFromMap(player->GetName(), this);
  11147. player = new_player;
  11148. player->SetClient(this);
  11149. }
  11150. bool Client::UseItem(Item* item, Spawn* target) {
  11151. if (item && item->GetItemScript()) {
  11152. int16 item_index = item->details.index;
  11153. if(!item->CheckFlag2(INDESTRUCTABLE) && item->generic_info.condition == 0) {
  11154. SimpleMessage(CHANNEL_COLOR_RED, "This item is broken and must be repaired at a mender before it can be used");
  11155. }
  11156. else if (item->CheckFlag(EVIL_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_EVIL) {
  11157. Message(0, "%s requires an evil race.", item->name.c_str());
  11158. }
  11159. else if (item->CheckFlag(GOOD_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_GOOD) {
  11160. Message(0, "%s requires a good race.", item->name.c_str());
  11161. }
  11162. else if (item->generic_info.max_charges == 0 || item->generic_info.max_charges == 0xFFFF) {
  11163. lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target);
  11164. return true;
  11165. }
  11166. else {
  11167. if (item->details.count > 0) {
  11168. std::string itemName = string(item->name);
  11169. int32 item_id = item->details.item_id;
  11170. sint64 flags = 0;
  11171. if(lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target, &flags) && flags >= 0)
  11172. {
  11173. //reobtain item make sure it wasn't removed
  11174. item = player->item_list.GetItemFromIndex(item_index);
  11175. if(!item) {
  11176. 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);
  11177. return true;
  11178. }
  11179. else if(!item->generic_info.display_charges && item->generic_info.max_charges == 1) {
  11180. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  11181. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  11182. return true;
  11183. }
  11184. else
  11185. {
  11186. item->details.count--; // charges
  11187. item->save_needed = true;
  11188. QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  11189. if(!item->details.count) {
  11190. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  11191. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  11192. }
  11193. return true;
  11194. }
  11195. }
  11196. else {
  11197. 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);
  11198. return true;
  11199. }
  11200. }
  11201. else
  11202. {
  11203. //reobtain item make sure it wasn't removed
  11204. item = player->item_list.GetItemFromIndex(item_index);
  11205. SimpleMessage(CHANNEL_COLOR_YELLOW, "Item is out of charges.");
  11206. if(item) {
  11207. 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);
  11208. }
  11209. }
  11210. }
  11211. }
  11212. return false;
  11213. }
  11214. void Client::SendPlayFlavor(Spawn* spawn, int8 language, VoiceOverStruct* non_garble,
  11215. VoiceOverStruct* garble, bool success, bool garble_success) {
  11216. VoiceOverStruct* resStruct = nullptr;
  11217. if(language == 0 || GetPlayer()->HasLanguage(language)) {
  11218. if(success) {
  11219. resStruct = non_garble;
  11220. }
  11221. }
  11222. else if(garble_success) {
  11223. resStruct = garble;
  11224. }
  11225. if(resStruct) {
  11226. 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);
  11227. }
  11228. }
  11229. void Client::SaveQuestRewardData(bool force_refresh) {
  11230. Query query;
  11231. if(force_refresh) {
  11232. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_rewards where char_id = %u",
  11233. GetCharacterID());
  11234. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_temporary_rewards where char_id = %u",
  11235. GetCharacterID());
  11236. }
  11237. vector<QuestRewardData*>::iterator itr;
  11238. vector<QuestRewardData*> tmp_quest_rewards;
  11239. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  11240. int index = 0;
  11241. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  11242. int32 questID = (*itr)->quest_id;
  11243. if(!(*itr)->db_saved || force_refresh) {
  11244. 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')",
  11245. 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());
  11246. (*itr)->db_saved = true;
  11247. (*itr)->db_index = index;
  11248. if(questID && (*itr)->is_temporary) {
  11249. std::vector<Item*> items;
  11250. GetPlayer()->GetQuestTemporaryRewards(questID, &items);
  11251. if(!force_refresh && items.size() > 0) {
  11252. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "delete from character_quest_temporary_rewards where char_id = %u and quest_id = %u",
  11253. GetCharacterID(), questID);
  11254. }
  11255. for(int i=0;i<items.size();i++) {
  11256. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_temporary_rewards (char_id, quest_id, item_id, count) values(%u, %u, %u, %u)",
  11257. GetCharacterID(), questID, items[i]->details.item_id, items[i]->details.count);
  11258. }
  11259. }
  11260. }
  11261. index++;
  11262. }
  11263. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  11264. }
  11265. void Client::UpdateCharacterRewardData(QuestRewardData* data) {
  11266. if(!data)
  11267. return;
  11268. if(data->db_saved) {
  11269. Query query;
  11270. 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",
  11271. 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);
  11272. }
  11273. }
  11274. void Client::AddRecipeToPlayerPack(Recipe* recipe, PacketStruct* packet, int16* i) {
  11275. int index = 0;
  11276. if(recipe == nullptr)
  11277. return;
  11278. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  11279. if (prl->GetRecipe(recipe->GetID())) {
  11280. delete recipe;
  11281. return;
  11282. }
  11283. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11284. if (res != devices.end())
  11285. index = res - devices.begin();
  11286. else
  11287. devices.push_back(recipe->GetDevice());
  11288. prl->AddRecipe(recipe);
  11289. database.SavePlayerRecipe(GetPlayer(), recipe->GetID());
  11290. Message(CHANNEL_NARRATIVE, "Recipe: \"%s\" put in recipe book.", recipe->GetName());
  11291. if (packet && GetRecipeListSent()) {
  11292. packet->setArrayDataByName("id", recipe->GetID(), *i);
  11293. packet->setArrayDataByName("tier", recipe->GetTier(), *i);
  11294. packet->setArrayDataByName("level", recipe->GetLevel(), *i);
  11295. packet->setArrayDataByName("icon", recipe->GetIcon(), *i);
  11296. packet->setArrayDataByName("classes", recipe->GetClasses(), *i);
  11297. //packet->setArrayDataByName("skill", recipe->GetSkill(), *i);
  11298. packet->setArrayDataByName("technique", recipe->GetTechnique(), *i);
  11299. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), *i);
  11300. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11301. if (recipe_device != devices.end())
  11302. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), *i);
  11303. else
  11304. {//TODO error should never get here
  11305. }
  11306. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), *i);
  11307. packet->setArrayDataByName("recipe_name", recipe->GetName(), *i);
  11308. packet->setArrayDataByName("recipe_book", recipe->GetBook(), *i);
  11309. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), *i);
  11310. if(i) {
  11311. (*i)++;
  11312. }
  11313. }
  11314. }
  11315. bool Client::SetPlayerPOVGhost(Spawn* spawn) {
  11316. if(!spawn) {
  11317. pov_ghost_spawn_id = 0;
  11318. SendCharPOVGhost();
  11319. return true;
  11320. }
  11321. int32 ghost_id = player->GetIDWithPlayerSpawn(spawn);
  11322. if(ghost_id) {
  11323. pov_ghost_spawn_id = spawn->GetID();
  11324. SendCharPOVGhost();
  11325. return true;
  11326. }
  11327. return false;
  11328. }
  11329. void Client::HandleDialogSelectMsg(int32 conversation_id, int32 response_index) {
  11330. std::string conversation = "";
  11331. bool conv_established = false;
  11332. MConversation.lock_shared();
  11333. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  11334. conversation = std::string(conversation_map[conversation_id][response_index].c_str());
  11335. conv_established = true;
  11336. }
  11337. int32 spawn_id = conversation_spawns[conversation_id];
  11338. Item* item = conversation_items[conversation_id];
  11339. MConversation.unlock_shared();
  11340. if (GetCurrentZone()) {
  11341. Spawn* spawn = nullptr;
  11342. if(spawn_id) {
  11343. spawn = GetCurrentZone()->GetSpawnByID(spawn_id);
  11344. }
  11345. if (conv_established) {
  11346. if (spawn) {
  11347. if(conversation == "CloseItemConversation") {
  11348. LogWrite(LUA__ERROR, 0, "LUA", "CloseItemConversation is an invalid function call for this conversation with spawn id %u", spawn_id);
  11349. }
  11350. else {
  11351. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation.c_str());
  11352. }
  11353. }
  11354. else if (item && lua_interface && item->GetItemScript())
  11355. lua_interface->RunItemScript(item->GetItemScript(), conversation.c_str(), item, player);
  11356. else
  11357. CloseDialog(conversation_id);
  11358. }
  11359. else
  11360. CloseDialog(conversation_id);
  11361. }
  11362. }
  11363. bool Client::SetPetName(const char* petName) {
  11364. int8 result = database.CheckNameFilter(petName,4,31);
  11365. if (result == BADNAMELENGTH_REPLY) {
  11366. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name length is invalid, must be greater then 3 characters and less then 31.");
  11367. return false;
  11368. }
  11369. else if (result == NAMEINVALID_REPLY) {
  11370. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is invalid, can only contain letters.");
  11371. return false;
  11372. }
  11373. else if (result == NAMETAKEN_REPLY) {
  11374. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is already taken, please choose another.");
  11375. return false;
  11376. }
  11377. else if (result == NAMEFILTER_REPLY) {
  11378. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name failed the filter check.");
  11379. return false;
  11380. }
  11381. else if (result == UNKNOWNERROR_REPLY) {
  11382. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unknown error while checking the name.");
  11383. return false;
  11384. }
  11385. GetPlayer()->GetInfoStruct()->set_pet_name(petName);
  11386. return true;
  11387. }
  11388. bool Client::CheckConsumptionAllowed(int16 slot, bool send_message) {
  11389. switch(slot) {
  11390. case EQ2_FOOD_SLOT: {
  11391. if(GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_FOOD)) {
  11392. if(send_message) {
  11393. Message(CHANNEL_NARRATIVE, "If you ate anymore you would explode!");
  11394. }
  11395. return false;
  11396. }
  11397. break;
  11398. }
  11399. case EQ2_DRINK_SLOT: {
  11400. if (GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_DRINK))
  11401. {
  11402. if(send_message) {
  11403. Message(CHANNEL_NARRATIVE, "If you drank anymore you would explode!");
  11404. }
  11405. return false;
  11406. }
  11407. break;
  11408. }
  11409. default: {
  11410. if (GetVersion() <= 373) {
  11411. Item* item = GetPlayer()->item_list.GetItemFromIndex(slot);
  11412. if(item->IsFood()) {
  11413. if(item->IsFoodFood()) {
  11414. if(GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_FOOD)) {
  11415. if(send_message) {
  11416. Message(CHANNEL_NARRATIVE, "If you ate anymore you would explode!");
  11417. }
  11418. return false;
  11419. }
  11420. return true;
  11421. }
  11422. else if(item->IsFoodDrink()) {
  11423. if (GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_DRINK))
  11424. {
  11425. if(send_message) {
  11426. Message(CHANNEL_NARRATIVE, "If you drank anymore you would explode!");
  11427. }
  11428. return false;
  11429. }
  11430. return true;
  11431. }
  11432. }
  11433. }
  11434. return false;
  11435. break;
  11436. }
  11437. }
  11438. return true;
  11439. }
  11440. void Client::StartLinkdeadTimer() {
  11441. if(!linkdead_timer) {
  11442. int32 LD_Timer = rule_manager.GetGlobalRule(R_World, LinkDeadTimer)->GetInt32();
  11443. LogWrite(CCLIENT__DEBUG, 0, "Client", "Starting linkdead timer for %s (timer %u seconds)", GetPlayer()->GetName(), (LD_Timer/1000));
  11444. linkdead_timer = new Timer(LD_Timer);
  11445. linkdead_timer->Enable();
  11446. if(GetPlayer()->GetGroupMemberInfo()) {
  11447. LogWrite(CCLIENT__DEBUG, 0, "Client", "Telling player %s group they are disconnecting", GetPlayer()->GetName());
  11448. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has gone Linkdead.", GetPlayer()->GetName());
  11449. }
  11450. }
  11451. }
  11452. bool Client::IsLinkdeadTimerEnabled() {
  11453. if(linkdead_timer) {
  11454. return linkdead_timer->Enabled();
  11455. }
  11456. return false;
  11457. }
  11458. void Client::SendNewAdventureSpells() {
  11459. SendNewSpells(player->GetAdventureClass());
  11460. int8 base_class = classes.GetBaseClass(player->GetAdventureClass());
  11461. int secondary_class = classes.GetSecondaryBaseClass(player->GetAdventureClass());
  11462. if(base_class != player->GetAdventureClass()) {
  11463. SendNewSpells(base_class);
  11464. }
  11465. if(secondary_class != player->GetAdventureClass() && secondary_class != base_class) {
  11466. SendNewSpells(secondary_class);
  11467. }
  11468. }
  11469. void Client::SendNewTradeskillSpells() {
  11470. SendNewTSSpells(player->GetTradeskillClass());
  11471. int8 secondary_class = classes.GetSecondaryTSBaseClass(player->GetTradeskillClass());
  11472. if(secondary_class != player->GetTradeskillClass()) {
  11473. SendNewTSSpells(secondary_class);
  11474. }
  11475. }
  11476. bool Client::AddRecipeBookToPlayer(int32 recipe_book_id, Item* item) {
  11477. Recipe* master_recipe = master_recipebook_list.GetRecipeBooks(recipe_book_id);
  11478. if(master_recipe) {
  11479. Recipe* recipe_book = new Recipe(master_recipe);
  11480. // if valid recipe book and the player doesn't have it
  11481. if (recipe_book && recipe_book->GetLevel() > GetPlayer()->GetTSLevel()) {
  11482. if(item) {
  11483. Message(CHANNEL_NARRATIVE, "Your tradeskill level is not high enough to scribe this book.");
  11484. }
  11485. safe_delete(recipe_book);
  11486. }
  11487. else if(recipe_book && item && !recipe_book->CanUseRecipeByClass(item, GetPlayer()->GetTradeskillClass())) {
  11488. if(item) {
  11489. Message(CHANNEL_NARRATIVE, "Your tradeskill class cannot use this recipe.");
  11490. }
  11491. safe_delete(recipe_book);
  11492. }
  11493. else if (recipe_book && (!item || !(GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)))){
  11494. LogWrite(PLAYER__DEBUG, 0, "Recipe", "Valid recipe book that the player doesn't have");
  11495. // Add recipe book to the players list
  11496. if(!GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)) {
  11497. GetPlayer()->GetRecipeBookList()->AddRecipeBook(recipe_book);
  11498. }
  11499. std::vector<Recipe*> recipes;
  11500. // Get a list of all recipes this book contains
  11501. if (item && item->recipebook_info) {
  11502. //Backup I guess if the recipe book is empty for whatever reason?
  11503. for (auto& itr : item->recipebook_info->recipes) {
  11504. Recipe* r = master_recipe_list.GetRecipeByCRC(itr); //GetRecipeByName(itr.c_str());
  11505. if (r) {
  11506. recipes.push_back(r);
  11507. }
  11508. }
  11509. LogWrite(PLAYER__DEBUG, 0, "Recipe", "%i recipes found for %s book", recipes.size(), recipe_book->GetBookName());
  11510. }
  11511. else {
  11512. LogWrite(PLAYER__ERROR, 0, "Recipe", "no recipes found for %s book", recipe_book->GetBookName());
  11513. }
  11514. //Filter out duplicate recipes the player already has
  11515. for (auto itr = recipes.begin(); itr != recipes.end();) {
  11516. Recipe* recipe = *itr;
  11517. if (GetPlayer()->GetRecipeList()->GetRecipe(recipe->GetID())) {
  11518. itr = recipes.erase(itr);
  11519. }
  11520. else itr++;
  11521. }
  11522. int16 i = 0;
  11523. // Create the packet to send to update the players recipe list
  11524. PacketStruct* packet = 0;
  11525. if (!recipes.empty() && GetRecipeListSent()) {
  11526. packet = configReader.getStruct("WS_RecipeList", GetVersion());
  11527. if (packet) {
  11528. packet->setArrayLengthByName("num_recipes", recipes.size());
  11529. }
  11530. }
  11531. for (int32 r = 0; r < recipes.size(); r++) {
  11532. Recipe* recipe = recipes[r];
  11533. if (recipe) {
  11534. Recipe* player_recipe = new Recipe(recipe);
  11535. AddRecipeToPlayerPack(player_recipe, packet, &i);
  11536. }
  11537. }
  11538. LogWrite(TRADESKILL__DEBUG, 0, "Recipe", "Done adding recipes");
  11539. database.SavePlayerRecipeBook(GetPlayer(), recipe_book->GetBookID());
  11540. if(item) {
  11541. database.DeleteItem(GetCharacterID(), item, 0);
  11542. GetPlayer()->item_list.RemoveItem(item, true);
  11543. }
  11544. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  11545. SetRecipeListSent(false);
  11546. SendRecipeList();
  11547. safe_delete(packet);
  11548. return true;
  11549. }
  11550. else {
  11551. if (recipe_book && item) {
  11552. Message(CHANNEL_NARRATIVE, "You have already learned all you can from this item.");
  11553. }
  11554. safe_delete(recipe_book);
  11555. }
  11556. }
  11557. else {
  11558. LogWrite(PLAYER__ERROR, 0, "Player", "%u recipe book id does not exist. Cannot AddRecipeToPlayer.", recipe_book_id);
  11559. }
  11560. return false;
  11561. }
  11562. bool Client::RemoveRecipeFromPlayer(int32 recipe_id) {
  11563. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  11564. PacketStruct* packet = configReader.getStruct("WS_RecipeList", version);
  11565. Recipe* recipe = prl->GetRecipe(recipe_id);
  11566. int8 level = player->GetTSLevel();
  11567. if(packet && recipe) {
  11568. packet->setDataByName("command_type", 1);
  11569. packet->setArrayLengthByName("num_recipes", 1);
  11570. int32 myid = recipe->GetID();
  11571. int8 rlevel = recipe->GetLevel();
  11572. int8 even = level - level * .05 + .5;
  11573. int8 easymin = level - level * .25 + .5;
  11574. int8 veasymin = level - level * .35 + .5;
  11575. if (rlevel > level )
  11576. packet->setArrayDataByName("tier", 4, 0);
  11577. else if ((rlevel <= level) & (rlevel >= even))
  11578. packet->setArrayDataByName("tier", 3, 0);
  11579. else if ((rlevel <= even) & (rlevel >= easymin))
  11580. packet->setArrayDataByName("tier", 2, 0);
  11581. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  11582. packet->setArrayDataByName("tier", 1, 0);
  11583. else if ((rlevel <= veasymin) & (rlevel >= 0))
  11584. packet->setArrayDataByName("tier", 0, 0);
  11585. if (rlevel == 2)
  11586. int xxx = 1;
  11587. packet->setArrayDataByName("recipe_id", myid, 0);
  11588. packet->setArrayDataByName("level", recipe->GetLevel(), 0);
  11589. packet->setArrayDataByName("unknown1", recipe->GetLevel(), 0);
  11590. packet->setArrayDataByName("icon", recipe->GetIcon(), 0);
  11591. packet->setArrayDataByName("classes", recipe->GetClasses(), 0);
  11592. packet->setArrayDataByName("technique", recipe->GetTechnique(), 0);
  11593. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), 0);
  11594. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11595. if (recipe_device != devices.end())
  11596. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), 0);
  11597. else
  11598. {//TODO error should never get here
  11599. }
  11600. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), 0);
  11601. packet->setArrayDataByName("recipe_name", recipe->GetName(), 0);
  11602. packet->setArrayDataByName("recipe_book", recipe->GetBook(), 0);
  11603. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), 0);
  11604. QueuePacket(packet->serialize());
  11605. }
  11606. safe_delete(packet);
  11607. bool res = prl->RemoveRecipe(recipe_id);
  11608. if(res) {
  11609. Query query;
  11610. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "DELETE FROM character_recipes where char_id=%u and recipe_id=%u", GetCharacterID(), recipe_id);
  11611. }
  11612. return res;
  11613. }
  11614. void Client::SaveSpells() {
  11615. MSaveSpellStateMutex.lock();
  11616. player->SaveSpellEffects();
  11617. player->SetSaveSpellEffects(true);
  11618. MSaveSpellStateMutex.unlock();
  11619. }
  11620. void Client::SendReplaceWidget(int32 widget_id, bool delete_widget, float x, float y, float z, int32 grid_id) {
  11621. Widget* new_spawn = new Widget();
  11622. new_spawn->SetWidgetID(widget_id);
  11623. new_spawn->SetLocation(grid_id);
  11624. new_spawn->SetWidgetX(x);
  11625. new_spawn->SetWidgetY(y);
  11626. new_spawn->SetWidgetZ(z);
  11627. new_spawn->SetX(x);
  11628. new_spawn->SetY(y);
  11629. new_spawn->SetZ(z);
  11630. EQ2Packet* ret = new_spawn->serialize(GetPlayer(), GetVersion());
  11631. QueuePacket(ret);
  11632. // we have to delete spawn* references anyway, we don't keep this widget live in the spawn list
  11633. GetPlayer()->RemoveSpawn(new_spawn, delete_widget);
  11634. safe_delete(new_spawn);
  11635. }
  11636. void Client::ProcessZoneIgnoreWidgets() {
  11637. GetPlayer()->MIgnoredWidgets.lock_shared();
  11638. std::map<int32, bool>::iterator itr;
  11639. for(itr = GetPlayer()->ignored_widgets.begin(); itr != GetPlayer()->ignored_widgets.end(); itr++) {
  11640. SendReplaceWidget(itr->first, true);
  11641. }
  11642. GetPlayer()->MIgnoredWidgets.unlock_shared();
  11643. }
  11644. void Client::PopulateRecipeData(Recipe* recipe, PacketStruct* packet, int i) {
  11645. if(!recipe || !packet)
  11646. return;
  11647. int8 level = player->GetTSLevel();
  11648. int32 myid = recipe->GetID();
  11649. int8 rlevel = recipe->GetLevel();
  11650. int8 even = level - level * .05 + .5;
  11651. int8 easymin = level - level * .25 + .5;
  11652. int8 veasymin = level - level * .35 + .5;
  11653. if (rlevel > level )
  11654. packet->setArrayDataByName("tier", 4, i);
  11655. else if ((rlevel <= level) & (rlevel >= even))
  11656. packet->setArrayDataByName("tier", 3, i);
  11657. else if ((rlevel <= even) & (rlevel >= easymin))
  11658. packet->setArrayDataByName("tier", 2, i);
  11659. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  11660. packet->setArrayDataByName("tier", 1, i);
  11661. else if ((rlevel <= veasymin) & (rlevel >= 0))
  11662. packet->setArrayDataByName("tier", 0, i);
  11663. if (rlevel == 2)
  11664. int xxx = 1;
  11665. packet->setArrayDataByName("recipe_id", myid, i);
  11666. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  11667. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  11668. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  11669. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  11670. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  11671. packet->setArrayDataByName("device", recipe->GetDevice(), i);
  11672. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  11673. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  11674. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  11675. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  11676. packet->setArrayDataByName("book_volume", 0x01, i);
  11677. packet->setArrayDataByName("device_id", 0x01, i);
  11678. }
  11679. int32 Client::GetRecipeCRC(Recipe* recipe) {
  11680. PacketStruct* packet = 0;
  11681. if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
  11682. return 0;
  11683. }
  11684. packet->setArrayLengthByName("num_recipes", 1);
  11685. PopulateRecipeData(recipe, packet);
  11686. string* generic_string_data = packet->serializeString();
  11687. int32 size = generic_string_data->length();
  11688. if(size < 5)
  11689. return 0;
  11690. uchar* out_data = new uchar[size+1];
  11691. uchar* out_ptr = out_data;
  11692. memcpy(out_ptr, (uchar*)generic_string_data->c_str()+4, generic_string_data->length()-4);
  11693. uint32 out_crc = GenerateCRCRecipe(0, (void*)out_ptr, size-4);
  11694. safe_delete(packet);
  11695. safe_delete_array(out_data);
  11696. return out_crc;
  11697. }
  11698. void Client::SendRecipeDetails(vector<int32>* recipes) {
  11699. if(!recipes || recipes->size() == 0)
  11700. return;
  11701. PacketStruct* packet = 0;
  11702. if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
  11703. return;
  11704. }
  11705. int32 recipe_size = player->GetRecipeList()->Size();
  11706. packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
  11707. int16 i = 0;
  11708. int32 count = 0;
  11709. vector<int32>::iterator recipe_itr;
  11710. for(recipe_itr = recipes->begin(); recipe_itr != recipes->end(); recipe_itr++) {
  11711. Recipe* recipe = player->GetRecipeList()->GetRecipe(*recipe_itr);
  11712. if(!recipe) {
  11713. continue;
  11714. }
  11715. else if(i > 99) {
  11716. QueuePacket(packet->serialize());
  11717. safe_delete(packet);
  11718. packet = configReader.getStruct("WS_RecipeDetailList", GetVersion());
  11719. recipe_size -= i;
  11720. packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
  11721. i = 0;
  11722. }
  11723. count++;
  11724. PopulateRecipeData(recipe, packet, i);
  11725. i++;
  11726. }
  11727. //packet->PrintPacket();
  11728. QueuePacket(packet->serialize());
  11729. safe_delete(packet);
  11730. }
  11731. ZoneServer* Client::GetHouseZoneServer(int32 spawn_id, int64 house_id) {
  11732. PlayerHouse* ph = nullptr;
  11733. HouseZone* hz = nullptr;
  11734. if(spawn_id) {
  11735. Spawn* houseWidget = GetPlayer()->GetSpawnByIndex(spawn_id);
  11736. if(houseWidget && houseWidget->IsWidget() && ((Widget*)houseWidget)->GetHouseID()) {
  11737. hz = world.GetHouseZone(((Widget*)houseWidget)->GetHouseID());
  11738. if (hz) {
  11739. ph = world.GetPlayerHouseByHouseID(GetPlayer()->GetCharacterID(), hz->id);
  11740. } else {
  11741. Message(CHANNEL_COLOR_YELLOW, "HouseWidget spawn index %u house zone could not be found.", spawn_id);
  11742. }
  11743. }
  11744. }
  11745. if(!ph && house_id) {
  11746. ph = world.GetPlayerHouseByUniqueID(house_id);
  11747. if (ph) {
  11748. hz = world.GetHouseZone(ph->house_id);
  11749. }
  11750. }
  11751. if (ph && hz) {
  11752. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id, false, true);
  11753. return house;
  11754. }
  11755. return nullptr;
  11756. }
  11757. void Client::SendHearCast(Spawn* caster, Spawn* target, int32 spell_visual, int16 cast_time) {
  11758. PacketStruct* packet = configReader.getStruct("WS_HearCastSpell", GetVersion());
  11759. if (packet) {
  11760. int32 caster_id = GetPlayer()->GetIDWithPlayerSpawn(caster);
  11761. int32 target_id = GetPlayer()->GetIDWithPlayerSpawn(target);
  11762. packet->setDataByName("spawn_id", caster_id);
  11763. packet->setArrayLengthByName("num_targets", 1);
  11764. packet->setArrayDataByName("target", target_id);
  11765. packet->setDataByName("num_targets", 1);
  11766. int32 visual = GetSpellVisualOverride(spell_visual);
  11767. packet->setDataByName("spell_visual", visual); //result
  11768. packet->setDataByName("cast_time", cast_time*.01f); //delay
  11769. packet->setDataByName("spell_id", 1);
  11770. packet->setDataByName("spell_level", 1);
  11771. packet->setDataByName("spell_tier", 1);
  11772. EQ2Packet* outapp = packet->serialize();
  11773. //DumpPacket(outapp);
  11774. QueuePacket(outapp);
  11775. safe_delete(packet);
  11776. }
  11777. }
  11778. int32 Client::GetSpellVisualOverride(int32 spell_visual) {
  11779. int32 visual = spell_visual;
  11780. if(GetVersion() <= 561) { // spell's spell_visual field is based on newer clients, DoF has to convert
  11781. Emote* spellVisualEmote = visual_states.FindSpellVisualByID(visual, 60085);
  11782. if(spellVisualEmote != nullptr && spellVisualEmote->GetMessageString().size() > 0) {
  11783. spellVisualEmote = visual_states.FindSpellVisual(spellVisualEmote->GetMessageString(), GetVersion());
  11784. if(spellVisualEmote) {
  11785. visual = (int32)spellVisualEmote->GetVisualState();
  11786. }
  11787. }
  11788. }
  11789. return visual;
  11790. }