client.cpp 343 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834
  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 "IRC/IRC.h"
  36. #include "Chat/Chat.h"
  37. #include "SpellProcess.h"
  38. #include "Zone/ChestTrap.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. extern WorldDatabase database;
  81. extern const char* ZONE_NAME;
  82. extern LoginServer loginserver;
  83. extern sint32 numclients;
  84. extern NetConnection net;
  85. extern Commands commands;
  86. extern ClientList client_list;
  87. extern ZoneList zone_list;
  88. extern ZoneAuth zone_auth;
  89. extern MasterItemList master_item_list;
  90. extern MasterSkillList master_skill_list;
  91. extern MasterSpellList master_spell_list;
  92. extern MasterTraitList master_trait_list;
  93. extern MasterQuestList master_quest_list;
  94. extern MasterFactionList master_faction_list;
  95. extern MasterRecipeList master_recipe_list;
  96. extern volatile bool RunLoops;
  97. extern ConfigReader configReader;
  98. extern LuaInterface* lua_interface;
  99. extern World world;
  100. extern Variables variables;
  101. extern Classes classes;
  102. extern Races races;
  103. extern GuildList guild_list;
  104. extern MasterCollectionList master_collection_list;
  105. extern MasterAchievementList master_achievement_list;
  106. extern RuleManager rule_manager;
  107. extern IRC irc;
  108. extern Chat chat;
  109. extern MasterAAList master_aa_list;
  110. extern MasterAAList master_tree_nodes;
  111. extern ChestTrapList chest_trap_list;
  112. using namespace std;
  113. Client::Client(EQStream* ieqs) : pos_update(125), quest_pos_timer(2000), lua_debug_timer(30000), delayTimer(500), transmuteID(0) {
  114. eqs = ieqs;
  115. ip = eqs->GetrIP();
  116. port = ntohs(eqs->GetrPort());
  117. merchant_transaction = nullptr;
  118. SetMailTransaction(nullptr);
  119. timestamp_flag = 0;
  120. current_quest_id = 0;
  121. last_update_time = 0;
  122. quest_updates = false;
  123. //autobootup_timeout = new Timer(10000);
  124. //autobootup_timeout->Disable();
  125. CLE_keepalive_timer = new Timer(15000);
  126. connect = new Timer(1000);
  127. connect->Disable();
  128. zoneID = 0;
  129. account_name[0] = 0;
  130. character_id = 0;
  131. account_id = 0;
  132. pwaitingforbootup = 0;
  133. current_zone = 0;
  134. connected_to_zone = false;
  135. connected = false;
  136. camp_timer = 0;
  137. disconnect_timer = 0;
  138. client_zoning = false;
  139. player_pos_changed = false;
  140. ++numclients;
  141. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  142. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  143. remove_from_list = false;
  144. new_client_login = false;
  145. UpdateWindowTitle(0);
  146. num_active_failures = 0;
  147. player = new Player();
  148. player->SetClient(this);
  149. combine_spawn = 0;
  150. lua_debug = false;
  151. ready_for_spawns = false;
  152. ready_for_updates = false;
  153. lua_debug_timer.Disable();
  154. transport_spawn = 0;
  155. MBuyBack.SetName("Client::MBuyBack");
  156. MPendingQuestAccept.SetName("Client::MPendingQuestAccept");
  157. MDeletePlayer.SetName("Client::MDeletePlayer");
  158. MQuestPendingUpdates.SetName("Client::MQuestPendingUpdates");
  159. search_items = 0;
  160. version = 0;
  161. next_conversation_id = 0;
  162. pending_guild_invite.guild = 0;
  163. pending_guild_invite.invited_by = 0;
  164. m_recipeListSent = false;
  165. m_resurrect.SetName("Client::m_resurrect");
  166. current_rez.expire_timer = 0;
  167. current_rez.should_delete = true;
  168. pending_last_name = 0;
  169. should_target = false;
  170. initial_spawns_sent = false;
  171. MQuestTimers.SetName("Client::quest_timers");
  172. memset(&incoming_paperdoll, 0, sizeof(incoming_paperdoll));
  173. on_auto_mount = false;
  174. should_load_spells = true;
  175. spawnPlacementMode = ServerSpawnPlacementMode::DEFAULT;
  176. delayedLogin = false;
  177. delayedAccountID = 0;
  178. delayedAccessKey = 0;
  179. delayTimer.Disable();
  180. tempPlacementSpawn = nullptr;
  181. placement_unique_item_id = 0;
  182. SetHasOwnerOrEditAccess(false);
  183. temporary_transport_id = 0;
  184. rejoin_group_id = 0;
  185. lastRegionRemapTime = 0;
  186. regionDebugMessaging = false;
  187. }
  188. Client::~Client() {
  189. if (current_zone && player) {
  190. if (player->GetGroupMemberInfo())
  191. {
  192. if ((player->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0)
  193. world.GetGroupManager()->RemoveGroupMember(player->GetGroupMemberInfo()->group_id, player);
  194. else
  195. TempRemoveGroup();
  196. }
  197. world.GetGroupManager()->ClearPendingInvite(player);
  198. }
  199. if (lua_interface)
  200. lua_interface->RemoveDebugClients(this);
  201. if (player)
  202. zone_list.RemoveClientFromMap(player->GetName(), this);
  203. //let the stream factory know were done with this stream
  204. if (eqs) {
  205. eqs->Close();
  206. try {
  207. eqs->ReleaseFromUse();
  208. }
  209. catch (...) {}
  210. }
  211. eqs = NULL;
  212. //safe_delete(autobootup_timeout);
  213. safe_delete(disconnect_timer);
  214. safe_delete(camp_timer);
  215. safe_delete(CLE_keepalive_timer);
  216. safe_delete(connect);
  217. --numclients;
  218. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  219. if (player && !player->GetPendingDeletion())
  220. safe_delete(player);
  221. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  222. safe_delete(search_items);
  223. safe_delete(current_rez.expire_timer);
  224. safe_delete(pending_last_name);
  225. safe_delete_array(incoming_paperdoll.image_bytes);
  226. if (GetTempPlacementSpawn())
  227. {
  228. Spawn* tmp = GetTempPlacementSpawn();
  229. delete tmp;
  230. SetTempPlacementSpawn(nullptr);
  231. }
  232. UpdateWindowTitle(0);
  233. }
  234. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  235. if (eqs) {
  236. if (!eqs->CheckActive()) {
  237. client_list.Remove(this);
  238. eqs = 0;
  239. }
  240. }
  241. if (app && eqs && version > 0)
  242. eqs->EQ2QueuePacket(app, attemptedCombine);
  243. else {
  244. safe_delete(app);
  245. }
  246. }
  247. void Client::PopulateSkillMap() {
  248. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  249. if (app)
  250. QueuePacket(app);
  251. else {
  252. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  253. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  254. }
  255. }
  256. void Client::SendLoginInfo() {
  257. if (firstlogin) {
  258. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  259. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  260. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  261. PopulateSkillMap();
  262. // 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!
  263. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  264. }
  265. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  266. database.ToggleCharacterOnline(this, 1);
  267. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  268. int32 count = database.LoadCharacterSkills(GetCharacterID(), player);
  269. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
  270. count = database.LoadCharacterSpells(GetCharacterID(), player);
  271. // get the latest character starting skills / spells, may have been updated after character creation
  272. world.SyncCharacterAbilities(this);
  273. count = database.LoadCharacterTitles(GetCharacterID(), player);
  274. if (count == 0) {
  275. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  276. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  277. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  278. }
  279. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  280. if (count == 0)
  281. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  282. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  283. if (count == 0)
  284. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  285. ClientPacketFunctions::SendLoginAccepted(this);
  286. ClientPacketFunctions::SendAbilities ( this );
  287. ClientPacketFunctions::SendCommandNamePacket(this);
  288. ClientPacketFunctions::SendQuickBarInit(this);
  289. // we only need to send the MOTD if it is the first time the person is logging in.
  290. if (firstlogin) {
  291. ClientPacketFunctions::SendMOTD(this);
  292. ClientPacketFunctions::SendCharacterMacros(this);
  293. zone_list.CheckFriendList(this);
  294. }
  295. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  296. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  297. {
  298. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  299. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  300. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  301. }
  302. database.LoadPlayerFactions(this);
  303. database.LoadCharacterQuests(this);
  304. database.LoadPlayerMail(this);
  305. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  306. SendQuestJournal(true, 0, false);
  307. if (version > 546) // right version? possibly not!
  308. master_aa_list.DisplayAA(this, 0, 3);
  309. if (version > 283)
  310. SendCollectionList();
  311. SendBiography();
  312. map<int32, Quest*>::iterator itr;
  313. Quest* quest = 0;
  314. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  315. quest = itr->second;
  316. if (quest->IsTracked()) {
  317. quest->SetTracked(false);
  318. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  319. quest->SetTracked(true);
  320. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  321. }
  322. }
  323. // SendAchievementsList();
  324. /*Guild* guild = player->GetGuild();
  325. if (guild) {
  326. guild->UpdateGuildMemberInfo(GetPlayer());
  327. if (firstlogin)
  328. guild->SendGuildMOTD(this);
  329. guild->SendGuildUpdate(this);
  330. guild->SendGuildMember(GetPlayer(), firstlogin);
  331. guild->SendGuildEventList(this);
  332. guild->SendGuildBankEventList(this);
  333. guild->SendAllGuildEvents(this);
  334. guild->SendGuildMemberList(this);
  335. }*/
  336. if (version > 283) {
  337. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  338. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  339. if (outapp) {
  340. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  341. //DumpPacket(outapp);
  342. QueuePacket(outapp);
  343. }
  344. }
  345. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  346. ClientPacketFunctions::SendCommandList(this);
  347. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  348. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  349. ClientPacketFunctions::SendInstanceList(this);
  350. SendZoneInfo();
  351. /*Spell* spell = 0;
  352. vector<QuickBarItem*>::iterator itr;
  353. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  354. if((*itr)->type == 1){
  355. spell = master_spell_list.GetSpell((*itr)->id);
  356. if(spell)
  357. QueuePacket(spell->serialize(this, false, 0x20));
  358. }
  359. }*/
  360. }
  361. void Client::SendPlayerDeathWindow()
  362. {
  363. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  364. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  365. vector<RevivePoint*>::iterator itr;
  366. if (results && results->size() > 0)
  367. {
  368. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  369. if (packet)
  370. {
  371. packet->setArrayLengthByName("location_count", results->size());
  372. RevivePoint* point = 0;
  373. int32 i = 0;
  374. for (itr = results->begin(); itr != results->end(); itr++, i++)
  375. {
  376. point = *itr;
  377. if (point)
  378. {
  379. packet->setArrayDataByName("location_id", point->id, i);
  380. //zone_name = database.GetZoneName(point->zone_id);
  381. string zone_name = database.GetZoneDescription(point->zone_id);
  382. if (zone_name.length() > 0)
  383. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  384. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  385. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  386. }
  387. if (point->id == 0xFFFFFFFF)//tmp location
  388. safe_delete(point);
  389. }
  390. // done with the revive points so lets free up the pointer
  391. safe_delete(results);
  392. #if EQDEBUG >= 3
  393. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  394. packet->PrintPacket();
  395. #endif
  396. EQ2Packet* outapp = packet->serialize();
  397. QueuePacket(outapp);
  398. safe_delete(packet);
  399. }
  400. }
  401. }
  402. void Client::DisplayDeadWindow()
  403. {
  404. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  405. player->SetHP(0);
  406. player->SetPower(0);
  407. GetCurrentZone()->TriggerCharSheetTimer();
  408. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  409. if (packet)
  410. {
  411. packet->setDataByName("parameter1", 8);
  412. packet->setDataByName("value", 1);
  413. QueuePacket(packet->serialize());
  414. packet->setDataByName("parameter1", 16);
  415. QueuePacket(packet->serialize());
  416. safe_delete(packet);
  417. }
  418. packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  419. if (packet)
  420. {
  421. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  422. QueuePacket(packet->serialize());
  423. safe_delete(packet);
  424. }
  425. SendPlayerDeathWindow();
  426. }
  427. void Client::HandlePlayerRevive(int32 point_id)
  428. {
  429. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  430. if (packet)
  431. {
  432. packet->setDataByName("parameter1", 8);
  433. QueuePacket(packet->serialize());
  434. packet->setDataByName("parameter1", 16);
  435. QueuePacket(packet->serialize());
  436. safe_delete(packet);
  437. }
  438. SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
  439. packet = configReader.getStruct("WS_Resurrected", GetVersion());
  440. if (packet)
  441. {
  442. QueuePacket(packet->serialize());
  443. safe_delete(packet);
  444. }
  445. float x, y, z, heading;
  446. RevivePoint* revive_point = 0;
  447. if (point_id != 0xFFFFFFFF)
  448. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  449. string zone_desc;
  450. const char* location_name = "Unknown";
  451. //revive at zone safe coords
  452. if (!revive_point)
  453. {
  454. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  455. x = GetCurrentZone()->GetSafeX();
  456. y = GetCurrentZone()->GetSafeY();
  457. z = GetCurrentZone()->GetSafeZ();
  458. heading = GetCurrentZone()->GetSafeHeading();
  459. zone_desc = GetCurrentZone()->GetZoneDescription();
  460. location_name = "Zone Safe Point";
  461. Zone(GetCurrentZone()->GetZoneName(), false);
  462. }
  463. else
  464. {
  465. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  466. x = revive_point->x;
  467. y = revive_point->y;
  468. z = revive_point->z;
  469. heading = revive_point->heading;
  470. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  471. location_name = revive_point->location_name.c_str();
  472. Zone(GetCurrentZone()->GetZoneName(), false);
  473. }
  474. player->SetResurrecting(true);
  475. player->SetX(x);
  476. player->SetY(y);
  477. player->SetZ(z);
  478. player->SetHeading(heading);
  479. player->SetHP(player->GetTotalHP());
  480. player->SetPower(player->GetTotalPower());
  481. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  482. zone_desc.c_str(),
  483. player->GetX(),
  484. player->GetY(),
  485. player->GetZ(),
  486. player->GetHeading(),
  487. player->GetHP(),
  488. player->GetPower(),
  489. location_name);
  490. //player->ClearEverything();
  491. Save();
  492. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  493. {
  494. string zone_name = database.GetZoneName(revive_point->zone_id);
  495. if (zone_name.length() == 0)
  496. {
  497. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  498. x = GetCurrentZone()->GetSafeX();
  499. y = GetCurrentZone()->GetSafeY();
  500. z = GetCurrentZone()->GetSafeZ();
  501. heading = GetCurrentZone()->GetSafeHeading();
  502. location_name = "Zone Safe Point";
  503. }
  504. else
  505. {
  506. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  507. location_name = revive_point->location_name.c_str();
  508. player->ClearEverything();
  509. Zone(zone_name.c_str(), false);
  510. }
  511. }
  512. zone_desc = GetCurrentZone()->GetZoneDescription();
  513. Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  514. player->SetSpawnType(4);
  515. if (version > 283) {
  516. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  517. if (packet)
  518. {
  519. QueuePacket(packet->serialize());
  520. safe_delete(packet);
  521. }
  522. }
  523. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  524. if (packet)
  525. {
  526. packet->setDataByName("x", x);
  527. packet->setDataByName("y", y);
  528. packet->setDataByName("z", z);
  529. QueuePacket(packet->serialize());
  530. safe_delete(packet);
  531. }
  532. packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  533. if (packet)
  534. {
  535. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  536. packet->setDataByName("speed", 32);
  537. packet->setDataByName("unknown2", 0);
  538. //DoF Merge: old value and speed wasn't included
  539. //packet->setDataByName("unknown2", 255);
  540. QueuePacket(packet->serialize());
  541. safe_delete(packet);
  542. }
  543. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  544. if (packet)
  545. {
  546. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  547. QueuePacket(packet->serialize());
  548. safe_delete(packet);
  549. }
  550. GetCurrentZone()->RemoveSpawn(false, player, false);
  551. m_resurrect.writelock(__FUNCTION__, __LINE__);
  552. if (current_rez.active)
  553. current_rez.should_delete = true;
  554. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  555. }
  556. void Client::SendCharInfo() {
  557. EQ2Packet* app;
  558. player->SetEquippedItemAppearances();
  559. ClientPacketFunctions::SendCharacterData(this);
  560. SendCharPOVGhost();
  561. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  562. if (packet) {
  563. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  564. packet->setDataByName("size", .56);
  565. packet->setDataByName("unknown2", 255);
  566. packet->setDataByName("speed", player->GetSpeed());
  567. packet->setDataByName("air_speed", player->GetAirSpeed());
  568. EQ2Packet* app = packet->serialize();
  569. QueuePacket(app);
  570. safe_delete(packet);
  571. }
  572. if (version <= 283) {
  573. //le: hack to allow client time to zone in, it gets stuck on Loading UI Resources if we go too fast, need to figure it out. Probably something it doesnt like with ExamineInfo packets
  574. Sleep(2000);
  575. }
  576. //sending bad spawn packet?
  577. //SendAchievementsList();
  578. ClientPacketFunctions::SendCharacterSheet(this);
  579. ClientPacketFunctions::SendTraitList(this);// moved from below
  580. ClientPacketFunctions::SendAbilities(this);
  581. ClientPacketFunctions::SendSkillBook(this);
  582. if (!player->IsResurrecting()) {
  583. if(GetVersion() > 546) //we will send this later on for 546 and below
  584. ClientPacketFunctions::SendUpdateSpellBook(this);
  585. }
  586. else {
  587. player->SetResurrecting(false);
  588. }
  589. ClientPacketFunctions::SendLoginCommandMessages(this);
  590. GetCurrentZone()->AddSpawn(player);
  591. //SendCollectionList();
  592. Guild* guild = player->GetGuild();
  593. if (guild)
  594. guild->GuildMemberLogin(this, firstlogin);
  595. app = player->item_list.serialize(GetPlayer(), GetVersion());
  596. if (app) {
  597. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  598. //DumpPacket(app);
  599. QueuePacket(app);
  600. }
  601. app = player->GetEquipmentList()->serialize(GetVersion());
  602. if (app) {
  603. QueuePacket(app);
  604. }
  605. vector<Item*>* items = player->item_list.GetItemsFromBagID(-3); // bank items
  606. if (items && items->size() > 0) {
  607. for (int32 i = 0; i < items->size(); i++) {
  608. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  609. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  610. //DumpPacket(outapp);
  611. QueuePacket(outapp);
  612. }
  613. }
  614. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  615. QueuePacket(app);
  616. safe_delete(items);
  617. items = player->item_list.GetItemsFromBagID(-4); //shared bank items
  618. if (items && items->size() > 0) {
  619. for (int32 i = 0; i < items->size(); i++)
  620. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  621. }
  622. safe_delete(items);
  623. if (version > 283) {
  624. SendTitleUpdate();
  625. }
  626. GetPlayer()->ChangePrimaryWeapon();
  627. GetPlayer()->ChangeSecondaryWeapon();
  628. GetPlayer()->ChangeRangedWeapon();
  629. database.LoadBuyBacks(this);
  630. if (version > 546)
  631. master_aa_list.DisplayAA(this, 0, 0);
  632. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  633. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  634. string zone_motd_send = "Zone MOTD: " + zone_motd;
  635. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  636. }
  637. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  638. if (zone_script && lua_interface)
  639. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  640. this->client_zoning = false;
  641. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  642. GetCurrentZone()->AddDamagedSpawn(player);
  643. if (firstlogin && rule_manager.GetGlobalRule(R_World, IRCGlobalEnabled)->GetBool())
  644. Message(CHANNEL_BROADCAST, "This server has a global IRC channel, join the world channel %s to use", rule_manager.GetGlobalRule(R_World, IRCChan)->GetString());
  645. if (firstlogin)
  646. firstlogin = false;
  647. player->ClearProcs();
  648. items = player->GetEquippedItemList();
  649. if (items && items->size() > 0) {
  650. for (int32 i = 0; i < items->size(); i++) {
  651. Item* item = items->at(i);
  652. if (item && item->GetItemScript() && lua_interface)
  653. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  654. }
  655. }
  656. //Allow this player to change their last name if they meet the level requirement
  657. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  658. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  659. safe_delete(items);
  660. if (!player->Alive())
  661. DisplayDeadWindow();
  662. ClientPacketFunctions::SendLocalizedTextMessage(this);
  663. if (GetCurrentZone()->GetInstanceID())
  664. {
  665. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  666. if (ph) {
  667. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  668. string name = string(GetPlayer()->GetName());
  669. if (name.compare(ph->player_name) == 0)
  670. SetHasOwnerOrEditAccess(true);
  671. }
  672. }
  673. if (version > 546)
  674. ClientPacketFunctions::SendHousingList(this);
  675. }
  676. void Client::SendZoneSpawns() {
  677. //Allows us to place spawns almost anywhere
  678. if (version > 283) {
  679. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  680. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  681. QueuePacket(app);
  682. }
  683. ClientPacketFunctions::SendSkillSlotMappings(this);
  684. ClientPacketFunctions::SendGameWorldTime(this);
  685. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  686. }
  687. void Client::SendCharPOVGhost() {
  688. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  689. if (set_pov) {
  690. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  691. EQ2Packet* app_pov = set_pov->serialize();
  692. QueuePacket(app_pov);
  693. safe_delete(set_pov);
  694. }
  695. }
  696. void Client::SendZoneInfo() {
  697. ZoneServer* zone = GetCurrentZone();
  698. if (zone) {
  699. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  700. QueuePacket(packet);
  701. if (version > 283) {
  702. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  703. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  704. #if EQDEBUG >= 9
  705. fog_packet->PrintPacket();
  706. #endif
  707. if (fog_packet) {
  708. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  709. QueuePacket(fog_packet->serialize());
  710. safe_delete(fog_packet);
  711. }
  712. zone->SendFlightPathsPackets(this);
  713. }
  714. }
  715. /*
  716. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  717. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  718. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  719. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  720. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  721. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  722. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  723. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  724. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  725. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  726. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  727. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  728. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  729. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  730. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  731. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  732. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  733. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  734. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  735. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  736. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  737. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  738. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  739. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  740. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  741. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  742. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  743. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  744. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  745. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  746. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  747. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  748. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  749. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  750. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  751. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
  752. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  753. QueuePacket(appA);
  754. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  755. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  756. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  757. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  758. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  759. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  760. QueuePacket(appB);
  761. */
  762. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  763. SendFriendList();
  764. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  765. SendIgnoreList();
  766. }
  767. void Client::SendDefaultGroupOptions() {
  768. /*
  769. 0 - loot method
  770. 1 - loot items rarity
  771. 2 - Auto split coin
  772. 4 - default yell method
  773. 6 - group autolock
  774. 7 - solo autolock
  775. */
  776. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  777. if (default_options) {
  778. default_options->setDataByName("loot_method", 1);
  779. default_options->setDataByName("loot_items_rarity", 1);
  780. default_options->setDataByName("auto_split_coin", 1);
  781. default_options->setDataByName("default_yell_method", 1);
  782. EQ2Packet* app7 = default_options->serialize();
  783. QueuePacket(app7);
  784. safe_delete(default_options);
  785. }
  786. }
  787. bool Client::HandlePacket(EQApplicationPacket* app) {
  788. bool ret = true;
  789. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  790. //DumpPacket(app);
  791. #if EQDEBUG >= 9
  792. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  793. DumpPacket(app, true);
  794. #endif
  795. EmuOpcode opcode = app->GetOpcode();
  796. #if EQDEBUG >= 9
  797. const char* name = app->GetOpcodeName();
  798. if (name)
  799. cout << name;
  800. else
  801. cout << "Unknown";
  802. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  803. DumpPacket(app);
  804. #endif
  805. //if (opcode != OP_UpdatePositionMsg) {
  806. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  807. //}
  808. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  809. {
  810. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  811. }
  812. switch (opcode) {
  813. case _maxEmuOpcode:
  814. break;
  815. case OP_LoginByNumRequestMsg: {
  816. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  817. PacketStruct* request;
  818. request = configReader.getStruct("LoginByNumRequest", 1);
  819. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  820. // test the original location of Version for clients older than 1212
  821. version = request->getType_int16_ByName("version");
  822. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  823. // must be new client data version method, re-fetch the packet
  824. safe_delete(request);
  825. request = configReader.getStruct("LoginByNumRequest", 1208);
  826. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  827. // Xinux suggests using an INT16 here. Our first new version = 57000
  828. version = request->getType_int16_ByName("version");
  829. }
  830. else {
  831. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  832. break;
  833. }
  834. }
  835. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  836. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  837. ClientPacketFunctions::SendLoginDenied(this);
  838. return false;
  839. }
  840. int32 account_id = request->getType_int32_ByName("account_id");
  841. int32 access_code = request->getType_int32_ByName("access_code");
  842. if (!HandleNewLogin(account_id, access_code))
  843. return false;
  844. }
  845. safe_delete(request);
  846. break;
  847. }
  848. case OP_SysClient: {
  849. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient", opcode, opcode);
  850. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  851. SetReadyForUpdates();
  852. break;
  853. }
  854. case OP_MapRequest: {
  855. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  856. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  857. if (packet && app->size > 2 && GetCurrentZone()) {
  858. packet->LoadPacketData(app->pBuffer, app->size);
  859. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  860. if (fog_packet) {
  861. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  862. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  863. fog_packet->setDataByName("unknown1", 1);
  864. fog_packet->setDataByName("unknown3", 1);
  865. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  866. //fog_packet->PrintPacket();
  867. QueuePacket(fog_packet->serialize());
  868. safe_delete(fog_packet);
  869. }
  870. safe_delete(packet);
  871. }
  872. break;
  873. }
  874. case OP_RequestCampMsg: {
  875. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  876. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  877. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  878. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  879. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  880. request->getType_int8_ByName("quit"),
  881. request->getType_int8_ByName("camp_desktop"),
  882. request->getType_int16_ByName("camp_char_select"),
  883. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  884. //DumpPacket(app->pBuffer, app->size);
  885. //request->PrintPacket();
  886. if (!camp_timer) {
  887. int16 camp_time = 20; // default if rule cannot be found
  888. if (GetAdminStatus() >= 100)
  889. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  890. else
  891. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  892. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  893. if (response) {
  894. bool disconnect = false;
  895. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  896. // Command: /camp desktop
  897. // Command: /quit
  898. response->setDataByName("camp_desktop", 1);
  899. disconnect = true;
  900. }
  901. else {
  902. // Command: /camp
  903. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  904. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  905. response->setDataByName("seconds", camp_time);
  906. }
  907. camp_timer = new Timer(camp_time * 1000);
  908. camp_timer->Enable();
  909. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  910. // /camp {char_name}
  911. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  912. }
  913. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  914. // /camp (go back to char selection screen)
  915. response->setDataByName("char_name", " ");
  916. response->setDataByName("camp_char_select", 1);
  917. }
  918. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  919. response->getType_int8_ByName("seconds"),
  920. response->getType_int8_ByName("camp_desktop"),
  921. response->getType_int8_ByName("camp_char_select"),
  922. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  923. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  924. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  925. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  926. //response->PrintPacket();
  927. QueuePacket(response->serialize());
  928. safe_delete(response);
  929. if (disconnect)
  930. Disconnect();
  931. }
  932. }
  933. }
  934. safe_delete(request);
  935. break;
  936. }
  937. case OP_StoodMsg: {
  938. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  939. if (camp_timer)
  940. {
  941. // JA: clear camping flag
  942. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  943. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  944. safe_delete(camp_timer);
  945. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  946. QueuePacket(outapp);
  947. }
  948. player->SetTempVisualState(0);
  949. break;
  950. }
  951. case OP_StandMsg: {
  952. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  953. if (camp_timer)
  954. {
  955. // JA: clear camping flag
  956. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  957. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  958. safe_delete(camp_timer);
  959. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  960. QueuePacket(outapp);
  961. }
  962. player->SetTempVisualState(539);
  963. break;
  964. }
  965. case OP_SitMsg: {
  966. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  967. player->SetTempVisualState(538);
  968. break;
  969. }
  970. case OP_SatMsg: {
  971. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  972. player->SetTempVisualState(540);
  973. break;
  974. }
  975. case OP_QuestJournalOpenMsg:
  976. case OP_QuestJournalInspectMsg: {
  977. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  978. if (app->size < sizeof(int32))
  979. break;
  980. int32 quest_id = 0;
  981. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  982. Quest* quest = GetActiveQuest(quest_id);
  983. if (quest)
  984. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  985. else {
  986. quest = player->GetCompletedQuest(quest_id);
  987. if (quest)
  988. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, 0, 1, true));
  989. }
  990. break;
  991. }
  992. case OP_QuestJournalSetVisibleMsg: {
  993. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  994. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  995. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  996. int32 quest_id = packet->getType_int32_ByName("quest_id");
  997. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  998. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  999. if (player_quests) {
  1000. if (player_quests->count(quest_id) > 0)
  1001. player_quests->at(quest_id)->SetHidden(hidden);
  1002. else
  1003. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1004. }
  1005. else
  1006. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1007. safe_delete(packet);
  1008. }
  1009. break;
  1010. }
  1011. case OP_MacroUpdateMsg: {
  1012. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1013. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1014. if (macro_update && macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1015. vector<string>* update = new vector<string>;
  1016. int8 number = macro_update->getType_int8_ByName("number");
  1017. int16 icon = macro_update->getType_int16_ByName("icon");
  1018. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1019. int8 count = macro_update->getType_int8_ByName("macro_count");
  1020. if (GetVersion() <= 283) {
  1021. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1022. }
  1023. else {
  1024. for (int8 i = 0; i < count; i++) {
  1025. char tmp_command[15] = { 0 };
  1026. sprintf(tmp_command, "command_%i", i);
  1027. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1028. }
  1029. }
  1030. if (name.length() == 0)
  1031. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1032. else
  1033. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1034. safe_delete(update);
  1035. safe_delete(macro_update);
  1036. }
  1037. break;
  1038. }
  1039. case OP_DialogSelectMsg: {
  1040. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1041. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1042. if (packet) {
  1043. packet->LoadPacketData(app->pBuffer, app->size);
  1044. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1045. int32 response_index = packet->getType_int32_ByName("response");
  1046. if (GetCurrentZone()) {
  1047. Spawn* spawn = conversation_spawns[conversation_id];
  1048. Item* item = conversation_items[conversation_id];
  1049. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  1050. if (spawn)
  1051. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation_map[conversation_id][response_index].c_str());
  1052. else if (item && lua_interface && item->GetItemScript())
  1053. lua_interface->RunItemScript(item->GetItemScript(), conversation_map[conversation_id][response_index].c_str(), item, player);
  1054. }
  1055. else
  1056. CloseDialog(conversation_id);
  1057. }
  1058. safe_delete(packet);
  1059. }
  1060. break;
  1061. }
  1062. case OP_CancelMoveObjectModeMsg: {
  1063. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1064. if (GetTempPlacementSpawn())
  1065. {
  1066. Spawn* tmp = GetTempPlacementSpawn();
  1067. GetCurrentZone()->RemoveSpawn(false, tmp);
  1068. delete tmp;
  1069. SetTempPlacementSpawn(nullptr);
  1070. SetPlacementUniqueItemID(0);
  1071. break; // break out early if we are tied to a temp spawn
  1072. }
  1073. // if we are moving some other object? other use-cases not covered
  1074. break;
  1075. }
  1076. case OP_PositionMoveableObject: {
  1077. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1078. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1079. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1080. Spawn* spawn = 0;
  1081. if (GetTempPlacementSpawn())
  1082. spawn = GetTempPlacementSpawn();
  1083. else
  1084. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1085. if (!spawn) {
  1086. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1087. break;
  1088. }
  1089. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1090. {
  1091. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1092. break;
  1093. }
  1094. // handles instantiation logic + adding to zone of a new house object
  1095. PopulateHouseSpawn(place_object);
  1096. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1097. char query[256];
  1098. switch (GetSpawnPlacementMode())
  1099. {
  1100. case ServerSpawnPlacementMode::OPEN_HEADING:
  1101. {
  1102. if (spawn && spawn->IsWidget())
  1103. {
  1104. Widget* widget = (Widget*)spawn;
  1105. widget->SetOpenHeading(newHeading);
  1106. widget->SetIncludeHeading(true);
  1107. spawn->position_changed = true;
  1108. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1109. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1110. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1111. }
  1112. else
  1113. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1114. break;
  1115. }
  1116. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1117. {
  1118. if (spawn && spawn->IsWidget())
  1119. {
  1120. Widget* widget = (Widget*)spawn;
  1121. widget->SetClosedHeading(newHeading);
  1122. widget->SetIncludeHeading(true);
  1123. spawn->position_changed = true;
  1124. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1125. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1126. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1127. if (spawn->GetSpawnLocationID())
  1128. {
  1129. Query query;
  1130. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1131. }
  1132. }
  1133. else
  1134. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1135. break;
  1136. }
  1137. default:
  1138. {
  1139. spawn->SetX(place_object->getType_float_ByName("x"));
  1140. spawn->SetY(place_object->getType_float_ByName("y"));
  1141. spawn->SetZ(place_object->getType_float_ByName("z"));
  1142. spawn->SetHeading(newHeading);
  1143. spawn->SetSpawnOrigX(spawn->GetX());
  1144. spawn->SetSpawnOrigY(spawn->GetY());
  1145. spawn->SetSpawnOrigZ(spawn->GetZ());
  1146. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1147. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1148. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1149. else if (spawn->GetSpawnLocationID() > 0)
  1150. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1151. }
  1152. }
  1153. PopulateHouseSpawnFinalize();
  1154. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1155. safe_delete(place_object);
  1156. }
  1157. break;
  1158. }
  1159. case OP_CampAbortedMsg: {
  1160. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1161. if (camp_timer)
  1162. {
  1163. // JA: clear camping flag
  1164. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1165. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1166. safe_delete(camp_timer);
  1167. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1168. QueuePacket(outapp);
  1169. }
  1170. break;
  1171. }
  1172. case OP_DoneLoadingUIResourcesMsg: {
  1173. ClientPacketFunctions::SendUpdateSpellBook(this);
  1174. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1175. QueuePacket(app);
  1176. break;
  1177. }
  1178. case OP_DoneLoadingZoneResourcesMsg: {
  1179. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1180. SendZoneSpawns();
  1181. break;
  1182. }
  1183. case OP_DefaultGroupOptionsRequestMsg: {
  1184. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1185. SendDefaultGroupOptions();
  1186. break;
  1187. }
  1188. case OP_DoneLoadingEntityResourcesMsg: {
  1189. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1190. if (!IsReadyForSpawns())
  1191. SetReadyForSpawns(true);
  1192. SendCharInfo();
  1193. world.RejoinGroup(this, rejoin_group_id);
  1194. pos_update.Start();
  1195. quest_pos_timer.Start();
  1196. break;
  1197. }
  1198. case OP_LootItemsRequestMsg: {
  1199. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1200. HandleLoot(app);
  1201. break;
  1202. }
  1203. case OP_WaypointSelectMsg: {
  1204. PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
  1205. if (packet) {
  1206. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1207. int32 selection = packet->getType_int32_ByName("selection");
  1208. if (selection > 0) {
  1209. SelectWaypoint(selection);
  1210. }
  1211. }
  1212. }
  1213. break;
  1214. }
  1215. case OP_KnowledgeWindowSlotMappingMsg: {
  1216. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1217. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1218. if (packet) {
  1219. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1220. int num_updates = packet->getType_int16_ByName("spell_count");
  1221. int32 spell_id = 0;
  1222. int16 slot_id = 0;
  1223. char tmp_spell_id[15];
  1224. char tmp_slot[15];
  1225. for (int i = 0; i < num_updates; i++) {
  1226. memset(tmp_spell_id, 0, 15);
  1227. memset(tmp_slot, 0, 15);
  1228. sprintf(tmp_spell_id, "spell_id_%i", i);
  1229. sprintf(tmp_slot, "slot_id_%i", i);
  1230. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1231. if (spell_id > 0) {
  1232. slot_id = packet->getType_int16_ByName(tmp_slot);
  1233. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1234. if (spell && spell->slot != slot_id) {
  1235. spell->slot = slot_id;
  1236. spell->save_needed = true;
  1237. }
  1238. }
  1239. }
  1240. }
  1241. safe_delete(packet);
  1242. }
  1243. //SendKnowledgeWindowSlot();
  1244. break;
  1245. }
  1246. case OP_ReadyToZoneMsg: {
  1247. if (!IsReadyForSpawns())
  1248. {
  1249. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1250. }
  1251. else
  1252. {
  1253. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1254. if (client_zoning)
  1255. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1256. else
  1257. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1258. Disconnect();
  1259. }
  1260. break;
  1261. }
  1262. case OP_ClientFellMsg: {
  1263. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1264. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1265. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1266. float height = request->getType_float_ByName("height");
  1267. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1268. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1269. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1270. break;
  1271. }*/
  1272. float safe_height = 13.0f;
  1273. Skill* skill = GetPlayer()->GetSkillByName("Safe Fall", true);
  1274. if (skill)
  1275. safe_height += (skill->current_val + 1) / 5;
  1276. if (height > safe_height) {
  1277. int16 damage = (int16)ceil((height - safe_height) * 125);
  1278. if (height >= 80)
  1279. damage = 30000;
  1280. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1281. if (damage > 0) {
  1282. GetPlayer()->TakeDamage(damage);
  1283. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1284. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1285. if (!GetPlayer()->GetInvulnerable())
  1286. GetPlayer()->SetCharSheetChanged(true);
  1287. 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);
  1288. if (GetPlayer()->GetHP() == 0) {
  1289. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1290. }
  1291. }
  1292. }
  1293. safe_delete(request);
  1294. }
  1295. break;
  1296. }
  1297. case OP_MapFogDataUpdateMsg: {
  1298. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1299. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1300. break;
  1301. }
  1302. case OP_SelectZoneTeleporterDestinatio: {
  1303. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1304. ProcessTeleportLocation(app);
  1305. break;
  1306. }
  1307. case OP_SendLatestRequestMsg: {
  1308. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1309. uchar blah25[] = { 0x01 };
  1310. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1311. QueuePacket(app25);
  1312. break;
  1313. }
  1314. case OP_ShowCreateFromRecipeUIMsg: {
  1315. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1316. break;
  1317. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1318. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1319. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1320. QueuePacket(app);
  1321. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1322. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1323. QueuePacket(app);
  1324. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1325. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1326. ,0xff,0xff,0xff};
  1327. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1328. QueuePacket(app);
  1329. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1330. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1331. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1332. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1333. QueuePacket(app);
  1334. uchar blah5[] ={0x00,0x00};
  1335. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1336. QueuePacket(app);
  1337. break;*/
  1338. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1339. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1340. //QueuePacket(app);
  1341. }
  1342. case OP_BeginItemCreationMsg: {
  1343. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1344. //DumpPacket(app->pBuffer, app->size);
  1345. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1346. if (packet) {
  1347. packet->LoadPacketData(app->pBuffer, app->size);
  1348. int32 item = 0;
  1349. vector<int32> items;
  1350. char tmp_item_id[20];
  1351. item = packet->getType_int32_ByName("primary_component_id");
  1352. if (item > 0)
  1353. items.push_back(item);
  1354. item = 0;
  1355. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1356. for (int8 i = 0; i < build_components; i++) {
  1357. memset(tmp_item_id, 0, 20);
  1358. sprintf(tmp_item_id, "component_id_%i", i);
  1359. item = packet->getType_int32_ByName(tmp_item_id);
  1360. if (item > 0)
  1361. items.push_back(item);
  1362. item = 0;
  1363. }
  1364. item = packet->getType_int32_ByName("fuel_id");
  1365. if (item > 0)
  1366. items.push_back(item);
  1367. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1368. safe_delete(packet);
  1369. }
  1370. break;
  1371. }
  1372. case OP_StopItemCreationMsg: {
  1373. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1374. //DumpPacket(app->pBuffer, app->size);
  1375. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1376. break;
  1377. }
  1378. case OP_SignalMsg: {
  1379. PacketStruct* packet = configReader.getStruct("WS_Signal", GetVersion());
  1380. if (packet) {
  1381. packet->LoadPacketData(app->pBuffer, app->size);
  1382. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1383. if (str.size > 0) {
  1384. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1385. SetReadyForUpdates();
  1386. GetPlayer()->SendSpawnChanges(true);
  1387. }
  1388. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1389. if (zone_script && lua_interface)
  1390. {
  1391. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1392. }
  1393. }
  1394. }
  1395. break;
  1396. }
  1397. case OP_EntityVerbsRequestMsg: {
  1398. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1399. HandleVerbRequest(app);
  1400. break;
  1401. }
  1402. case OP_EntityVerbsVerbMsg: {
  1403. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1404. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1405. if (packet) {
  1406. packet->LoadPacketData(app->pBuffer, app->size);
  1407. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1408. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1409. Spawn* spawn = player->GetTarget();
  1410. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1411. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1412. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1413. {
  1414. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1415. if (spawn->IsGroundSpawn())
  1416. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1417. else if (spawn->IsObject())
  1418. ((Object*)spawn)->HandleUse(this, command);
  1419. else if (spawn->IsWidget())
  1420. ((Widget*)spawn)->HandleUse(this, command);
  1421. else if (spawn->IsSign())
  1422. ((Sign*)spawn)->HandleUse(this, command);
  1423. }
  1424. }
  1425. }
  1426. else {
  1427. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1428. if (command.size > 0) {
  1429. string command_name = command.data;
  1430. if (command_name.find(" ") < 0xFFFFFFFF) {
  1431. if (GetVersion() <= 546) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
  1432. string::size_type pos = command_name.find(" ");
  1433. while(pos != string::npos){
  1434. command_name.replace(pos, 1, "_");
  1435. pos = command_name.find(" ");
  1436. }
  1437. }
  1438. else
  1439. command_name = command_name.substr(0, command_name.find(" "));
  1440. }
  1441. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1442. if (handler != 0xFFFFFFFF) {
  1443. if (command.data == command_name) {
  1444. command.data = "";
  1445. command.size = 0;
  1446. }
  1447. else {
  1448. command.data = command.data.substr(command.data.find(" ") + 1);
  1449. command.size = command.data.length();
  1450. }
  1451. commands.Process(handler, &command, this);
  1452. }
  1453. else {
  1454. if (spawn && spawn->IsNPC()) {
  1455. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1456. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1457. command_name = command.data;
  1458. string::size_type pos = command_name.find(" ");
  1459. while (pos != string::npos) {
  1460. command_name.replace(pos, 1, "_");
  1461. pos = command_name.find(" ");
  1462. }
  1463. if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
  1464. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1465. }
  1466. }
  1467. }
  1468. }
  1469. else
  1470. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1471. }
  1472. }
  1473. }
  1474. safe_delete(packet);
  1475. }
  1476. break;
  1477. }
  1478. case OP_SkillInfoRequest: {
  1479. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1480. HandleSkillInfoRequest(app);
  1481. break;
  1482. }
  1483. case OP_UpdateTargetMsg: {
  1484. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1485. int16 index = 0;
  1486. memcpy(&index, app->pBuffer, sizeof(int16));
  1487. if (index == 0xFFFF)
  1488. GetPlayer()->SetTarget(0);
  1489. else
  1490. GetPlayer()->SetTarget(GetPlayer()->GetSpawnByIndex(index));
  1491. if (GetPlayer()->GetTarget())
  1492. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1493. //player->SetTarget((int16*)app->pBuffer);
  1494. break;
  1495. }
  1496. case OP_ExamineInfoRequestMsg: {
  1497. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1498. HandleExamineInfoRequest(app);
  1499. break;
  1500. }
  1501. case OP_QuickbarUpdateMsg:
  1502. //case OP_QuickbarAddMsg:
  1503. {
  1504. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1505. HandleQuickbarUpdateRequest(app);
  1506. break;
  1507. }
  1508. case OP_PredictionUpdateMsg: {
  1509. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
  1510. if (version <= 546) {
  1511. int8 offset = 9;
  1512. if (app->pBuffer[0] == 0xFF)
  1513. offset += 2;
  1514. if (app->size > offset) {
  1515. if (player->IsCasting()) {
  1516. float distance = 0;
  1517. float x = player->GetX();
  1518. float y = player->GetY();
  1519. float z = player->GetZ();
  1520. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1521. distance = player->GetDistance(x, y, z, false);
  1522. if (distance > .5)
  1523. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1524. }
  1525. else
  1526. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1527. player_pos_changed = true;
  1528. //DumpPacket(app);
  1529. }
  1530. }
  1531. else {
  1532. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1533. QueuePacket(app);
  1534. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1535. }
  1536. break;
  1537. }
  1538. case OP_RemoteCmdMsg: {
  1539. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1540. if (app->size > 0) {
  1541. EQ2_CommandString remote(app->pBuffer, app->size);
  1542. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1543. #if EQDEBUG >= 9
  1544. DumpPacket(app);
  1545. #endif
  1546. commands.Process(remote.handler, &remote.command, this);
  1547. }
  1548. else //bad client, disconnect
  1549. Disconnect();
  1550. break;
  1551. }
  1552. case OP_CancelSpellCast: {
  1553. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1554. current_zone->Interrupted(player, 0, 0, true);
  1555. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1556. break;
  1557. }
  1558. case OP_UpdatePositionMsg: {
  1559. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
  1560. int8 offset = 13;
  1561. if (app->pBuffer[0] == 0xFF)
  1562. offset += 2;
  1563. if (app->size > offset) {
  1564. if (player->IsCasting()) {
  1565. float distance = 0;
  1566. float x = player->GetX();
  1567. float y = player->GetY();
  1568. float z = player->GetZ();
  1569. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1570. distance = player->GetDistance(x, y, z, false);
  1571. if (distance > .5)
  1572. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1573. }
  1574. else
  1575. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1576. player_pos_changed = true;
  1577. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1578. //DumpPacket(app);
  1579. }
  1580. break;
  1581. }
  1582. case OP_MailSendMessageMsg: {
  1583. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1584. HandleSentMail(app);
  1585. break;
  1586. }
  1587. case OP_StopTrackingMsg: {
  1588. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1589. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1590. break;
  1591. }
  1592. case OP_BeginTrackingMsg: {
  1593. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1594. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1595. if (packet) {
  1596. packet->LoadPacketData(app->pBuffer, app->size);
  1597. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1598. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1599. if (spawn) {
  1600. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1601. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1602. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1603. }
  1604. safe_delete(packet);
  1605. }
  1606. break;
  1607. }
  1608. case OP_BioUpdateMsg: {
  1609. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1610. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1611. if (packet) {
  1612. packet->LoadPacketData(app->pBuffer, app->size);
  1613. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1614. safe_delete(packet);
  1615. }
  1616. break;
  1617. }
  1618. case OP_RewardPackMsg: {
  1619. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1620. /* 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
  1621. when we come across it (scatman) */
  1622. const char* name = app->GetOpcodeName();
  1623. if (name)
  1624. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1625. else
  1626. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1627. //DumpPacket(app);
  1628. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1629. if (packet) {
  1630. packet->LoadPacketData(app->pBuffer, app->size);
  1631. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1632. /* Player has contacted a guild recruiter */
  1633. if (recruiter_name.length() > 0) {
  1634. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1635. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1636. if (recruiter && guild) {
  1637. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1638. 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()));
  1639. recruiter->PlaySound("ui_guild_page");
  1640. }
  1641. }
  1642. /* New picture taken for guild recruiting */
  1643. else {
  1644. //DumpPacket(app->pBuffer, app->size);
  1645. int32 guild_id = 0;
  1646. int16 picture_data_size = 0;
  1647. unsigned char* recruiter_picture_data = 0;
  1648. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1649. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1650. Guild* guild = guild_list.GetGuild(guild_id);
  1651. if (guild) {
  1652. GuildMember* gm = guild->GetGuildMember(player);
  1653. if (gm) {
  1654. safe_delete_array(gm->recruiter_picture_data);
  1655. recruiter_picture_data = new unsigned char[picture_data_size];
  1656. for (int16 i = 0; i < picture_data_size; i++)
  1657. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1658. gm->recruiter_picture_data = recruiter_picture_data;
  1659. gm->recruiter_picture_data_size = picture_data_size;
  1660. guild->SetMemberSaveNeeded(true);
  1661. }
  1662. }
  1663. }
  1664. safe_delete(packet);
  1665. }
  1666. break;
  1667. }
  1668. case OP_PetOptions: {
  1669. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  1670. Spawn* target = player->GetTarget();
  1671. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  1672. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  1673. bool change = false;
  1674. packet->LoadPacketData(app->pBuffer, app->size);
  1675. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  1676. if (strlen(name.c_str()) != 0) {
  1677. target->SetName(name.c_str());
  1678. strcpy(player->GetInfoStruct()->pet_name, name.c_str());
  1679. GetCurrentZone()->SendUpdateTitles(target);
  1680. change = true;
  1681. }
  1682. // Check protect self setting and update if needed
  1683. if (packet->getType_int8_ByName("protect_self") == 1) {
  1684. if ((player->GetInfoStruct()->pet_behavior & 2) == 0) {
  1685. player->GetInfoStruct()->pet_behavior += 2;
  1686. change = true;
  1687. }
  1688. }
  1689. else {
  1690. if ((player->GetInfoStruct()->pet_behavior & 2) != 0) {
  1691. player->GetInfoStruct()->pet_behavior -= 2;
  1692. change = true;
  1693. }
  1694. }
  1695. // Check protect master setting and update if needed
  1696. if (packet->getType_int8_ByName("protect_master") == 1) {
  1697. if ((player->GetInfoStruct()->pet_behavior & 1) == 0) {
  1698. player->GetInfoStruct()->pet_behavior += 1;
  1699. change = true;
  1700. }
  1701. }
  1702. else {
  1703. if ((player->GetInfoStruct()->pet_behavior & 1) != 0) {
  1704. player->GetInfoStruct()->pet_behavior -= 1;
  1705. change = true;
  1706. }
  1707. }
  1708. // Check stay/follow setting and update if needed
  1709. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  1710. if (player->GetInfoStruct()->pet_movement != 2) {
  1711. player->GetInfoStruct()->pet_movement = 2;
  1712. change = true;
  1713. }
  1714. }
  1715. else {
  1716. if (player->GetInfoStruct()->pet_movement != 1) {
  1717. player->GetInfoStruct()->pet_movement = 1;
  1718. change = true;
  1719. }
  1720. }
  1721. // Ranged/Melee settings are not implemented yet
  1722. if (change)
  1723. player->SetCharSheetChanged(true);
  1724. safe_delete(packet);
  1725. }
  1726. break;
  1727. }
  1728. case OP_RecipeBook: {
  1729. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  1730. SendRecipeList();
  1731. break;
  1732. }
  1733. case OP_BuyPlayerHouseMsg: {
  1734. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  1735. DumpPacket(app);
  1736. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  1737. if (packet) {
  1738. packet->LoadPacketData(app->pBuffer, app->size);
  1739. HouseZone* hz = world.GetHouseZone(packet->getType_int64_ByName("house_id"));
  1740. if (hz) {
  1741. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  1742. if (houses.size() > 24)
  1743. {
  1744. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  1745. safe_delete(packet);
  1746. break;
  1747. }
  1748. if ((!hz->upkeep_coin && !hz->cost_coin) || player->RemoveCoins(hz->cost_coin+hz->upkeep_coin)) // TODO: Need option to take from bank if player does not have enough coin on them
  1749. {
  1750. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id);
  1751. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  1752. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  1753. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  1754. //ClientPacketFunctions::SendHousingList(this);
  1755. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  1756. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1757. PlaySound("coin_cha_ching");
  1758. }
  1759. else
  1760. {
  1761. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  1762. PlaySound("buy_failed");
  1763. }
  1764. }
  1765. }
  1766. safe_delete(packet);
  1767. break;
  1768. }
  1769. case OP_EnterHouseMsg: {
  1770. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  1771. DumpPacket(app);
  1772. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  1773. if (packet) {
  1774. packet->LoadPacketData(app->pBuffer, app->size);
  1775. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(packet->getType_int64_ByName("house_id"));
  1776. if (ph) {
  1777. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1778. if (hz) {
  1779. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id);
  1780. if (house) {
  1781. Zone(house, true);
  1782. }
  1783. }
  1784. }
  1785. }
  1786. safe_delete(packet);
  1787. break;
  1788. }
  1789. case OP_PayHouseUpkeepMsg: {
  1790. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  1791. DumpPacket(app);
  1792. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  1793. if (packet) {
  1794. packet->LoadPacketData(app->pBuffer, app->size);
  1795. int64 houseID = packet->getType_int64_ByName("house_id");
  1796. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(houseID);
  1797. if (ph)
  1798. {
  1799. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1800. if (!hz)
  1801. {
  1802. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  1803. safe_delete(packet);
  1804. break;
  1805. }
  1806. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  1807. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  1808. {
  1809. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  1810. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  1811. {
  1812. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  1813. PlaySound("buy_failed");
  1814. safe_delete(packet);
  1815. break;
  1816. }
  1817. }
  1818. int64 coinReq = hz->upkeep_coin;
  1819. int64 tmpRecoverCoins = 0;
  1820. bool escrowChange = false;
  1821. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  1822. {
  1823. escrowChange = true;
  1824. tmpRecoverCoins = ph->escrow_coins;
  1825. coinReq -= ph->escrow_coins;
  1826. ph->escrow_coins = 0;
  1827. }
  1828. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  1829. {
  1830. escrowChange = true;
  1831. // more than enough in escrow, subtract and make our cost 0!
  1832. ph->escrow_coins -= coinReq;
  1833. coinReq = 0;
  1834. }
  1835. // TODO: Need support for upkeep_status, but alas status_points are not implemented!
  1836. if (!coinReq || coinReq && player->RemoveCoins(coinReq)) // TODO: Need option to take from bank if player does not have enough coin on them
  1837. {
  1838. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  1839. if (escrowChange)
  1840. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins);
  1841. ph->upkeep_due = upkeep_due;
  1842. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  1843. //ClientPacketFunctions::SendHousingList(this);
  1844. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1845. PlaySound("coin_cha_ching");
  1846. }
  1847. else
  1848. {
  1849. // recover the escrow we were going to use but could not spend due to lack of funds
  1850. if (tmpRecoverCoins)
  1851. ph->escrow_coins += tmpRecoverCoins;
  1852. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to pay for upkeep.");
  1853. PlaySound("buy_failed");
  1854. }
  1855. }
  1856. else
  1857. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", houseID);
  1858. }
  1859. safe_delete(packet);
  1860. break;
  1861. }
  1862. case OP_ExitHouseMsg: {
  1863. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  1864. int32 instance_id = GetCurrentZone()->GetInstanceID();
  1865. if (instance_id > 0) {
  1866. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  1867. if (ph) {
  1868. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1869. if (hz) {
  1870. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  1871. // determine if this is an instanced zone that already exists
  1872. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  1873. if (instance_zone || new_zone) {
  1874. GetPlayer()->SetX(hz->exit_x);
  1875. GetPlayer()->SetY(hz->exit_y);
  1876. GetPlayer()->SetZ(hz->exit_z);
  1877. GetPlayer()->SetHeading(hz->exit_heading);
  1878. if (instance_zone)
  1879. Zone(instance_zone->GetInstanceID(), false, true);
  1880. else
  1881. Zone(new_zone, false);
  1882. }
  1883. }
  1884. }
  1885. }
  1886. DumpPacket(app);
  1887. break;
  1888. }
  1889. case OP_QuestJournalWaypointMsg: {
  1890. //DumpPacket(app);
  1891. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  1892. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  1893. if (packet) {
  1894. packet->LoadPacketData(app->pBuffer, app->size);
  1895. int32 quests = packet->getType_int32_ByName("num_quests");
  1896. if (quests > 100) // just picking a number higher than max allowed
  1897. {
  1898. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  1899. break;
  1900. }
  1901. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  1902. for (int32 i = 0; i < quests; i++) {
  1903. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  1904. if (id == 0)
  1905. continue;
  1906. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  1907. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  1908. if (player->player_quests.count(id) > 0) {
  1909. player->player_quests[id]->SetTracked(tracked);
  1910. player->player_quests[id]->SetSaveNeeded(true);
  1911. }
  1912. }
  1913. safe_delete(packet);
  1914. }
  1915. break;
  1916. }
  1917. case OP_PaperdollImage: {
  1918. PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  1919. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1920. //First check if this is a new image... delete an existing partial image if one exists
  1921. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  1922. if (packet_index == 0) {
  1923. safe_delete_array(incoming_paperdoll.image_bytes);
  1924. incoming_paperdoll.last_received_packet_index = 0;
  1925. incoming_paperdoll.current_size_bytes = 0;
  1926. }
  1927. //return if this packet is not the one we are expecting...
  1928. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  1929. safe_delete(packet);
  1930. break;
  1931. }
  1932. //Check how many packets we're supposed to be receiving for this/these images
  1933. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  1934. //Check the image type, if this is a new type in the same series of packets we have a new image
  1935. int8 img_type = packet->getType_int8_ByName("image_type");
  1936. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  1937. //We have a new image. Save the old data and clear before continuing
  1938. SavePlayerImages();
  1939. }
  1940. incoming_paperdoll.image_type = img_type;
  1941. //Get the size of the image data in this packet
  1942. sint64 image_size = packet->getType_int32_ByName("imageSize");
  1943. if (image_size <= 0 || image_size > 1048576) {
  1944. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  1945. safe_delete(packet);
  1946. break;
  1947. }
  1948. //Create a new array
  1949. int32 new_image_size = image_size;
  1950. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  1951. if (incoming_paperdoll.image_bytes) {
  1952. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  1953. safe_delete_array(incoming_paperdoll.image_bytes);
  1954. }
  1955. //variable i should be the index in the packet of the first PNG file byte
  1956. vector<DataStruct*>* d_structs = packet->getStructs();
  1957. vector<DataStruct*>::iterator itr;
  1958. int32 i = 0;
  1959. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  1960. DataStruct* ds = (*itr);
  1961. if (strcmp(ds->GetName(), "pngData_0") != 0)
  1962. i += ds->GetDataSizeInBytes();
  1963. else
  1964. break;
  1965. }
  1966. //Return if this packet is bad and we would read out of bounds
  1967. if (app->size - i < new_image_size) {
  1968. safe_delete(packet);
  1969. safe_delete_array(new_image);
  1970. break;
  1971. }
  1972. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  1973. memcpy(tmp, app->pBuffer + i, new_image_size);
  1974. incoming_paperdoll.current_size_bytes += new_image_size;
  1975. incoming_paperdoll.image_bytes = new_image;
  1976. //Check if this is the last packet we're expecting for this image. Create a final image if so
  1977. if (incoming_paperdoll.image_num_packets == 1 ||
  1978. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  1979. SavePlayerImages();
  1980. }
  1981. incoming_paperdoll.last_received_packet_index = packet_index;
  1982. }
  1983. safe_delete(packet);
  1984. break;
  1985. }
  1986. case OP_ReadyForTakeOffMsg:
  1987. {
  1988. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  1989. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  1990. if (GetPendingFlightPath() > 0) {
  1991. if (index != -1) {
  1992. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  1993. if (packet) {
  1994. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  1995. packet->setDataByName("path_id", index);
  1996. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  1997. QueuePacket(packet->serialize());
  1998. safe_delete(packet);
  1999. on_auto_mount = true;
  2000. }
  2001. }
  2002. else {
  2003. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2004. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2005. EndAutoMount();
  2006. }
  2007. SetPendingFlightPath(0);
  2008. }
  2009. else
  2010. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  2011. break;
  2012. }
  2013. case OP_EarlyLandingRequestMsg:
  2014. {
  2015. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  2016. EndAutoMount();
  2017. break;
  2018. }
  2019. case OP_SubmitCharCust:
  2020. {
  2021. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  2022. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  2023. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2024. int8 type = packet->getType_int8_ByName("type");
  2025. if (type == 0) {
  2026. if (player->custNPC) {
  2027. player->custNPCTarget->CustomizeAppearance(packet);
  2028. current_zone->SendSpawnChanges(player->custNPCTarget);
  2029. }
  2030. else {
  2031. player->CustomizeAppearance(packet);
  2032. current_zone->SendSpawnChanges(player);
  2033. }
  2034. }
  2035. }
  2036. if (player->custNPC) {
  2037. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2038. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2039. if (player->custNPCTarget->IsBot())
  2040. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2041. player->custNPC = false;
  2042. player->custNPCTarget = 0;
  2043. player->changed = true;
  2044. player->info_changed = true;
  2045. current_zone->SendSpawnChanges(player, this);
  2046. }
  2047. break;
  2048. }
  2049. default: {
  2050. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2051. const char* name = app->GetOpcodeName();
  2052. if (name)
  2053. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2054. else
  2055. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2056. //DumpPacket(app);
  2057. }
  2058. }
  2059. if (!eqs || !eqs->CheckActive()) {
  2060. return false;
  2061. }
  2062. return ret;
  2063. }
  2064. bool Client::HandleLootItem(Spawn* entity, Item* item) {
  2065. if (!item) {
  2066. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2067. return false;
  2068. }
  2069. if (player->item_list.HasFreeSlot() || player->item_list.CanStack(item)) {
  2070. if (player->item_list.AssignItemToFreeSlot(item)) {
  2071. int8 type = CHANNEL_LOOT;
  2072. if (entity) {
  2073. Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2074. }
  2075. else {
  2076. Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2077. }
  2078. Guild* guild = player->GetGuild();
  2079. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2080. char adjective[32];
  2081. int8 type;
  2082. memset(adjective, 0, sizeof(adjective));
  2083. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2084. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2085. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2086. }
  2087. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2088. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2089. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2090. }
  2091. else {
  2092. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2093. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2094. }
  2095. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2096. guild->SendMessageToGuild(type, "%s has looted the %s %s", player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2097. }
  2098. CheckPlayerQuestsItemUpdate(item);
  2099. return true;
  2100. }
  2101. else
  2102. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2103. }
  2104. else
  2105. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2106. return false;
  2107. }
  2108. bool Client::HandleLootItem(Spawn* entity, int32 item_id) {
  2109. if (!entity) {
  2110. return false;
  2111. }
  2112. return HandleLootItem(entity, entity->LootItem(item_id));
  2113. }
  2114. void Client::HandleLoot(EQApplicationPacket* app) {
  2115. PacketStruct* packet = configReader.getStruct("WS_LootType", GetVersion());
  2116. if (packet) {
  2117. packet->LoadPacketData(app->pBuffer, app->size);
  2118. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2119. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2120. safe_delete(packet);
  2121. int32 item_id = 0;
  2122. Item* item = 0;
  2123. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2124. if (player->HasPendingLootItems(loot_id)) {
  2125. Item* master_item = 0;
  2126. if (loot_all) {
  2127. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2128. if (items) {
  2129. for (int32 i = 0; loot_all && i < items->size(); i++) {
  2130. master_item = items->at(i);
  2131. if (master_item) {
  2132. item = new Item(master_item);
  2133. if (item) {
  2134. loot_all = HandleLootItem(0, item);
  2135. if (loot_all)
  2136. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2137. }
  2138. }
  2139. }
  2140. safe_delete(items);
  2141. }
  2142. }
  2143. else {
  2144. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2145. if (packet) {
  2146. packet->LoadPacketData(app->pBuffer, app->size);
  2147. item_id = packet->getType_int32_ByName("item_id");
  2148. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2149. if (items) {
  2150. for (int32 i = 0; i < items->size(); i++) {
  2151. master_item = items->at(i);
  2152. if (master_item && master_item->details.item_id == item_id) {
  2153. item = new Item(master_item);
  2154. if (item && HandleLootItem(0, item))
  2155. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2156. break;
  2157. }
  2158. }
  2159. safe_delete(items);
  2160. }
  2161. safe_delete(packet);
  2162. }
  2163. }
  2164. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2165. if (outapp)
  2166. QueuePacket(outapp);
  2167. Loot(0, player->GetPendingLootItems(loot_id), spawn);
  2168. }
  2169. else {
  2170. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2171. if (loot_all) {
  2172. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2173. loot_all = HandleLootItem(spawn, item_id);
  2174. }
  2175. }
  2176. else {
  2177. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2178. if (packet) {
  2179. packet->LoadPacketData(app->pBuffer, app->size);
  2180. item_id = packet->getType_int32_ByName("item_id");
  2181. HandleLootItem(spawn, item_id);
  2182. safe_delete(packet);
  2183. }
  2184. }
  2185. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2186. if (outapp)
  2187. QueuePacket(outapp);
  2188. Loot(spawn);
  2189. if (!spawn->HasLoot()) {
  2190. CloseLoot(loot_id);
  2191. if (spawn->IsNPC())
  2192. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2193. }
  2194. }
  2195. else {
  2196. if (!spawn) {
  2197. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2198. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2199. }
  2200. else
  2201. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2202. }
  2203. }
  2204. }
  2205. }
  2206. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2207. PacketStruct* request = 0;
  2208. // cout << "Request: \n";
  2209. // DumpPacket(app);
  2210. switch (app->pBuffer[0]) {
  2211. case 0: { //items
  2212. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2213. if (request) {
  2214. request->LoadPacketData(app->pBuffer, app->size);
  2215. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2216. if (!item)
  2217. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2218. if (item) {
  2219. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2220. if (response) {
  2221. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2222. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2223. response->setSmallStringByName("name", item->name.c_str());
  2224. EQ2Packet* app2 = response->serialize();
  2225. //DumpPacket(app2);
  2226. QueuePacket(app2);
  2227. safe_delete(response);
  2228. }
  2229. }
  2230. }
  2231. break;
  2232. }
  2233. case 2: {//spells
  2234. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2235. if (request) {
  2236. request->LoadPacketData(app->pBuffer, app->size);
  2237. int32 id = request->getType_int32_ByName("id");
  2238. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2239. Spell* spell = master_spell_list.GetSpell(id, tier);
  2240. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2241. if (response) {
  2242. response->setDataByName("request_type", 2);
  2243. response->setDataByName("unique_id", tier);
  2244. response->setDataByName("id", id);
  2245. if (spell)
  2246. response->setSmallStringByName("name", spell->GetName());
  2247. else
  2248. response->setSmallStringByName("name", "Unknown Spell");
  2249. EQ2Packet* app2 = response->serialize();
  2250. // DumpPacket(app2);
  2251. QueuePacket(app2);
  2252. safe_delete(response);
  2253. }
  2254. }
  2255. break;
  2256. }
  2257. default: {
  2258. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2259. }
  2260. }
  2261. safe_delete(request);
  2262. }
  2263. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2264. PacketStruct* request = 0;
  2265. if (!app || app->size == 0)
  2266. return;
  2267. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2268. //DumpPacket(app);
  2269. int8 type = app->pBuffer[0];
  2270. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2271. if (version <= 283) {
  2272. if (type == 1)
  2273. type = 4;
  2274. else if (type == 2)
  2275. type = 5;
  2276. }
  2277. if (type == 3) {
  2278. Spell* spell = 0;
  2279. bool trait_display;
  2280. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2281. if (!request) {
  2282. return;
  2283. }
  2284. request->LoadPacketData(app->pBuffer, app->size);
  2285. int32 id = request->getType_int32_ByName("id");
  2286. int32 tier = request->getType_int32_ByName("tier");
  2287. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2288. bool display = true;
  2289. if (version <= 283 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2290. display = false;
  2291. else if (version <= 546)
  2292. display = request->getType_int8_ByName("display");
  2293. else if (version > 546)
  2294. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  2295. //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
  2296. if (trait_tier != 0xFFFFFFFF) {
  2297. spell = master_spell_list.GetSpell(id, trait_tier);
  2298. if (!spell) {
  2299. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2300. }
  2301. trait_display = true;
  2302. }
  2303. else {
  2304. spell = master_spell_list.GetSpell(id, tier);
  2305. trait_display = false;
  2306. }
  2307. // if we can't find it on the master spell list, see if it is a custom spell
  2308. if (!spell)
  2309. {
  2310. lua_interface->FindCustomSpellLock();
  2311. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2312. if (tmpSpell)
  2313. spell = tmpSpell->spell;
  2314. lua_interface->FindCustomSpellUnlock();
  2315. }
  2316. if (spell && sent_spell_details.count(id) == 0) {
  2317. if (!spell->IsCopiedSpell())
  2318. sent_spell_details[id] = true;
  2319. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  2320. //DumpPacket(app);
  2321. QueuePacket(app);
  2322. }
  2323. }
  2324. else if (type == 0) {
  2325. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2326. if (!request) {
  2327. return;
  2328. }
  2329. request->LoadPacketData(app->pBuffer, app->size);
  2330. int32 id = request->getType_int32_ByName("id");
  2331. Item* item = 0;
  2332. // translate from unique id to spawn id for houses
  2333. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2334. bool wasSpawn = false;
  2335. if (spawn)
  2336. {
  2337. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2338. if (item)
  2339. {
  2340. wasSpawn = true;
  2341. item = new Item(item);
  2342. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2343. }
  2344. }
  2345. if (!item)
  2346. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2347. if (!item)
  2348. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2349. if (!item)
  2350. item = master_item_list.GetItem(id);
  2351. if (item) {// && sent_item_details.count(id) == 0){
  2352. sent_item_details[id] = true;
  2353. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2354. //DumpPacket(app);
  2355. QueuePacket(app);
  2356. if (wasSpawn)
  2357. delete item;
  2358. }
  2359. else {
  2360. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2361. DumpPacket(app);
  2362. }
  2363. }
  2364. else if (type == 1) {
  2365. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2366. if (!request) {
  2367. return;
  2368. }
  2369. request->LoadPacketData(app->pBuffer, app->size);
  2370. int32 id = request->getType_int32_ByName("id");
  2371. int32 unique_id = request->getType_int32_ByName("unique_id");
  2372. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  2373. if (!item)
  2374. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  2375. if (!item)
  2376. item = master_item_list.GetItem(id);
  2377. if (item) {
  2378. sent_item_details[id] = true;
  2379. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2380. //DumpPacket(app);
  2381. QueuePacket(app);
  2382. }
  2383. else {
  2384. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2385. DumpPacket(app);
  2386. }
  2387. }
  2388. else if (type == 2) {
  2389. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  2390. if (!request) {
  2391. return;
  2392. }
  2393. request->LoadPacketData(app->pBuffer, app->size);
  2394. int32 id = request->getType_int32_ByName("item_id");
  2395. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  2396. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  2397. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  2398. //int32 unique_id = request->getType_int32_ByName("unique_id");
  2399. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  2400. //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);
  2401. Item* item = master_item_list.GetItem(id);
  2402. if (item) {
  2403. //only display popup for non merchant links
  2404. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, true);
  2405. //DumpPacket(app);
  2406. QueuePacket(app);
  2407. }
  2408. else {
  2409. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2410. DumpPacket(app);
  2411. }
  2412. }
  2413. else if (type == 4) { //spell effect
  2414. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  2415. if (!request) {
  2416. return;
  2417. }
  2418. request->LoadPacketData(app->pBuffer, app->size);
  2419. int32 id = request->getType_int32_ByName("id");
  2420. int16 display = request->getType_int8_ByName("partial_info");
  2421. SpellEffects* effect = player->GetSpellEffect(id);
  2422. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  2423. if (effect) {
  2424. int8 tier = effect->tier;
  2425. Spell* spell = master_spell_list.GetSpell(id, tier);
  2426. // if we can't find it on the master spell list, see if it is a custom spell
  2427. if (!spell)
  2428. {
  2429. lua_interface->FindCustomSpellLock();
  2430. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2431. EQ2Packet* pack = 0;
  2432. if (tmpSpell)
  2433. spell = tmpSpell->spell;
  2434. lua_interface->FindCustomSpellUnlock();
  2435. }
  2436. if (spell && sent_spell_details.count(id) == 0) {
  2437. if (!spell->IsCopiedSpell())
  2438. sent_spell_details[id] = true;
  2439. int8 type = 0;
  2440. if (version <= 283)
  2441. type = 1;
  2442. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  2443. //DumpPacket(app);
  2444. QueuePacket(app);
  2445. }
  2446. }
  2447. }
  2448. else if (type == 5) { // recipe info
  2449. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2450. if (!request)
  2451. return;
  2452. request->LoadPacketData(app->pBuffer, app->size);
  2453. int32 id = request->getType_int32_ByName("unknown_id");
  2454. Recipe* recipe = master_recipe_list.GetRecipe(id);
  2455. if (recipe) {
  2456. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  2457. //DumpPacket(app);
  2458. QueuePacket(app);
  2459. }
  2460. }
  2461. else if (type == 6) { // AA spell info
  2462. Spell* spell = 0;
  2463. //Spell* spell2 = 0;
  2464. //AltAdvanceData* data = 0;
  2465. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2466. if (!request)
  2467. return;
  2468. request->LoadPacketData(app->pBuffer, app->size);
  2469. int32 id = request->getType_int32_ByName("id");
  2470. int32 tier = GetPlayer()->GetSpellTier(id);
  2471. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  2472. //data = master_aa_list.GetAltAdvancement(id);
  2473. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  2474. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  2475. spell = master_spell_list.GetSpell(id, tier);
  2476. if (!spell)
  2477. spell = master_spell_list.GetSpell(id, 1);
  2478. if (!spell)
  2479. {
  2480. lua_interface->FindCustomSpellLock();
  2481. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2482. if (tmpSpell)
  2483. spell = tmpSpell->spell;
  2484. lua_interface->FindCustomSpellUnlock();
  2485. }
  2486. if (!spell)
  2487. {
  2488. LogWrite(WORLD__ERROR, 0, "WORLD", "FAILED Examine Info Request-> Spell ID: %u, tier: %i", id, tier);
  2489. return;
  2490. }
  2491. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  2492. if (!spell->IsCopiedSpell())
  2493. sent_spell_details[spell->GetSpellID()] = true;
  2494. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  2495. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  2496. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  2497. //DumpPacket(app);
  2498. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  2499. QueuePacket(app);
  2500. //}
  2501. }
  2502. else {
  2503. LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
  2504. DumpPacket(app);
  2505. }
  2506. safe_delete(request);
  2507. }
  2508. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  2509. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  2510. if (request) {
  2511. request->LoadPacketData(app->pBuffer, app->size);
  2512. int32 id = request->getType_int32_ByName("id");
  2513. int32 bar = request->getType_int32_ByName("hotbar_number");
  2514. int32 slot = request->getType_int32_ByName("hotkey_slot");
  2515. int32 type = request->getType_int32_ByName("type");
  2516. int8 tier = request->getType_int32_ByName("unique_id");
  2517. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  2518. Spell* spell = 0;
  2519. if (type == 0xFFFFFFFF)
  2520. GetPlayer()->RemoveQuickbarItem(bar, slot);
  2521. else {
  2522. if (type == QUICKBAR_NORMAL)
  2523. spell = master_spell_list.GetSpell(id, tier);
  2524. if (spell)
  2525. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  2526. else
  2527. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  2528. }
  2529. safe_delete(request);
  2530. }
  2531. }
  2532. bool Client::Process(bool zone_process) {
  2533. if (!eqs) {
  2534. return false;
  2535. }
  2536. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  2537. return true;
  2538. }
  2539. if (new_client_login) {
  2540. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  2541. SendLoginInfo();
  2542. new_client_login = false;
  2543. }
  2544. bool ret = true;
  2545. sockaddr_in to;
  2546. memset((char*)&to, 0, sizeof(to));
  2547. to.sin_family = AF_INET;
  2548. to.sin_port = port;
  2549. to.sin_addr.s_addr = ip;
  2550. /************ Get all packets from packet manager out queue and process them ************/
  2551. EQApplicationPacket* app = 0;
  2552. if (eqs && !eqs->CheckActive()) {
  2553. num_active_failures++;
  2554. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  2555. if (num_active_failures > 100) {
  2556. return false;
  2557. }
  2558. return true;
  2559. }
  2560. while (ret && eqs && (app = eqs->PopPacket())) {
  2561. ret = HandlePacket(app);
  2562. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  2563. delete app;
  2564. }
  2565. if (GetCurrentZone() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  2566. player->ApplyPassiveSpells();
  2567. //database.LoadCharacterActiveSpells(player);
  2568. player->UnlockAllSpells(true);
  2569. should_load_spells = false;
  2570. }
  2571. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  2572. {
  2573. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  2574. return false;
  2575. }
  2576. if (quest_updates) {
  2577. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  2578. ProcessQuestUpdates();
  2579. }
  2580. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - 300)) {
  2581. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  2582. CheckQuestQueue();
  2583. }
  2584. if (pos_update.Check())
  2585. {
  2586. if(GetPlayer()->GetRegionMap())
  2587. GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2588. if(player_pos_changed && IsReadyForUpdates() && ( !disconnect_timer || !disconnect_timer->Enabled())) {
  2589. //GetPlayer()->CalculateLocation();
  2590. client_list.CheckPlayersInvisStatus(this);
  2591. GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
  2592. player_pos_changed = false;
  2593. GetCurrentZone()->CheckTransporters(this);
  2594. if(GetPlayer()->GetRegionMap())
  2595. {
  2596. if((lastRegionRemapTime+1000) < Timer::GetCurrentTime2())
  2597. {
  2598. lastRegionRemapTime = Timer::GetCurrentTime2() + 1000;
  2599. GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2600. }
  2601. else
  2602. GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2603. }
  2604. }
  2605. }
  2606. if (lua_interface && lua_debug && lua_debug_timer.Check())
  2607. lua_interface->UpdateDebugClients(this);
  2608. if (quest_pos_timer.Check())
  2609. CheckPlayerQuestsLocationUpdate();
  2610. if (camp_timer && camp_timer->Check() && getConnection()) {
  2611. getConnection()->SendDisconnect(false);
  2612. safe_delete(camp_timer);
  2613. disconnect_timer = new Timer(2000);
  2614. disconnect_timer->Start();
  2615. }
  2616. if (player->GetSkills()->HasSkillUpdates()) {
  2617. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  2618. if (skills) {
  2619. Skill* skill = 0;
  2620. vector<Skill*>::iterator itr;
  2621. for (itr = skills->begin(); itr != skills->end(); itr++) {
  2622. skill = *itr;
  2623. SkillChanged(skill, skill->previous_val, skill->current_val);
  2624. }
  2625. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  2626. if (app) QueuePacket(app);
  2627. safe_delete(skills);
  2628. }
  2629. }
  2630. if (disconnect_timer && disconnect_timer->Check()) {
  2631. safe_delete(disconnect_timer);
  2632. ret = false;
  2633. }
  2634. m_resurrect.writelock(__FUNCTION__, __LINE__);
  2635. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  2636. safe_delete(current_rez.expire_timer);
  2637. current_rez.expire_timer = 0;
  2638. current_rez.active = false;
  2639. current_rez.caster = 0;
  2640. current_rez.crit = false;
  2641. current_rez.crit_mod = 0;
  2642. current_rez.expire_timer = 0;
  2643. current_rez.heal_name = "";
  2644. current_rez.hp_perc = 0;
  2645. current_rez.mp_perc = 0;
  2646. current_rez.no_calcs = false;
  2647. current_rez.range = 0;
  2648. current_rez.should_delete = false;
  2649. current_rez.spell_name = "";
  2650. current_rez.spell_visual = 0;
  2651. current_rez.subspell = 0;
  2652. }
  2653. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  2654. // Quest timers
  2655. Quest* failed_step = 0;
  2656. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  2657. if (quest_timers.size() > 0) {
  2658. vector<int32>::iterator itr;
  2659. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  2660. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  2661. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  2662. Quest* quest = player_quests->at(*itr);
  2663. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  2664. failed_step = quest;
  2665. break;
  2666. }
  2667. }
  2668. else {
  2669. quest_timers.erase(itr);
  2670. break;
  2671. }
  2672. }
  2673. }
  2674. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  2675. if (failed_step)
  2676. failed_step->StepFailed(failed_step->GetTimerStep());
  2677. if (player->ControlFlagsChanged())
  2678. player->SendControlFlagUpdates(this);
  2679. if (!eqs || (eqs && !eqs->CheckActive()))
  2680. ret = false;
  2681. // redundant to client disconnect
  2682. // if(!ret)
  2683. // Save();
  2684. return ret;
  2685. }
  2686. ClientList::ClientList() {
  2687. MClients.SetName("ClientList::MClients");
  2688. }
  2689. ClientList::~ClientList() {
  2690. }
  2691. void ClientList::ReloadQuests() {
  2692. list<Client*>::iterator client_iter;
  2693. Client* client = 0;
  2694. MClients.readlock(__FUNCTION__, __LINE__);
  2695. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2696. client = *client_iter;
  2697. if (client)
  2698. client->ReloadQuests();
  2699. }
  2700. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2701. }
  2702. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  2703. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  2704. return;
  2705. list<Client*>::iterator client_iter;
  2706. Client* client = 0;
  2707. MClients.readlock(__FUNCTION__, __LINE__);
  2708. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2709. client = *client_iter;
  2710. if (client == owner || client->GetPlayer() == NULL)
  2711. continue;
  2712. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  2713. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  2714. }
  2715. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2716. }
  2717. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  2718. list<Client*>::iterator client_iter;
  2719. Client* client = 0;
  2720. MClients.readlock(__FUNCTION__, __LINE__);
  2721. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2722. client = *client_iter;
  2723. if (!client->GetPlayer())
  2724. continue;
  2725. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  2726. }
  2727. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2728. }
  2729. int32 ClientList::Count() {
  2730. return client_list.size();
  2731. }
  2732. void ClientList::Add(Client* client) {
  2733. MClients.writelock(__FUNCTION__, __LINE__);
  2734. client_list.push_back(client);
  2735. MClients.releasewritelock(__FUNCTION__, __LINE__);
  2736. }
  2737. Client* ClientList::FindByAccountID(int32 account_id) {
  2738. list<Client*>::iterator client_iter;
  2739. Client* client = 0;
  2740. Client* ret = 0;
  2741. MClients.readlock(__FUNCTION__, __LINE__);
  2742. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2743. client = *client_iter;
  2744. if (client->GetAccountID() == account_id) {
  2745. ret = client;
  2746. break;
  2747. }
  2748. }
  2749. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2750. return ret;
  2751. }
  2752. Client* ClientList::FindByName(char* charName) {
  2753. list<Client*>::iterator client_iter;
  2754. Client* client = 0;
  2755. Client* ret = 0;
  2756. MClients.readlock(__FUNCTION__, __LINE__);
  2757. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2758. client = *client_iter;
  2759. if (!client || !client->GetPlayer())
  2760. continue;
  2761. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  2762. ret = client;
  2763. break;
  2764. }
  2765. }
  2766. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2767. return ret;
  2768. }
  2769. Client* ClientList::Get(int32 ip, int16 port) {
  2770. list<Client*>::iterator client_iter;
  2771. Client* client = 0;
  2772. Client* ret = 0;
  2773. MClients.readlock(__FUNCTION__, __LINE__);
  2774. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2775. client = *client_iter;
  2776. if (client->GetIP() == ip && client->GetPort() == port) {
  2777. ret = client;
  2778. break;
  2779. }
  2780. }
  2781. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2782. return ret;
  2783. }
  2784. void ClientList::Process() {
  2785. list<Client*>::iterator client_iter;
  2786. list<Client*>::iterator erase_iter;
  2787. Client* client = 0;
  2788. MClients.readlock(__FUNCTION__, __LINE__);
  2789. erase_iter = client_list.end();
  2790. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2791. client = *client_iter;
  2792. // have a sanity check because the client list can sometimes obtain null client pointers
  2793. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  2794. erase_iter = client_iter;
  2795. break;
  2796. }
  2797. }
  2798. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2799. if (erase_iter != client_list.end()) {
  2800. client = *erase_iter;
  2801. MClients.writelock(__FUNCTION__, __LINE__);
  2802. client_list.erase(erase_iter);
  2803. MClients.releasewritelock(__FUNCTION__, __LINE__);
  2804. if (client && !client->remove_from_list) {
  2805. struct in_addr in;
  2806. in.s_addr = client->GetIP();
  2807. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  2808. safe_delete(client);
  2809. }
  2810. }
  2811. }
  2812. void ClientList::RemoveConnection(EQStream* eqs) {
  2813. Client* client;
  2814. if (eqs) {
  2815. list<Client*>::iterator client_iter;
  2816. MClients.readlock(__FUNCTION__, __LINE__);
  2817. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2818. client = *client_iter;
  2819. if (client->getConnection() == eqs)
  2820. client->Disconnect(false);
  2821. }
  2822. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2823. }
  2824. }
  2825. bool ClientList::ContainsStream(EQStream* eqs) {
  2826. if (!eqs) {
  2827. return false;
  2828. }
  2829. list<Client*>::iterator client_iter;
  2830. bool ret = false;
  2831. MClients.readlock(__FUNCTION__, __LINE__);
  2832. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2833. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  2834. ret = true;
  2835. break;
  2836. }
  2837. }
  2838. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2839. return ret;
  2840. }
  2841. void ClientList::Remove(Client* client, bool remove_data) {
  2842. client->remove_from_list = true;
  2843. if (remove_data) {
  2844. safe_delete(client);
  2845. }
  2846. }
  2847. void Client::SetCurrentZone(int32 id) {
  2848. if (current_zone) {
  2849. //current_zone->GetCombat()->RemoveHate(player);
  2850. current_zone->RemoveSpawn(false, player, false);
  2851. }
  2852. SetCurrentZone(zone_list.Get(id));
  2853. }
  2854. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  2855. if (current_zone) {
  2856. //current_zone->GetCombat()->RemoveHate(player);
  2857. current_zone->RemoveSpawn(false, player, false);
  2858. }
  2859. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  2860. }
  2861. ZoneServer* Client::GetCurrentZone() {
  2862. return current_zone;
  2863. }
  2864. int8 Client::GetMessageChannelColor(int8 channel_type) {
  2865. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  2866. if (channel_type == CHANNEL_LOOT)
  2867. return CHANNEL_COLOR_NEW_LOOT;
  2868. }
  2869. else if (GetVersion() >= 973) {
  2870. if (channel_type == CHANNEL_LOOT)
  2871. return CHANNEL_COLOR_NEWEST_LOOT;
  2872. }
  2873. if (GetVersion() <= 283) {
  2874. if (channel_type <=12)
  2875. return channel_type;
  2876. switch (channel_type) {
  2877. case CHANNEL_GROUP_CHAT:
  2878. case CHANNEL_GROUP_SAY:
  2879. case CHANNEL_RAID_SAY:
  2880. case CHANNEL_GUILD_CHAT:
  2881. case CHANNEL_GUILD_SAY:
  2882. case CHANNEL_OFFICER_SAY:
  2883. case CHANNEL_GUILD_MOTD:
  2884. return channel_type - 1;
  2885. case CHANNEL_PRIVATE_CHAT:
  2886. case CHANNEL_NONPLAYER_TELL:
  2887. return channel_type - 5;
  2888. case CHANNEL_PRIVATE_TELL:
  2889. case CHANNEL_TELL_FROM_CS:
  2890. return channel_type - 6;
  2891. case CHANNEL_CHAT_CHANNEL_TEXT:
  2892. case CHANNEL_OUT_OF_CHARACTER:
  2893. case CHANNEL_AUCTION:
  2894. case CHANNEL_CUSTOM_CHANNEL:
  2895. case CHANNEL_CHARACTER_TEXT:
  2896. case CHANNEL_REWARD:
  2897. case CHANNEL_DEATH:
  2898. case CHANNEL_PET_CHAT:
  2899. case CHANNEL_SKILL:
  2900. return channel_type - 7;
  2901. case CHANNEL_SPELLS:
  2902. case CHANNEL_YOU_CAST:
  2903. case CHANNEL_YOU_FAIL:
  2904. return channel_type - 8;
  2905. case CHANNEL_FRIENDLY_CAST:
  2906. case CHANNEL_FRIENDLY_FAIL:
  2907. case CHANNEL_OTHER_CAST:
  2908. case CHANNEL_OTHER_FAIL:
  2909. case CHANNEL_HOSTILE_CAST:
  2910. case CHANNEL_HOSTILE_FAIL:
  2911. case CHANNEL_WORN_OFF:
  2912. case CHANNEL_SPELLS_OTHER:
  2913. return channel_type - 9;
  2914. case CHANNEL_COMBAT:
  2915. return channel_type - 15;
  2916. case CHANNEL_HEROIC_OPPORTUNITY:
  2917. case CHANNEL_NON_MELEE_DAMAGE:
  2918. case CHANNEL_DAMAGE_SHIELD:
  2919. return channel_type - 16;
  2920. case CHANNEL_MELEE_COMBAT:
  2921. case CHANNEL_WARNINGS:
  2922. case CHANNEL_YOU_HIT:
  2923. case CHANNEL_YOU_MISS:
  2924. case CHANNEL_ATTACKER_HITS:
  2925. case CHANNEL_ATTACKER_MISSES:
  2926. return channel_type - 18;
  2927. case CHANNEL_OTHER_HIT:
  2928. case CHANNEL_OTHER_MISSES:
  2929. case CHANNEL_CRITICAL_HIT:
  2930. return channel_type - 22;
  2931. case CHANNEL_OTHER:
  2932. case CHANNEL_MONEY_SPLIT:
  2933. case CHANNEL_LOOT:
  2934. return channel_type - 30;
  2935. case CHANNEL_COMMAND_TEXT:
  2936. case CHANNEL_BROADCAST:
  2937. case CHANNEL_WHO:
  2938. case CHANNEL_COMMANDS:
  2939. case CHANNEL_MERCHANT:
  2940. case CHANNEL_MERCHANT_BUY_SELL:
  2941. case CHANNEL_CONSIDER_MESSAGE:
  2942. case CHANNEL_CON_MINUS_2:
  2943. case CHANNEL_CON_MINUS_1:
  2944. case CHANNEL_CON_0:
  2945. case CHANNEL_CON_1:
  2946. case CHANNEL_CON_2:
  2947. return channel_type - 31;
  2948. default: {
  2949. return CHANNEL_DEFAULT;
  2950. }
  2951. }
  2952. }
  2953. else if (GetVersion() <= 546) {
  2954. if (channel_type < 20)
  2955. return channel_type;
  2956. switch (channel_type) {
  2957. case CHANNEL_GUILD_MOTD:
  2958. case CHANNEL_GUILD_MEMBER_ONLINE:
  2959. case CHANNEL_GUILD_EVENT:
  2960. return channel_type + 1;
  2961. case CHANNEL_PRIVATE_CHAT:
  2962. case CHANNEL_NONPLAYER_TELL:
  2963. return channel_type - 1;
  2964. case CHANNEL_PRIVATE_TELL:
  2965. case CHANNEL_TELL_FROM_CS:
  2966. case CHANNEL_ARENA:
  2967. case CHANNEL_CHAT_CHANNEL_TEXT:
  2968. case CHANNEL_OUT_OF_CHARACTER:
  2969. case CHANNEL_AUCTION:
  2970. case CHANNEL_CUSTOM_CHANNEL:
  2971. case CHANNEL_CHARACTER_TEXT:
  2972. case CHANNEL_REWARD:
  2973. case CHANNEL_DEATH:
  2974. case CHANNEL_PET_CHAT:
  2975. case CHANNEL_SKILL:
  2976. case CHANNEL_FACTION:
  2977. case CHANNEL_SPELLS:
  2978. case CHANNEL_YOU_CAST:
  2979. case CHANNEL_YOU_FAIL:
  2980. return channel_type - 2;
  2981. case CHANNEL_FRIENDLY_CAST:
  2982. case CHANNEL_FRIENDLY_FAIL:
  2983. case CHANNEL_OTHER_CAST:
  2984. case CHANNEL_OTHER_FAIL:
  2985. case CHANNEL_HOSTILE_CAST:
  2986. case CHANNEL_HOSTILE_FAIL:
  2987. case CHANNEL_WORN_OFF:
  2988. case CHANNEL_SPELLS_OTHER:
  2989. case CHANNEL_HEAL_SPELLS:
  2990. case CHANNEL_HEALS:
  2991. case CHANNEL_FRIENDLY_HEALS:
  2992. case CHANNEL_OTHER_HEALS:
  2993. case CHANNEL_HOSTILE_HEALS:
  2994. return channel_type - 3;
  2995. case CHANNEL_COMBAT:
  2996. case CHANNEL_GENERAL_COMBAT:
  2997. case CHANNEL_HEROIC_OPPORTUNITY:
  2998. case CHANNEL_NON_MELEE_DAMAGE:
  2999. case CHANNEL_DAMAGE_SHIELD:
  3000. case CHANNEL_WARD:
  3001. return channel_type - 4;
  3002. case CHANNEL_MELEE_COMBAT:
  3003. case CHANNEL_WARNINGS:
  3004. case CHANNEL_YOU_HIT:
  3005. case CHANNEL_YOU_MISS:
  3006. case CHANNEL_ATTACKER_HITS:
  3007. case CHANNEL_ATTACKER_MISSES:
  3008. case CHANNEL_YOUR_PET_HITS:
  3009. case CHANNEL_YOUR_PET_MISSES:
  3010. case CHANNEL_ATTACKER_HITS_PET:
  3011. case CHANNEL_ATTACKER_MISSES_PET:
  3012. case CHANNEL_OTHER_HIT:
  3013. case CHANNEL_OTHER_MISSES:
  3014. return channel_type - 5;
  3015. case CHANNEL_OTHER:
  3016. case CHANNEL_MONEY_SPLIT:
  3017. case CHANNEL_LOOT:
  3018. return channel_type - 14;
  3019. case CHANNEL_COMMAND_TEXT:
  3020. case CHANNEL_BROADCAST:
  3021. case CHANNEL_WHO:
  3022. case CHANNEL_COMMANDS:
  3023. case CHANNEL_MERCHANT:
  3024. case CHANNEL_MERCHANT_BUY_SELL:
  3025. case CHANNEL_CONSIDER_MESSAGE:
  3026. case CHANNEL_CON_MINUS_2:
  3027. case CHANNEL_CON_MINUS_1:
  3028. case CHANNEL_CON_0:
  3029. case CHANNEL_CON_1:
  3030. case CHANNEL_CON_2:
  3031. case CHANNEL_TRADESKILLS:
  3032. case CHANNEL_HARVESTING:
  3033. case CHANNEL_HARVESTING_WARNINGS:
  3034. return channel_type - 15;
  3035. default: {
  3036. return CHANNEL_DEFAULT;
  3037. }
  3038. }
  3039. }
  3040. else {
  3041. switch (channel_type) {
  3042. default: {
  3043. return channel_type;
  3044. }
  3045. }
  3046. }
  3047. return channel_type;
  3048. }
  3049. void Client::HandleTellMessage(Client* from, const char* message) {
  3050. if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  3051. return;
  3052. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  3053. if (packet) {
  3054. packet->setDataByName("from", from->GetPlayer()->GetName());
  3055. packet->setDataByName("to", GetPlayer()->GetName());
  3056. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  3057. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  3058. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  3059. packet->setDataByName("unknown2", 1, 1);
  3060. packet->setDataByName("show_bubble", 1);
  3061. packet->setDataByName("understood", 1);
  3062. packet->setDataByName("time", 2);
  3063. packet->setMediumStringByName("message", message);
  3064. EQ2Packet* outpacket = packet->serialize();
  3065. QueuePacket(outpacket);
  3066. safe_delete(packet);
  3067. }
  3068. }
  3069. void Client::SimpleMessage(int8 color, const char* message) {
  3070. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  3071. if (command_packet) {
  3072. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  3073. command_packet->setMediumStringByName("text", message);
  3074. command_packet->setDataByName("unknown02", 0x00ff);
  3075. EQ2Packet* outapp = command_packet->serialize();
  3076. QueuePacket(outapp);
  3077. safe_delete(command_packet);
  3078. }
  3079. }
  3080. void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
  3081. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  3082. if (packet) {
  3083. int8 xxx = spell->GetSpellData()->is_aa;
  3084. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  3085. packet->setDataByName("spell_id", spell->GetSpellID());
  3086. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  3087. packet->setDataByName("spell_name", spell->GetName());
  3088. if(add_silently)
  3089. packet->setDataByName("add_silently", 1);
  3090. if(add_to_hotbar)
  3091. packet->setDataByName("add_to_hotbar", 1);
  3092. packet->setDataByName("unknown", xxx);
  3093. packet->setDataByName("display_spell_tier", 1);
  3094. packet->setDataByName("unknown3", 1);
  3095. packet->setDataByName("tier", spell->GetSpellTier());
  3096. packet->setDataByName("icon", spell->GetSpellIcon());
  3097. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  3098. packet->setDataByName("unknown5", 0xFFFFFFFF);
  3099. //packet->PrintPacket();
  3100. EQ2Packet* outapp = packet->serialize();
  3101. //DumpPacket(outapp);
  3102. QueuePacket(outapp);
  3103. safe_delete(packet);
  3104. }
  3105. }
  3106. void Client::Message(int8 type, const char* message, ...) {
  3107. va_list argptr;
  3108. char buffer[4096];
  3109. va_start(argptr, message);
  3110. vsnprintf(buffer, sizeof(buffer), message, argptr);
  3111. va_end(argptr);
  3112. SimpleMessage(type, buffer);
  3113. }
  3114. void Client::Disconnect(bool send_disconnect)
  3115. {
  3116. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  3117. SetConnected(false);
  3118. if (send_disconnect && getConnection())
  3119. getConnection()->SendDisconnect(true);
  3120. this->Save();
  3121. this->GetPlayer()->WritePlayerStatistics();
  3122. eqs = 0;
  3123. }
  3124. bool Client::Summon(const char* search_name) {
  3125. Spawn* target = 0;
  3126. if (search_name || GetPlayer()->GetTarget()) {
  3127. Client* search_client = 0;
  3128. if (search_name) {
  3129. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3130. if (target && target->IsPlayer())
  3131. search_client = GetCurrentZone()->GetClientBySpawn(target);
  3132. if (!target) {
  3133. search_client = zone_list.GetClientByCharName(string(search_name));
  3134. if (search_client)
  3135. target = search_client->GetPlayer();
  3136. }
  3137. }
  3138. else
  3139. target = GetPlayer()->GetTarget();
  3140. if (target && target != GetPlayer()) {
  3141. target->SetX(GetPlayer()->GetX());
  3142. target->SetY(GetPlayer()->GetY());
  3143. target->SetZ(GetPlayer()->GetZ());
  3144. target->SetHeading(GetPlayer()->GetHeading());
  3145. if (!target->IsPlayer()) {
  3146. target->SetSpawnOrigX(target->GetX());
  3147. target->SetSpawnOrigY(target->GetY());
  3148. target->SetSpawnOrigZ(target->GetZ());
  3149. target->SetSpawnOrigHeading(target->GetHeading());
  3150. }
  3151. target->SetLocation(GetPlayer()->GetLocation());
  3152. }
  3153. else if (target)
  3154. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  3155. if (search_client && search_client != this) {
  3156. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  3157. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  3158. if (search_client->GetCurrentZone() != GetCurrentZone())
  3159. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  3160. else {
  3161. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  3162. if (app)
  3163. search_client->QueuePacket(app);
  3164. }
  3165. }
  3166. }
  3167. if (!target)
  3168. return false;
  3169. else
  3170. return true;
  3171. }
  3172. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  3173. ZoneServer* instance_zone = NULL;
  3174. int8 instanceType = 0;
  3175. // determine if this is a group instanced zone that already exists
  3176. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  3177. if (instance_zone != NULL)
  3178. Zone(instance_zone->GetInstanceID(), zone_coords_valid, true);
  3179. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  3180. {
  3181. // best to check if we already have our own instance!
  3182. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3183. if (data) {
  3184. // If lockout instances check to see if we are locked out
  3185. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  3186. int32 time = 0;
  3187. // Check success timer
  3188. if (data->last_success_timestamp > 0) {
  3189. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  3190. // Timer has not expired yet can't re enter
  3191. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3192. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  3193. }
  3194. }
  3195. // Check failure timer
  3196. if (data->last_failure_timestamp > 0) {
  3197. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  3198. // Timer has not expired yet
  3199. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3200. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  3201. }
  3202. }
  3203. // Time > 0 then we are locked out, make the message and send it and return true
  3204. if (time > 0) {
  3205. string time_msg = "";
  3206. int16 hour;
  3207. int8 min;
  3208. int8 sec;
  3209. hour = time / 3600;
  3210. time = time % 3600;
  3211. min = time / 60;
  3212. time = time % 60;
  3213. sec = time;
  3214. if (hour > 0) {
  3215. char temp[10];
  3216. sprintf(temp, " %i", hour);
  3217. time_msg.append(temp);
  3218. time_msg.append(" hour");
  3219. time_msg.append((hour > 1) ? "s" : "");
  3220. }
  3221. if (min > 0) {
  3222. char temp[5];
  3223. sprintf(temp, " %i", min);
  3224. time_msg.append(temp);
  3225. time_msg.append(" minute");
  3226. time_msg.append((min > 1) ? "s" : "");
  3227. }
  3228. // Only add seconds if minutes and hours are 0
  3229. if (hour == 0 && min == 0 && sec > 0) {
  3230. char temp[5];
  3231. sprintf(temp, " %i", sec);
  3232. time_msg.append(temp);
  3233. time_msg.append(" second");
  3234. time_msg.append((sec > 1) ? "s" : "");
  3235. }
  3236. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  3237. return true;
  3238. }
  3239. }
  3240. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  3241. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID);
  3242. // 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
  3243. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  3244. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  3245. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  3246. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  3247. }
  3248. else
  3249. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  3250. data->instance_id = instance_zone->GetInstanceID();
  3251. }
  3252. }
  3253. else {
  3254. switch (instanceType)
  3255. {
  3256. case SOLO_LOCKOUT_INSTANCE:
  3257. case GROUP_LOCKOUT_INSTANCE:
  3258. case RAID_LOCKOUT_INSTANCE:
  3259. {
  3260. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3261. if (instance_zone) {
  3262. // 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
  3263. // so delete `instances` entry for the zone when it shuts down.
  3264. 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());
  3265. if (db_id > 0)
  3266. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  3267. }
  3268. break;
  3269. }
  3270. case SOLO_PERSIST_INSTANCE:
  3271. case GROUP_PERSIST_INSTANCE:
  3272. case RAID_PERSIST_INSTANCE:
  3273. {
  3274. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3275. if (instance_zone) {
  3276. 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());
  3277. if (db_id > 0)
  3278. 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()));
  3279. }
  3280. break;
  3281. }
  3282. case PUBLIC_INSTANCE:
  3283. case TRADESKILL_INSTANCE:
  3284. {
  3285. // if its public/tradeskill, look for a public already setup
  3286. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  3287. if (instance_zone) {
  3288. // Check the current population against the max population, if greater or equal start a new version
  3289. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  3290. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3291. }
  3292. else
  3293. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3294. break;
  3295. }
  3296. case PERSONAL_HOUSE_INSTANCE:
  3297. case GUILD_HOUSE_INSTANCE:
  3298. {
  3299. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  3300. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  3301. // with the OP_EnterHouseMsg opcode
  3302. break;
  3303. }
  3304. case QUEST_INSTANCE:
  3305. {
  3306. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3307. break;
  3308. /*
  3309. 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`;
  3310. */
  3311. }
  3312. default:
  3313. {
  3314. // NONE
  3315. }
  3316. }
  3317. }
  3318. if (instance_zone != NULL)
  3319. Zone(instance_zone, zone_coords_valid);
  3320. }
  3321. if (instance_zone != NULL)
  3322. return true;
  3323. else
  3324. return false;
  3325. }
  3326. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  3327. Spawn* target = 0;
  3328. if (search_name || GetPlayer()->GetTarget()) {
  3329. Client* search_client = 0;
  3330. if (search_name) {
  3331. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3332. if (!target) {
  3333. search_client = zone_list.GetClientByCharName(search_name);
  3334. if (search_client)
  3335. target = search_client->GetPlayer();
  3336. }
  3337. if (target)
  3338. GetPlayer()->SetTarget(target);
  3339. }
  3340. else
  3341. target = GetPlayer()->GetTarget();
  3342. if (target && target != GetPlayer()) {
  3343. GetPlayer()->SetX(target->GetX());
  3344. GetPlayer()->SetY(target->GetY());
  3345. GetPlayer()->SetZ(target->GetZ());
  3346. GetPlayer()->SetHeading(target->GetHeading());
  3347. GetPlayer()->SetLocation(target->GetLocation());
  3348. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  3349. }
  3350. else if (target)
  3351. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  3352. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  3353. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  3354. else if (target) {
  3355. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion());
  3356. if (app)
  3357. QueuePacket(app);
  3358. }
  3359. }
  3360. if (!target)
  3361. return false;
  3362. else
  3363. return true;
  3364. }
  3365. bool Client::CheckZoneAccess(const char* zoneName) {
  3366. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  3367. ZoneServer* zone = zone_list.Get(zoneName, false);
  3368. // JA: implemented /zone lock|unlock commands (2012.07.28)
  3369. if (zone && zone->GetZoneLockState())
  3370. {
  3371. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  3372. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  3373. return false;
  3374. }
  3375. sint16 zoneMinStatus = 0;
  3376. int16 zoneMinLevel = 0;
  3377. int16 zoneMaxLevel = 0;
  3378. int16 zoneMinVersion = 0;
  3379. if (!zone)
  3380. {
  3381. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  3382. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  3383. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  3384. return true;
  3385. }
  3386. }
  3387. else
  3388. {
  3389. zoneMinStatus = zone->GetMinimumStatus();
  3390. zoneMinLevel = zone->GetMinimumLevel();
  3391. zoneMaxLevel = zone->GetMaximumLevel();
  3392. zoneMinVersion = zone->GetMinimumVersion();
  3393. }
  3394. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  3395. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  3396. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  3397. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  3398. {
  3399. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  3400. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  3401. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  3402. return false;
  3403. }
  3404. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  3405. {
  3406. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3407. {
  3408. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3409. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  3410. return false;
  3411. }
  3412. }
  3413. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  3414. {
  3415. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3416. {
  3417. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3418. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  3419. return false;
  3420. }
  3421. }
  3422. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  3423. {
  3424. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  3425. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  3426. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  3427. {
  3428. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  3429. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  3430. return false;
  3431. }
  3432. }
  3433. return true;
  3434. }
  3435. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID) {
  3436. Zone(zone_list.GetByInstanceID(instanceid), set_coords);
  3437. }
  3438. void Client::Zone(ZoneServer* new_zone, bool set_coords) {
  3439. if (!new_zone) {
  3440. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  3441. return;
  3442. }
  3443. client_zoning = true;
  3444. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  3445. player->SetResurrecting(true);
  3446. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  3447. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  3448. // Remove players pet from zone if there is one
  3449. player->DismissPet((NPC*)player->GetPet());
  3450. player->DismissPet((NPC*)player->GetCharmedPet());
  3451. player->DismissPet((NPC*)player->GetDeityPet());
  3452. player->DismissPet((NPC*)player->GetCosmeticPet());
  3453. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  3454. GetCurrentZone()->RemoveSpawn(false, player, false);
  3455. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  3456. SetCurrentZone(new_zone);
  3457. if (player->GetGroupMemberInfo())
  3458. {
  3459. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  3460. player->UpdateGroupMemberInfo();
  3461. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  3462. }
  3463. // block out the member info for the group
  3464. TempRemoveGroup();
  3465. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  3466. if (set_coords)
  3467. {
  3468. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  3469. __FUNCTION__,
  3470. GetCurrentZone()->GetSafeX(),
  3471. GetCurrentZone()->GetSafeY(),
  3472. GetCurrentZone()->GetSafeZ(),
  3473. GetCurrentZone()->GetSafeHeading(),
  3474. new_zone->GetZoneName()
  3475. );
  3476. player->SetX(GetCurrentZone()->GetSafeX());
  3477. player->SetY(GetCurrentZone()->GetSafeY());
  3478. player->SetZ(GetCurrentZone()->GetSafeZ());
  3479. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3480. }
  3481. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  3482. Save();
  3483. char* new_zone_ip = 0;
  3484. struct in_addr in;
  3485. in.s_addr = this->GetIP();
  3486. if (strncmp(inet_ntoa(in), "192.168", 7) == 0 && strlen(net.GetInternalWorldAddress()) > 0)
  3487. new_zone_ip = net.GetInternalWorldAddress();
  3488. else
  3489. new_zone_ip = net.GetWorldAddress();
  3490. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  3491. int32 key = Timer::GetUnixTimeStamp();
  3492. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  3493. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  3494. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  3495. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  3496. if (version > 283) {
  3497. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  3498. if (packet)
  3499. {
  3500. QueuePacket(packet->serialize());
  3501. safe_delete(packet);
  3502. }
  3503. }
  3504. }
  3505. void Client::Zone(const char* new_zone, bool set_coords)
  3506. {
  3507. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  3508. Zone(zone_list.Get(new_zone), set_coords);
  3509. }
  3510. float Client::DistanceFrom(Client* client) {
  3511. float ret = 0;
  3512. if (client && client != this) {
  3513. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  3514. ret = sqrt(ret);
  3515. }
  3516. return ret;
  3517. }
  3518. void Client::DetermineCharacterUpdates() {
  3519. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  3520. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  3521. cdu->account_id = GetAccountID();
  3522. cdu->char_id = GetCharacterID();
  3523. int32 timestamp = Timer::GetUnixTimeStamp();
  3524. int8 flag = GetTimeStampFlag();
  3525. if (flag & LEVEL_UPDATE_FLAG)
  3526. {
  3527. cdu->update_field = LEVEL_UPDATE_FLAG;
  3528. cdu->update_data = player->GetLevel();
  3529. loginserver.SendPacket(outpack);
  3530. }
  3531. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  3532. if (flag & CLASS_UPDATE_FLAG)
  3533. {
  3534. cdu->update_field = CLASS_UPDATE_FLAG;
  3535. cdu->update_data = player->GetAdventureClass();
  3536. loginserver.SendPacket(outpack);
  3537. }
  3538. if (flag & GENDER_UPDATE_FLAG)
  3539. {
  3540. cdu->update_field = GENDER_UPDATE_FLAG;
  3541. cdu->update_data = player->GetGender();
  3542. loginserver.SendPacket(outpack);
  3543. }
  3544. if (flag & DELETE_UPDATE_FLAG) {
  3545. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3546. }
  3547. safe_delete(outpack); // Zone, armor and name use a different structure
  3548. if (flag & RACE_UPDATE_FLAG)
  3549. {
  3550. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  3551. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  3552. ru->account_id = GetAccountID();
  3553. ru->char_id = GetCharacterID();
  3554. ru->race = player->GetRace();
  3555. ru->model_type = player->GetModelType();
  3556. loginserver.SendPacket(outpack);
  3557. safe_delete(outpack);
  3558. }
  3559. if (flag & ZONE_UPDATE_FLAG) {
  3560. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  3561. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  3562. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  3563. czu->account_id = GetAccountID();
  3564. czu->char_id = GetCharacterID();
  3565. czu->zone_id = GetCurrentZone()->GetZoneID();
  3566. const char* zone_file = GetCurrentZone()->GetZoneFile();
  3567. czu->zone_length = strlen(zone_file);
  3568. if (czu->zone_length > 64)
  3569. czu->zone_length = 64;
  3570. strncpy(czu->new_zone, zone_file, czu->zone_length);
  3571. loginserver.SendPacket(outpack);
  3572. safe_delete(outpack);
  3573. }
  3574. if (flag & ARMOR_UPDATE_FLAG) {
  3575. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3576. }
  3577. if (flag & NAME_UPDATE_FLAG) {
  3578. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3579. }
  3580. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  3581. }
  3582. void Client::Save() {
  3583. if (GetCharacterID() == 0)
  3584. return;
  3585. if (current_zone) {
  3586. DetermineCharacterUpdates();
  3587. UpdateCharacterInstances();
  3588. database.Save(this);
  3589. if (GetPlayer()->UpdateQuickbarNeeded()) {
  3590. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  3591. GetPlayer()->ResetQuickbarNeeded();
  3592. }
  3593. database.SaveItems(this);
  3594. database.SaveBuyBacks(this);
  3595. GetPlayer()->SaveHistory();
  3596. GetPlayer()->SaveLUAHistory();
  3597. }
  3598. }
  3599. void Client::UpdateCharacterInstances() {
  3600. if (GetPlayer() != NULL)
  3601. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  3602. /*if ( GetPlayer() != NULL )
  3603. {
  3604. // determine the last timestamp then get a new one, determine the difference in the timestamp
  3605. // to use for applying the update to each instances timer
  3606. int32 lastSaveTS = GetLastSavedTimeStamp();
  3607. int32 newSaveTS = Timer::GetUnixTimeStamp();
  3608. int32 diffTS = newSaveTS - lastSaveTS;
  3609. // update instance timers
  3610. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  3611. // update with the new timestamp and save the db
  3612. this->SetLastSavedTimeStamp(newSaveTS);
  3613. }*/
  3614. }
  3615. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  3616. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  3617. if (packet) {
  3618. packet->LoadPacketData(app->pBuffer, app->size);
  3619. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  3620. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  3621. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  3622. vector<EntityCommand*> commands;
  3623. vector<EntityCommand*> delete_commands;
  3624. if (out && spawn) {
  3625. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  3626. {
  3627. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  3628. if (!spawn->primary_command_list[i]->default_allow_list)
  3629. {
  3630. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3631. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  3632. continue;
  3633. }
  3634. else
  3635. {
  3636. // default is allow list, only deny if added to the list as deny (false itr second)
  3637. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3638. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  3639. continue;
  3640. }
  3641. commands.push_back(spawn->primary_command_list[i]);
  3642. }
  3643. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  3644. commands.push_back(spawn->secondary_command_list[i]);
  3645. if (spawn->IsPlayer()) {
  3646. if (player->IsFriend(spawn->GetName()))
  3647. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  3648. else
  3649. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  3650. if (player->IsIgnored(spawn->GetName()))
  3651. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  3652. else
  3653. {
  3654. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  3655. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  3656. }
  3657. if (((Player*)spawn)->GetGroupMemberInfo()) {
  3658. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  3659. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  3660. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  3661. }
  3662. }
  3663. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  3664. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  3665. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  3666. }
  3667. out->setDataByName("spawn_id", spawn_id);
  3668. out->setArrayLengthByName("num_verbs", commands.size());
  3669. for (int32 i = 0; i < commands.size(); i++) {
  3670. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  3671. out->setArrayDataByName("distance", commands[i]->distance, i);
  3672. if (commands[i]->error_text.length() == 0)
  3673. out->setArrayAddToPacketByName("error", false, i);
  3674. else {
  3675. out->setArrayDataByName("display_error", 1, i);
  3676. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  3677. }
  3678. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  3679. }
  3680. EQ2Packet* outapp = out->serialize();
  3681. //DumpPacket(outapp);
  3682. QueuePacket(outapp);
  3683. safe_delete(out);
  3684. for (int32 i = 0; i < delete_commands.size(); i++) {
  3685. safe_delete(delete_commands[i]);
  3686. }
  3687. }
  3688. safe_delete(packet);
  3689. }
  3690. }
  3691. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  3692. if (previous_value != new_value) {
  3693. 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);
  3694. char tmp[200] = { 0 };
  3695. 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);
  3696. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  3697. }
  3698. }
  3699. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  3700. {
  3701. /* JA notes on the unknown:
  3702. 2 = ding glimmer
  3703. 16 = Achievement Unlocked
  3704. 6 no longer does anything
  3705. */
  3706. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  3707. if (packet) {
  3708. packet->setDataByName("unknown", unknown);
  3709. packet->setMediumStringByName("text", text);
  3710. if (type && strlen(type) > 0)
  3711. packet->setMediumStringByName("message_type", type);
  3712. packet->setDataByName("size", size);
  3713. packet->setDataByName("red", red);
  3714. packet->setDataByName("green", green);
  3715. packet->setDataByName("blue", blue);
  3716. QueuePacket(packet->serialize());
  3717. safe_delete(packet);
  3718. }
  3719. }
  3720. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  3721. if (new_level < 1) {
  3722. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  3723. return;
  3724. }
  3725. if (player->GetLevel() != new_level) {
  3726. player->SetLevel(new_level);
  3727. if (player->GetGroupMemberInfo()) {
  3728. player->UpdateGroupMemberInfo();
  3729. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  3730. }
  3731. }
  3732. if (new_level > old_level) {
  3733. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  3734. }
  3735. if (player->GetPet()) {
  3736. NPC* pet = (NPC*)player->GetPet();
  3737. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  3738. pet->SetLevel(new_level);
  3739. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3740. if (command_packet) {
  3741. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  3742. command_packet->setDataByName("anim_type", 1753);
  3743. QueuePacket(command_packet->serialize());
  3744. safe_delete(command_packet);
  3745. }
  3746. }
  3747. }
  3748. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  3749. if (level_update) {
  3750. level_update->setDataByName("old_level", old_level);
  3751. level_update->setDataByName("new_level", new_level);
  3752. QueuePacket(level_update->serialize());
  3753. safe_delete(level_update);
  3754. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  3755. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  3756. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  3757. }
  3758. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3759. if (command_packet) {
  3760. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  3761. command_packet->setDataByName("anim_type", 1753);
  3762. QueuePacket(command_packet->serialize());
  3763. safe_delete(command_packet);
  3764. }
  3765. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  3766. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  3767. SendNewSpells(player->GetAdventureClass());
  3768. SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  3769. SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  3770. GetPlayer()->ChangePrimaryWeapon();
  3771. GetPlayer()->ChangeSecondaryWeapon();
  3772. GetPlayer()->ChangeRangedWeapon();
  3773. GetPlayer()->GetInfoStruct()->level = new_level;
  3774. // GetPlayer()->SetLevel(new_level);
  3775. 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__);
  3776. GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
  3777. GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
  3778. GetPlayer()->CalculateBonuses();
  3779. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  3780. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  3781. InfoStruct* info = player->GetInfoStruct();
  3782. info->agi_base = new_level * 2 + 15;
  3783. info->intel_base = new_level * 2 + 15;
  3784. info->wis_base = new_level * 2 + 15;
  3785. info->str_base = new_level * 2 + 15;
  3786. info->sta_base = new_level * 2 + 15;
  3787. info->cold_base = (int16)(new_level * 1.5 + 10);
  3788. info->heat_base = (int16)(new_level * 1.5 + 10);
  3789. info->disease_base = (int16)(new_level * 1.5 + 10);
  3790. info->mental_base = (int16)(new_level * 1.5 + 10);
  3791. info->magic_base = (int16)(new_level * 1.5 + 10);
  3792. info->divine_base = (int16)(new_level * 1.5 + 10);
  3793. info->poison_base = (int16)(new_level * 1.5 + 10);
  3794. GetPlayer()->SetHPRegen((int)(new_level * .75) + (int)(new_level / 10) + 3);
  3795. GetPlayer()->SetPowerRegen(new_level + (int)(new_level / 10) + 4);
  3796. GetPlayer()->GetInfoStruct()->poison_base = (int16)(new_level * 1.5 + 10);
  3797. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  3798. GetPlayer()->SetCharSheetChanged(true);
  3799. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  3800. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  3801. int16 new_skill_cap = 5 * new_level;
  3802. PlayerSkillList* player_skills = player->GetSkills();
  3803. player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
  3804. player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
  3805. //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
  3806. player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
  3807. player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
  3808. player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
  3809. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
  3810. //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
  3811. player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
  3812. player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
  3813. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  3814. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  3815. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  3816. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  3817. if (new_level > player->GetTSLevel())
  3818. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  3819. //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
  3820. if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
  3821. player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
  3822. if (player_skills->HasSkill(SKILL_ID_FISTS))
  3823. player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
  3824. if (player_skills->HasSkill(SKILL_ID_DESTROYING))
  3825. player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
  3826. if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
  3827. player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
  3828. Guild* guild = GetPlayer()->GetGuild();
  3829. if (guild) {
  3830. int8 event_type = 0;
  3831. if (new_level < 10)
  3832. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  3833. else if (new_level == 10)
  3834. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  3835. else if (new_level >= 11 && new_level < 20)
  3836. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  3837. else if (new_level == 20)
  3838. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  3839. else if (new_level >= 21 && new_level < 30)
  3840. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  3841. else if (new_level == 30)
  3842. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  3843. else if (new_level >= 31 && new_level < 40)
  3844. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  3845. else if (new_level == 40)
  3846. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  3847. else if (new_level >= 41 && new_level < 50)
  3848. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  3849. else if (new_level == 50)
  3850. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  3851. else if (new_level >= 51 && new_level < 60)
  3852. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  3853. else if (new_level == 60)
  3854. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  3855. else if (new_level >= 61 && new_level < 70)
  3856. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  3857. else if (new_level == 70)
  3858. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  3859. else if (new_level >= 71 && new_level < 80)
  3860. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  3861. else if (new_level == 80)
  3862. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  3863. 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());
  3864. 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());
  3865. guild->UpdateGuildMemberInfo(GetPlayer());
  3866. guild->SendGuildMember(GetPlayer());
  3867. guild->SendGuildMemberList();
  3868. }
  3869. // Need to send the trait list every time the players level changes
  3870. // Also need to force the char sheet update or else there can be a large delay from when you level
  3871. // to when you are actually able to select traits.
  3872. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  3873. QueuePacket(master_trait_list.GetTraitListPacket(this));
  3874. if (version > 546)
  3875. master_aa_list.DisplayAA(this, 0, 0);
  3876. if (GetPlayer()->SpawnedBots.size() > 0) {
  3877. map<int32, int32>::iterator itr;
  3878. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  3879. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  3880. if (bot && bot->IsBot())
  3881. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  3882. }
  3883. }
  3884. }
  3885. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  3886. if (new_level < 1) {
  3887. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  3888. return;
  3889. }
  3890. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  3891. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  3892. return;
  3893. }
  3894. if (new_level > old_level)
  3895. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  3896. if (player->GetTSLevel() != new_level) {
  3897. player->SetTSLevel(new_level);
  3898. if (player->GetGroupMemberInfo()) {
  3899. player->UpdateGroupMemberInfo();
  3900. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  3901. }
  3902. }
  3903. // Only tradeskill skills should increace, and then only those related to your class
  3904. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  3905. if (level_update) {
  3906. level_update->setDataByName("old_level", old_level);
  3907. level_update->setDataByName("new_level", new_level);
  3908. level_update->setDataByName("type", 1);
  3909. QueuePacket(level_update->serialize());
  3910. safe_delete(level_update);
  3911. }
  3912. // Need to make tradeskill versions of the following
  3913. //SendNewSpells(player->GetAdventureClass());
  3914. //SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  3915. //SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  3916. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3917. if (command_packet) {
  3918. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  3919. command_packet->setDataByName("anim_type", 1753);
  3920. QueuePacket(command_packet->serialize());
  3921. safe_delete(command_packet);
  3922. }
  3923. GetPlayer()->GetInfoStruct()->tradeskill_level = new_level;
  3924. GetPlayer()->SetTSLevel(new_level);
  3925. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  3926. GetPlayer()->SetCharSheetChanged(true);
  3927. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  3928. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  3929. PlayerSkillList* player_skills = player->GetSkills();
  3930. int16 specialize_skill_cap = new_level * 5;
  3931. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  3932. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  3933. int8 ts_class = player->GetTradeskillClass();
  3934. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  3935. int32 skill_id_1, skill_id_2, skill_id_3;
  3936. switch (base_ts_class) {
  3937. case ARTISAN:
  3938. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3939. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3940. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3941. break;
  3942. case OUTFITTER:
  3943. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3944. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3945. skill_id_1 = SKILL_ID_TAILORING;
  3946. skill_id_2 = SKILL_ID_METALSHAPING;
  3947. skill_id_3 = SKILL_ID_METALWORKING;
  3948. if (ts_class == TAILOR) {
  3949. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3950. skill_id_1 = 0;
  3951. }
  3952. else if (ts_class == ARMORER) {
  3953. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3954. skill_id_2 = 0;
  3955. }
  3956. else if (ts_class == WEAPONSMITH) {
  3957. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3958. skill_id_3 = 0;
  3959. }
  3960. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3961. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3962. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3963. break;
  3964. case SCHOLAR:
  3965. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3966. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3967. skill_id_1 = SKILL_ID_SCRIBING;
  3968. skill_id_2 = SKILL_ID_CHEMISTRY;
  3969. skill_id_3 = SKILL_ID_ARTIFICING;
  3970. if (ts_class == SAGE) {
  3971. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3972. skill_id_1 = 0;
  3973. }
  3974. else if (ts_class == ALCHEMIST) {
  3975. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3976. skill_id_2 = 0;
  3977. }
  3978. else if (ts_class == JEWELER) {
  3979. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3980. skill_id_3 = 0;
  3981. }
  3982. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3983. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3984. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3985. break;
  3986. case CRAFTSMAN:
  3987. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3988. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3989. skill_id_1 = SKILL_ID_ARTISTRY;
  3990. skill_id_2 = SKILL_ID_FLETCHING;
  3991. skill_id_3 = SKILL_ID_SCULPTING;
  3992. if (ts_class == PROVISIONER) {
  3993. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3994. skill_id_1 = 0;
  3995. }
  3996. else if (ts_class == WOODWORKER) {
  3997. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3998. skill_id_2 = 0;
  3999. }
  4000. else if (ts_class == CARPENTER) {
  4001. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4002. skill_id_3 = 0;
  4003. }
  4004. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4005. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4006. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4007. break;
  4008. default:
  4009. break;
  4010. }
  4011. if (new_level > player->GetAdventureClass())
  4012. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  4013. Guild* guild = GetPlayer()->GetGuild();
  4014. if (guild) {
  4015. int8 event_type = 0;
  4016. if (new_level < 10)
  4017. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  4018. else if (new_level == 10)
  4019. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  4020. else if (new_level >= 11 && new_level < 20)
  4021. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  4022. else if (new_level == 20)
  4023. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  4024. else if (new_level >= 21 && new_level < 30)
  4025. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  4026. else if (new_level == 30)
  4027. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  4028. else if (new_level >= 31 && new_level < 40)
  4029. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  4030. else if (new_level == 40)
  4031. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  4032. else if (new_level >= 41 && new_level < 50)
  4033. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  4034. else if (new_level == 50)
  4035. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  4036. else if (new_level >= 51 && new_level < 60)
  4037. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  4038. else if (new_level == 60)
  4039. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  4040. else if (new_level >= 61 && new_level < 70)
  4041. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  4042. else if (new_level == 70)
  4043. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  4044. else if (new_level >= 71 && new_level < 80)
  4045. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  4046. else if (new_level == 80)
  4047. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  4048. 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());
  4049. 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());
  4050. guild->UpdateGuildMemberInfo(GetPlayer());
  4051. guild->SendGuildMember(GetPlayer());
  4052. guild->SendGuildMemberList();
  4053. }
  4054. // Need to send the trait list every time the players level changes
  4055. // Also need to force the char sheet update or else there can be a large delay from when you level
  4056. // to when you are actually able to select traits.
  4057. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4058. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4059. }
  4060. void Client::SendPendingLoot(int32 total_coins, Spawn* entity) {
  4061. if (entity)
  4062. Loot(total_coins, player->GetPendingLootItems(entity->GetID()), entity);
  4063. }
  4064. void Client::CloseLoot(int32 spawn_id) {
  4065. if (GetVersion() > 546) {
  4066. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  4067. if (packet) {
  4068. packet->setDataByName("window_id", 4);
  4069. EQ2Packet* outapp = packet->serialize();
  4070. if (outapp) {
  4071. //DumpPacket(outapp);
  4072. QueuePacket(outapp);
  4073. }
  4074. safe_delete(packet);
  4075. }
  4076. }
  4077. else if(spawn_id > 0){
  4078. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  4079. if (packet) {
  4080. packet->setDataByName("spawn_id", spawn_id);
  4081. EQ2Packet* outapp = packet->serialize();
  4082. if (outapp)
  4083. QueuePacket(outapp);
  4084. safe_delete(packet);
  4085. }
  4086. }
  4087. }
  4088. string Client::GetCoinMessage(int32 total_coins) {
  4089. if (total_coins == 0) {
  4090. return " 0 Copper";
  4091. }
  4092. char tmp[64] = { 0 };
  4093. string message = "";
  4094. int32 val = 0;
  4095. if (total_coins >= 1000000) {
  4096. val = total_coins / 1000000;
  4097. total_coins -= 1000000 * val;
  4098. sprintf(tmp, " %u Platinum", val);
  4099. message.append(tmp);
  4100. memset(tmp, 0, 64);
  4101. }
  4102. if (total_coins >= 10000) {
  4103. val = total_coins / 10000;
  4104. total_coins -= 10000 * val;
  4105. sprintf(tmp, " %u Gold", val);
  4106. message.append(tmp);
  4107. memset(tmp, 0, 64);
  4108. }
  4109. if (total_coins >= 100) {
  4110. val = total_coins / 100;
  4111. total_coins -= 100 * val;
  4112. sprintf(tmp, " %u Silver", val);
  4113. message.append(tmp);
  4114. memset(tmp, 0, 64);
  4115. }
  4116. if (total_coins > 0) {
  4117. sprintf(tmp, " %u Copper", (int32)total_coins);
  4118. message.append(tmp);
  4119. }
  4120. return message;
  4121. }
  4122. void Client::Loot(int32 total_coins, vector<Item*>* items, Spawn* entity) {
  4123. if (!entity) {
  4124. CloseLoot(0);
  4125. return;
  4126. }
  4127. if (total_coins > 0) {
  4128. player->AddCoins(total_coins);
  4129. //PlaySound("coin_cha_ching");
  4130. string message = "";
  4131. if (entity->GetHP() == 0) {
  4132. message = "You loot ";
  4133. entity->SetLootCoins(0);
  4134. }
  4135. else
  4136. message = "You receive ";
  4137. message.append(GetCoinMessage(total_coins));
  4138. if (entity->GetHP() == 0)
  4139. message.append(" from the corpse of ").append(entity->GetName());
  4140. int8 type = CHANNEL_LOOT;
  4141. SimpleMessage(type, message.c_str());
  4142. }
  4143. if (!items || items->size() == 0)
  4144. CloseLoot(entity->GetID());
  4145. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  4146. if (packet) {
  4147. vector<Item*>::iterator itr;
  4148. int32 packet_size = 0;
  4149. EQ2Packet* outapp = 0;
  4150. uchar* data = 0;
  4151. if (GetVersion() >= 284) {
  4152. if (GetVersion() > 546) {
  4153. if (items && items->size() > 0) {
  4154. packet->setDataByName("loot_count", items->size());
  4155. packet->setDataByName("display", 1);
  4156. }
  4157. packet->setDataByName("loot_type", 1);
  4158. if (version >= 1096)
  4159. packet->setDataByName("lotto_timeout", 0x78);
  4160. else
  4161. packet->setDataByName("lotto_timeout", 0x3C);
  4162. packet->setDataByName("loot_id", entity->GetID());
  4163. EQ2Packet* tmpPacket = packet->serialize();
  4164. packet_size += tmpPacket->size;
  4165. if (items && items->size() > 0) {
  4166. data = new uchar[items->size() * 1000 + packet_size];
  4167. memset(data, 0, items->size() * 1000 + packet_size);
  4168. }
  4169. else {
  4170. data = new uchar[packet_size];
  4171. memset(data, 0, packet_size);
  4172. }
  4173. uchar* ptr = data;
  4174. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  4175. ptr += tmpPacket->size;
  4176. safe_delete(tmpPacket);
  4177. Item* item = 0;
  4178. if (items && items->size() > 0) {
  4179. for (itr = items->begin(); itr != items->end(); itr++) {
  4180. item = *itr;
  4181. memcpy(ptr, &item->details.item_id, sizeof(int32));
  4182. ptr += sizeof(int32);
  4183. packet_size += sizeof(int32);
  4184. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  4185. int8 offset = 0;
  4186. if (GetVersion() >= 1188) {
  4187. offset = 13;
  4188. }
  4189. else if (GetVersion() >= 860) {
  4190. offset = 11;
  4191. }
  4192. else if (GetVersion() <= 546) {
  4193. offset = 19;
  4194. }
  4195. else {
  4196. offset = 10;
  4197. }
  4198. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  4199. ptr += tmpPacket->size - offset;
  4200. packet_size += tmpPacket->size - offset;
  4201. safe_delete(tmpPacket);
  4202. }
  4203. }
  4204. packet_size -= sizeof(int32);
  4205. memcpy(data, &packet_size, sizeof(int32));
  4206. packet_size += sizeof(int32);
  4207. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  4208. }
  4209. else {
  4210. if (items && items->size() > 0) {
  4211. packet->setArrayLengthByName("loot_count", items->size());
  4212. Item* item = 0;
  4213. if (items && items->size() > 0) {
  4214. int i = 0;
  4215. for (itr = items->begin(); itr != items->end(); itr++) {
  4216. item = *itr;
  4217. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  4218. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  4219. i++;
  4220. }
  4221. }
  4222. packet->setDataByName("display", 1);
  4223. }
  4224. packet->setDataByName("loot_type", 1); // normal
  4225. packet->setDataByName("lotto_timeout", 0x3c); // 60 seconds
  4226. packet->setDataByName("spawn_id", entity->GetID());
  4227. outapp = packet->serialize();
  4228. }
  4229. }
  4230. else {
  4231. if (items && items->size() > 0) {
  4232. packet->setArrayLengthByName("loot_count", items->size());
  4233. for (int i = 0; i < items->size(); i++) {
  4234. Item* item = (*items)[i];
  4235. packet->setArrayDataByName("name", item->name.c_str(), i);
  4236. packet->setArrayDataByName("item_id", item->details.item_id, i);
  4237. packet->setArrayDataByName("count", item->details.count, i);
  4238. packet->setArrayDataByName("icon", item->details.icon, i);
  4239. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  4240. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  4241. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  4242. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  4243. else
  4244. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  4245. }
  4246. }
  4247. packet->setDataByName("object_id", entity->GetID());
  4248. packet->setDataByName("unknown3", 1);
  4249. packet->setDataByName("unknown4", 1);
  4250. packet->setDataByName("unknown5", 60);
  4251. outapp = packet->serialize();
  4252. }
  4253. if (outapp) {
  4254. DumpPacket(outapp);
  4255. QueuePacket(outapp);
  4256. }
  4257. safe_delete_array(data);
  4258. safe_delete(packet);
  4259. }
  4260. }
  4261. void Client::Loot(Spawn* entity, bool attemptDisarm) {
  4262. if (entity->IsNPC() && ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  4263. int32 total_coins = entity->GetLootCoins();
  4264. entity->LockLoot();
  4265. Loot(total_coins, entity->GetLootItems(), entity);
  4266. entity->UnlockLoot();
  4267. OpenChest(entity, attemptDisarm);
  4268. }
  4269. else
  4270. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  4271. }
  4272. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  4273. {
  4274. if (!entity)
  4275. return;
  4276. int8 chest_difficulty = 0;
  4277. int32 state = 0;
  4278. // Check for the chest and set the action state
  4279. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  4280. string modelName;
  4281. if (entity->GetModelType() == 4034) {
  4282. // small chest, open with copper coins
  4283. // does not include traps, however can be disarmed
  4284. chest_difficulty = 1;
  4285. state = 11899;
  4286. modelName.append("Small Chest");
  4287. }
  4288. else if (entity->GetModelType() == 5864) {
  4289. // treasure chest, open with silver coins
  4290. chest_difficulty = 2;
  4291. state = 11901;
  4292. modelName.append("Treasure Chest");
  4293. }
  4294. else if (entity->GetModelType() == 5865) {
  4295. // ornate chest, open with gold coins
  4296. chest_difficulty = 3;
  4297. state = 11900;
  4298. modelName.append("Ornate Chest");
  4299. }
  4300. else if (entity->GetModelType() == 4015) {
  4301. // exquisite chest, open with gold coins and jewels as well as a glow effect
  4302. chest_difficulty = 5;
  4303. state = 11898;
  4304. modelName.append("Exquisite Chest");
  4305. }
  4306. bool firstChestOpen = false;
  4307. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  4308. {
  4309. ChestTrap::ChestTrapInfo nextTrap;
  4310. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  4311. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  4312. firstChestOpen = true;
  4313. entity->SetTrapTriggered(true);
  4314. if (ret)
  4315. {
  4316. if (disarmSkill && attemptDisarm)
  4317. {
  4318. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  4319. {
  4320. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4321. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4322. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4323. }
  4324. else
  4325. {
  4326. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  4327. }
  4328. // despite fail/succeed we should always try to increase skill if disarm is available
  4329. GetPlayer()->GetSkillByName("Disarm Trap", true);
  4330. }
  4331. else // no disarm skill, always fail
  4332. {
  4333. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4334. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4335. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4336. }
  4337. }
  4338. }
  4339. else if (!entity->HasTrapTriggered())
  4340. {
  4341. firstChestOpen = true;
  4342. entity->SetTrapTriggered(true);
  4343. }
  4344. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  4345. // for those in range the SendStateCommand will cause it to animate open.
  4346. // TODO: when player enters radius that does not have visual state, update visual state
  4347. if (firstChestOpen)
  4348. entity->SetVisualState(state, false);
  4349. GetCurrentZone()->SendStateCommand(entity, state);
  4350. }
  4351. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  4352. {
  4353. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  4354. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  4355. if (source == NULL)
  4356. source = (Entity*)GetPlayer();
  4357. if (spell)
  4358. {
  4359. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  4360. if (gmi && gmi->group_id)
  4361. {
  4362. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  4363. if (group)
  4364. {
  4365. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4366. deque<GroupMemberInfo*>* members = group->GetMembers();
  4367. for (int8 i = 0; i < members->size(); i++) {
  4368. Entity* member = members->at(i)->member;
  4369. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  4370. continue;
  4371. // if we have a radius provided then check if the group member is outside the radius or not
  4372. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  4373. continue;
  4374. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4375. }
  4376. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4377. }
  4378. }
  4379. else
  4380. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4381. }
  4382. }
  4383. Spawn* Client::GetBanker() {
  4384. return banker;
  4385. }
  4386. void Client::SetBanker(Spawn* in_banker) {
  4387. banker = in_banker;
  4388. }
  4389. void Client::Bank(Spawn* banker, bool cancel) {
  4390. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  4391. if (!cancel)
  4392. SetBanker(banker);
  4393. else
  4394. SetBanker(0);
  4395. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  4396. if (packet) {
  4397. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  4398. int64 coins = GetPlayer()->GetInfoStruct()->bank_coin_copper + GetPlayer()->GetInfoStruct()->bank_coin_silver * 100 +
  4399. GetPlayer()->GetInfoStruct()->bank_coin_gold * 10000 + (int64)GetPlayer()->GetInfoStruct()->bank_coin_plat * 1000000;
  4400. int32 coins1, coins2;
  4401. coins1 = ((int32*)&coins)[0];
  4402. coins2 = ((int32*)&coins)[1];
  4403. packet->setDataByName("bank_coins", coins1);
  4404. packet->setDataByName("bank_coins2", coins2);
  4405. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->coin_copper);
  4406. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->coin_silver);
  4407. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->coin_gold);
  4408. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->coin_plat);
  4409. if (!cancel)
  4410. packet->setDataByName("display", 1);
  4411. QueuePacket(packet->serialize());
  4412. safe_delete(packet);
  4413. }
  4414. }
  4415. }
  4416. void Client::BankWithdrawal(int64 amount) {
  4417. bool cheater = false;
  4418. if (GetBanker() && amount > 0) {
  4419. string withdrawal = "";
  4420. char withdrawal_data[512] = { 0 };
  4421. int32 tmp = 0;
  4422. if (amount >= 1000000) {
  4423. tmp = amount / 1000000;
  4424. if (tmp > GetPlayer()->GetBankCoinsPlat())
  4425. cheater = true;
  4426. else {
  4427. GetPlayer()->GetInfoStruct()->bank_coin_plat -= tmp;
  4428. GetPlayer()->GetInfoStruct()->coin_plat += tmp;
  4429. amount -= (int64)tmp * 1000000;
  4430. sprintf(withdrawal_data, "%u Platinum ", tmp);
  4431. withdrawal.append(withdrawal_data);
  4432. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4433. }
  4434. }
  4435. if (!cheater && amount >= 10000) {
  4436. tmp = amount / 10000;
  4437. if (tmp > GetPlayer()->GetBankCoinsGold())
  4438. cheater = true;
  4439. else {
  4440. GetPlayer()->GetInfoStruct()->bank_coin_gold -= tmp;
  4441. if ((GetPlayer()->GetInfoStruct()->coin_gold + tmp) > 100) {
  4442. GetPlayer()->GetInfoStruct()->coin_gold = (GetPlayer()->GetInfoStruct()->coin_gold + tmp) - 100;
  4443. GetPlayer()->GetInfoStruct()->coin_plat += 1;
  4444. }
  4445. else
  4446. GetPlayer()->GetInfoStruct()->coin_gold += tmp;
  4447. amount -= tmp * 10000;
  4448. sprintf(withdrawal_data, "%u Gold ", tmp);
  4449. withdrawal.append(withdrawal_data);
  4450. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4451. }
  4452. }
  4453. if (!cheater && amount >= 100) {
  4454. tmp = amount / 100;
  4455. if (tmp > GetPlayer()->GetBankCoinsSilver())
  4456. cheater = true;
  4457. else {
  4458. GetPlayer()->GetInfoStruct()->bank_coin_silver -= tmp;
  4459. if ((GetPlayer()->GetInfoStruct()->coin_silver + tmp) > 100) {
  4460. GetPlayer()->GetInfoStruct()->coin_silver = (GetPlayer()->GetInfoStruct()->coin_silver + tmp) - 100;
  4461. GetPlayer()->GetInfoStruct()->coin_gold += 1;
  4462. }
  4463. else
  4464. GetPlayer()->GetInfoStruct()->coin_silver += tmp;
  4465. amount -= tmp * 100;
  4466. sprintf(withdrawal_data, "%u Silver ", tmp);
  4467. withdrawal.append(withdrawal_data);
  4468. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4469. }
  4470. }
  4471. if (!cheater) {
  4472. if (amount > 0) {
  4473. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  4474. withdrawal.append(withdrawal_data);
  4475. GetPlayer()->GetInfoStruct()->bank_coin_copper -= amount;
  4476. if ((GetPlayer()->GetInfoStruct()->coin_copper + amount) > 100) {
  4477. GetPlayer()->GetInfoStruct()->coin_copper = (GetPlayer()->GetInfoStruct()->coin_copper + amount) - 100;
  4478. GetPlayer()->GetInfoStruct()->coin_silver += 1;
  4479. }
  4480. else
  4481. GetPlayer()->GetInfoStruct()->coin_copper += amount;
  4482. }
  4483. if (withdrawal.length() > 0) {
  4484. withdrawal.append("withdrawn ");
  4485. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->bank_coin_plat,
  4486. GetPlayer()->GetInfoStruct()->bank_coin_gold, GetPlayer()->GetInfoStruct()->bank_coin_silver, GetPlayer()->GetInfoStruct()->bank_coin_copper);
  4487. withdrawal.append(withdrawal_data);
  4488. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  4489. }
  4490. }
  4491. else
  4492. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4493. player->SetCharSheetChanged(true);
  4494. Bank(banker);
  4495. }
  4496. }
  4497. void Client::BankDeposit(int64 amount) {
  4498. bool cheater = false;
  4499. if (GetBanker() && amount > 0) {
  4500. int32 tmp = 0;
  4501. char deposit_data[512] = { 0 };
  4502. string deposit = "";
  4503. if (amount >= 1000000) {
  4504. tmp = amount / 1000000;
  4505. if (tmp > GetPlayer()->GetCoinsPlat())
  4506. cheater = true;
  4507. else {
  4508. GetPlayer()->GetInfoStruct()->bank_coin_plat += tmp;
  4509. GetPlayer()->GetInfoStruct()->coin_plat -= tmp;
  4510. amount -= (int64)tmp * 1000000;
  4511. sprintf(deposit_data, "%u Platinum ", tmp);
  4512. deposit.append(deposit_data);
  4513. memset(deposit_data, 0, sizeof(deposit_data));
  4514. }
  4515. }
  4516. if (!cheater && amount >= 10000) {
  4517. tmp = amount / 10000;
  4518. if (tmp > GetPlayer()->GetCoinsGold())
  4519. cheater = true;
  4520. else {
  4521. if ((GetPlayer()->GetInfoStruct()->bank_coin_gold + tmp) > 100) {
  4522. GetPlayer()->GetInfoStruct()->bank_coin_gold = (GetPlayer()->GetInfoStruct()->bank_coin_gold + tmp) - 100;
  4523. GetPlayer()->GetInfoStruct()->bank_coin_plat += 1;
  4524. }
  4525. else
  4526. GetPlayer()->GetInfoStruct()->bank_coin_gold += tmp;
  4527. GetPlayer()->GetInfoStruct()->coin_gold -= tmp;
  4528. amount -= tmp * 10000;
  4529. sprintf(deposit_data, "%u Gold ", tmp);
  4530. deposit.append(deposit_data);
  4531. memset(deposit_data, 0, sizeof(deposit_data));
  4532. }
  4533. }
  4534. if (!cheater && amount >= 100) {
  4535. tmp = amount / 100;
  4536. if (tmp > GetPlayer()->GetCoinsSilver())
  4537. cheater = true;
  4538. else {
  4539. if ((GetPlayer()->GetInfoStruct()->bank_coin_silver + tmp) > 100) {
  4540. GetPlayer()->GetInfoStruct()->bank_coin_silver = (GetPlayer()->GetInfoStruct()->bank_coin_silver + tmp) - 100;
  4541. GetPlayer()->GetInfoStruct()->bank_coin_gold += 1;
  4542. }
  4543. else
  4544. GetPlayer()->GetInfoStruct()->bank_coin_silver += tmp;
  4545. GetPlayer()->GetInfoStruct()->coin_silver -= tmp;
  4546. amount -= tmp * 100;
  4547. sprintf(deposit_data, "%u Silver ", tmp);
  4548. deposit.append(deposit_data);
  4549. memset(deposit_data, 0, sizeof(deposit_data));
  4550. }
  4551. }
  4552. if (!cheater) {
  4553. if (amount > 0) {
  4554. sprintf(deposit_data, "%u Copper ", (int32)amount);
  4555. deposit.append(deposit_data);
  4556. if ((GetPlayer()->GetInfoStruct()->bank_coin_copper + amount) > 100) {
  4557. GetPlayer()->GetInfoStruct()->bank_coin_copper = (GetPlayer()->GetInfoStruct()->bank_coin_copper + amount) - 100;
  4558. GetPlayer()->GetInfoStruct()->bank_coin_silver += 1;
  4559. }
  4560. else
  4561. GetPlayer()->GetInfoStruct()->bank_coin_copper += amount;
  4562. GetPlayer()->GetInfoStruct()->coin_copper -= amount;
  4563. }
  4564. if (deposit.length() > 0) {
  4565. deposit.append("deposited ");
  4566. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->bank_coin_plat,
  4567. GetPlayer()->GetInfoStruct()->bank_coin_gold, GetPlayer()->GetInfoStruct()->bank_coin_silver, GetPlayer()->GetInfoStruct()->bank_coin_copper);
  4568. deposit.append(deposit_data);
  4569. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  4570. }
  4571. }
  4572. else
  4573. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4574. player->SetCharSheetChanged(true);
  4575. Bank(banker);
  4576. }
  4577. }
  4578. void Client::AddPendingQuestReward(Quest* quest) {
  4579. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4580. quest_pending_reward.push_back(quest);
  4581. quest_updates = true;
  4582. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4583. }
  4584. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  4585. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4586. quest_pending_updates[quest_id][step_id] = progress;
  4587. quest_updates = true;
  4588. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4589. }
  4590. void Client::ProcessQuestUpdates() {
  4591. if (quest_pending_updates.size() > 0) {
  4592. map<int32, map<int32, int32> > tmp_quest_updates;
  4593. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4594. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  4595. quest_pending_updates.clear();
  4596. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4597. map<int32, map<int32, int32> >::iterator quest_itr;
  4598. map<int32, int32>::iterator step_itr;
  4599. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  4600. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  4601. if (step_itr->second == 0xFFFFFFFF) {
  4602. SetStepComplete(quest_itr->first, step_itr->first);
  4603. player->SendQuestRequiredSpawns(quest_itr->first);
  4604. }
  4605. else
  4606. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  4607. }
  4608. }
  4609. }
  4610. if (quest_pending_reward.size() > 0) {
  4611. vector<Quest*>::iterator itr;
  4612. vector<Quest*> tmp_quest_rewards;
  4613. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4614. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.end());
  4615. quest_pending_reward.clear();
  4616. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4617. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end(); itr++) {
  4618. GiveQuestReward(*itr);
  4619. }
  4620. }
  4621. quest_updates = false;
  4622. }
  4623. void Client::CheckQuestQueue() {
  4624. MQuestQueue.writelock();
  4625. last_update_time = 0;
  4626. vector<QueuedQuest*>::iterator itr;
  4627. QueuedQuest* queued_quest = 0;
  4628. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  4629. queued_quest = *itr;
  4630. SendQuestUpdateStepImmediately(queued_quest->quest, queued_quest->step, queued_quest->display_quest_helper);
  4631. if(queued_quest->quest && queued_quest->quest->GetTurnedIn()) //update the journal so the old quest isn't the one displayed in the client's quest helper
  4632. SendQuestJournal();
  4633. safe_delete(queued_quest);
  4634. }
  4635. quest_queue.clear();
  4636. MQuestQueue.releasewritelock();
  4637. }
  4638. void Client::SetStepComplete(int32 quest_id, int32 step) {
  4639. Quest* quest = player->SetStepComplete(quest_id, step);
  4640. if (quest) {
  4641. SendQuestUpdate(quest);
  4642. GetCurrentZone()->SendQuestUpdates(this);
  4643. }
  4644. }
  4645. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  4646. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  4647. if (quest) {
  4648. SendQuestUpdate(quest);
  4649. GetCurrentZone()->SendQuestUpdates(this);
  4650. }
  4651. }
  4652. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  4653. bool hadUpdates = false;
  4654. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  4655. if (quest_updates) {
  4656. for (int32 i = 0; i < quest_updates->size(); i++)
  4657. {
  4658. SendQuestUpdate(quest_updates->at(i));
  4659. hadUpdates = true;
  4660. }
  4661. }
  4662. safe_delete(quest_updates);
  4663. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4664. if (quest_failures) {
  4665. for (int32 i = 0; i < quest_failures->size(); i++)
  4666. {
  4667. SendQuestFailure(quest_failures->at(i));
  4668. hadUpdates = true;
  4669. }
  4670. }
  4671. safe_delete(quest_failures);
  4672. if (hadUpdates)
  4673. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4674. }
  4675. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  4676. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  4677. if (quest_updates) {
  4678. for (int32 i = 0; i < quest_updates->size(); i++)
  4679. SendQuestUpdate(quest_updates->at(i));
  4680. GetCurrentZone()->SendQuestUpdates(this);
  4681. }
  4682. safe_delete(quest_updates);
  4683. }
  4684. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  4685. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  4686. if (quest_updates) {
  4687. for (int32 i = 0; i < quest_updates->size(); i++)
  4688. SendQuestUpdate(quest_updates->at(i));
  4689. }
  4690. safe_delete(quest_updates);
  4691. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4692. if (quest_failures) {
  4693. for (int32 i = 0; i < quest_failures->size(); i++)
  4694. SendQuestFailure(quest_failures->at(i));
  4695. }
  4696. safe_delete(quest_failures);
  4697. }
  4698. void Client::CheckPlayerQuestsLocationUpdate() {
  4699. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  4700. if (quest_updates) {
  4701. for (int32 i = 0; i < quest_updates->size(); i++)
  4702. SendQuestUpdate(quest_updates->at(i));
  4703. }
  4704. safe_delete(quest_updates);
  4705. }
  4706. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  4707. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  4708. if (quest_updates) {
  4709. for (int32 i = 0; i < quest_updates->size(); i++)
  4710. SendQuestUpdate(quest_updates->at(i));
  4711. }
  4712. safe_delete(quest_updates);
  4713. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4714. if (quest_failures) {
  4715. for (int32 i = 0; i < quest_failures->size(); i++)
  4716. SendQuestFailure(quest_failures->at(i));
  4717. }
  4718. safe_delete(quest_failures);
  4719. }
  4720. void Client::AddPendingQuest(Quest* quest, bool forced) {
  4721. if (version <= 283 || forced) { //this client doesn't ask if you want the quest, so auto accept
  4722. player->pending_quests[quest->GetQuestID()] = quest;
  4723. AcceptQuest(quest->GetQuestID());
  4724. }
  4725. else {
  4726. player->pending_quests[quest->GetQuestID()] = quest;
  4727. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  4728. //DumpPacket(outapp);
  4729. QueuePacket(outapp);
  4730. }
  4731. }
  4732. Quest* Client::GetActiveQuest(int32 quest_id) {
  4733. if (player->player_quests.count(quest_id) > 0) {
  4734. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u active quests for char_id: %u", player->player_quests.count(quest_id), player->GetCharacterID());
  4735. return player->player_quests[quest_id];
  4736. }
  4737. return 0;
  4738. }
  4739. void Client::AcceptQuest(int32 id) {
  4740. Quest* quest = GetPendingQuest(id);
  4741. if (quest) {
  4742. RemovePendingQuest(quest);
  4743. AddPlayerQuest(quest);
  4744. GetCurrentZone()->SendQuestUpdates(this);
  4745. // If character has already completed this quest once update the given date in the database
  4746. if (GetPlayer()->GetCompletedPlayerQuests()->count(id) > 0) {
  4747. Quest* quest2 = GetPlayer()->GetCompletedQuest(id);
  4748. if (quest2)
  4749. quest->SetCompleteCount(quest2->GetCompleteCount());
  4750. database.SaveCharRepeatableQuest(this, id, quest->GetCompleteCount());
  4751. }
  4752. }
  4753. }
  4754. Quest* Client::GetPendingQuest(int32 id) {
  4755. if (player->pending_quests.count(id) > 0) {
  4756. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u pending quests for char_id: %u", player->pending_quests.count(id), player->GetCharacterID());
  4757. return player->pending_quests[id];
  4758. }
  4759. return 0;
  4760. }
  4761. void Client::RemovePendingQuest(Quest* quest) {
  4762. player->pending_quests.erase(quest->GetQuestID());
  4763. }
  4764. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  4765. if (!quest || !progress) {
  4766. return;
  4767. }
  4768. map<int32, int32>::iterator itr;
  4769. QuestStep* step = 0;
  4770. player->SetZone(GetCurrentZone(), GetVersion());
  4771. for (itr = progress->begin(); itr != progress->end(); itr++) {
  4772. step = quest->GetQuestStep(itr->first);
  4773. if (step && itr->second > 0) {
  4774. step->SetStepProgress(itr->second);
  4775. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  4776. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  4777. }
  4778. }
  4779. if (lua_interface)
  4780. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  4781. }
  4782. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  4783. if (player->player_quests.count(quest->GetQuestID()) > 0) {
  4784. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  4785. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  4786. RemovePlayerQuest(quest->GetQuestID(), false, false);
  4787. }
  4788. player->player_quests[quest->GetQuestID()] = quest;
  4789. quest->SetPlayer(player);
  4790. current_quest_id = quest->GetQuestID();
  4791. if (send_packets && quest->GetQuestGiver() > 0)
  4792. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  4793. if (lua_interface && call_accepted)
  4794. lua_interface->CallQuestFunction(quest, "Accepted", player);
  4795. if (send_packets) {
  4796. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4797. //SendQuestJournal();
  4798. SendQuestJournalUpdate(quest);
  4799. // sent twice to match live
  4800. quest->SetTracked(false);
  4801. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  4802. quest->SetTracked(true);
  4803. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  4804. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4805. }
  4806. //This isn't during a load screen, so update spawns with required quests
  4807. if (call_accepted)
  4808. player->SendQuestRequiredSpawns(quest->GetQuestID());
  4809. }
  4810. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  4811. if (current_quest_id == id)
  4812. current_quest_id = 0;
  4813. if (player->player_quests.count(id) > 0) {
  4814. if (delete_quest) {
  4815. player->player_quests[id]->SetDeleted(true);
  4816. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  4817. }
  4818. if (send_update && player->player_quests[id]->GetQuestGiver() > 0)
  4819. GetCurrentZone()->SendSpawnChangesByDBID(player->player_quests[id]->GetQuestGiver(), this, false, true);
  4820. if (send_update) {
  4821. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4822. SendQuestJournal(false, 0, true);
  4823. }
  4824. player->RemoveQuest(id, delete_quest);
  4825. if (send_update) {
  4826. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4827. SendQuestJournal(false, 0, true);
  4828. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4829. }
  4830. }
  4831. }
  4832. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  4833. if (quest) {
  4834. QuestStep* quest_step = quest->GetQuestStep(step);
  4835. if (quest_step) {
  4836. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  4837. quest_step->WasUpdated(false);
  4838. }
  4839. }
  4840. }
  4841. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  4842. QueuedQuest* item = new QueuedQuest;
  4843. item->quest = quest;
  4844. item->step = step;
  4845. item->display_quest_helper = display_quest_helper;
  4846. MQuestQueue.writelock();
  4847. quest_queue.push_back(item);
  4848. last_update_time = Timer::GetCurrentTime2();
  4849. MQuestQueue.releasewritelock();
  4850. }
  4851. void Client::SendQuestFailure(Quest* quest) {
  4852. vector<QuestStep*>* failures = quest->GetQuestFailures();
  4853. if (failures) {
  4854. QuestStep* step = 0;
  4855. for (int32 i = 0; i < failures->size(); i++) {
  4856. step = failures->at(i);
  4857. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  4858. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4859. SendQuestJournal(false, 0, true);
  4860. }
  4861. failures->clear();
  4862. }
  4863. }
  4864. void Client::SendQuestUpdate(Quest* quest) {
  4865. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  4866. if (updates) {
  4867. QuestStep* step = 0;
  4868. bool updated = false;
  4869. for (int32 i = 0; i < updates->size(); i++) {
  4870. step = updates->at(i);
  4871. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  4872. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  4873. if (step->WasUpdated()) {
  4874. // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
  4875. SendQuestJournal(false, 0, true);
  4876. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  4877. }
  4878. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4879. }
  4880. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  4881. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  4882. SendQuestJournalUpdate(quest, false);
  4883. }
  4884. if (quest->GetCompleted()) {
  4885. if (quest->GetQuestReturnNPC() > 0)
  4886. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  4887. if (quest->GetCompletedFlag())
  4888. quest->SetCompletedFlag(false);
  4889. }
  4890. updates->clear();
  4891. }
  4892. }
  4893. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  4894. if (!client)
  4895. client = this;
  4896. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  4897. if (packet) {
  4898. EQ2Packet* outapp = packet->serialize();
  4899. //DumpPacket(outapp);
  4900. client->QueuePacket(outapp);
  4901. safe_delete(packet);
  4902. }
  4903. }
  4904. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  4905. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  4906. if (packet) {
  4907. QueuePacket(packet->serialize());
  4908. safe_delete(packet);
  4909. }
  4910. }
  4911. void Client::ReloadQuests() {
  4912. vector<int32> ids = player->GetQuestIDs();
  4913. Quest* quest = 0;
  4914. for (int32 i = 0; i < ids.size(); i++) {
  4915. quest = master_quest_list.GetQuest(ids[i]);
  4916. if (quest)
  4917. AddPlayerQuest(quest, false);
  4918. else
  4919. RemovePlayerQuest(ids[i]);
  4920. }
  4921. }
  4922. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  4923. bool found_quest = false;
  4924. vector<Quest*>::iterator itr;
  4925. vector<Item*>* items = 0;
  4926. Quest* quest = 0;
  4927. MPendingQuestAccept.lock();
  4928. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end(); itr++) {
  4929. quest = *itr;
  4930. items = quest->GetRewardItems();
  4931. if (item_id == 0 && items && items->size() > 0) {
  4932. found_quest = true;
  4933. }
  4934. else {
  4935. items = quest->GetSelectableRewardItems();
  4936. if (items && items->size() > 0) {
  4937. for (int32 i = 0; i < items->size(); i++) {
  4938. if (items->at(i)->details.item_id == item_id) {
  4939. found_quest = true;
  4940. break;
  4941. }
  4942. }
  4943. }
  4944. }
  4945. if (found_quest) {
  4946. pending_quest_accept.erase(itr);
  4947. break;
  4948. }
  4949. }
  4950. MPendingQuestAccept.unlock();
  4951. if (found_quest)
  4952. return quest;
  4953. return 0;
  4954. }
  4955. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  4956. int8 num_slots_needed = 0;
  4957. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  4958. Item* master_item = 0;
  4959. if (item_id > 0) {
  4960. num_slots_needed++;
  4961. master_item = master_item_list.GetItem(item_id);
  4962. }
  4963. vector<Item*>* items = quest->GetRewardItems();
  4964. if (items && items->size() > 0)
  4965. num_slots_needed += items->size();
  4966. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= items->size())) {
  4967. if (master_item)
  4968. AddItem(item_id);
  4969. if (items && items->size() > 0) {
  4970. for (int32 i = 0; i < items->size(); i++)
  4971. AddItem(new Item(items->at(i)));
  4972. }
  4973. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  4974. if (outapp)
  4975. QueuePacket(outapp);
  4976. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  4977. map<int32, sint32>::iterator itr;
  4978. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  4979. int32 faction_id = itr->first;
  4980. sint32 amount = itr->second;
  4981. if (amount > 0)
  4982. player->GetFactions()->IncreaseFaction(faction_id, amount);
  4983. else
  4984. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  4985. }
  4986. if (player->GetGuild()) {
  4987. player->GetInfoStruct()->status_points += quest->GetStatusPoints();
  4988. player->SetCharSheetChanged(true);
  4989. }
  4990. }
  4991. else {
  4992. MPendingQuestAccept.lock();
  4993. pending_quest_accept.push_back(quest);
  4994. MPendingQuestAccept.unlock();
  4995. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  4996. DisplayQuestComplete(quest);
  4997. }
  4998. }
  4999. 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) {
  5000. 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))) {
  5001. /*if (quest)
  5002. text = quest->GetName();
  5003. else*/
  5004. return;//nothing to give
  5005. }
  5006. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  5007. if (packet2) {
  5008. int32 source_id = 0;
  5009. if (quest)
  5010. source_id = quest->GetQuestID();
  5011. int64 rewarded_coin = 0;
  5012. if (quest) {
  5013. if (quest->GetCoinsReward() > 0) {
  5014. if (quest->GetCoinsRewardMax() > 0)
  5015. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5016. else
  5017. rewarded_coin = quest->GetCoinsReward();
  5018. }
  5019. quest->SetGeneratedCoin(rewarded_coin);
  5020. }
  5021. if (rewarded_coin > coin)
  5022. coin = rewarded_coin;
  5023. if (!quest) { //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5024. if (coin > 0) {
  5025. player->AddCoins(coin);
  5026. PlaySound("coin_cha_ching");
  5027. }
  5028. }
  5029. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  5030. packet2->setSubstructDataByName("reward_data", "reward", header);
  5031. packet2->setSubstructDataByName("reward_data", "max_coin", coin);
  5032. if (player->GetGuild()) {
  5033. if (!quest) { //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5034. player->GetInfoStruct()->status_points += status_points;
  5035. player->SetCharSheetChanged(true);
  5036. }
  5037. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  5038. }
  5039. if(text)
  5040. packet2->setSubstructDataByName("reward_data", "text", text);
  5041. if(rewards){
  5042. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", rewards->size());
  5043. for (int i = 0; i < rewards->size(); i++) {
  5044. Item* item = rewards->at(i);
  5045. if (item) {
  5046. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  5047. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  5048. }
  5049. if(!quest) //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5050. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  5051. }
  5052. }
  5053. if (selectable_rewards) {
  5054. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  5055. for (int i = 0; i < selectable_rewards->size(); i++) {
  5056. Item* item = selectable_rewards->at(i);
  5057. if (item) {
  5058. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  5059. packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  5060. if (!quest) //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5061. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  5062. }
  5063. }
  5064. }
  5065. if (factions) {
  5066. map<int32, sint32>::iterator itr;
  5067. map<Faction*, signed int> factions_map;
  5068. for (itr = factions->begin(); itr != factions->end(); itr++) {
  5069. Faction* faction = master_faction_list.GetFaction(itr->first);
  5070. if (faction)
  5071. factions_map[faction] = itr->second;
  5072. }
  5073. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  5074. map<Faction*, signed int>::iterator faction_itr;
  5075. int8 i = 0;
  5076. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  5077. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  5078. sint32 amount = faction_itr->second;
  5079. packet2->setArrayDataByName("amount", amount, i);
  5080. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5081. if (amount > 0)
  5082. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  5083. else
  5084. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  5085. }
  5086. i++;
  5087. }
  5088. }
  5089. QueuePacket(packet2->serialize());
  5090. safe_delete(packet2);
  5091. }
  5092. }
  5093. void Client::DisplayQuestComplete(Quest* quest) {
  5094. if (!quest)
  5095. return;
  5096. if (GetVersion() <= 546) {
  5097. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints());
  5098. return;
  5099. }
  5100. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  5101. if (packet) {
  5102. packet->setDataByName("title", "Quest Reward!");
  5103. packet->setDataByName("name", quest->GetName());
  5104. packet->setDataByName("description", quest->GetDescription());
  5105. packet->setDataByName("level", quest->GetLevel());
  5106. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  5107. int8 difficulty = 0;
  5108. if ((string)quest->GetType() == "Tradeskill")
  5109. difficulty = player->GetTSArrowColor(quest->GetLevel());
  5110. else
  5111. difficulty = player->GetArrowColor(quest->GetLevel());
  5112. packet->setDataByName("difficulty", difficulty);
  5113. int64 rewarded_coin = 0;
  5114. if (quest->GetCoinsReward() > 0) {
  5115. if (quest->GetCoinsRewardMax() > 0)
  5116. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5117. else
  5118. rewarded_coin = quest->GetCoinsReward();
  5119. }
  5120. quest->SetGeneratedCoin(rewarded_coin);
  5121. packet->setDataByName("max_coin", rewarded_coin);
  5122. packet->setDataByName("min_coin", rewarded_coin);
  5123. packet->setDataByName("status_points", quest->GetStatusPoints());
  5124. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  5125. vector<Item*>* items = quest->GetRewardItems();
  5126. if (items) {
  5127. packet->setArrayLengthByName("num_rewards", items->size());
  5128. for (int32 i = 0; i < items->size(); i++) {
  5129. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  5130. if (version < 860)
  5131. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  5132. else if (version < 1193)
  5133. packet->setItemArrayDataByName("item", items->at(i), player, i);
  5134. else
  5135. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  5136. }
  5137. }
  5138. if (items2 && items2->size() > 0) {
  5139. packet->setArrayLengthByName("num_select_rewards", items2->size());
  5140. for (int32 i = 0; i < items2->size(); i++) {
  5141. packet->setArrayDataByName("select_reward_id", items2->at(i)->details.item_id, i);
  5142. if (version < 860)
  5143. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, -1);
  5144. else if (version < 1193)
  5145. packet->setItemArrayDataByName("select_item", items2->at(i), player, i);
  5146. else
  5147. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, 2);
  5148. }
  5149. }
  5150. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  5151. if (reward_factions && reward_factions->size() > 0) {
  5152. packet->setArrayLengthByName("num_factions", reward_factions->size());
  5153. map<int32, sint32>::iterator itr;
  5154. int16 index = 0;
  5155. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  5156. int32 faction_id = itr->first;
  5157. sint32 amount = itr->second;
  5158. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  5159. if (faction_name) {
  5160. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  5161. packet->setArrayDataByName("amount", amount, index);
  5162. }
  5163. index++;
  5164. }
  5165. }
  5166. EQ2Packet* outapp = packet->serialize();
  5167. // DumpPacket(outapp);
  5168. QueuePacket(outapp);
  5169. safe_delete(packet);
  5170. }
  5171. }
  5172. void Client::DisplayRandomizeFeatures(int32 flags) {
  5173. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  5174. if (flags > 0) {
  5175. if (flags & RANDOMIZE_GENDER)
  5176. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  5177. if (flags & RANDOMIZE_RACE)
  5178. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  5179. if (flags & RANDOMIZE_MODEL_TYPE)
  5180. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  5181. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  5182. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  5183. if (flags & RANDOMIZE_HAIR_TYPE)
  5184. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  5185. if (flags & RANDOMIZE_WING_TYPE)
  5186. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  5187. if (flags & RANDOMIZE_CHEEK_TYPE)
  5188. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  5189. if (flags & RANDOMIZE_CHIN_TYPE)
  5190. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  5191. if (flags & RANDOMIZE_EAR_TYPE)
  5192. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  5193. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  5194. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  5195. if (flags & RANDOMIZE_EYE_TYPE)
  5196. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  5197. if (flags & RANDOMIZE_LIP_TYPE)
  5198. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  5199. if (flags & RANDOMIZE_NOSE_TYPE)
  5200. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  5201. if (flags & RANDOMIZE_EYE_COLOR)
  5202. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  5203. if (flags & RANDOMIZE_HAIR_COLOR1)
  5204. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  5205. if (flags & RANDOMIZE_HAIR_COLOR2)
  5206. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  5207. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  5208. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  5209. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  5210. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  5211. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  5212. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  5213. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  5214. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  5215. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  5216. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  5217. if (flags & RANDOMIZE_SKIN_COLOR)
  5218. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  5219. if (flags & RANDOMIZE_WING_COLOR1)
  5220. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  5221. if (flags & RANDOMIZE_WING_COLOR2)
  5222. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  5223. }
  5224. else
  5225. {
  5226. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  5227. }
  5228. }
  5229. void Client::GiveQuestReward(Quest* quest) {
  5230. current_quest_id = 0;
  5231. MPendingQuestAccept.lock();
  5232. pending_quest_accept.push_back(quest);
  5233. MPendingQuestAccept.unlock();
  5234. quest->IncrementCompleteCount();
  5235. player->AddCompletedQuest(quest);
  5236. DisplayQuestComplete(quest);
  5237. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5238. SendQuestJournal();
  5239. player->RemoveQuest(quest->GetQuestID(), false);
  5240. if (quest->GetExpReward() > 0) {
  5241. int16 level = player->GetLevel();
  5242. int32 xp = quest->GetExpReward();
  5243. if (player->AddXP(xp)) {
  5244. Message(CHANNEL_REWARD, "You gain %u experience!", (int32)xp);
  5245. if (player->GetLevel() != level)
  5246. ChangeLevel(level, player->GetLevel());
  5247. player->SetCharSheetChanged(true);
  5248. }
  5249. }
  5250. if (quest->GetTSExpReward() > 0) {
  5251. int8 ts_level = player->GetTSLevel();
  5252. int32 xp = quest->GetTSExpReward();
  5253. if (player->AddTSXP(xp)) {
  5254. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  5255. if (player->GetTSLevel() != ts_level)
  5256. ChangeTSLevel(ts_level, player->GetTSLevel());
  5257. player->SetCharSheetChanged(true);
  5258. }
  5259. }
  5260. int64 total_coins = quest->GetGeneratedCoin();
  5261. if (total_coins > 0) {
  5262. player->AddCoins(total_coins);
  5263. PlaySound("coin_cha_ching");
  5264. char tmp[64] = { 0 };
  5265. string message = "You receive ";
  5266. int32 val = 0;
  5267. if (total_coins >= 1000000) {
  5268. val = total_coins / 1000000;
  5269. total_coins -= 1000000 * val;
  5270. sprintf(tmp, "%u Platinum ", val);
  5271. message.append(tmp);
  5272. memset(tmp, 0, 64);
  5273. }
  5274. if (total_coins >= 10000) {
  5275. val = total_coins / 10000;
  5276. total_coins -= 10000 * val;
  5277. sprintf(tmp, "%u Gold ", val);
  5278. message.append(tmp);
  5279. memset(tmp, 0, 64);
  5280. }
  5281. if (total_coins >= 100) {
  5282. val = total_coins / 100;
  5283. total_coins -= 100 * val;
  5284. sprintf(tmp, "%u Silver ", val);
  5285. message.append(tmp);
  5286. memset(tmp, 0, 64);
  5287. }
  5288. if (total_coins > 0) {
  5289. sprintf(tmp, "%u Copper ", (int32)total_coins);
  5290. message.append(tmp);
  5291. }
  5292. message.append("for completing ").append(quest->GetName());
  5293. int8 type = CHANNEL_LOOT;
  5294. SimpleMessage(type, message.c_str());
  5295. }
  5296. if (quest->GetQuestGiver() > 0)
  5297. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5298. RemovePlayerQuest(quest->GetQuestID(), true, false);
  5299. }
  5300. void Client::DisplayConversation(int32 conversation_id, int32 spawn_id, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  5301. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  5302. if (packet) {
  5303. packet->setDataByName("conversation_id", conversation_id);
  5304. packet->setDataByName("text", text);
  5305. packet->setDataByName("unknown2", 1);
  5306. conversation_map[conversation_id].clear();
  5307. if (conversations) {
  5308. packet->setArrayLengthByName("num_responses", conversations->size());
  5309. for (int32 i = 0; i < conversations->size(); i++) {
  5310. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  5311. if (conversations->at(i).function.length() > 0)
  5312. conversation_map[conversation_id][i] = conversations->at(i).function;
  5313. }
  5314. }
  5315. packet->setDataByName("spawn_id", spawn_id);
  5316. if (mp3) {
  5317. packet->setDataByName("voice", mp3);
  5318. packet->setDataByName("key1", key1);
  5319. packet->setDataByName("key2", key2);
  5320. }
  5321. QueuePacket(packet->serialize());
  5322. safe_delete(packet);
  5323. }
  5324. }
  5325. void Client::DisplayConversation(Item* item, vector<ConversationOption>* conversations, const char* text, int8 type, const char* mp3, int32 key1, int32 key2) {
  5326. if (!item || !text || !conversations || conversations->size() == 0) {
  5327. return;
  5328. }
  5329. int32 conversation_id = GetConversationID(0, item);
  5330. if (conversation_id == 0) {
  5331. next_conversation_id++;
  5332. conversation_id = next_conversation_id;
  5333. }
  5334. conversation_items[conversation_id] = item;
  5335. if (type == 4)
  5336. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  5337. else
  5338. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  5339. }
  5340. void Client::DisplayConversation(Entity* npc, int8 type, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  5341. if (!npc || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  5342. return;
  5343. }
  5344. int32 conversation_id = GetConversationID(npc, 0);
  5345. if (conversation_id == 0) {
  5346. next_conversation_id++;
  5347. conversation_id = next_conversation_id;
  5348. }
  5349. conversation_spawns[conversation_id] = npc;
  5350. /* NPCs can start two different types of conversations.
  5351. * Type 1: The chat type with bubbles.
  5352. * Type 2: The dialog type with the blue box. */
  5353. if (type == 1)
  5354. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(npc), conversations, text, mp3, key1, key2);
  5355. else if (type == 2)
  5356. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  5357. else //if (type == 3)
  5358. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  5359. }
  5360. void Client::CloseDialog(int32 conversation_id) {
  5361. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  5362. if (packet) {
  5363. packet->setDataByName("conversation_id", conversation_id);
  5364. QueuePacket(packet->serialize());
  5365. safe_delete(packet);
  5366. }
  5367. conversation_items.erase(conversation_id);
  5368. conversation_spawns.erase(conversation_id);
  5369. }
  5370. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  5371. int32 conversation_id = 0;
  5372. if (spawn) {
  5373. map<int32, Spawn*>::iterator itr;
  5374. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  5375. if (itr->second == spawn) {
  5376. conversation_id = itr->first;
  5377. break;
  5378. }
  5379. }
  5380. }
  5381. else if (item) {
  5382. map<int32, Item*>::iterator itr;
  5383. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  5384. if (itr->second == item) {
  5385. conversation_id = itr->first;
  5386. break;
  5387. }
  5388. }
  5389. }
  5390. return conversation_id;
  5391. }
  5392. Spawn* Client::GetCombineSpawn() {
  5393. return combine_spawn;
  5394. }
  5395. bool Client::ShouldTarget() {
  5396. return should_target;
  5397. }
  5398. void Client::TargetSpawn(Spawn* spawn) {
  5399. should_target = false;
  5400. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  5401. if (packet) {
  5402. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  5403. QueuePacket(packet->serialize());
  5404. safe_delete(packet);
  5405. }
  5406. }
  5407. void Client::CombineSpawns(float radius, Spawn* spawn) {
  5408. combine_spawn = spawn;
  5409. spawn->RemoveSpawnFromGroup(true);
  5410. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  5411. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  5412. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5413. should_target = true;
  5414. }
  5415. void Client::AddCombineSpawn(Spawn* spawn) {
  5416. if (combine_spawn && combine_spawn != spawn && spawn) {
  5417. combine_spawn->AddSpawnToGroup(spawn);
  5418. spawn->AddSpawnToGroup(combine_spawn);
  5419. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5420. }
  5421. else if (spawn)
  5422. combine_spawn = spawn;
  5423. should_target = true;
  5424. }
  5425. void Client::RemoveCombineSpawn(Spawn* spawn) {
  5426. if (combine_spawn && spawn)
  5427. spawn->RemoveSpawnFromGroup();
  5428. if (combine_spawn == spawn)
  5429. combine_spawn->RemoveSpawnFromGroup(true);
  5430. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5431. if (combine_spawn == spawn)
  5432. combine_spawn = 0;
  5433. }
  5434. void Client::SaveCombineSpawns(const char* name) {
  5435. if (!combine_spawn) {
  5436. return;
  5437. }
  5438. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  5439. if (!spawns) {
  5440. return;
  5441. }
  5442. int32 count = spawns->size();
  5443. int32 spawnLocationID = 0;
  5444. if (count == 1)
  5445. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  5446. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  5447. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  5448. // we remove the spawn inside SaveCombinedSpawnLocation
  5449. //GetCurrentZone()->RemoveSpawn(false, combine_spawn);
  5450. }
  5451. else
  5452. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  5453. safe_delete(spawns);
  5454. combine_spawn = 0;
  5455. }
  5456. bool Client::AddItem(int32 item_id, int16 quantity) {
  5457. Item* master_item = master_item_list.GetItem(item_id);
  5458. Item* item = 0;
  5459. if (master_item)
  5460. item = new Item(master_item);
  5461. if (item) {
  5462. if (quantity > 0)
  5463. item->details.count = quantity;
  5464. return AddItem(item);
  5465. }
  5466. else
  5467. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  5468. return false;
  5469. }
  5470. bool Client::AddItem(Item* item) {
  5471. if (!item) {
  5472. return false;
  5473. }
  5474. if (item->IsBag()) {
  5475. if (GetVersion() <= 283 && item->details.num_slots > CLASSIC_EQ_MAX_BAG_SLOTS)
  5476. item->details.num_slots = CLASSIC_EQ_MAX_BAG_SLOTS;
  5477. }
  5478. if (player->AddItem(item)) {
  5479. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5480. if (outapp) {
  5481. //DumpPacket(outapp);
  5482. QueuePacket(outapp);
  5483. //resend bag desc with new item name added
  5484. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  5485. if (outapp) {
  5486. //DumpPacket(outapp);
  5487. QueuePacket(outapp);
  5488. }
  5489. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  5490. DumpPacket(app);
  5491. client->QueuePacket(app);
  5492. */
  5493. }
  5494. CheckPlayerQuestsItemUpdate(item);
  5495. if (item->GetItemScript() && lua_interface)
  5496. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  5497. }
  5498. else {
  5499. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  5500. safe_delete(item);
  5501. return false;
  5502. }
  5503. return true;
  5504. }
  5505. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  5506. Item* master_item = master_item_list.GetItem(item_id);
  5507. Item* item = 0;
  5508. if (master_item)
  5509. item = new Item(master_item);
  5510. if (item) {
  5511. if (quantity > 0)
  5512. item->details.count = quantity;
  5513. return AddItemToBank(item);
  5514. }
  5515. else
  5516. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  5517. return false;
  5518. }
  5519. bool Client::AddItemToBank(Item* item) {
  5520. if (!item) {
  5521. return false;
  5522. }
  5523. if (player->AddItemToBank(item)) {
  5524. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5525. if (outapp) {
  5526. QueuePacket(outapp);
  5527. //resend bag desc with new item name added
  5528. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  5529. if (outapp)
  5530. QueuePacket(outapp);
  5531. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  5532. DumpPacket(app);
  5533. client->QueuePacket(app);
  5534. */
  5535. }
  5536. CheckPlayerQuestsItemUpdate(item);
  5537. if (item->GetItemScript() && lua_interface)
  5538. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  5539. }
  5540. else {
  5541. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  5542. safe_delete(item);
  5543. return false;
  5544. }
  5545. return true;
  5546. }
  5547. bool Client::RemoveItem(Item* item, int16 quantity) {
  5548. EQ2Packet* outapp;
  5549. bool delete_item = false;
  5550. assert(item);
  5551. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  5552. item->details.count -= quantity;
  5553. item->save_needed = true;
  5554. }
  5555. else {
  5556. database.DeleteItem(character_id, item, 0);
  5557. player->GetPlayerItemList()->RemoveItem(item, false);
  5558. delete_item = true;
  5559. }
  5560. if ((outapp = player->SendInventoryUpdate(version))) {
  5561. QueuePacket(outapp);
  5562. if (item->GetItemScript() && lua_interface)
  5563. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  5564. if (delete_item)
  5565. safe_delete(item);
  5566. return true;
  5567. }
  5568. return false;
  5569. }
  5570. void Client::SetLuaDebugClient(bool val) {
  5571. if (val)
  5572. lua_debug_timer.Start();
  5573. lua_debug = val;
  5574. if (lua_interface && !val) {
  5575. lua_interface->RemoveDebugClients(this);
  5576. lua_debug_timer.Disable();
  5577. }
  5578. }
  5579. void Client::SetMerchantTransaction(Spawn* spawn) {
  5580. merchant_transaction = spawn;
  5581. }
  5582. Spawn* Client::GetMerchantTransaction() {
  5583. return merchant_transaction;
  5584. }
  5585. void Client::SetMailTransaction(Spawn* spawn) {
  5586. mail_transaction = spawn;
  5587. mail_window.coin_copper = 0;
  5588. mail_window.coin_silver = 0;
  5589. mail_window.coin_gold = 0;
  5590. mail_window.coin_plat = 0;
  5591. mail_window.char_item_id = 0;
  5592. }
  5593. Spawn* Client::GetMailTransaction() {
  5594. return mail_transaction;
  5595. }
  5596. void Client::PlaySound(const char* name) {
  5597. if (name) {
  5598. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  5599. if (packet) {
  5600. packet->setMediumStringByName("name", name);
  5601. QueuePacket(packet->serialize());
  5602. safe_delete(packet);
  5603. }
  5604. }
  5605. }
  5606. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  5607. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  5608. if(multiplier){
  5609. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  5610. float diff_low = faction_val - multiplier->faction_min;
  5611. if(diff_low < 0)
  5612. diff_low*=-1;
  5613. float total_diff = multiplier->faction_max - multiplier->faction_min;
  5614. if(total_diff < 0)
  5615. total_diff*=-1;
  5616. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  5617. float total1 = (diff_low/total_diff);
  5618. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  5619. return final_buy_multiplier;
  5620. }*/
  5621. return 1;
  5622. }
  5623. float Client::CalculateSellMultiplier(int32 merchant_id) {
  5624. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  5625. if(multiplier){
  5626. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  5627. float diff_low = faction_val - multiplier->faction_min;
  5628. if(diff_low < 0)
  5629. diff_low*=-1;
  5630. float total_diff = multiplier->faction_max - multiplier->faction_min;
  5631. if(total_diff < 0)
  5632. total_diff*=-1;
  5633. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  5634. float total1 = (diff_low/total_diff);
  5635. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  5636. return final_sell_multiplier;
  5637. }*/
  5638. return 1;
  5639. }
  5640. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  5641. Spawn* spawn = GetMerchantTransaction();
  5642. Guild* guild = GetPlayer()->GetGuild();
  5643. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5644. int32 total_sell_price = 0;
  5645. int32 total_status_sell_price = 0; //for status
  5646. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  5647. int32 sell_price = 0;
  5648. int32 status_sell_price = 0; //for status
  5649. Item* master_item = master_item_list.GetItem(item_id);
  5650. Item* item = 0;
  5651. if (unique_id == 0)
  5652. item = player->item_list.GetItemFromID(item_id, quantity);
  5653. else
  5654. item = player->item_list.GetItemFromUniqueID(unique_id);
  5655. if (!item)
  5656. player->item_list.GetItemFromID(item_id);
  5657. if (item && master_item) {
  5658. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  5659. if (sell_price > item->sell_price)
  5660. sell_price = item->sell_price;
  5661. if (quantity > item->details.count)
  5662. quantity = item->details.count;
  5663. total_sell_price = sell_price * quantity;
  5664. //------------------------------For Selling Status Items
  5665. status_sell_price = (int32)(master_item->sell_status * multiplier);
  5666. if (status_sell_price > item->sell_status)
  5667. status_sell_price = item->sell_status;
  5668. if (quantity > item->details.count)
  5669. quantity = item->details.count;
  5670. if (player->GetGuild()) {
  5671. total_status_sell_price = status_sell_price * quantity;
  5672. player->GetInfoStruct()->status_points += total_status_sell_price;
  5673. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  5674. guild->SendGuildMemberList();
  5675. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  5676. }
  5677. if (quantity > 1)
  5678. 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());
  5679. else
  5680. 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());
  5681. player->AddCoins(total_sell_price);
  5682. AddBuyBack(unique_id, item_id, quantity, sell_price);
  5683. if (quantity >= item->details.count) {
  5684. database.DeleteItem(GetCharacterID(), item, 0);
  5685. player->item_list.DestroyItem(item->details.index);
  5686. }
  5687. else {
  5688. item->details.count -= quantity;
  5689. item->save_needed = true;
  5690. }
  5691. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5692. if (outapp)
  5693. QueuePacket(outapp);
  5694. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY))
  5695. SendSellMerchantList();
  5696. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  5697. SendBuyBackList();
  5698. }
  5699. }
  5700. }
  5701. void Client::BuyBack(int32 item_id, int16 quantity) {
  5702. Spawn* spawn = GetMerchantTransaction();
  5703. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5704. deque<BuyBackItem*>::iterator itr;
  5705. BuyBackItem* buyback = 0;
  5706. BuyBackItem* closest = 0;
  5707. MBuyBack.readlock(__FUNCTION__, __LINE__);
  5708. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  5709. buyback = *itr;
  5710. if (buyback->unique_id == item_id) {
  5711. closest = buyback;
  5712. quantity = buyback->quantity;
  5713. break;
  5714. }
  5715. }
  5716. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  5717. if (closest) {
  5718. Item* item = 0;
  5719. Item* master_item = master_item_list.GetItem(closest->item_id);
  5720. if (master_item) {
  5721. item = new Item(master_item);
  5722. if (closest->quantity >= quantity)
  5723. item->details.count = quantity;
  5724. else
  5725. item->details.count = closest->quantity;
  5726. }
  5727. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  5728. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  5729. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  5730. bool removed = false;
  5731. if (closest->quantity == quantity) {
  5732. MBuyBack.writelock(__FUNCTION__, __LINE__);
  5733. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  5734. if (*itr == closest) {
  5735. buy_back_items.erase(itr);
  5736. removed = true;
  5737. break;
  5738. }
  5739. }
  5740. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  5741. }
  5742. else {
  5743. closest->quantity -= quantity;
  5744. closest->save_needed = true;
  5745. }
  5746. AddItem(item);
  5747. //EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5748. //if(outapp)
  5749. //QueuePacket(outapp);
  5750. if (removed) {
  5751. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  5752. safe_delete(closest);
  5753. }
  5754. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY))
  5755. SendSellMerchantList();
  5756. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  5757. SendBuyBackList();
  5758. }
  5759. else
  5760. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  5761. }
  5762. }
  5763. }
  5764. void Client::BuyItem(int32 item_id, int16 quantity) {
  5765. // Get the merchant we are buying from
  5766. Spawn* spawn = GetMerchantTransaction();
  5767. // Make sure the spawn has a merchant list
  5768. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5769. int32 total_buy_price = 0;
  5770. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  5771. int32 sell_price = 0;
  5772. Item* master_item = master_item_list.GetItem(item_id);
  5773. Item* item = 0;
  5774. int16 total_available = 0;
  5775. vector<MerchantItemInfo>* temp;
  5776. vector<MerchantItemInfo>::iterator itr;
  5777. MerchantItemInfo* ItemInfo = 0;
  5778. temp = world.GetMerchantList(spawn->GetMerchantID());
  5779. for (itr = temp->begin(); itr != temp->end(); itr++) {
  5780. if ((*itr).item_id == item_id) {
  5781. ItemInfo = &(*itr);
  5782. break;
  5783. }
  5784. }
  5785. if (master_item && ItemInfo) {
  5786. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  5787. quantity = 1;
  5788. total_available = 0xFFFF;
  5789. sell_price = master_item->sell_price;
  5790. }
  5791. else {
  5792. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  5793. sell_price = (int32)(master_item->sell_price * multiplier);
  5794. if (quantity > total_available)
  5795. quantity = total_available;
  5796. }
  5797. total_buy_price = sell_price * quantity;
  5798. item = new Item(master_item);
  5799. item->details.count = quantity;
  5800. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  5801. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  5802. safe_delete(item);
  5803. }
  5804. else {
  5805. // Price not set in the merchant_inventory table, use the old method
  5806. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  5807. if (player->RemoveCoins(total_buy_price)) {
  5808. item->SetMaxSellValue(sell_price);
  5809. if (quantity > 1)
  5810. 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());
  5811. else
  5812. 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());
  5813. AddItem(item);
  5814. CheckPlayerQuestsItemUpdate(item);
  5815. if (item && total_available < 0xFFFF) {
  5816. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  5817. SendBuyMerchantList();
  5818. }
  5819. //EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5820. //if(outapp)
  5821. // QueuePacket(outapp);
  5822. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) && !(spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  5823. SendSellMerchantList();
  5824. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  5825. PlayLotto(total_buy_price, item->details.item_id);
  5826. }
  5827. else {
  5828. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  5829. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5830. PlaySound("buy_failed");
  5831. }
  5832. }
  5833. else {
  5834. // Price set in merchant_inventory table
  5835. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  5836. // TODO: need to add support for station cash
  5837. if (player->GetInfoStruct()->status_points >= ItemInfo->price_status && player->HasCoins(ItemInfo->price_coins * quantity)) {
  5838. // Check items
  5839. int16 item_quantity = 0;
  5840. // Default these to true in case price_item_id or price_item2_id was never set
  5841. bool hasItem1 = true;
  5842. bool hasItem2 = true;
  5843. Item* tempItem1 = 0;
  5844. Item* tempItem2 = 0;
  5845. if (ItemInfo->price_item_id != 0) {
  5846. // Same item for whatever reason lets add the quantities together
  5847. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  5848. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  5849. else
  5850. item_quantity = ItemInfo->price_item_qty;
  5851. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  5852. if (tempItem1) {
  5853. if (tempItem1->details.count < item_quantity)
  5854. hasItem1 = false;
  5855. }
  5856. else {
  5857. hasItem1 = false;
  5858. }
  5859. }
  5860. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  5861. // as item1 and we already checked for it so we can skip this check
  5862. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  5863. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  5864. if (tempItem2) {
  5865. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  5866. hasItem2 = false;
  5867. }
  5868. else {
  5869. hasItem2 = false;
  5870. }
  5871. }
  5872. // if we have every thing then remove the price and give the item
  5873. if (hasItem1 && hasItem2) {
  5874. player->GetInfoStruct()->status_points -= ItemInfo->price_status;
  5875. // TODO: station cash
  5876. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  5877. // so there is no need to send it more then that one time
  5878. if (tempItem1) {
  5879. if (tempItem1->details.count > item_quantity) {
  5880. tempItem1->details.count -= item_quantity;
  5881. tempItem1->save_needed = true;
  5882. }
  5883. else {
  5884. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  5885. player->item_list.DestroyItem(tempItem1->details.index);
  5886. }
  5887. }
  5888. if (tempItem2) {
  5889. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  5890. tempItem2->details.count -= ItemInfo->price_item2_qty;
  5891. tempItem2->save_needed = true;
  5892. }
  5893. else {
  5894. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  5895. player->item_list.DestroyItem(tempItem2->details.index);
  5896. }
  5897. }
  5898. // 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
  5899. player->RemoveCoins(ItemInfo->price_coins * quantity);
  5900. item->SetMaxSellValue(sell_price);
  5901. if (quantity > 1)
  5902. 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());
  5903. else
  5904. 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());
  5905. AddItem(item);
  5906. CheckPlayerQuestsItemUpdate(item);
  5907. if (item && total_available < 0xFFFF) {
  5908. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  5909. SendBuyMerchantList();
  5910. }
  5911. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) && !(spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  5912. SendSellMerchantList();
  5913. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  5914. PlayLotto(total_buy_price, item->details.item_id);
  5915. }
  5916. else {
  5917. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  5918. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5919. PlaySound("buy_failed");
  5920. }
  5921. }
  5922. else {
  5923. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  5924. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5925. PlaySound("buy_failed");
  5926. }
  5927. }
  5928. }
  5929. }
  5930. }
  5931. }
  5932. void Client::RepairItem(int32 item_id) {
  5933. Spawn* spawn = GetMerchantTransaction();
  5934. if (spawn) {
  5935. Item* item = player->item_list.GetItemFromID(item_id);
  5936. if (!item)
  5937. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  5938. if (item) {
  5939. int32 repair_cost = item->CalculateRepairCost();
  5940. if (player->RemoveCoins((int32)repair_cost)) {
  5941. item->generic_info.condition = 100;
  5942. item->save_needed = true;
  5943. QueuePacket(player->GetEquipmentList()->serialize(GetVersion()));
  5944. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  5945. QueuePacket(item->serialize(version, false, player));
  5946. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  5947. PlaySound("coin_cha_ching");
  5948. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  5949. SendRepairList();
  5950. }
  5951. else {
  5952. LogWrite(MISC__TODO, 1, "TODO", " Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  5953. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  5954. PlaySound("buy_failed");
  5955. }
  5956. }
  5957. }
  5958. }
  5959. void Client::RepairAllItems() {
  5960. Spawn* spawn = GetMerchantTransaction();
  5961. if (spawn) {
  5962. vector<Item*>* repairable_items = GetRepairableItems();
  5963. if (repairable_items && repairable_items->size() > 0) {
  5964. vector<Item*>::iterator itr;
  5965. int64 total_cost = 0;
  5966. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  5967. total_cost += (*itr)->CalculateRepairCost();
  5968. if (player->RemoveCoins((int32)total_cost)) {
  5969. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  5970. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  5971. Item* item = *itr;
  5972. if (item) {
  5973. item->generic_info.condition = 100;
  5974. item->save_needed = true;
  5975. QueuePacket(item->serialize(version, false, player));
  5976. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  5977. }
  5978. }
  5979. QueuePacket(player->GetEquipmentList()->serialize(GetVersion()));
  5980. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  5981. PlaySound("coin_cha_ching");
  5982. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  5983. SendRepairList();
  5984. }
  5985. else {
  5986. LogWrite(MISC__TODO, 1, "TODO", "Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  5987. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  5988. PlaySound("buy_failed");
  5989. }
  5990. }
  5991. safe_delete(repairable_items);
  5992. }
  5993. }
  5994. void Client::SendAchievementsList()
  5995. {
  5996. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  5997. map<int32, Achievement *>::iterator itr;
  5998. Achievement *achievement;
  5999. vector<AchievementRequirements *> *requirements = 0;
  6000. vector<AchievementRequirements *>::iterator itr2;
  6001. AchievementRequirements *requirement;
  6002. vector<AchievementRewards *> *rewards = 0;
  6003. vector<AchievementRewards *>::iterator itr3;
  6004. AchievementRewards *reward;
  6005. PacketStruct *packet;
  6006. int16 i = 0;
  6007. int16 j = 0;
  6008. int16 k = 0;
  6009. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  6010. return;
  6011. }
  6012. packet->setArrayLengthByName("num_achievements" , achievements->size());
  6013. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  6014. achievement = itr->second;
  6015. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  6016. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  6017. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  6018. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  6019. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  6020. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  6021. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  6022. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  6023. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  6024. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  6025. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  6026. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  6027. requirements = achievement->GetRequirements();
  6028. rewards = achievement->GetRewards();
  6029. j = 0;
  6030. k = 0;
  6031. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  6032. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  6033. requirement = *itr2;
  6034. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  6035. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  6036. j++;
  6037. }
  6038. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  6039. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  6040. reward = *itr3;
  6041. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  6042. k++;
  6043. }
  6044. i++;
  6045. }
  6046. //packet->PrintPacket();
  6047. EQ2Packet* data = packet->serialize();
  6048. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6049. safe_delete(packet);
  6050. safe_delete(data);
  6051. //DumpPacket(app);
  6052. QueuePacket(app);*/
  6053. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  6054. SendAchievementUpdate(true);
  6055. }
  6056. void Client::SendAchievementUpdate(bool first_login) {
  6057. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  6058. map<int32, AchievementUpdate*>::iterator itr;
  6059. AchievementUpdate* update;
  6060. vector<AchievementUpdateItems*>* update_items = 0;
  6061. vector<AchievementUpdateItems*>::iterator itr2;
  6062. AchievementUpdateItems* update_item;
  6063. int16 i = 0;
  6064. int16 j = 0;
  6065. PacketStruct* packet;
  6066. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  6067. return;
  6068. }
  6069. packet->setDataByName("unknown1", first_login ? 1 : 0);
  6070. packet->setArrayLengthByName("num_achievements", updates->size());
  6071. for (itr = updates->begin(); itr != updates->end(); itr++) {
  6072. update = itr->second;
  6073. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  6074. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  6075. update_items = update->GetUpdateItems();
  6076. j = 0;
  6077. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  6078. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  6079. update_item = *itr2;
  6080. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  6081. j++;
  6082. }
  6083. i++;
  6084. }
  6085. //packet->PrintPacket();
  6086. EQ2Packet* data = packet->serialize();
  6087. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6088. safe_delete(packet);
  6089. safe_delete(data);
  6090. //DumpPacket(app);
  6091. QueuePacket(app);
  6092. }
  6093. void Client::SendBuyMerchantList(bool sell) {
  6094. Spawn* spawn = GetMerchantTransaction();
  6095. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6096. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  6097. if (items) {
  6098. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6099. if (packet) {
  6100. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6101. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6102. packet->setArrayLengthByName("num_items", items->size());
  6103. vector<MerchantItemInfo>::iterator itr;
  6104. sint8 item_difficulty = 0;
  6105. int32 sell_price = 0;
  6106. int i = 0;
  6107. int tmp_level = 0;
  6108. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  6109. MerchantItemInfo ItemInfo = *itr;
  6110. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  6111. if (!item)
  6112. continue;
  6113. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6114. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6115. packet->setArrayDataByName("stack_size", item->stack_count, i);
  6116. packet->setArrayDataByName("icon", item->details.icon, i);
  6117. if (item->generic_info.adventure_default_level > 0)
  6118. tmp_level = item->generic_info.adventure_default_level;
  6119. else
  6120. tmp_level = item->generic_info.tradeskill_default_level;
  6121. packet->setArrayDataByName("level", tmp_level, i);
  6122. packet->setArrayDataByName("tier", item->details.tier, i);
  6123. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6124. item_difficulty = player->GetArrowColor(tmp_level);
  6125. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6126. item_difficulty = ARROW_COLOR_WHITE;
  6127. item_difficulty -= 6;
  6128. if (item_difficulty < 0)
  6129. item_difficulty *= -1;
  6130. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6131. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  6132. packet->setArrayDataByName("unknown5", 255, i);
  6133. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  6134. if (GetVersion() <= 1096)
  6135. packet->setArrayDataByName("description", item->description.c_str(), i);
  6136. // If no price set in the merchant_inventory table then use the old method
  6137. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  6138. sell_price = (int32)(item->sell_price * multiplier);
  6139. packet->setArrayDataByName("price", sell_price, i);
  6140. }
  6141. else {
  6142. int8 count = 0;
  6143. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  6144. count++;
  6145. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  6146. count++;
  6147. if (count != 0) {
  6148. packet->setSubArrayLengthByName("num_tokens", count, i);
  6149. int8 index = 0;
  6150. Item* token = 0;
  6151. if (ItemInfo.price_item_id != 0) {
  6152. token = master_item_list.GetItem(ItemInfo.price_item_id);
  6153. if (item) {
  6154. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6155. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  6156. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  6157. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6158. }
  6159. token = 0;
  6160. index++;
  6161. }
  6162. if (ItemInfo.price_item2_id != 0) {
  6163. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  6164. if (item) {
  6165. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6166. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  6167. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  6168. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6169. }
  6170. }
  6171. }
  6172. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  6173. packet->setArrayDataByName("status", ItemInfo.price_status, i);
  6174. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  6175. }
  6176. }
  6177. if (GetVersion() <= 546) {
  6178. //buy is 0 so dont need to set it
  6179. if (sell)
  6180. packet->setDataByName("type", 1);
  6181. }
  6182. else {
  6183. if (sell)
  6184. packet->setDataByName("type", 130);
  6185. else
  6186. packet->setDataByName("type", 2);
  6187. }
  6188. EQ2Packet* outapp = packet->serialize();
  6189. // DumpPacket(outapp);
  6190. QueuePacket(outapp);
  6191. safe_delete(packet);
  6192. }
  6193. safe_delete(items);
  6194. }
  6195. else {
  6196. // Need to send an empty packet in the event there is no item list, otherwise the
  6197. // last item list sent to the player will show for this merchant
  6198. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6199. if (packet) {
  6200. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6201. if (GetVersion() <= 546) {
  6202. //buy is 0 so dont need to set it
  6203. if (sell)
  6204. packet->setDataByName("type", 1);
  6205. }
  6206. else {
  6207. if (sell)
  6208. packet->setDataByName("type", 130);
  6209. else
  6210. packet->setDataByName("type", 2);
  6211. }
  6212. EQ2Packet* outapp = packet->serialize();
  6213. QueuePacket(outapp);
  6214. safe_delete(packet);
  6215. }
  6216. }
  6217. }
  6218. }
  6219. void Client::SendSellMerchantList(bool sell) {
  6220. Spawn* spawn = GetMerchantTransaction();
  6221. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6222. map<int32, Item*>* items = player->GetItemList();
  6223. if (items) {
  6224. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6225. if (packet) {
  6226. vector<Item*> sellable_items;
  6227. map<int32, Item*>::iterator test_itr;
  6228. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  6229. if (test_itr->second && !test_itr->second->CheckFlag(NO_VALUE))
  6230. sellable_items.push_back(test_itr->second);
  6231. }
  6232. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6233. packet->setArrayLengthByName("num_items", sellable_items.size());
  6234. vector<Item*>::iterator itr;
  6235. Item* item = 0;
  6236. sint8 item_difficulty = 0;
  6237. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  6238. int32 sell_price = 0;
  6239. Item* master_item = 0;
  6240. int i = 0;
  6241. int tmp_level = 0;
  6242. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  6243. item = *itr;
  6244. master_item = master_item_list.GetItem(item->details.item_id);
  6245. if (master_item)
  6246. sell_price = (int32)(master_item->sell_price * multiplier);
  6247. else
  6248. sell_price = 0;
  6249. if (sell_price > item->sell_price)
  6250. sell_price = item->sell_price;
  6251. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6252. string thename = item->name;
  6253. packet->setArrayDataByName("price", sell_price, i);
  6254. if (player->GetGuild()) {
  6255. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  6256. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  6257. }
  6258. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6259. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  6260. packet->setArrayDataByName("stack_size", item->details.count, i);
  6261. packet->setArrayDataByName("icon", item->details.icon, i);
  6262. if (item->generic_info.adventure_default_level > 0)
  6263. tmp_level = item->generic_info.adventure_default_level;
  6264. else
  6265. tmp_level = item->generic_info.tradeskill_default_level;
  6266. packet->setArrayDataByName("level", item->details.recommended_level, i);
  6267. packet->setArrayDataByName("tier", item->details.tier, i);
  6268. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6269. item_difficulty = player->GetArrowColor(tmp_level);
  6270. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6271. item_difficulty = ARROW_COLOR_WHITE;
  6272. item_difficulty -= 6;
  6273. if (item_difficulty < 0)
  6274. item_difficulty *= -1;
  6275. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6276. if (item->details.count == 1)
  6277. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6278. else
  6279. packet->setArrayDataByName("quantity", item->details.count, i);
  6280. packet->setArrayDataByName("stack_size2", item->details.count, i);
  6281. if (GetVersion() <= 1096)
  6282. packet->setArrayDataByName("description", item->description.c_str(), i);
  6283. }
  6284. if (GetVersion() <= 546) {
  6285. packet->setDataByName("type", 1);
  6286. }
  6287. else {
  6288. if (sell)
  6289. packet->setDataByName("type", 129);
  6290. else
  6291. packet->setDataByName("type", 1);
  6292. }
  6293. packet->setDataByName("unknown8a", 16256, 6);
  6294. packet->setDataByName("unknown8a", 16256, 10);
  6295. //packet->PrintPacket();
  6296. EQ2Packet* outapp = packet->serialize();
  6297. //DumpPacket(outapp);
  6298. QueuePacket(outapp);
  6299. safe_delete(packet);
  6300. }
  6301. safe_delete(items);
  6302. }
  6303. }
  6304. }
  6305. void Client::SendBuyBackList(bool sell) {
  6306. if (GetVersion() <= 546) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  6307. return;
  6308. Spawn* spawn = GetMerchantTransaction();
  6309. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6310. deque<BuyBackItem*>::iterator itr;
  6311. int i = 0;
  6312. Item* master_item = 0;
  6313. BuyBackItem* buyback = 0;
  6314. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6315. if (packet) {
  6316. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6317. packet->setArrayLengthByName("num_items", buy_back_items.size());
  6318. sint8 item_difficulty = 0;
  6319. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6320. int tmp_level = 0;
  6321. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  6322. buyback = *itr;
  6323. master_item = master_item_list.GetItem(buyback->item_id);
  6324. if (master_item) {
  6325. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  6326. packet->setArrayDataByName("price", buyback->price, i);
  6327. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  6328. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  6329. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  6330. packet->setArrayDataByName("icon", master_item->details.icon, i);
  6331. if (master_item->generic_info.adventure_default_level > 0)
  6332. tmp_level = master_item->generic_info.adventure_default_level;
  6333. else
  6334. tmp_level = master_item->generic_info.tradeskill_default_level;
  6335. packet->setArrayDataByName("level", tmp_level, i);
  6336. packet->setArrayDataByName("tier", master_item->details.tier, i);
  6337. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  6338. item_difficulty = player->GetArrowColor(tmp_level);
  6339. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6340. item_difficulty = ARROW_COLOR_WHITE;
  6341. item_difficulty -= 6;
  6342. if (item_difficulty < 0)
  6343. item_difficulty *= -1;
  6344. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6345. if (buyback->quantity == 1)
  6346. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6347. else
  6348. packet->setArrayDataByName("quantity", buyback->quantity, i);
  6349. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  6350. if (GetVersion() <= 1096)
  6351. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  6352. }
  6353. }
  6354. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  6355. if (sell)
  6356. packet->setDataByName("type", 640);
  6357. else
  6358. packet->setDataByName("type", 512);
  6359. EQ2Packet* outapp = packet->serialize();
  6360. // DumpPacket(outapp);
  6361. QueuePacket(outapp);
  6362. safe_delete(packet);
  6363. }
  6364. }
  6365. }
  6366. void Client::SendRepairList() {
  6367. Spawn* spawn = GetMerchantTransaction();
  6368. if (spawn) {
  6369. vector<Item*>* repairable_items = GetRepairableItems();
  6370. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6371. if (packet) {
  6372. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6373. packet->setArrayLengthByName("num_items", repairable_items->size());
  6374. Item* item = 0;
  6375. sint8 item_difficulty = 0;
  6376. int32 i = 0;
  6377. vector<Item*>::iterator itr;
  6378. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  6379. item = *itr;
  6380. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6381. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  6382. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6383. packet->setArrayDataByName("stack_size", item->details.count, i);
  6384. packet->setArrayDataByName("icon", item->details.icon, i);
  6385. /*if (item->generic_info.adventure_default_level > 0)
  6386. tmp_level = item->generic_info.adventure_default_level;
  6387. else
  6388. tmp_level = item->generic_info.tradeskill_default_level;
  6389. packet->setArrayDataByName("level", tmp_level, i);*/
  6390. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  6391. packet->setArrayDataByName("tier", item->details.tier, i);
  6392. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6393. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  6394. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6395. item_difficulty = ARROW_COLOR_WHITE;
  6396. item_difficulty -= 6;
  6397. if (item_difficulty < 0)
  6398. item_difficulty *= -1;
  6399. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6400. if (item->details.count == 1)
  6401. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6402. else
  6403. packet->setArrayDataByName("quantity", item->details.count, i);
  6404. packet->setArrayDataByName("stack_size2", item->details.count, i);
  6405. if (GetVersion() <= 1096)
  6406. packet->setArrayDataByName("description", item->description.c_str(), i);
  6407. }
  6408. if (GetVersion() <= 546) {
  6409. packet->setDataByName("type", 16);
  6410. }
  6411. else {
  6412. packet->setDataByName("type", 96);
  6413. }
  6414. EQ2Packet* outapp = packet->serialize();
  6415. QueuePacket(outapp);
  6416. safe_delete(packet);
  6417. }
  6418. safe_delete(repairable_items);
  6419. }
  6420. }
  6421. void Client::ShowLottoWindow() {
  6422. Spawn* spawn = GetMerchantTransaction();
  6423. if (spawn) {
  6424. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  6425. if (!item_id)
  6426. {
  6427. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  6428. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  6429. return;
  6430. }
  6431. else if (item_id == 0)
  6432. {
  6433. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  6434. return;
  6435. }
  6436. Item* item = master_item_list.GetItem(item_id);
  6437. if (!item) {
  6438. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  6439. return;
  6440. }
  6441. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  6442. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6443. if (packet) {
  6444. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6445. packet->setArrayLengthByName("num_items", 1);
  6446. packet->setArrayDataByName("item_name", item->name.c_str());
  6447. packet->setArrayDataByName("price", item->sell_price);
  6448. packet->setArrayDataByName("item_id", item->details.item_id);
  6449. packet->setArrayDataByName("stack_size", item->details.count);
  6450. packet->setArrayDataByName("icon", item->details.icon);
  6451. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  6452. packet->setArrayDataByName("tier", item->details.tier);
  6453. packet->setArrayDataByName("item_id2", item->details.item_id);
  6454. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  6455. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6456. item_difficulty = ARROW_COLOR_WHITE;
  6457. item_difficulty -= 6;
  6458. if (item_difficulty < 0)
  6459. item_difficulty *= -1;
  6460. packet->setArrayDataByName("item_difficulty", item_difficulty);
  6461. //if(item->details.count == 1)
  6462. packet->setArrayDataByName("quantity", 0xFFFF);
  6463. //else
  6464. // packet->setArrayDataByName("quantity", item->details.count);
  6465. packet->setArrayDataByName("stack_size2", item->details.count);
  6466. packet->setArrayDataByName("description", item->description.c_str());
  6467. if (GetVersion() <= 546) {
  6468. packet->setDataByName("type", 128);
  6469. }
  6470. else {
  6471. packet->setDataByName("type", 0x00000102);
  6472. }
  6473. QueuePacket(packet->serialize());
  6474. safe_delete(packet);
  6475. }
  6476. }
  6477. }
  6478. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  6479. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  6480. if (packet) {
  6481. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  6482. int32 rolls[6] = { 0 };
  6483. int32 lottery_digits[6] = { 0 };
  6484. int8 num_matches = 0;
  6485. int64 jackpot = 0;
  6486. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  6487. if (!item) {
  6488. return;
  6489. }
  6490. database.DeleteItem(GetCharacterID(), item, 0);
  6491. GetPlayer()->item_list.RemoveItem(item, true);
  6492. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  6493. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  6494. if (!winning_numbers) {
  6495. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  6496. variables.AddVariable(winning_numbers);
  6497. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6498. }
  6499. if (strlen(winning_numbers->GetValue()) != 12) {
  6500. winning_numbers->SetValue("231205182236");
  6501. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6502. }
  6503. try {
  6504. for (int32 i = 0; i < 12; i += 2) {
  6505. char num[4];
  6506. strncpy(num, winning_numbers->GetValue() + i, 2);
  6507. lottery_digits[i / 2] = atoi(num);
  6508. }
  6509. }
  6510. catch (...) {
  6511. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  6512. return;
  6513. }
  6514. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  6515. if (!jackpot_var) {
  6516. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  6517. variables.AddVariable(jackpot_var);
  6518. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6519. }
  6520. try {
  6521. jackpot = atoul(jackpot_var->GetValue());
  6522. if (jackpot < 10000)
  6523. jackpot = 10000;
  6524. }
  6525. catch (...) {
  6526. jackpot = 10000;
  6527. }
  6528. char new_jackpot[128] = { 0 };
  6529. sprintf(new_jackpot, "%llu", jackpot + price);
  6530. jackpot_var->SetValue(new_jackpot);
  6531. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6532. world.PickRandomLottoDigits(rolls);
  6533. packet->setDataByName("roll_digit1", rolls[0]);
  6534. packet->setDataByName("roll_digit2", rolls[1]);
  6535. packet->setDataByName("roll_digit3", rolls[2]);
  6536. packet->setDataByName("roll_digit4", rolls[3]);
  6537. packet->setDataByName("roll_digit5", rolls[4]);
  6538. packet->setDataByName("roll_digit6", rolls[5]);
  6539. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  6540. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  6541. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  6542. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  6543. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  6544. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  6545. QueuePacket(packet->serialize());
  6546. safe_delete(packet);
  6547. for (int32 i = 0; i < 6; i++) {
  6548. for (int32 j = 0; j < 6; j++) {
  6549. if (rolls[i] == lottery_digits[j]) {
  6550. num_matches++;
  6551. break;
  6552. }
  6553. }
  6554. }
  6555. char new_jackpot_str[16];
  6556. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  6557. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  6558. if (num_matches == 6) {
  6559. world.PickRandomLottoDigits(lottery_digits);
  6560. for (int32 i = 0; i < 12; i += 2)
  6561. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  6562. winning_numbers->SetValue(new_jackpot_str);
  6563. jackpot_var->SetValue("10000");
  6564. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6565. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6566. }
  6567. }
  6568. }
  6569. void Client::SendGuildCreateWindow() {
  6570. if (GetVersion() <= 546) {
  6571. SimpleMessage(0, "Not implemented on this client...yet?");
  6572. }
  6573. else {
  6574. Spawn* spawn = GetPlayer()->GetTarget();
  6575. if (spawn) {
  6576. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6577. if (packet) {
  6578. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6579. packet->setArrayLengthByName("num_items", 0);
  6580. packet->setDataByName("type", 0x00008000);
  6581. QueuePacket(packet->serialize());
  6582. safe_delete(packet);
  6583. }
  6584. }
  6585. }
  6586. }
  6587. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  6588. BuyBackItem* item = new BuyBackItem;
  6589. item->item_id = item_id;
  6590. item->unique_id = unique_id;
  6591. item->price = price;
  6592. item->quantity = quantity;
  6593. item->save_needed = save_needed;
  6594. MBuyBack.writelock(__FUNCTION__, __LINE__);
  6595. buy_back_items.push_back(item);
  6596. if (buy_back_items.size() > 10) {
  6597. safe_delete(buy_back_items.front());
  6598. buy_back_items.pop_front();
  6599. }
  6600. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  6601. }
  6602. deque<BuyBackItem*>* Client::GetBuyBacks() {
  6603. return &buy_back_items;
  6604. }
  6605. vector<Item*>* Client::GetRepairableItems() {
  6606. vector<Item*>* repairable_items = new vector<Item*>;
  6607. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  6608. map<int32, Item*>* items = player->GetItemList();
  6609. if (equipped_items && equipped_items->size() > 0) {
  6610. for (int32 i = 0; i < equipped_items->size(); i++) {
  6611. Item* item = equipped_items->at(i);
  6612. if (item && item->generic_info.condition < 100)
  6613. repairable_items->push_back(item);
  6614. }
  6615. }
  6616. if (items && items->size() > 0) {
  6617. map<int32, Item*>::iterator itr;
  6618. for (itr = items->begin(); itr != items->end(); itr++) {
  6619. Item* item = itr->second;
  6620. if (item && item->generic_info.condition < 100)
  6621. repairable_items->push_back(item);
  6622. }
  6623. }
  6624. safe_delete(equipped_items);
  6625. safe_delete(items);
  6626. return repairable_items;
  6627. }
  6628. void Client::SendMailList() {
  6629. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  6630. if (kiosk_id > 0) {
  6631. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  6632. if (p) {
  6633. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  6634. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  6635. int16 i = 0;
  6636. p->setDataByName("kiosk_id", kiosk_id);
  6637. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  6638. while (itr.Next()) {
  6639. Mail* mail = itr->second;
  6640. p->setArrayDataByName("mail_id", mail->mail_id, i);
  6641. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  6642. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  6643. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  6644. p->setArrayDataByName("unknown1", 0x0000, i);
  6645. p->setArrayDataByName("already_read", mail->already_read, i);
  6646. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  6647. p->setArrayDataByName("mail_type", mail->mail_type, i);
  6648. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  6649. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  6650. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  6651. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  6652. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  6653. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  6654. p->setArrayDataByName("num_items", mail->stack, i);
  6655. p->setArrayDataByName("packettype", GetItemPacketType(GetVersion()));
  6656. p->setArrayDataByName("packetsubtype", 0xFF, i);
  6657. p->setArrayDataByName("unknown2", 0, i);
  6658. //p->setArrayDataByName("item_id", 5, i, 0);
  6659. //Item* item = master_item_list.GetItem(5);
  6660. //if (item)
  6661. // printf("%s\n", item->name.c_str());
  6662. //else
  6663. // printf("no item\n");
  6664. //p->setItemArrayDataByName("item", master_item_list.GetItem(5), i, 0);
  6665. i++;
  6666. }
  6667. // GMs send mail for free!
  6668. if (GetAdminStatus() > 0)
  6669. {
  6670. p->setDataByName("postage_cost", 0);
  6671. p->setDataByName("attachment_cost", 0);
  6672. }
  6673. else
  6674. {
  6675. p->setDataByName("postage_cost", 10);
  6676. p->setDataByName("attachment_cost", 50);
  6677. }
  6678. p->setDataByName("unknown3", 0x01F4);
  6679. p->setDataByName("unknown4", 0x01000000);
  6680. QueuePacket(p->serialize());
  6681. safe_delete(p);
  6682. }
  6683. }
  6684. else
  6685. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  6686. }
  6687. void Client::DisplayMailMessage(int32 mail_id) {
  6688. Mail* mail = player->GetMail(mail_id);
  6689. if (mail) {
  6690. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  6691. if (kiosk_id > 0) {
  6692. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6693. if (update) {
  6694. update->setDataByName("action", 0x03);
  6695. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  6696. update->setDataByName("packetsubtype", 0xFF);
  6697. QueuePacket(update->serialize());
  6698. safe_delete(update);
  6699. }
  6700. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  6701. if (packet) {
  6702. packet->setDataByName("kiosk_id", kiosk_id);
  6703. packet->setDataByName("mail_id", mail->mail_id);
  6704. packet->setDataByName("player_to_id", mail->player_to_id);
  6705. packet->setDataByName("player_from", mail->player_from.c_str());
  6706. packet->setDataByName("subject", mail->subject.c_str());
  6707. packet->setDataByName("mail_body", mail->mail_body.c_str());
  6708. packet->setDataByName("unknown1", 1);
  6709. packet->setDataByName("unknown2", 0);
  6710. packet->setDataByName("lock_report_button", 1);
  6711. packet->setDataByName("unknown3", 0xFFFFFFFF);
  6712. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  6713. packet->setDataByName("coin_copper", mail->coin_copper);
  6714. packet->setDataByName("coin_silver", mail->coin_silver);
  6715. packet->setDataByName("coin_gold", mail->coin_gold);
  6716. packet->setDataByName("coin_plat", mail->coin_plat);
  6717. packet->setDataByName("stack", mail->stack);
  6718. packet->setDataByName("packettype", GetItemPacketType(GetVersion()));
  6719. packet->setDataByName("packetsubtype", 0xFF);
  6720. packet->setDataByName("unknown4", 0);
  6721. packet->setDataByName("unknown5", 0);
  6722. packet->setDataByName("unknown6", 0);
  6723. packet->setDataByName("unknown7", 0);
  6724. mail->already_read = true;
  6725. mail->save_needed = true;
  6726. QueuePacket(packet->serialize());
  6727. safe_delete(packet);
  6728. //SendMailList();
  6729. }
  6730. }
  6731. else
  6732. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  6733. }
  6734. }
  6735. /* 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
  6736. packet back to the client before the mail actually sent. */
  6737. void Client::HandleSentMail(EQApplicationPacket* app) {
  6738. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  6739. if (packet) {
  6740. packet->LoadPacketData(app->pBuffer, app->size);
  6741. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  6742. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  6743. vector<int32>* ids = 0;
  6744. if (reply_packet) {
  6745. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  6746. if (player_to.length() == 0)
  6747. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  6748. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  6749. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  6750. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  6751. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  6752. else {
  6753. if (player_to.compare("<all>") == 0) {
  6754. if (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat == 0)
  6755. ids = database.GetAllPlayerIDs();
  6756. else
  6757. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  6758. }
  6759. else {
  6760. ids = new vector<int32>;
  6761. ids->push_back(database.GetCharacterID(player_to.c_str()));
  6762. }
  6763. if (ids) {
  6764. for (int32 i = 0; i < ids->size(); i++) {
  6765. int32 player_to_id = ids->at(i);
  6766. if (player_to_id > 0) {
  6767. reply_type = MAIL_SEND_RESULT_SUCCESS;
  6768. Mail* mail = new Mail;
  6769. mail->mail_id = 0;
  6770. mail->player_to_id = player_to_id;
  6771. mail->player_from = string(GetPlayer()->GetName());
  6772. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  6773. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  6774. mail->already_read = 0;
  6775. mail->mail_type = MAIL_TYPE_REGULAR;
  6776. mail->coin_copper = mail_window.coin_copper;
  6777. mail->coin_silver = mail_window.coin_silver;
  6778. mail->coin_gold = mail_window.coin_gold;
  6779. mail->coin_plat = mail_window.coin_plat;
  6780. mail->stack = 0;
  6781. // GM's send mail for free!
  6782. if (GetAdminStatus() > 0)
  6783. {
  6784. mail->postage_cost = 0;
  6785. mail->attachment_cost = 0;
  6786. }
  6787. else
  6788. {
  6789. mail->postage_cost = 10;
  6790. mail->attachment_cost = 50;
  6791. }
  6792. mail->char_item_id = 0;
  6793. mail->time_sent = Timer::GetUnixTimeStamp();
  6794. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  6795. //int16 packettype = packet->getType_int16_ByName("packettype");
  6796. //int8 packetsubtype = packet->getType_int8_ByName("packetsubtype");
  6797. /*int32 postage_cost = packet->getType_int32_ByName("postage_cost");
  6798. int32 attachment_cost = packet->getType_int32_ByName("attachment_cost");
  6799. if (postage_cost > 0 || attachment_cost > 0)
  6800. PlaySoundA("coin_cha_ching");*/
  6801. mail->save_needed = false;
  6802. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  6803. if (to_client) {
  6804. to_client->GetPlayer()->AddMail(mail);
  6805. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You've got mail! :)");
  6806. }
  6807. database.SavePlayerMail(mail);
  6808. mail_window.coin_copper = 0;
  6809. mail_window.coin_silver = 0;
  6810. mail_window.coin_gold = 0;
  6811. mail_window.coin_plat = 0;
  6812. }
  6813. else
  6814. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  6815. }
  6816. }
  6817. }
  6818. string players_to = "";
  6819. if (ids) {
  6820. for (int32 i = 0; i < ids->size(); i++) {
  6821. if (ids->at(i) != 0)
  6822. players_to.append(database.GetCharacterName(ids->at(i)));
  6823. if (i < (ids->size() - 1))
  6824. players_to.append(", ");
  6825. }
  6826. }
  6827. reply_packet->setDataByName("player_to", players_to.c_str());
  6828. reply_packet->setDataByName("reply_type", reply_type);
  6829. QueuePacket(reply_packet->serialize());
  6830. safe_delete(reply_packet);
  6831. safe_delete(ids);
  6832. }
  6833. safe_delete(packet);
  6834. }
  6835. }
  6836. void Client::DeleteMail(int32 mail_id, bool from_database) {
  6837. player->DeleteMail(mail_id, from_database);
  6838. }
  6839. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  6840. bool ret = false;
  6841. if (GetMailTransaction()) {
  6842. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6843. if (packet) {
  6844. if (copper > 0) {
  6845. if (player->RemoveCoins(copper)) {
  6846. mail_window.coin_copper += copper;
  6847. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  6848. ret = true;
  6849. }
  6850. }
  6851. else if (silver > 0) {
  6852. if (player->RemoveCoins(silver * 100)) {
  6853. mail_window.coin_silver += silver;
  6854. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  6855. ret = true;
  6856. }
  6857. }
  6858. else if (gold > 0) {
  6859. if (player->RemoveCoins(gold * 10000)) {
  6860. mail_window.coin_gold += gold;
  6861. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  6862. ret = true;
  6863. }
  6864. }
  6865. else if (plat > 0) {
  6866. if (player->RemoveCoins(plat * 1000000)) {
  6867. mail_window.coin_plat += plat;
  6868. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  6869. ret = true;
  6870. }
  6871. }
  6872. if (ret) {
  6873. packet->setDataByName("coin_copper", mail_window.coin_copper);
  6874. packet->setDataByName("coin_silver", mail_window.coin_silver);
  6875. packet->setDataByName("coin_gold", mail_window.coin_gold);
  6876. packet->setDataByName("coin_plat", mail_window.coin_plat);
  6877. packet->setDataByName("stack", 0);
  6878. packet->setDataByName("packettype", GetItemPacketType(version));
  6879. packet->setDataByName("packetsubtype", 0xFF);
  6880. packet->setDataByName("unknown2", 0);
  6881. //packet->PrintPacket();
  6882. QueuePacket(packet->serialize());
  6883. }
  6884. else
  6885. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  6886. safe_delete(packet);
  6887. }
  6888. }
  6889. else
  6890. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  6891. return ret;
  6892. }
  6893. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  6894. bool ret = false;
  6895. if (GetMailTransaction()) {
  6896. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6897. if (packet) {
  6898. if (copper > 0) {
  6899. player->AddCoins(copper);
  6900. mail_window.coin_copper -= copper;
  6901. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  6902. ret = true;
  6903. }
  6904. else if (silver > 0) {
  6905. player->AddCoins(silver * 100);
  6906. mail_window.coin_silver -= silver;
  6907. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  6908. ret = true;
  6909. }
  6910. else if (gold > 0) {
  6911. player->AddCoins(gold * 10000);
  6912. mail_window.coin_gold -= gold;
  6913. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  6914. ret = true;
  6915. }
  6916. else if (plat > 0) {
  6917. player->AddCoins(plat * 1000000);
  6918. mail_window.coin_plat -= plat;
  6919. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  6920. ret = true;
  6921. }
  6922. if (ret) {
  6923. packet->setDataByName("coin_copper", mail_window.coin_copper);
  6924. packet->setDataByName("coin_silver", mail_window.coin_silver);
  6925. packet->setDataByName("coin_gold", mail_window.coin_gold);
  6926. packet->setDataByName("coin_plat", mail_window.coin_plat);
  6927. packet->setDataByName("stack", 0);
  6928. packet->setDataByName("packettype", 0x2BFE);
  6929. packet->setDataByName("packetsubtype", 0xFF);
  6930. packet->setDataByName("unknown2", 0);
  6931. QueuePacket(packet->serialize());
  6932. }
  6933. safe_delete(packet);
  6934. }
  6935. }
  6936. else
  6937. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  6938. return ret;
  6939. }
  6940. void Client::TakeMailAttachments(int32 mail_id) {
  6941. if (GetMailTransaction()) {
  6942. Mail* mail = player->GetMail(mail_id);
  6943. if (mail) {
  6944. int64 amount = 0;
  6945. if (mail->coin_copper > 0) {
  6946. amount += mail->coin_copper;
  6947. mail->coin_copper = 0;
  6948. }
  6949. if (mail->coin_silver > 0) {
  6950. amount += mail->coin_silver * 100;
  6951. mail->coin_silver = 0;
  6952. }
  6953. if (mail->coin_gold > 0) {
  6954. amount += mail->coin_gold * 10000;
  6955. mail->coin_gold = 0;
  6956. }
  6957. if (mail->coin_plat > 0) {
  6958. amount += mail->coin_plat * 1000000;
  6959. mail->coin_plat = 0;
  6960. }
  6961. if (mail->char_item_id > 0) {
  6962. LogWrite(MISC__TODO, 1, "TODO", "Items by Mail\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  6963. }
  6964. /* 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
  6965. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  6966. find it in any packet logs.*/
  6967. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6968. if (packet) {
  6969. packet->setDataByName("unknown", 0x03);
  6970. packet->setDataByName("coin_copper", mail->coin_copper);
  6971. packet->setDataByName("coin_silver", mail->coin_silver);
  6972. packet->setDataByName("coin_gold", mail->coin_gold);
  6973. packet->setDataByName("coin_plat", mail->coin_plat);
  6974. packet->setDataByName("stack", 0);
  6975. packet->setDataByName("packettype", 0x2BFE);
  6976. packet->setDataByName("packetsubtype", 0xFF);
  6977. packet->setDataByName("unknown2", 0);
  6978. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  6979. DumpPacket(packet->serialize());
  6980. QueuePacket(packet->serialize());
  6981. safe_delete(packet);
  6982. }*/
  6983. database.SavePlayerMail(mail);
  6984. if (amount > 0)
  6985. player->AddCoins(amount);
  6986. SendMailList();
  6987. }
  6988. }
  6989. else
  6990. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  6991. }
  6992. void Client::CancelSendMail() {
  6993. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  6994. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  6995. mail_window.coin_copper = 0;
  6996. mail_window.coin_silver = 0;
  6997. mail_window.coin_gold = 0;
  6998. mail_window.coin_plat = 0;
  6999. mail_window.char_item_id = 0;
  7000. }
  7001. bool Client::GateAllowed() {
  7002. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  7003. LogWrite(MISC__TODO, 1, "TODO", "possibly add a check here to see if a player is allowed to gate from this spot, allow for now\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  7004. if (zone)
  7005. return true;
  7006. return false;
  7007. }
  7008. bool Client::BindAllowed() {
  7009. LogWrite(MISC__TODO, 1, "TODO", "possibly add a check here to see if a player is allowed to bind in this spot, allow anywhere for now\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  7010. return true;
  7011. }
  7012. bool Client::Bind() {
  7013. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  7014. player->GetPlayerInfo()->SetBindX(player->GetX());
  7015. player->GetPlayerInfo()->SetBindY(player->GetY());
  7016. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  7017. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  7018. return true;
  7019. }
  7020. bool Client::Gate() {
  7021. if (player->GetPlayerInfo()->GetBindZoneID() == 0)
  7022. return false;
  7023. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  7024. if (zone) {
  7025. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  7026. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  7027. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  7028. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  7029. Zone(zone, false);
  7030. return true;
  7031. }
  7032. return false;
  7033. }
  7034. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id) {
  7035. if (!destinations || !spawn) {
  7036. return;
  7037. }
  7038. bool has_map = false;
  7039. if (transport_id > 0)
  7040. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  7041. transport_spawn = spawn;
  7042. vector<TransportDestination*> transport_list;
  7043. vector<TransportDestination*>::iterator itr;
  7044. TransportDestination* destination = 0;
  7045. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  7046. destination = *itr;
  7047. 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)))
  7048. transport_list.push_back(destination);
  7049. }
  7050. if (transport_list.size() == 0 && destination) {
  7051. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7052. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7053. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7054. else
  7055. {
  7056. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7057. if (app)
  7058. QueuePacket(app);
  7059. }
  7060. }
  7061. else {
  7062. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7063. // determine if this is an instanced zone that already exists
  7064. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  7065. if (instance_zone || new_zone) {
  7066. GetPlayer()->SetX(destination->destination_x);
  7067. GetPlayer()->SetY(destination->destination_y);
  7068. GetPlayer()->SetZ(destination->destination_z);
  7069. GetPlayer()->SetHeading(destination->destination_heading);
  7070. if (instance_zone)
  7071. Zone(instance_zone->GetInstanceID(), false, true);
  7072. else
  7073. Zone(new_zone, false);
  7074. }
  7075. }
  7076. if (destination->message.length() > 0)
  7077. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7078. }
  7079. else if (transport_list.size() > 0) {
  7080. if (!spawn->IsSoundsDisabled())
  7081. PlaySound("mariner_bell");
  7082. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  7083. if (packet) {
  7084. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  7085. // Put all the destinations the player can go in a new vector
  7086. vector<TransportDestination*> destinations;
  7087. for (int32 i = 0; i < transport_list.size(); i++) {
  7088. destination = transport_list.at(i);
  7089. // Check min level
  7090. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  7091. continue;
  7092. // Check max level
  7093. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  7094. continue;
  7095. // Check quest complete
  7096. if (destination->req_quest_complete > 0 && GetPlayer()->GetCompletedQuest(destination->req_quest_complete) == 0)
  7097. continue;
  7098. // Check req quest and step
  7099. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  7100. continue;
  7101. // 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
  7102. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  7103. packet->setDataByName("current_zone", destination->display_name.c_str());
  7104. packet->setDataByName("current_map_x", destination->map_x);
  7105. packet->setDataByName("current_map_y", destination->map_y);
  7106. }
  7107. else {
  7108. destinations.push_back(destination);
  7109. }
  7110. }
  7111. // Use the new vector to create the packet
  7112. destination = 0;
  7113. packet->setArrayLengthByName("num_destinations", destinations.size());
  7114. for (int32 i = 0; i < destinations.size(); i++) {
  7115. destination = destinations.at(i);
  7116. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  7117. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  7118. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  7119. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  7120. packet->setArrayDataByName("cost", destination->cost, i);
  7121. if (has_map) {
  7122. packet->setArrayDataByName("map_x", destination->map_x, i);
  7123. packet->setArrayDataByName("map_y", destination->map_y, i);
  7124. }
  7125. }
  7126. if (has_map)
  7127. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  7128. EQ2Packet* app = packet->serialize();
  7129. //DumpPacket(app);
  7130. if (destinations.size() > 0)
  7131. QueuePacket(app);
  7132. safe_delete(packet);
  7133. }
  7134. }
  7135. }
  7136. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  7137. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  7138. if (packet) {
  7139. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  7140. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  7141. int32 unique_id = packet->getType_int32_ByName("unique_id");
  7142. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  7143. int32 cost = packet->getType_int32_ByName("cost");
  7144. vector<TransportDestination*> destinations;
  7145. TransportDestination* destination = 0;
  7146. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  7147. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  7148. vector<TransportDestination*>::iterator itr;
  7149. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  7150. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  7151. destination = *itr;
  7152. break;
  7153. }
  7154. }
  7155. SetTemporaryTransportID(0);
  7156. if (!destination)
  7157. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  7158. else {
  7159. if (cost == 0 || player->RemoveCoins(cost)) {
  7160. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7161. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7162. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7163. else
  7164. {
  7165. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7166. if (outapp)
  7167. QueuePacket(outapp);
  7168. }
  7169. }
  7170. else {
  7171. GetPlayer()->SetX(destination->destination_x);
  7172. GetPlayer()->SetY(destination->destination_y);
  7173. GetPlayer()->SetZ(destination->destination_z);
  7174. GetPlayer()->SetHeading(destination->destination_heading);
  7175. // Test if where we're going is an Instanced zone
  7176. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  7177. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  7178. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7179. Zone(new_zone, false);
  7180. }
  7181. }
  7182. if (destination->message.length() > 0)
  7183. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7184. }
  7185. else
  7186. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  7187. }
  7188. }
  7189. safe_delete(packet);
  7190. }
  7191. }
  7192. void Client::SendNewSpells(int8 class_id) {
  7193. if (class_id > 0) {
  7194. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  7195. vector<Spell*>::iterator itr;
  7196. Spell* spell = 0;
  7197. bool send_updates = false;
  7198. for (itr = spells->begin(); itr != spells->end(); itr++) {
  7199. spell = *itr;
  7200. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  7201. send_updates = true;
  7202. SendSpellUpdate(spell);
  7203. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  7204. player->UnlockSpell(spell);
  7205. }
  7206. }
  7207. if (send_updates) {
  7208. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  7209. if (outapp)
  7210. QueuePacket(outapp);
  7211. }
  7212. safe_delete(spells);
  7213. }
  7214. }
  7215. void Client::SetItemSearch(vector<Item*>* items) {
  7216. if (items) {
  7217. safe_delete(search_items);
  7218. search_items = items;
  7219. }
  7220. }
  7221. vector<Item*>* Client::GetSearchItems() {
  7222. return search_items;
  7223. }
  7224. void Client::SearchStore(int32 page) {
  7225. if (search_items) {
  7226. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  7227. if (packet) {
  7228. int32 x = page * 8;
  7229. if (search_items->size() > 8) {
  7230. if ((search_items->size() - x) > 8)
  7231. packet->setArrayLengthByName("num_items", 8);
  7232. else
  7233. packet->setArrayLengthByName("num_items", search_items->size() - x);
  7234. }
  7235. else
  7236. packet->setArrayLengthByName("num_items", search_items->size());
  7237. if (search_items->size() > 0) {
  7238. packet->setArrayLengthByName("num_sellers", 1);
  7239. packet->setArrayDataByName("seller_seller_id", 1);
  7240. packet->setArrayDataByName("seller_name", "EQ2EmuDevs");
  7241. packet->setDataByName("per_page", 8);
  7242. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  7243. packet->setDataByName("page", page);
  7244. Item* item = 0;
  7245. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  7246. for (int32 i = 0; i < limit; i++, x++) {
  7247. if (x >= search_items->size())
  7248. break;
  7249. item = search_items->at(x);
  7250. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7251. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7252. packet->setArrayDataByName("icon", item->details.icon, i);
  7253. //packet->setArrayDataByName("unknown2b", i, i);
  7254. packet->setArrayDataByName("item_seller_id", 1, i);
  7255. if (item->stack_count == 0)
  7256. packet->setArrayDataByName("quantity", 1, i);
  7257. else
  7258. packet->setArrayDataByName("quantity", item->stack_count, i);
  7259. packet->setArrayDataByName("stack_size", item->stack_count, i);
  7260. std::string tmpStr("");
  7261. tmpStr.append(item->name.c_str());
  7262. tmpStr.append(" (");
  7263. tmpStr.append(std::to_string(item->details.item_id));
  7264. tmpStr.append(")");
  7265. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  7266. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  7267. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  7268. }
  7269. }
  7270. /*EQ2Packet* outapp = packet->serialize();
  7271. DumpPacket(outapp);
  7272. QueuePacket(outapp);*/
  7273. QueuePacket(packet->serialize());
  7274. safe_delete(packet);
  7275. }
  7276. }
  7277. }
  7278. void Client::SetReadyForUpdates() {
  7279. GetPlayer()->SetFullyLoggedIn(true);
  7280. if (!ready_for_updates)
  7281. database.loadCharacterProperties(this);
  7282. ready_for_updates = true;
  7283. }
  7284. void Client::SetReadyForSpawns(bool val) {
  7285. ready_for_spawns = val;
  7286. if (GetPlayer()->GetActivityStatus() > 0) {
  7287. GetPlayer()->SetActivityStatus(0);
  7288. if (GetPlayer()->GetGroupMemberInfo()) {
  7289. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  7290. }
  7291. }
  7292. zone_list.CheckFriendZoned(this);
  7293. }
  7294. void Client::SendChatRelationship(int8 type, const char* name) {
  7295. if (!name) {
  7296. return;
  7297. }
  7298. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  7299. if (packet) {
  7300. packet->setDataByName("account_id", GetAccountID());
  7301. packet->setDataByName("type", type);
  7302. packet->setArrayLengthByName("num_names", 1);
  7303. packet->setArrayDataByName("name", name);
  7304. if (type == 0) {
  7305. Client* client = zone_list.GetClientByCharName(name);
  7306. if (client) {
  7307. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  7308. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  7309. }
  7310. }
  7311. QueuePacket(packet->serialize());
  7312. safe_delete(packet);
  7313. }
  7314. }
  7315. void Client::SendFriendList() {
  7316. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  7317. if (packet) {
  7318. packet->setDataByName("account_id", GetAccountID());
  7319. map<string, int8>::iterator itr;
  7320. map<string, int8>* friends = player->GetFriends();
  7321. if (friends && friends->size() > 0) {
  7322. Client* client = 0;
  7323. vector<string> names;
  7324. for (itr = friends->begin(); itr != friends->end(); itr++) {
  7325. if (itr->second == 2)
  7326. continue;
  7327. names.push_back(itr->first);
  7328. }
  7329. packet->setArrayLengthByName("num_names", names.size());
  7330. for (int32 i = 0; i < names.size(); i++) {
  7331. client = zone_list.GetClientByCharName(names[i]);
  7332. packet->setArrayDataByName("name", names[i].c_str(), i);
  7333. if (client) {
  7334. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  7335. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  7336. }
  7337. }
  7338. }
  7339. QueuePacket(packet->serialize());
  7340. safe_delete(packet);
  7341. }
  7342. }
  7343. void Client::SendIgnoreList() {
  7344. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  7345. if (packet) {
  7346. packet->setDataByName("account_id", GetAccountID());
  7347. packet->setDataByName("type", 2);
  7348. map<string, int8>::iterator itr;
  7349. map<string, int8>* ignored = player->GetIgnoredPlayers();
  7350. if (ignored && ignored->size() > 0) {
  7351. vector<string> names;
  7352. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  7353. if (itr->second == 2)
  7354. continue;
  7355. names.push_back(itr->first);
  7356. }
  7357. packet->setArrayLengthByName("num_names", names.size());
  7358. for (int32 i = 0; i < names.size(); i++)
  7359. packet->setArrayDataByName("name", names[i].c_str(), i);
  7360. }
  7361. QueuePacket(packet->serialize());
  7362. safe_delete(packet);
  7363. }
  7364. }
  7365. void Client::AddWaypoint(string name, int8 type) {
  7366. waypoint_id++;
  7367. WaypointInfo info;
  7368. info.id = waypoint_id;
  7369. info.type = type;
  7370. waypoints[name] = info;
  7371. }
  7372. void Client::SendWaypoints() {
  7373. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  7374. if (packet) {
  7375. packet->setArrayLengthByName("num_updates", waypoints.size());
  7376. map<string, WaypointInfo>::iterator itr;
  7377. int16 i = 0;
  7378. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  7379. packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
  7380. packet->setArrayDataByName("waypoint_category", itr->second.type, i);
  7381. packet->setArrayDataByName("spawn_id", itr->second.id, i);
  7382. i++;
  7383. }
  7384. packet->setDataByName("unknown", 0xFFFFFFFF);
  7385. QueuePacket(packet->serialize());
  7386. safe_delete(packet);
  7387. }
  7388. }
  7389. void Client::SelectWaypoint(int32 id) {
  7390. string found_name = "";
  7391. map<string, WaypointInfo>::iterator itr;
  7392. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  7393. if (itr->second.id == id) {
  7394. found_name = itr->first;
  7395. break;
  7396. }
  7397. }
  7398. if (found_name.length() > 0) {
  7399. Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
  7400. ShowPathToTarget(spawn);
  7401. }
  7402. }
  7403. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  7404. if (waypoint_name) {
  7405. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  7406. if (packet) {
  7407. packet->setArrayLengthByName("num_updates", 1);
  7408. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  7409. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  7410. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  7411. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  7412. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  7413. packet->setDataByName("unknown", 0xFFFFFFFF);
  7414. QueuePacket(packet->serialize());
  7415. safe_delete(packet);
  7416. }
  7417. }
  7418. }
  7419. void Client::ClearWaypoint() {
  7420. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  7421. if (packet) {
  7422. QueuePacket(packet->serialize());
  7423. safe_delete(packet);
  7424. }
  7425. }
  7426. bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
  7427. if (current_zone->pathing) {
  7428. if (GetPlayer()->GetMap()) {
  7429. if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
  7430. return false;
  7431. if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
  7432. return false;
  7433. auto loc = glm::vec3(x, z, y);
  7434. float new_z = GetPlayer()->GetMap()->FindBestZ(loc, nullptr);
  7435. if (new_z != BEST_Z_INVALID) //this is actually y
  7436. y = new_z;
  7437. }
  7438. bool partial = false;
  7439. bool stuck = false;
  7440. PathfinderOptions opts;
  7441. opts.smooth_path = true;
  7442. opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
  7443. opts.offset = y_offset + 1.0f;
  7444. opts.flags = PathingNotDisabled ^ PathingZoneLine;
  7445. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  7446. if (packet) {
  7447. auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
  7448. packet->setArrayLengthByName("num_points", path.size());
  7449. int i = 0;
  7450. for (auto& node : path)
  7451. {
  7452. packet->setArrayDataByName("x", node.pos.x, i);
  7453. packet->setArrayDataByName("y", node.pos.z, i);
  7454. packet->setArrayDataByName("z", node.pos.y, i);
  7455. packet->setDataByName("waypoint_x", x);
  7456. packet->setDataByName("waypoint_y", y);
  7457. packet->setDataByName("waypoint_z", z);
  7458. i++;
  7459. }
  7460. if (i > 0)
  7461. QueuePacket(packet->serialize());
  7462. safe_delete(packet);
  7463. return (i > 0);
  7464. }
  7465. }
  7466. return false;
  7467. }
  7468. bool Client::ShowPathToTarget(Spawn* spawn) {
  7469. if (spawn) {
  7470. return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
  7471. }
  7472. return false;
  7473. }
  7474. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  7475. if (waypoint_name) {
  7476. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  7477. if (packet) {
  7478. packet->setArrayLengthByName("num_points", 1);
  7479. packet->setArrayDataByName("x", x, 0);
  7480. packet->setArrayDataByName("y", y, 0);
  7481. packet->setArrayDataByName("z", z, 0);
  7482. packet->setDataByName("waypoint_x", x);
  7483. packet->setDataByName("waypoint_y", y);
  7484. packet->setDataByName("waypoint_z", z);
  7485. packet->setDataByName("waypoint_name", waypoint_name);
  7486. packet->setDataByName("unknown", 0);
  7487. QueuePacket(packet->serialize());
  7488. safe_delete(packet);
  7489. }
  7490. }
  7491. }
  7492. void Client::InspectPlayer(Player* player_to_inspect) {
  7493. if (player_to_inspect) {
  7494. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  7495. if (packet) {
  7496. packet->setDataByName("unknown", 0);
  7497. packet->setSmallStringByName("name", player_to_inspect->GetName());
  7498. packet->setDataByName("race", player_to_inspect->GetRace());
  7499. packet->setDataByName("gender", player_to_inspect->GetGender());
  7500. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  7501. LogWrite(MISC__TODO, 1, "TODO", "Put mentored level here (adventure_level_effective)\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  7502. packet->setDataByName("adventure_level_effective", player_to_inspect->GetLevel());
  7503. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  7504. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  7505. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  7506. packet->setDataByName("health", player_to_inspect->GetHP());
  7507. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  7508. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  7509. packet->setDataByName("power", player_to_inspect->GetPower());
  7510. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  7511. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  7512. packet->setDataByName("mitigation", 0);
  7513. packet->setDataByName("unknown1", 0);
  7514. packet->setDataByName("avoidance", 0);
  7515. packet->setDataByName("unknown2", 0);
  7516. packet->setDataByName("mitigation_percentage", 0);
  7517. packet->setDataByName("strength", player_to_inspect->GetStr());
  7518. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  7519. packet->setDataByName("stamina", player_to_inspect->GetSta());
  7520. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  7521. packet->setDataByName("agility", player_to_inspect->GetAgi());
  7522. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  7523. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  7524. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  7525. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  7526. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  7527. packet->setDataByName("unknown4", 0);
  7528. packet->setDataByName("unknown5", 0);
  7529. packet->setDataByName("unknown6", 0);
  7530. packet->setDataByName("unknown7", 0);
  7531. packet->setDataByName("unknown8", 0);
  7532. packet->setDataByName("unknown9", 0);
  7533. packet->setDataByName("unknown10", 0);
  7534. packet->setDataByName("unknown11", 0);
  7535. packet->setDataByName("unknown12", 0);
  7536. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  7537. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  7538. packet->setDataByName("heat_resist_percentage", 0);
  7539. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  7540. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  7541. packet->setDataByName("cold_resist_percentage", 0);
  7542. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  7543. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  7544. packet->setDataByName("magic_resist_percentage", 0);
  7545. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  7546. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  7547. packet->setDataByName("mental_resist_percentage", 0);
  7548. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  7549. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  7550. packet->setDataByName("divine_resist_percentage", 0);
  7551. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  7552. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  7553. packet->setDataByName("disease_resist_percentage", 0);
  7554. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  7555. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  7556. packet->setDataByName("poison_resist_percentage", 0);
  7557. packet->setArrayLengthByName("num_chars", 0x01FF);
  7558. string biography = player_to_inspect->GetBiography();
  7559. for (size_t i = 0; i < biography.length(); i++)
  7560. packet->setArrayDataByName("biography_char", biography[i], i);
  7561. LogWrite(MISC__TODO, 0, "TODO", "Why is inspect player weapons commented out? in func: %s, line: %i", __FUNCTION__, __LINE__);
  7562. /*Item* pw = player_to_inspect->GetEquipmentList()->GetItem(0);
  7563. if (pw)
  7564. packet->setItemByName("primary", pw, player_to_inspect, 0);
  7565. Item* sw = player_to_inspect->GetEquipmentList()->GetItem(1);
  7566. if (sw)
  7567. packet->setItemByName("secondary", sw, player_to_inspect, 0);*/
  7568. //DumpPacket(packet->serialize());
  7569. QueuePacket(packet->serialize());
  7570. safe_delete(packet);
  7571. }
  7572. }
  7573. }
  7574. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  7575. pending_guild_invite.guild = guild;
  7576. pending_guild_invite.invited_by = invited_by;
  7577. }
  7578. void Client::ShowClaimWindow() {
  7579. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  7580. if (packet) {
  7581. map<int32, Item*>* items = &master_item_list.items;
  7582. map<int32, Item*>::iterator itr;
  7583. int32 i = 0;
  7584. if (items->size() > 10)
  7585. packet->setArrayLengthByName("num_claim_items", 10);
  7586. else
  7587. packet->setArrayLengthByName("num_claim_items", items->size());
  7588. for (itr = items->begin(); itr != items->end(); itr++) {
  7589. if (i == 10)
  7590. break;
  7591. Item* item = itr->second;
  7592. packet->setArrayDataByName("id", i, i);
  7593. packet->setArrayDataByName("not_yet_claimed", 1, i);
  7594. packet->setArrayDataByName("num_remaining", 5, i);
  7595. packet->setArrayDataByName("one_per_character", 1, i);
  7596. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  7597. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7598. packet->setArrayDataByName("text", "If you ever see this text, let Scatman know, thanks! :)", i);
  7599. packet->setArrayDataByName("category", "Scott's Shit", i);
  7600. packet->setArrayDataByName("icon", item->details.icon, i);
  7601. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7602. i++;
  7603. }
  7604. packet->setDataByName("unknown3", 1);
  7605. QueuePacket(packet->serialize());
  7606. safe_delete(packet);
  7607. }
  7608. }
  7609. void Client::ShowGuildSearchWindow() {
  7610. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  7611. if (packet) {
  7612. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  7613. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  7614. packet->setArrayLengthByName("num_guilds", guilds->size());
  7615. int32 i = 0;
  7616. while (itr.Next()) {
  7617. Guild* guild = itr.second;
  7618. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  7619. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  7620. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  7621. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  7622. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  7623. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  7624. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  7625. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  7626. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  7627. packet->setArrayDataByName("unknown7", 0x02, i);
  7628. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  7629. i++;
  7630. }
  7631. QueuePacket(packet->serialize());
  7632. safe_delete(packet);
  7633. }
  7634. }
  7635. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  7636. PacketStruct* packet;
  7637. vector<int8>* slot_data;
  7638. vector<int8>::iterator itr;
  7639. int32 slots = 0;
  7640. assert(item);
  7641. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  7642. return;
  7643. }
  7644. slot_data = &item->slot_data;
  7645. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  7646. if (version >= 1188)
  7647. slots = *itr;
  7648. else
  7649. slots += (int8)pow(2.0, *itr);
  7650. }
  7651. packet->setDataByName("slot", slots);
  7652. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  7653. if (slots == 2) {
  7654. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  7655. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  7656. }
  7657. else {
  7658. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  7659. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  7660. }
  7661. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  7662. if (slots == 4) {
  7663. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  7664. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  7665. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  7666. }
  7667. else if (slots == 7) {
  7668. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  7669. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  7670. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  7671. }
  7672. else {
  7673. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  7674. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  7675. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  7676. }
  7677. packet->setDataByName("icon", item->details.icon);
  7678. packet->setDataByName("item_id", item->details.item_id);
  7679. packet->setDataByName("item_crc", crc);
  7680. packet->setDataByName("unknown2", 0xFFFFFFFF);
  7681. packet->setDataByName("unknown4", 0xFFFFFFFF);
  7682. packet->setDataByName("unknown5", 0xFF, 9);
  7683. packet->setDataByName("unknown5", 0xFF, 10);
  7684. QueuePacket(packet->serialize());
  7685. safe_delete(packet);
  7686. }
  7687. void Client::SendCollectionList() {
  7688. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  7689. map<int32, Collection*>::iterator itr;
  7690. vector<struct CollectionItem*>* collection_items;
  7691. Collection* collection;
  7692. struct CollectionItem* collection_item;
  7693. PacketStruct* packet = 0;
  7694. int16 i = 0, j;
  7695. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  7696. return;
  7697. packet->setArrayLengthByName("num_collections", collections->size());
  7698. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7699. collection = itr->second;
  7700. collection_items = collection->GetCollectionItems();
  7701. packet->setArrayDataByName("unknown", 1, i);
  7702. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  7703. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  7704. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  7705. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  7706. packet->setArrayDataByName("level", collection->GetLevel(), i);
  7707. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  7708. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  7709. for (j = 0; j < collection_items->size(); j++) {
  7710. collection_item = collection_items->at(j);
  7711. Item* item = master_item_list.GetItem(collection_item->item);
  7712. if (item) {
  7713. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  7714. if (version < 955)
  7715. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  7716. else
  7717. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  7718. }
  7719. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  7720. }
  7721. i++;
  7722. }
  7723. packet->setDataByName("new_collection_flag", 1);
  7724. QueuePacket(packet->serialize());
  7725. safe_delete(packet);
  7726. }
  7727. bool Client::SendCollectionsForItem(Item* item) {
  7728. map<int32, Collection*> collections_to_send;
  7729. map<int32, Collection*>* collections;
  7730. map<int32, Collection*>::iterator itr;
  7731. vector<struct CollectionItem*>* collection_items;
  7732. Collection* collection;
  7733. struct CollectionItem* collection_item;
  7734. PacketStruct* packet;
  7735. int16 i;
  7736. assert(item);
  7737. /* get any collections required by this item that the player already has */
  7738. collections = player->GetCollectionList()->GetCollections();
  7739. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7740. collection = itr->second;
  7741. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  7742. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  7743. collections_to_send[collection->GetID()] = collection;
  7744. }
  7745. }
  7746. /* get any collections required by this item that the player does not have and send it to the client */
  7747. collections = master_collection_list.GetCollections();
  7748. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7749. collection = itr->second;
  7750. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  7751. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  7752. return false;
  7753. }
  7754. packet->setArrayLengthByName("num_collections", 1);
  7755. packet->setArrayDataByName("unknown", 1, 0);
  7756. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  7757. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  7758. packet->setArrayDataByName("completed", 0, 0);
  7759. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  7760. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  7761. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  7762. packet->setArrayDataByName("unknown3", 0x28, 0);
  7763. collection_items = collection->GetCollectionItems();
  7764. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  7765. for (i = 0; i < collection_items->size(); i++) {
  7766. collection_item = collection_items->at(i);
  7767. Item* item2 = master_item_list.GetItem(collection_item->item);
  7768. if (item2) {
  7769. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  7770. if (version < 955)
  7771. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  7772. else
  7773. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  7774. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  7775. }
  7776. }
  7777. packet->setDataByName("new_collection_flag", 0);
  7778. QueuePacket(packet->serialize());
  7779. safe_delete(packet);
  7780. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  7781. collections_to_send[collection->GetID()] = collection;
  7782. }
  7783. }
  7784. /* send the client a list of collections that should be filtered for this item */
  7785. if (collections_to_send.size() > 0) {
  7786. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  7787. return false;
  7788. }
  7789. i = 0;
  7790. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  7791. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  7792. collection = itr->second;
  7793. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  7794. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  7795. i++;
  7796. }
  7797. packet->setDataByName("item_icon", item->details.icon);
  7798. packet->setDataByName("item_name", item->name.c_str());
  7799. packet->setDataByName("item_id", item->details.item_id);
  7800. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  7801. QueuePacket(packet->serialize());
  7802. safe_delete(packet);
  7803. }
  7804. return collections_to_send.size() > 0;
  7805. }
  7806. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  7807. Collection* collection;
  7808. struct CollectionItem* collection_item;
  7809. PacketStruct* packet;
  7810. char tmp[200] = { 0 };
  7811. assert(item);
  7812. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  7813. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  7814. /* get the item struct that represents the item for this collection */
  7815. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  7816. SendCollectionList();
  7817. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  7818. return;
  7819. }
  7820. /* sanity check */
  7821. if (collection_item->found) {
  7822. SendCollectionList();
  7823. 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());
  7824. return;
  7825. }
  7826. }
  7827. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  7828. collection = new Collection(collection);
  7829. /* get the item struct that represents the item for this collection */
  7830. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  7831. SendCollectionList();
  7832. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  7833. safe_delete(collection);
  7834. return;
  7835. }
  7836. /* add the new collection to the player's collection list */
  7837. if (!player->GetCollectionList()->AddCollection(collection)) {
  7838. SendCollectionList();
  7839. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  7840. safe_delete(collection);
  7841. return;
  7842. }
  7843. }
  7844. else {
  7845. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  7846. return;
  7847. }
  7848. collection_item->found = 1;
  7849. collection->SetSaveNeeded(true);
  7850. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  7851. SendCollectionList();
  7852. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  7853. return;
  7854. }
  7855. packet->setDataByName("collection_id", collection_id);
  7856. packet->setDataByName("collection_item_num", collection_item->index);
  7857. packet->setDataByName("add", 1);
  7858. QueuePacket(packet->serialize());
  7859. Item* item2 = master_item_list.GetItem(collection_item->item);
  7860. if (item2) {
  7861. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  7862. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  7863. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  7864. }
  7865. safe_delete(packet);
  7866. RemoveItem(item, 1);
  7867. SendCollectionList();
  7868. }
  7869. void Client::DisplayCollectionComplete(Collection* collection) {
  7870. vector<struct CollectionRewardItem*>* reward_items;
  7871. vector<struct CollectionRewardItem*>* selectable_reward_items;
  7872. struct CollectionRewardItem* reward_item;
  7873. PacketStruct* packet;
  7874. int32 i;
  7875. assert(collection);
  7876. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  7877. return;
  7878. }
  7879. reward_items = collection->GetRewardItems();
  7880. selectable_reward_items = collection->GetSelectableRewardItems();
  7881. packet->setDataByName("title", "Quest Reward!");
  7882. packet->setDataByName("name", collection->GetName());
  7883. packet->setDataByName("description", collection->GetCategory());
  7884. packet->setDataByName("level", collection->GetLevel());
  7885. packet->setDataByName("max_coin", collection->GetRewardCoin());
  7886. packet->setDataByName("min_coin", collection->GetRewardCoin());
  7887. //packet->setDataByName("status_points", quest->GetStatusPoints());
  7888. packet->setArrayLengthByName("num_rewards", reward_items->size());
  7889. for (i = 0; i < reward_items->size(); i++) {
  7890. reward_item = reward_items->at(i);
  7891. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  7892. if (version < 860)
  7893. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
  7894. else if (version < 1193)
  7895. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  7896. else
  7897. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  7898. }
  7899. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  7900. for (i = 0; i < selectable_reward_items->size(); i++) {
  7901. reward_item = selectable_reward_items->at(i);
  7902. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  7903. if (version < 860)
  7904. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
  7905. else if (version < 1193)
  7906. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  7907. else
  7908. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  7909. }
  7910. QueuePacket(packet->serialize());
  7911. safe_delete(packet);
  7912. }
  7913. void Client::HandInCollections() {
  7914. map<int32, Collection*>* collections;
  7915. map<int32, Collection*>::iterator itr;
  7916. Collection* collection;
  7917. /* only show 1 collection reward dialog at a time */
  7918. if (player->GetPendingCollectionReward()) {
  7919. return;
  7920. }
  7921. collections = player->GetCollectionList()->GetCollections();
  7922. /* 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
  7923. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  7924. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7925. collection = itr->second;
  7926. if (collection->GetIsReadyToTurnIn()) {
  7927. player->SetPendingCollectionReward(collection);
  7928. DisplayCollectionComplete(collection);
  7929. return;
  7930. }
  7931. }
  7932. }
  7933. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  7934. vector<struct CollectionRewardItem*>* reward_items;
  7935. vector<struct CollectionRewardItem*>::iterator itr;
  7936. struct CollectionRewardItem* reward_item;
  7937. int16 num_slots_needed;
  7938. int16 num_slots;
  7939. assert(collection);
  7940. reward_items = collection->GetRewardItems();
  7941. num_slots_needed = (int16)reward_items->size();
  7942. if (selectable_item_id > 0)
  7943. num_slots_needed++;
  7944. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  7945. if (num_slots < num_slots_needed) {
  7946. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  7947. HandInCollections();
  7948. return;
  7949. }
  7950. /* add manditory items */
  7951. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  7952. reward_item = *itr;
  7953. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  7954. }
  7955. /* find and add the selectable item if there's one */
  7956. if (selectable_item_id > 0) {
  7957. reward_items = collection->GetSelectableRewardItems();
  7958. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  7959. reward_item = *itr;
  7960. if (reward_item->item->details.item_id == selectable_item_id) {
  7961. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  7962. break;
  7963. }
  7964. }
  7965. }
  7966. if (collection->GetRewardXP() > 0) {
  7967. player->AddXP((int32)collection->GetRewardXP());
  7968. SimpleMessage(CHANNEL_COLOR_YELLOW, "You gain experience!");
  7969. }
  7970. if (collection->GetRewardCoin() > 0) {
  7971. player->AddCoins(collection->GetRewardCoin());
  7972. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  7973. }
  7974. collection->SetCompleted(true);
  7975. //update achievements for completeing collection here
  7976. collection->SetSaveNeeded(true);
  7977. SendCollectionList();
  7978. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  7979. player->SetPendingCollectionReward(0);
  7980. HandInCollections();
  7981. }
  7982. void Client::SendRecipeList() {
  7983. PacketStruct* packet = 0;
  7984. if (GetRecipeListSent()) {
  7985. return;
  7986. }
  7987. if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  7988. return;
  7989. }
  7990. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  7991. map<int32, Recipe*>::iterator itr;
  7992. Recipe* recipe;
  7993. int16 i = 0;
  7994. packet->setArrayLengthByName("num_recipes", recipes->size());
  7995. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  7996. recipe = itr->second;
  7997. packet->setArrayDataByName("id", recipe->GetID(), i);
  7998. packet->setArrayDataByName("tier", recipe->GetTier(), i);
  7999. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  8000. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  8001. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  8002. packet->setArrayDataByName("skill", recipe->GetSkill(), i);
  8003. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  8004. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  8005. packet->setArrayDataByName("unknown2", recipe->GetUnknown2(), i);
  8006. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  8007. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  8008. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  8009. i++;
  8010. }
  8011. //packet->PrintPacket();
  8012. //DumpPacket(packet->serialize());
  8013. QueuePacket(packet->serialize());
  8014. safe_delete(packet);
  8015. SetRecipeListSent(true);
  8016. }
  8017. void Client::ShowRecipeBook() {
  8018. PacketStruct* packet = 0;
  8019. Spawn* target = 0;
  8020. if (!(target = player->GetTarget())) {
  8021. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  8022. return;
  8023. }
  8024. if (!target->IsObject()) {
  8025. return;
  8026. }
  8027. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  8028. return;
  8029. }
  8030. packet->setDataByName("device", target->GetName());
  8031. packet->setDataByName("unknown1", 1);
  8032. if (((Object*)target)->GetDeviceID() > 0) {
  8033. int32 deviceID = (int32)pow(2.0, (double)((Object*)target)->GetDeviceID());
  8034. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  8035. packet->setDataByName("unknown2", 8);
  8036. packet->setDataByName("unknown3", deviceID);
  8037. }
  8038. //packet->PrintPacket();
  8039. QueuePacket(packet->serialize());
  8040. safe_delete(packet);
  8041. }
  8042. void Client::SendTitleUpdate() {
  8043. list<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  8044. list<Title*>::iterator itr;
  8045. Title* title;
  8046. int16 i = 0;
  8047. sint16 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  8048. sint16 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  8049. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  8050. if (packet) {
  8051. packet->setArrayLengthByName("num_titles", titles->size());
  8052. for (itr = titles->begin(); itr != titles->end(); itr++) {
  8053. title = *itr;
  8054. packet->setArrayDataByName("title", title->GetName(), i);
  8055. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  8056. i++;
  8057. }
  8058. packet->setDataByName("current_prefix", prefix_index);
  8059. packet->setDataByName("current_suffix", suffix_index);
  8060. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  8061. #if EQDEBUG >= 9
  8062. packet->PrintPacket();
  8063. #endif
  8064. QueuePacket(packet->serialize());
  8065. safe_delete(packet);
  8066. SendUpdateTitles(prefix_index, suffix_index);
  8067. }
  8068. }
  8069. void Client::SendUpdateTitles(sint16 prefix, sint16 suffix) {
  8070. Title* suffix_title = 0;
  8071. Title* prefix_title = 0;
  8072. if (suffix != -1) {
  8073. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  8074. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  8075. }
  8076. else
  8077. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  8078. if (prefix != -1) {
  8079. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  8080. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  8081. }
  8082. else
  8083. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  8084. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  8085. }
  8086. void Client::SendLanguagesUpdate(int32 id) {
  8087. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  8088. list<Language*>::iterator itr;
  8089. Language* language;
  8090. int32 i = 0;
  8091. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  8092. if (packet) {
  8093. packet->setArrayLengthByName("num_languages", languages->size());
  8094. for (itr = languages->begin(); itr != languages->end(); itr++) {
  8095. language = *itr;
  8096. packet->setArrayDataByName("language_id", language->GetID(), i);
  8097. i++;
  8098. }
  8099. packet->setDataByName("current_language", id);
  8100. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  8101. #if EQDEBUG >= 9
  8102. packet->PrintPacket();
  8103. #endif
  8104. QueuePacket(packet->serialize());
  8105. safe_delete(packet);
  8106. }
  8107. }
  8108. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  8109. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  8110. if (packet) {
  8111. if (pet_name)
  8112. packet->setDataByName("pet_name", pet_name);
  8113. if (player->GetInfoStruct()->pet_behavior & 1)
  8114. packet->setDataByName("protect_master", 1);
  8115. if (player->GetInfoStruct()->pet_behavior & 2)
  8116. packet->setDataByName("protect_self", 1);
  8117. if (player->GetInfoStruct()->pet_movement == 2)
  8118. packet->setDataByName("stay_follow_toggle", 1);
  8119. packet->setDataByName("pet_type", type);
  8120. QueuePacket(packet->serialize());
  8121. }
  8122. safe_delete(packet);
  8123. }
  8124. bool Client::IsCrafting() {
  8125. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  8126. }
  8127. void Client::SendBiography() {
  8128. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  8129. if (packet) {
  8130. if (strlen(player->GetInfoStruct()->biography) > 0)
  8131. packet->setDataByName("biography", player->GetInfoStruct()->biography);
  8132. QueuePacket(packet->serialize());
  8133. }
  8134. safe_delete(packet);
  8135. }
  8136. PendingResurrection* Client::GetCurrentRez() {
  8137. return &current_rez;
  8138. }
  8139. Mutex* Client::GetResurrectMutex() {
  8140. return &m_resurrect;
  8141. }
  8142. void Client::SendResurrectionWindow() {
  8143. Spawn* caster = current_rez.caster;
  8144. if (!caster || !player)
  8145. return;
  8146. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  8147. if (!packet)
  8148. return;
  8149. char* tmp = new char[512];
  8150. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  8151. packet->setMediumStringByName("text", tmp);
  8152. packet->setMediumStringByName("accept_text", "Yes");
  8153. packet->setMediumStringByName("cancel_text", "No");
  8154. sprintf(tmp, "accept_resurrection %u", player->GetID());
  8155. packet->setMediumStringByName("accept_command", tmp);
  8156. sprintf(tmp, "decline_resurrection %u", player->GetID());
  8157. packet->setMediumStringByName("cancel_command", tmp);
  8158. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  8159. QueuePacket(packet->serialize());
  8160. safe_delete(packet);
  8161. safe_delete_array(tmp);
  8162. }
  8163. void Client::AcceptResurrection() {
  8164. Spawn* caster = current_rez.caster;
  8165. if (!player || !caster)
  8166. return;
  8167. if (player->Alive())
  8168. return;
  8169. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  8170. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  8171. SendResurrectionWindow();
  8172. return;
  8173. }
  8174. player->GetZone()->ResurrectSpawn(player, this);
  8175. current_rez.should_delete = true;
  8176. }
  8177. void Client::SetPendingLastName(string last_name) {
  8178. pending_last_name = new string;
  8179. pending_last_name->assign(last_name);
  8180. }
  8181. string* Client::GetPendingLastName() {
  8182. return pending_last_name;
  8183. }
  8184. void Client::RemovePendingLastName() {
  8185. safe_delete(pending_last_name);
  8186. }
  8187. void Client::SendLastNameConfirmation() {
  8188. if (!pending_last_name)
  8189. return;
  8190. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  8191. if (packet) {
  8192. char* text = new char[128];
  8193. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  8194. packet->setDataByName("text", text);
  8195. packet->setDataByName("accept_text", "Yes");
  8196. packet->setDataByName("accept_command", "confirmedlastname");
  8197. packet->setDataByName("cancel_text", "No");
  8198. packet->setDataByName("max_length", 50);
  8199. packet->setDataByName("unknown4", 1);
  8200. packet->setDataByName("unknown5", 1);
  8201. QueuePacket(packet->serialize());
  8202. safe_delete(packet);
  8203. safe_delete_array(text);
  8204. }
  8205. }
  8206. void Client::AddQuestTimer(int32 quest_id) {
  8207. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  8208. quest_timers.push_back(quest_id);
  8209. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  8210. }
  8211. void Client::RemoveQuestTimer(int32 quest_id) {
  8212. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  8213. vector<int32>::iterator itr;
  8214. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  8215. if ((*itr) == quest_id) {
  8216. quest_timers.erase(itr);
  8217. break;
  8218. }
  8219. }
  8220. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  8221. }
  8222. void Client::SavePlayerImages() {
  8223. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  8224. // Save the paperdoll image if the server allows it
  8225. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  8226. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  8227. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  8228. // Save the head shot if the server allows it
  8229. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  8230. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  8231. // Send the head shot to the login server
  8232. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  8233. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  8234. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  8235. memset(packet->pBuffer, 0, size);
  8236. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  8237. pic->account_id = GetAccountID();
  8238. pic->char_id = GetCharacterID();
  8239. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  8240. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  8241. loginserver.SendPacket(packet);
  8242. safe_delete(packet);
  8243. }
  8244. }
  8245. safe_delete_array(incoming_paperdoll.image_bytes);
  8246. incoming_paperdoll.current_size_bytes = 0;
  8247. }
  8248. void Client::EndAutoMount() {
  8249. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  8250. if (packet) {
  8251. packet->setDataByName("parameter1", 128);
  8252. packet->setDataByName("parameter2", 64);
  8253. packet->setDataByName("value", 1);
  8254. QueuePacket(packet->serialize());
  8255. safe_delete(packet);
  8256. }
  8257. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  8258. if (packet) {
  8259. packet->setDataByName("parameter3", 4);
  8260. packet->setDataByName("parameter5", 2);
  8261. packet->setDataByName("value", 0);
  8262. QueuePacket(packet->serialize());
  8263. safe_delete(packet);
  8264. }
  8265. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  8266. if (packet) {
  8267. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  8268. QueuePacket(packet->serialize());
  8269. safe_delete(packet);
  8270. }
  8271. on_auto_mount = false;
  8272. player->SetMount(((Player*)player)->GetTempMount());
  8273. EQ2_Color mount_color = player->GetTempMountColor();
  8274. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  8275. player->SetMountColor(&mount_color);
  8276. player->SetMountSaddleColor(&saddle_color);
  8277. player->SetTempMount(0);
  8278. }
  8279. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  8280. const char* spawn_script = spawn->GetSpawnScript();
  8281. bool should_use_spawn = true;
  8282. if (spawn_script) {
  8283. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  8284. if (state) {
  8285. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  8286. if (state_mutex)
  8287. state_mutex->writelock(__FUNCTION__, __LINE__);
  8288. lua_getglobal(state, "can_use_command");
  8289. if (lua_isfunction(state, -1)) {
  8290. lua_interface->SetSpawnValue(state, spawn);
  8291. lua_interface->SetSpawnValue(state, GetPlayer());
  8292. lua_interface->SetStringValue(state, command ? command : "");
  8293. if (lua_pcall(state, 3, 1, 0) == 0) {
  8294. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  8295. }
  8296. }
  8297. lua_interface->ResetFunctionStack(state);
  8298. if (state_mutex)
  8299. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  8300. }
  8301. }
  8302. return should_use_spawn;
  8303. }
  8304. bool Client::IsCurrentTransmuteID(int32 req_id) {
  8305. return req_id == transmuteID;
  8306. }
  8307. void Client::SetTransmuteID(int32 trans_id) {
  8308. transmuteID = trans_id;
  8309. }
  8310. int32 Client::GetTransmuteID() {
  8311. return transmuteID;
  8312. }
  8313. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  8314. {
  8315. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  8316. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  8317. if (zar)
  8318. {
  8319. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  8320. if (database.IsActiveQuery(charID))
  8321. {
  8322. delayedLogin = true;
  8323. delayedAccountID = account_id;
  8324. delayedAccessKey = access_code;
  8325. delayTimer.Start(500);
  8326. 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);
  8327. return true;
  8328. }
  8329. delayedLogin = false;
  8330. delayTimer.Disable();
  8331. firstlogin = zar->isFirstLogin();
  8332. 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);
  8333. if (database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  8334. GetPlayer()->vis_changed = false;
  8335. GetPlayer()->info_changed = false;
  8336. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  8337. if (pvp_allowed)
  8338. this->GetPlayer()->SetAttackable(1);
  8339. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  8340. Client* client = zone_list.GetClientByCharName(player->GetName());
  8341. if (client) {
  8342. if (client->getConnection())
  8343. client->getConnection()->SendDisconnect(true);
  8344. if (client->GetCurrentZone() && !client->IsZoning()) {
  8345. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  8346. if (client->GetVersion() == version) {
  8347. Player* current_player = GetPlayer();
  8348. SetPlayer(client->GetPlayer());
  8349. client->SetPlayer(current_player);
  8350. client->GetPlayer()->SetPendingDeletion(true);
  8351. GetPlayer()->SetPendingDeletion(false);
  8352. GetPlayer()->ResetSavedSpawns();
  8353. GetPlayer()->SetReturningFromLD(true);
  8354. }
  8355. ZoneServer* tmpZone = client->GetCurrentZone();
  8356. tmpZone->RemoveClientImmediately(client);
  8357. }
  8358. }
  8359. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  8360. if (!GetCurrentZone()) {
  8361. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  8362. ClientPacketFunctions::SendLoginDenied(this);
  8363. }
  8364. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  8365. getConnection()->SetClientVersion(version);
  8366. GetCurrentZone()->SetSpawnStructs(this);
  8367. connected_to_zone = true;
  8368. client_list.Remove(this); //remove from master client list
  8369. new_client_login = true;
  8370. GetCurrentZone()->AddClient(this); //add to zones client list
  8371. zone_list.AddClientToMap(player->GetName(), this);
  8372. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  8373. if (zone_script && lua_interface)
  8374. lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
  8375. }
  8376. else {
  8377. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  8378. ClientPacketFunctions::SendLoginDenied(this);
  8379. return false;
  8380. }
  8381. }
  8382. else {
  8383. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  8384. ClientPacketFunctions::SendLoginDenied(this);
  8385. }
  8386. zone_auth.RemoveAuth(zar);
  8387. }
  8388. else
  8389. {
  8390. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  8391. Disconnect();
  8392. }
  8393. return true;
  8394. }
  8395. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  8396. if (!IsReadyForUpdates())
  8397. return;
  8398. map<int32, SpawnData> info_changes;
  8399. map<int32, SpawnData> pos_changes;
  8400. map<int32, SpawnData> vis_changes;
  8401. map<int32, SpawnData> empty_changes;
  8402. int32 info_size = 0;
  8403. int32 pos_size = 0;
  8404. int32 vis_size = 0;
  8405. int count = 0;
  8406. for (const auto& spawn : spawns) {
  8407. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  8408. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()) || GetPlayer()->NeedsSpawnResent(spawn) || GetPlayer()->GetDistance(spawn) >= SEND_SPAWN_DISTANCE)
  8409. continue;
  8410. if (spawn->vis_changed)
  8411. {
  8412. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  8413. if (vis_change) {
  8414. SpawnData data;
  8415. data.spawn = spawn;
  8416. data.data = vis_change;
  8417. data.size = spawn->vis_packet_size;
  8418. map<int32, SpawnData> tmp_vis_changes;
  8419. tmp_vis_changes[index] = data;
  8420. map<int32, SpawnData> tmp_info_changes;
  8421. map<int32, SpawnData> tmp_pos_changes;
  8422. int32 tmp_info_size = 0;
  8423. int32 tmp_pos_size = 0;
  8424. if (spawn->info_changed) {
  8425. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  8426. if (info_change) {
  8427. SpawnData data;
  8428. data.spawn = spawn;
  8429. data.data = info_change;
  8430. data.size = spawn->info_packet_size;
  8431. tmp_info_size = data.size;
  8432. tmp_info_changes[index] = data;
  8433. }
  8434. }
  8435. if (spawn->position_changed) {
  8436. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  8437. if (pos_change) {
  8438. SpawnData data;
  8439. data.spawn = spawn;
  8440. data.data = pos_change;
  8441. data.size = spawn->pos_packet_size;
  8442. tmp_pos_size = data.size;
  8443. tmp_pos_changes[index] = data;
  8444. }
  8445. }
  8446. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  8447. for (auto& kv : tmp_info_changes) {
  8448. safe_delete_array(kv.second.data);
  8449. }
  8450. for (auto& kv : tmp_pos_changes) {
  8451. safe_delete_array(kv.second.data);
  8452. }
  8453. for (auto& kv : tmp_vis_changes) {
  8454. safe_delete_array(kv.second.data);
  8455. }
  8456. continue;
  8457. }
  8458. }
  8459. if (spawn->info_changed) {
  8460. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  8461. if (info_change) {
  8462. SpawnData data;
  8463. data.spawn = spawn;
  8464. data.data = info_change;
  8465. data.size = spawn->info_packet_size;
  8466. info_size += spawn->info_packet_size;
  8467. info_changes[index] = data;
  8468. }
  8469. count++;
  8470. }
  8471. if (spawn->position_changed) {
  8472. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  8473. if (pos_change) {
  8474. SpawnData data;
  8475. data.spawn = spawn;
  8476. data.data = pos_change;
  8477. data.size = spawn->pos_packet_size;
  8478. pos_size += spawn->pos_packet_size;
  8479. pos_changes[index] = data;
  8480. }
  8481. count++;
  8482. }
  8483. if (spawn->vis_changed) {
  8484. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  8485. if (vis_change) {
  8486. SpawnData data;
  8487. data.spawn = spawn;
  8488. data.data = vis_change;
  8489. data.size = spawn->vis_packet_size;
  8490. vis_size += spawn->vis_packet_size;
  8491. vis_changes[index] = data;
  8492. }
  8493. count++;
  8494. }
  8495. }
  8496. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  8497. return;
  8498. }
  8499. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  8500. for (auto& kv : info_changes) {
  8501. safe_delete_array(kv.second.data);
  8502. }
  8503. for (auto& kv : pos_changes) {
  8504. safe_delete_array(kv.second.data);
  8505. }
  8506. for (auto& kv : vis_changes) {
  8507. safe_delete_array(kv.second.data);
  8508. }
  8509. }
  8510. 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)
  8511. {
  8512. static const int8 oversized = 255;
  8513. int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  8514. int32 size = info_size + pos_size + vis_size + 8;
  8515. if (version > 283) //version 283 and below uses an overload for size, not always 4 bytes
  8516. size += 3;
  8517. size += CheckOverLoadSize(info_size);
  8518. size += CheckOverLoadSize(pos_size);
  8519. size += CheckOverLoadSize(vis_size);
  8520. if (version <= 283 && size >= 255) {//1 byte to 3 for overloaded val
  8521. size += 2;
  8522. }
  8523. uchar* tmp = new uchar[size];
  8524. uchar* ptr = tmp;
  8525. memset(tmp, 0, size);
  8526. if (version <= 283) {
  8527. if (size >= 255) {
  8528. size -= 3;
  8529. memcpy(ptr, &oversized, sizeof(int8));
  8530. ptr += sizeof(int8);
  8531. memcpy(ptr, &size, sizeof(int16));
  8532. ptr += sizeof(int16);
  8533. size += 3;
  8534. }
  8535. else {
  8536. size -= 1;
  8537. memcpy(ptr, &size, sizeof(int8));
  8538. ptr += sizeof(int8);
  8539. size += 1;
  8540. }
  8541. }
  8542. else {
  8543. size -= 4;
  8544. memcpy(ptr, &size, sizeof(int32));
  8545. ptr += sizeof(int32);
  8546. size += 4;
  8547. }
  8548. memcpy(ptr, &oversized, sizeof(int8));
  8549. ptr += sizeof(int8);
  8550. memcpy(ptr, &opcode_val, sizeof(int16));
  8551. ptr += sizeof(int16);
  8552. int32 current_time = Timer::GetCurrentTime2();
  8553. memcpy(ptr, &current_time, sizeof(int32));
  8554. ptr += sizeof(int32);
  8555. ptr += DoOverLoad(info_size, ptr);
  8556. for (const auto& kv : info_changes) {
  8557. auto info = kv.second;
  8558. memcpy(ptr, info.data, info.size);
  8559. ptr += info.size;
  8560. }
  8561. ptr += DoOverLoad(pos_size, ptr);
  8562. for (const auto& kv : pos_changes) {
  8563. auto pos = kv.second;
  8564. memcpy(ptr, pos.data, pos.size);
  8565. ptr += pos.size;
  8566. }
  8567. ptr += DoOverLoad(vis_size, ptr);
  8568. for (const auto& kv : vis_changes) {
  8569. auto vis = kv.second;
  8570. memcpy(ptr, vis.data, vis.size);
  8571. ptr += vis.size;
  8572. }
  8573. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  8574. if (packet) {
  8575. /*char blah[64];
  8576. snprintf(blah, 64, "Sending %i", current_time);
  8577. SimpleMessage(4, blah);*/
  8578. QueuePacket(packet);
  8579. }
  8580. delete[] tmp;
  8581. }
  8582. void Client::SendHailCommand(Spawn* spawn)
  8583. {
  8584. // hardcoded 'hail' entity commands
  8585. switch (spawn->secondary_command_list_id)
  8586. {
  8587. case 9:
  8588. case 1262:
  8589. case 1265:
  8590. case 1267:
  8591. {
  8592. EQ2_16BitString* command = new EQ2_16BitString();
  8593. command->data = "";
  8594. command->size = 0;
  8595. commands.Process(COMMAND_HAIL, command, this, spawn);
  8596. safe_delete(command);
  8597. break;
  8598. }
  8599. }
  8600. }
  8601. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  8602. {
  8603. if (GetPlayer()->WasSentSpawn(spawn->GetID()) && GetPlayer()->WasSpawnRemoved(spawn) == false) {
  8604. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  8605. if (packet) {
  8606. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  8607. packet->setMediumStringByName("command_name", command);
  8608. packet->setDataByName("distance", distance);
  8609. QueuePacket(packet->serialize());
  8610. safe_delete(packet);
  8611. }
  8612. }
  8613. }
  8614. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  8615. {
  8616. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  8617. return false;
  8618. if (command == "house_spawn_examine")
  8619. {
  8620. uint32 itemID = spawn->GetPickupItemID();
  8621. if (itemID)
  8622. {
  8623. Item* item = master_item_list.GetItem(itemID);
  8624. if (item)
  8625. {
  8626. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  8627. //DumpPacket(app);
  8628. QueuePacket(app);
  8629. }
  8630. }
  8631. return true;
  8632. }
  8633. return false;
  8634. }
  8635. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  8636. {
  8637. if (GetTempPlacementSpawn())
  8638. {
  8639. Spawn* tmp = GetTempPlacementSpawn();
  8640. int32 spawn_group_id = database.GetNextSpawnLocation();
  8641. tmp->SetSpawnLocationID(spawn_group_id);
  8642. float newHeading = place_object->getType_float_ByName("heading") + 180;
  8643. int32 spawnDBID = 0;
  8644. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  8645. {
  8646. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  8647. tmp->SetDatabaseID(spawnDBID);
  8648. }
  8649. else
  8650. {
  8651. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  8652. if (spawnDBID)
  8653. {
  8654. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  8655. tmp->SetDatabaseID(spawnDBID);
  8656. }
  8657. }
  8658. tmp->SetX(place_object->getType_float_ByName("x"));
  8659. tmp->SetY(place_object->getType_float_ByName("y"));
  8660. tmp->SetZ(place_object->getType_float_ByName("z"));
  8661. tmp->SetHeading(newHeading);
  8662. tmp->SetSpawnOrigX(tmp->GetX());
  8663. tmp->SetSpawnOrigY(tmp->GetY());
  8664. tmp->SetSpawnOrigZ(tmp->GetZ());
  8665. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  8666. database.SaveSpawnInfo(tmp);
  8667. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  8668. if (!spawnDBID)
  8669. {
  8670. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  8671. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), (Object*)tmp);
  8672. }
  8673. return true;
  8674. }
  8675. return false;
  8676. }
  8677. bool Client::PopulateHouseSpawnFinalize()
  8678. {
  8679. if (GetTempPlacementSpawn())
  8680. {
  8681. Spawn* tmp = GetTempPlacementSpawn();
  8682. GetCurrentZone()->AddSpawn(tmp);
  8683. GetCurrentZone()->SendSpawnChanges(tmp, this);
  8684. SetTempPlacementSpawn(nullptr);
  8685. int32 uniqueID = GetPlacementUniqueItemID();
  8686. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  8687. tmp->SetPickupItemID(uniqueItem->details.item_id);
  8688. tmp->SetPickupUniqueItemID(uniqueID);
  8689. if (uniqueItem)
  8690. {
  8691. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  8692. {
  8693. Query query;
  8694. 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);
  8695. }
  8696. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  8697. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  8698. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  8699. SetPlacementUniqueItemID(0);
  8700. }
  8701. return true;
  8702. }
  8703. return false;
  8704. }
  8705. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  8706. {
  8707. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  8708. packet->setDataByName("placement_mode", placementMode);
  8709. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  8710. packet->setDataByName("model_type", spawn->GetModelType());
  8711. packet->setDataByName("unknown", 1); //size
  8712. packet->setDataByName("unknown2", 1); //size 2
  8713. packet->setDataByName("unknown2", .5, 1); //size 3
  8714. packet->setDataByName("unknown2", 3, 2);
  8715. packet->setDataByName("unknown2", unknown2_3, 3);
  8716. packet->setDataByName("max_distance", 500);
  8717. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  8718. QueuePacket(packet->serialize());
  8719. safe_delete(packet);
  8720. }
  8721. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  8722. {
  8723. SetPendingFlightPath(path_id);
  8724. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  8725. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  8726. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  8727. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  8728. if (packet) {
  8729. QueuePacket(packet->serialize());
  8730. safe_delete(packet);
  8731. }
  8732. if (mount_id)
  8733. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  8734. }
  8735. void Client::SendShowBook(Spawn* sender, string title, int8 num_pages, ...)
  8736. {
  8737. if (!sender)
  8738. {
  8739. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  8740. return;
  8741. }
  8742. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  8743. if (!packet) {
  8744. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  8745. return;
  8746. }
  8747. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  8748. packet->setDataByName("book_title", title.c_str());
  8749. packet->setDataByName("book_type", "simple");
  8750. packet->setDataByName("unknown2", 1);
  8751. if (GetVersion() > 546)
  8752. packet->setDataByName("unknown5", 1, 4);
  8753. packet->setArrayLengthByName("num_pages", num_pages);
  8754. va_list args;
  8755. va_start(args, num_pages);
  8756. std::string endString("");
  8757. for (int8 p = 0; p < num_pages; p++)
  8758. {
  8759. std::string page = va_arg(args, string);
  8760. switch (GetVersion())
  8761. {
  8762. // release client
  8763. case 283:
  8764. {
  8765. endString.append(page);
  8766. break;
  8767. }
  8768. // DoF trial
  8769. case 546:
  8770. {
  8771. if (p == 0)
  8772. packet->setDataByName("cover_page", page.c_str());
  8773. else
  8774. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  8775. break;
  8776. }
  8777. // all other clients
  8778. default:
  8779. {
  8780. packet->setArrayDataByName("page_text", page.c_str(), p);
  8781. break;
  8782. }
  8783. }
  8784. }
  8785. if (GetVersion() == 283)
  8786. {
  8787. packet->setDataByName("page_text", endString.c_str());
  8788. }
  8789. va_end(args);
  8790. QueuePacket(packet->serialize());
  8791. safe_delete(packet);
  8792. }
  8793. void Client::SendShowBook(Spawn* sender, string title, vector<Item::BookPage*> pages)
  8794. {
  8795. if (!sender)
  8796. {
  8797. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  8798. return;
  8799. }
  8800. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  8801. if (!packet) {
  8802. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  8803. return;
  8804. }
  8805. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  8806. packet->setDataByName("book_title", title.c_str());
  8807. packet->setDataByName("book_type", "simple");
  8808. packet->setDataByName("unknown2", 1);
  8809. if (GetVersion() > 546)
  8810. packet->setDataByName("unknown5", 1, 4);
  8811. packet->setArrayLengthByName("num_pages", pages.size());
  8812. std::string endString("");
  8813. for (int8 p = 0; p < pages.size(); p++)
  8814. {
  8815. Item::BookPage* page = pages[p];
  8816. std::string pageText = string(page->page_text.data);
  8817. switch (GetVersion())
  8818. {
  8819. // release client
  8820. case 283:
  8821. {
  8822. endString.append(pageText);
  8823. break;
  8824. }
  8825. // DoF trial
  8826. case 546:
  8827. {
  8828. if (p == 0)
  8829. packet->setDataByName("cover_page", pageText.c_str());
  8830. else
  8831. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  8832. break;
  8833. }
  8834. // all other clients
  8835. default:
  8836. {
  8837. int8 valign = int8(page->valign);
  8838. int8 halign = int8(page->halign);
  8839. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  8840. packet->setArrayDataByName("page_text_valign", valign, p);
  8841. packet->setArrayDataByName("page_text_halign", halign, p);
  8842. break;
  8843. }
  8844. }
  8845. }
  8846. if (GetVersion() == 283)
  8847. {
  8848. packet->setDataByName("page_text", endString.c_str());
  8849. }
  8850. QueuePacket(packet->serialize());
  8851. safe_delete(packet);
  8852. }
  8853. void Client::TempRemoveGroup()
  8854. {
  8855. if (this->GetPlayer()->GetGroupMemberInfo())
  8856. {
  8857. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8858. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  8859. group->MGroupMembers.writelock();
  8860. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  8861. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  8862. group->MGroupMembers.releasewritelock();
  8863. group->RemoveClientReference(this);
  8864. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8865. }
  8866. }