9
3

client.cpp 318 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063
  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 "Items/Items.h"
  71. #include "Skills.h"
  72. #include "LuaInterface.h"
  73. #include "Quests.h"
  74. #include "Collections/Collections.h"
  75. #include "Achievements/Achievements.h"
  76. #include "Traits/Traits.h"
  77. #include "Recipes/Recipe.h"
  78. #include "Tradeskills/Tradeskills.h"
  79. #include "AltAdvancement/AltAdvancement.h"
  80. #include "Bots/Bot.h"
  81. extern WorldDatabase database;
  82. extern const char* ZONE_NAME;
  83. extern LoginServer loginserver;
  84. extern sint32 numclients;
  85. extern NetConnection net;
  86. extern Commands commands;
  87. extern ClientList client_list;
  88. extern ZoneList zone_list;
  89. extern ZoneAuth zone_auth;
  90. extern MasterItemList master_item_list;
  91. extern MasterSkillList master_skill_list;
  92. extern MasterSpellList master_spell_list;
  93. extern MasterTraitList master_trait_list;
  94. extern MasterQuestList master_quest_list;
  95. extern MasterFactionList master_faction_list;
  96. extern MasterRecipeList master_recipe_list;
  97. extern volatile bool RunLoops;
  98. extern ConfigReader configReader;
  99. extern LuaInterface* lua_interface;
  100. extern World world;
  101. extern Variables variables;
  102. extern Classes classes;
  103. extern Races races;
  104. extern GuildList guild_list;
  105. extern MasterCollectionList master_collection_list;
  106. extern MasterAchievementList master_achievement_list;
  107. extern RuleManager rule_manager;
  108. extern IRC irc;
  109. extern Chat chat;
  110. extern MasterAAList master_aa_list;
  111. extern MasterAAList master_tree_nodes;
  112. extern ChestTrapList chest_trap_list;
  113. using namespace std;
  114. Client::Client(EQStream* ieqs) : pos_update(125), quest_pos_timer(2000), lua_debug_timer(30000), delayTimer(500), transmuteID(0) {
  115. eqs = ieqs;
  116. ip = eqs->GetrIP();
  117. port = ntohs(eqs->GetrPort());
  118. merchant_transaction = nullptr;
  119. SetMailTransaction(nullptr);
  120. timestamp_flag = 0;
  121. current_quest_id = 0;
  122. last_update_time = 0;
  123. quest_updates = false;
  124. //autobootup_timeout = new Timer(10000);
  125. //autobootup_timeout->Disable();
  126. CLE_keepalive_timer = new Timer(15000);
  127. connect = new Timer(1000);
  128. connect->Disable();
  129. zoneID = 0;
  130. account_name[0] = 0;
  131. character_id = 0;
  132. account_id = 0;
  133. pwaitingforbootup = 0;
  134. current_zone = 0;
  135. connected_to_zone = false;
  136. connected = false;
  137. camp_timer = 0;
  138. disconnect_timer = 0;
  139. client_zoning = false;
  140. player_pos_changed = false;
  141. ++numclients;
  142. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  143. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  144. remove_from_list = false;
  145. new_client_login = false;
  146. UpdateWindowTitle(0);
  147. num_active_failures = 0;
  148. player = new Player();
  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. }
  185. Client::~Client() {
  186. if (current_zone && player) {
  187. if (player->GetGroupMemberInfo() && (player->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0)
  188. world.GetGroupManager()->RemoveGroupMember(player->GetGroupMemberInfo()->group_id, player);
  189. world.GetGroupManager()->ClearPendingInvite(player);
  190. }
  191. if (lua_interface)
  192. lua_interface->RemoveDebugClients(this);
  193. if (player)
  194. zone_list.RemoveClientFromMap(player->GetName(), this);
  195. //let the stream factory know were done with this stream
  196. if (eqs) {
  197. eqs->Close();
  198. try {
  199. eqs->ReleaseFromUse();
  200. }
  201. catch (...) {}
  202. }
  203. eqs = NULL;
  204. //safe_delete(autobootup_timeout);
  205. safe_delete(disconnect_timer);
  206. safe_delete(camp_timer);
  207. safe_delete(CLE_keepalive_timer);
  208. safe_delete(connect);
  209. --numclients;
  210. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  211. if (player && !player->GetPendingDeletion())
  212. safe_delete(player);
  213. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  214. safe_delete(search_items);
  215. safe_delete(current_rez.expire_timer);
  216. safe_delete(pending_last_name);
  217. safe_delete_array(incoming_paperdoll.image_bytes);
  218. if (GetTempPlacementSpawn())
  219. {
  220. Spawn* tmp = GetTempPlacementSpawn();
  221. delete tmp;
  222. SetTempPlacementSpawn(nullptr);
  223. }
  224. UpdateWindowTitle(0);
  225. }
  226. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  227. if (eqs) {
  228. if (!eqs->CheckActive()) {
  229. client_list.Remove(this);
  230. eqs = 0;
  231. }
  232. }
  233. if (app && eqs && version > 0)
  234. eqs->EQ2QueuePacket(app, attemptedCombine);
  235. else {
  236. safe_delete(app);
  237. }
  238. }
  239. void Client::PopulateSkillMap() {
  240. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  241. if (app)
  242. QueuePacket(app);
  243. else {
  244. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  245. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  246. }
  247. }
  248. void Client::SendLoginInfo() {
  249. if (firstlogin) {
  250. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  251. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  252. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  253. PopulateSkillMap();
  254. // 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!
  255. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  256. }
  257. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  258. database.ToggleCharacterOnline(this, 1);
  259. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  260. int32 count = database.LoadCharacterSkills(GetCharacterID(), player);
  261. if (count == 0) {
  262. LogWrite(CCLIENT__WARNING, 0, "Client", "No character skills found!");
  263. database.UpdateStartingSkills(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  264. database.LoadCharacterSkills(GetCharacterID(), player);
  265. }
  266. count = database.LoadCharacterTitles(GetCharacterID(), player);
  267. if (count == 0) {
  268. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  269. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  270. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  271. }
  272. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  273. if (count == 0)
  274. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  275. count = database.LoadCharacterSpells(GetCharacterID(), player);
  276. if (count == 0) {
  277. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character spells found!");
  278. database.UpdateStartingSpells(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  279. database.LoadCharacterSpells(GetCharacterID(), player);
  280. }
  281. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  282. if (count == 0)
  283. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  284. ClientPacketFunctions::SendLoginAccepted(this);
  285. ClientPacketFunctions::SendAbilities ( this );
  286. ClientPacketFunctions::SendCommandNamePacket(this);
  287. ClientPacketFunctions::SendQuickBarInit(this);
  288. // we only need to send the MOTD if it is the first time the person is logging in.
  289. if (firstlogin) {
  290. ClientPacketFunctions::SendMOTD(this);
  291. ClientPacketFunctions::SendCharacterMacros(this);
  292. zone_list.CheckFriendList(this);
  293. }
  294. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  295. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  296. {
  297. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  298. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  299. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  300. }
  301. database.LoadPlayerFactions(this);
  302. database.LoadCharacterQuests(this);
  303. database.LoadPlayerMail(this);
  304. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  305. SendQuestJournal(true);
  306. if (version > 546) // right version? possibly not!
  307. master_aa_list.DisplayAA(this, 0, 3);
  308. if (version > 283)
  309. SendCollectionList();
  310. SendBiography();
  311. map<int32, Quest*>::iterator itr;
  312. Quest* quest = 0;
  313. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  314. quest = itr->second;
  315. if (quest->IsTracked()) {
  316. quest->SetTracked(false);
  317. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  318. quest->SetTracked(true);
  319. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  320. }
  321. }
  322. // SendAchievementsList();
  323. /*Guild* guild = player->GetGuild();
  324. if (guild) {
  325. guild->UpdateGuildMemberInfo(GetPlayer());
  326. if (firstlogin)
  327. guild->SendGuildMOTD(this);
  328. guild->SendGuildUpdate(this);
  329. guild->SendGuildMember(GetPlayer(), firstlogin);
  330. guild->SendGuildEventList(this);
  331. guild->SendGuildBankEventList(this);
  332. guild->SendAllGuildEvents(this);
  333. guild->SendGuildMemberList(this);
  334. }*/
  335. if (version > 283) {
  336. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  337. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  338. if (outapp) {
  339. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  340. //DumpPacket(outapp);
  341. QueuePacket(outapp);
  342. }
  343. }
  344. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  345. ClientPacketFunctions::SendCommandList(this);
  346. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  347. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  348. ClientPacketFunctions::SendInstanceList(this);
  349. SendZoneInfo();
  350. /*Spell* spell = 0;
  351. vector<QuickBarItem*>::iterator itr;
  352. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  353. if((*itr)->type == 1){
  354. spell = master_spell_list.GetSpell((*itr)->id);
  355. if(spell)
  356. QueuePacket(spell->serialize(this, false, 0x20));
  357. }
  358. }*/
  359. }
  360. void Client::SendPlayerDeathWindow()
  361. {
  362. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  363. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  364. vector<RevivePoint*>::iterator itr;
  365. if (results && results->size() > 0)
  366. {
  367. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  368. if (packet)
  369. {
  370. packet->setArrayLengthByName("location_count", results->size());
  371. RevivePoint* point = 0;
  372. int32 i = 0;
  373. for (itr = results->begin(); itr != results->end(); itr++, i++)
  374. {
  375. point = *itr;
  376. if (point)
  377. {
  378. packet->setArrayDataByName("location_id", point->id, i);
  379. //zone_name = database.GetZoneName(point->zone_id);
  380. string zone_name = database.GetZoneDescription(point->zone_id);
  381. if (zone_name.length() > 0)
  382. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  383. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  384. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  385. }
  386. if (point->id == 0xFFFFFFFF)//tmp location
  387. safe_delete(point);
  388. }
  389. // done with the revive points so lets free up the pointer
  390. safe_delete(results);
  391. #if EQDEBUG >= 3
  392. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  393. packet->PrintPacket();
  394. #endif
  395. EQ2Packet* outapp = packet->serialize();
  396. QueuePacket(outapp);
  397. safe_delete(packet);
  398. }
  399. }
  400. }
  401. void Client::DisplayDeadWindow()
  402. {
  403. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  404. player->SetHP(0);
  405. player->SetPower(0);
  406. GetCurrentZone()->TriggerCharSheetTimer();
  407. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  408. if (packet)
  409. {
  410. packet->setDataByName("parameter1", 8);
  411. packet->setDataByName("value", 1);
  412. QueuePacket(packet->serialize());
  413. packet->setDataByName("parameter1", 16);
  414. QueuePacket(packet->serialize());
  415. safe_delete(packet);
  416. }
  417. packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  418. if (packet)
  419. {
  420. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  421. QueuePacket(packet->serialize());
  422. safe_delete(packet);
  423. }
  424. SendPlayerDeathWindow();
  425. }
  426. void Client::HandlePlayerRevive(int32 point_id)
  427. {
  428. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  429. if (packet)
  430. {
  431. packet->setDataByName("parameter1", 8);
  432. QueuePacket(packet->serialize());
  433. packet->setDataByName("parameter1", 16);
  434. QueuePacket(packet->serialize());
  435. safe_delete(packet);
  436. }
  437. SimpleMessage(CHANNEL_COLOR_REVIVE, "You regain consciousness!");
  438. packet = configReader.getStruct("WS_Resurrected", GetVersion());
  439. if (packet)
  440. {
  441. QueuePacket(packet->serialize());
  442. safe_delete(packet);
  443. }
  444. float x, y, z, heading;
  445. RevivePoint* revive_point = 0;
  446. if (point_id != 0xFFFFFFFF)
  447. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  448. string zone_desc;
  449. const char* location_name = "Unknown";
  450. //revive at zone safe coords
  451. if (!revive_point)
  452. {
  453. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  454. x = GetCurrentZone()->GetSafeX();
  455. y = GetCurrentZone()->GetSafeY();
  456. z = GetCurrentZone()->GetSafeZ();
  457. heading = GetCurrentZone()->GetSafeHeading();
  458. zone_desc = GetCurrentZone()->GetZoneDescription();
  459. location_name = "Zone Safe Point";
  460. Zone(GetCurrentZone()->GetZoneName(), false);
  461. }
  462. else
  463. {
  464. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  465. x = revive_point->x;
  466. y = revive_point->y;
  467. z = revive_point->z;
  468. heading = revive_point->heading;
  469. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  470. location_name = revive_point->location_name.c_str();
  471. Zone(GetCurrentZone()->GetZoneName(), false);
  472. }
  473. player->SetResurrecting(true);
  474. player->SetX(x);
  475. player->SetY(y);
  476. player->SetZ(z);
  477. player->SetHeading(heading);
  478. player->SetHP(player->GetTotalHP());
  479. player->SetPower(player->GetTotalPower());
  480. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  481. zone_desc.c_str(),
  482. player->GetX(),
  483. player->GetY(),
  484. player->GetZ(),
  485. player->GetHeading(),
  486. player->GetHP(),
  487. player->GetPower(),
  488. location_name);
  489. //player->ClearEverything();
  490. Save();
  491. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  492. {
  493. string* zone_name = database.GetZoneName(revive_point->zone_id);
  494. if (!zone_name || zone_name->length() == 0)
  495. {
  496. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  497. x = GetCurrentZone()->GetSafeX();
  498. y = GetCurrentZone()->GetSafeY();
  499. z = GetCurrentZone()->GetSafeZ();
  500. heading = GetCurrentZone()->GetSafeHeading();
  501. location_name = "Zone Safe Point";
  502. }
  503. else
  504. {
  505. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  506. location_name = revive_point->location_name.c_str();
  507. player->ClearEverything();
  508. Zone(zone_name->c_str(), false);
  509. }
  510. safe_delete(zone_name);
  511. }
  512. zone_desc = GetCurrentZone()->GetZoneDescription();
  513. Message(CHANNEL_COLOR_REVIVE, "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. ClientPacketFunctions::SendUpdateSpellBook(this);
  584. }
  585. else {
  586. player->SetResurrecting(false);
  587. }
  588. ClientPacketFunctions::SendLoginCommandMessages(this);
  589. GetCurrentZone()->AddSpawn(player);
  590. //SendCollectionList();
  591. Guild* guild = player->GetGuild();
  592. if (guild)
  593. guild->GuildMemberLogin(this, firstlogin);
  594. app = player->item_list.serialize(GetPlayer(), GetVersion());
  595. if (app) {
  596. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  597. //DumpPacket(app);
  598. QueuePacket(app);
  599. }
  600. app = player->GetEquipmentList()->serialize(GetVersion());
  601. if (app) {
  602. QueuePacket(app);
  603. }
  604. vector<Item*>* items = player->item_list.GetItemsFromBagID(-3); // bank items
  605. if (items && items->size() > 0) {
  606. for (int32 i = 0; i < items->size(); i++) {
  607. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  608. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  609. //DumpPacket(outapp);
  610. QueuePacket(outapp);
  611. }
  612. }
  613. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  614. QueuePacket(app);
  615. safe_delete(items);
  616. items = player->item_list.GetItemsFromBagID(-4); //shared bank items
  617. if (items && items->size() > 0) {
  618. for (int32 i = 0; i < items->size(); i++)
  619. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  620. }
  621. safe_delete(items);
  622. if (version > 283) {
  623. SendTitleUpdate();
  624. }
  625. GetPlayer()->ChangePrimaryWeapon();
  626. GetPlayer()->ChangeSecondaryWeapon();
  627. GetPlayer()->ChangeRangedWeapon();
  628. database.LoadBuyBacks(this);
  629. if (version > 546)
  630. master_aa_list.DisplayAA(this, 0, 0);
  631. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  632. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  633. string zone_motd_send = "Zone MOTD: " + zone_motd;
  634. SimpleMessage(CHANNEL_COLOR_WHITE, zone_motd_send.c_str());
  635. }
  636. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  637. if (zone_script && lua_interface)
  638. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  639. this->client_zoning = false;
  640. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  641. GetCurrentZone()->AddDamagedSpawn(player);
  642. if (firstlogin && rule_manager.GetGlobalRule(R_World, IRCGlobalEnabled)->GetBool())
  643. Message(CHANNEL_BROADCAST, "This server has a global IRC channel, join the world channel %s to use", rule_manager.GetGlobalRule(R_World, IRCChan)->GetString());
  644. if (firstlogin)
  645. firstlogin = false;
  646. player->ClearProcs();
  647. items = player->GetEquippedItemList();
  648. if (items && items->size() > 0) {
  649. for (int32 i = 0; i < items->size(); i++) {
  650. Item* item = items->at(i);
  651. if (item && item->GetItemScript() && lua_interface)
  652. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  653. }
  654. }
  655. //Allow this player to change their last name if they meet the level requirement
  656. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  657. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  658. safe_delete(items);
  659. if (!player->Alive())
  660. DisplayDeadWindow();
  661. ClientPacketFunctions::SendLocalizedTextMessage(this);
  662. if (GetCurrentZone()->GetInstanceID())
  663. {
  664. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  665. if (ph) {
  666. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  667. string name = string(GetPlayer()->GetName());
  668. if (name.compare(ph->player_name) == 0)
  669. SetHasOwnerOrEditAccess(true);
  670. }
  671. }
  672. if (version > 546)
  673. ClientPacketFunctions::SendHousingList(this);
  674. }
  675. void Client::SendZoneSpawns() {
  676. //Allows us to place spawns almost anywhere
  677. if (version > 283) {
  678. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  679. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  680. QueuePacket(app);
  681. }
  682. ClientPacketFunctions::SendSkillSlotMappings(this);
  683. ClientPacketFunctions::SendGameWorldTime(this);
  684. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  685. }
  686. void Client::SendCharPOVGhost() {
  687. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  688. if (set_pov) {
  689. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  690. EQ2Packet* app_pov = set_pov->serialize();
  691. QueuePacket(app_pov);
  692. safe_delete(set_pov);
  693. }
  694. }
  695. void Client::SendZoneInfo() {
  696. ZoneServer* zone = GetCurrentZone();
  697. if (zone) {
  698. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  699. QueuePacket(packet);
  700. if (version > 283) {
  701. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  702. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  703. #if EQDEBUG >= 9
  704. fog_packet->PrintPacket();
  705. #endif
  706. if (fog_packet) {
  707. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  708. QueuePacket(fog_packet->serialize());
  709. safe_delete(fog_packet);
  710. }
  711. zone->SendFlightPathsPackets(this);
  712. }
  713. }
  714. /*
  715. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  716. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  717. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  718. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  719. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  720. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  721. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0xFF,0x00};
  751. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  752. QueuePacket(appA);
  753. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  754. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x01,0x00,0x00
  757. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  758. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  759. QueuePacket(appB);
  760. */
  761. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  762. SendFriendList();
  763. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  764. SendIgnoreList();
  765. }
  766. void Client::SendDefaultGroupOptions() {
  767. /*
  768. 0 - loot method
  769. 1 - loot items rarity
  770. 2 - Auto split coin
  771. 4 - default yell method
  772. 6 - group autolock
  773. 7 - solo autolock
  774. */
  775. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  776. if (default_options) {
  777. default_options->setDataByName("loot_method", 1);
  778. default_options->setDataByName("loot_items_rarity", 1);
  779. default_options->setDataByName("auto_split_coin", 1);
  780. default_options->setDataByName("default_yell_method", 1);
  781. EQ2Packet* app7 = default_options->serialize();
  782. QueuePacket(app7);
  783. safe_delete(default_options);
  784. }
  785. }
  786. bool Client::HandlePacket(EQApplicationPacket* app) {
  787. bool ret = true;
  788. #if EQDEBUG >= 9
  789. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  790. DumpPacket(app, true);
  791. #endif
  792. EmuOpcode opcode = app->GetOpcode();
  793. #if EQDEBUG >= 9
  794. const char* name = app->GetOpcodeName();
  795. if (name)
  796. cout << name;
  797. else
  798. cout << "Unknown";
  799. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  800. DumpPacket(app);
  801. #endif
  802. //if (opcode != OP_UpdatePositionMsg) {
  803. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  804. //}
  805. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  806. {
  807. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  808. }
  809. switch (opcode) {
  810. case _maxEmuOpcode:
  811. break;
  812. case OP_LoginByNumRequestMsg: {
  813. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  814. PacketStruct* request;
  815. request = configReader.getStruct("LoginByNumRequest", 1);
  816. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  817. // test the original location of Version for clients older than 1212
  818. version = request->getType_int16_ByName("version");
  819. if (version == 0 || version >= 1212 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  820. // must be new client data version method, re-fetch the packet
  821. safe_delete(request);
  822. request = configReader.getStruct("LoginByNumRequest", 1212);
  823. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  824. // Xinux suggests using an INT16 here. Our first new version = 57000
  825. version = request->getType_int16_ByName("version");
  826. }
  827. else {
  828. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  829. break;
  830. }
  831. }
  832. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  833. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  834. ClientPacketFunctions::SendLoginDenied(this);
  835. return false;
  836. }
  837. int32 account_id = request->getType_int32_ByName("account_id");
  838. int32 access_code = request->getType_int32_ByName("access_code");
  839. if (!HandleNewLogin(account_id, access_code))
  840. return false;
  841. }
  842. safe_delete(request);
  843. break;
  844. }
  845. case OP_SysClient: {
  846. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient", opcode, opcode);
  847. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  848. SetReadyForUpdates();
  849. break;
  850. }
  851. case OP_MapRequest: {
  852. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  853. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  854. if (packet && app->size > 2 && GetCurrentZone()) {
  855. packet->LoadPacketData(app->pBuffer, app->size);
  856. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  857. if (fog_packet) {
  858. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  859. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  860. fog_packet->setDataByName("unknown1", 1);
  861. fog_packet->setDataByName("unknown3", 1);
  862. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  863. //fog_packet->PrintPacket();
  864. QueuePacket(fog_packet->serialize());
  865. safe_delete(fog_packet);
  866. }
  867. safe_delete(packet);
  868. }
  869. break;
  870. }
  871. case OP_RequestCampMsg: {
  872. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  873. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  874. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  875. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  876. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  877. request->getType_int8_ByName("quit"),
  878. request->getType_int8_ByName("camp_desktop"),
  879. request->getType_int16_ByName("camp_char_select"),
  880. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  881. //DumpPacket(app->pBuffer, app->size);
  882. //request->PrintPacket();
  883. if (!camp_timer) {
  884. int16 camp_time = 20; // default if rule cannot be found
  885. if (GetAdminStatus() >= 100)
  886. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  887. else
  888. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  889. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  890. if (response) {
  891. bool disconnect = false;
  892. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  893. // Command: /camp desktop
  894. // Command: /quit
  895. response->setDataByName("camp_desktop", 1);
  896. disconnect = true;
  897. }
  898. else {
  899. // Command: /camp
  900. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  901. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  902. response->setDataByName("seconds", camp_time);
  903. }
  904. camp_timer = new Timer(camp_time * 1000);
  905. camp_timer->Enable();
  906. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  907. // /camp {char_name}
  908. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  909. }
  910. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  911. // /camp (go back to char selection screen)
  912. response->setDataByName("char_name", " ");
  913. response->setDataByName("camp_char_select", 1);
  914. }
  915. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  916. response->getType_int8_ByName("seconds"),
  917. response->getType_int8_ByName("camp_desktop"),
  918. response->getType_int8_ByName("camp_char_select"),
  919. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  920. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  921. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  922. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  923. //response->PrintPacket();
  924. QueuePacket(response->serialize());
  925. safe_delete(response);
  926. if (disconnect)
  927. Disconnect();
  928. }
  929. }
  930. }
  931. safe_delete(request);
  932. break;
  933. }
  934. case OP_StoodMsg: {
  935. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  936. if (camp_timer)
  937. {
  938. // JA: clear camping flag
  939. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  940. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  941. safe_delete(camp_timer);
  942. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  943. QueuePacket(outapp);
  944. }
  945. player->SetTempVisualState(0);
  946. break;
  947. }
  948. case OP_StandMsg: {
  949. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  950. if (camp_timer)
  951. {
  952. // JA: clear camping flag
  953. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  954. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  955. safe_delete(camp_timer);
  956. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  957. QueuePacket(outapp);
  958. }
  959. player->SetTempVisualState(539);
  960. break;
  961. }
  962. case OP_SitMsg: {
  963. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  964. player->SetTempVisualState(538);
  965. break;
  966. }
  967. case OP_SatMsg: {
  968. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  969. player->SetTempVisualState(540);
  970. break;
  971. }
  972. case OP_QuestJournalOpenMsg:
  973. case OP_QuestJournalInspectMsg: {
  974. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  975. if (app->size < sizeof(int32))
  976. break;
  977. int32 quest_id = 0;
  978. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  979. Quest* quest = GetActiveQuest(quest_id);
  980. if (quest)
  981. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  982. else {
  983. quest = player->GetCompletedQuest(quest_id);
  984. if (quest)
  985. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, 0, 1, true));
  986. }
  987. break;
  988. }
  989. case OP_QuestJournalSetVisibleMsg: {
  990. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  991. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  992. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  993. int32 quest_id = packet->getType_int32_ByName("quest_id");
  994. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  995. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  996. if (player_quests) {
  997. if (player_quests->count(quest_id) > 0)
  998. player_quests->at(quest_id)->SetHidden(hidden);
  999. else
  1000. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1001. }
  1002. else
  1003. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1004. safe_delete(packet);
  1005. }
  1006. break;
  1007. }
  1008. case OP_MacroUpdateMsg: {
  1009. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1010. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1011. if (macro_update && macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1012. vector<string>* update = new vector<string>;
  1013. int8 number = macro_update->getType_int8_ByName("number");
  1014. int16 icon = macro_update->getType_int16_ByName("icon");
  1015. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1016. int8 count = macro_update->getType_int8_ByName("macro_count");
  1017. if (GetVersion() <= 283) {
  1018. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1019. }
  1020. else {
  1021. for (int8 i = 0; i < count; i++) {
  1022. char tmp_command[15] = { 0 };
  1023. sprintf(tmp_command, "command_%i", i);
  1024. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1025. }
  1026. }
  1027. if (name.length() == 0)
  1028. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1029. else
  1030. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1031. safe_delete(update);
  1032. safe_delete(macro_update);
  1033. }
  1034. break;
  1035. }
  1036. case OP_DialogSelectMsg: {
  1037. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1038. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1039. if (packet) {
  1040. packet->LoadPacketData(app->pBuffer, app->size);
  1041. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1042. int32 response_index = packet->getType_int32_ByName("response");
  1043. if (GetCurrentZone()) {
  1044. Spawn* spawn = conversation_spawns[conversation_id];
  1045. Item* item = conversation_items[conversation_id];
  1046. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  1047. if (spawn)
  1048. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation_map[conversation_id][response_index].c_str());
  1049. else if (item && lua_interface && item->GetItemScript())
  1050. lua_interface->RunItemScript(item->GetItemScript(), conversation_map[conversation_id][response_index].c_str(), item, player);
  1051. }
  1052. else
  1053. CloseDialog(conversation_id);
  1054. }
  1055. safe_delete(packet);
  1056. }
  1057. break;
  1058. }
  1059. case OP_CancelMoveObjectModeMsg: {
  1060. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1061. if (GetTempPlacementSpawn())
  1062. {
  1063. Spawn* tmp = GetTempPlacementSpawn();
  1064. GetCurrentZone()->RemoveSpawn(false, tmp);
  1065. delete tmp;
  1066. SetTempPlacementSpawn(nullptr);
  1067. SetPlacementUniqueItemID(0);
  1068. break; // break out early if we are tied to a temp spawn
  1069. }
  1070. // if we are moving some other object? other use-cases not covered
  1071. break;
  1072. }
  1073. case OP_PositionMoveableObject: {
  1074. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1075. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1076. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1077. Spawn* spawn = 0;
  1078. if (GetTempPlacementSpawn())
  1079. spawn = GetTempPlacementSpawn();
  1080. else
  1081. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1082. if (!spawn) {
  1083. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1084. break;
  1085. }
  1086. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1087. {
  1088. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1089. break;
  1090. }
  1091. // handles instantiation logic + adding to zone of a new house object
  1092. PopulateHouseSpawn(place_object);
  1093. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1094. char query[256];
  1095. switch (GetSpawnPlacementMode())
  1096. {
  1097. case ServerSpawnPlacementMode::OPEN_HEADING:
  1098. {
  1099. if (spawn && spawn->IsWidget())
  1100. {
  1101. Widget* widget = (Widget*)spawn;
  1102. widget->SetOpenHeading(newHeading);
  1103. widget->SetIncludeHeading(true);
  1104. spawn->position_changed = true;
  1105. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1106. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1107. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1108. }
  1109. else
  1110. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1111. break;
  1112. }
  1113. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1114. {
  1115. if (spawn && spawn->IsWidget())
  1116. {
  1117. Widget* widget = (Widget*)spawn;
  1118. widget->SetClosedHeading(newHeading);
  1119. widget->SetIncludeHeading(true);
  1120. spawn->position_changed = true;
  1121. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1122. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1123. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1124. if (spawn->GetSpawnLocationID())
  1125. {
  1126. Query query;
  1127. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1128. }
  1129. }
  1130. else
  1131. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1132. break;
  1133. }
  1134. default:
  1135. {
  1136. spawn->SetX(place_object->getType_float_ByName("x"));
  1137. spawn->SetY(place_object->getType_float_ByName("y"));
  1138. spawn->SetZ(place_object->getType_float_ByName("z"));
  1139. spawn->SetHeading(newHeading);
  1140. spawn->SetSpawnOrigX(spawn->GetX());
  1141. spawn->SetSpawnOrigY(spawn->GetY());
  1142. spawn->SetSpawnOrigZ(spawn->GetZ());
  1143. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1144. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1145. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1146. else if (spawn->GetSpawnLocationID() > 0)
  1147. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1148. }
  1149. }
  1150. PopulateHouseSpawnFinalize();
  1151. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1152. safe_delete(place_object);
  1153. }
  1154. break;
  1155. }
  1156. case OP_CampAbortedMsg: {
  1157. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1158. if (camp_timer)
  1159. {
  1160. // JA: clear camping flag
  1161. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1162. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1163. safe_delete(camp_timer);
  1164. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1165. QueuePacket(outapp);
  1166. }
  1167. break;
  1168. }
  1169. case OP_DoneLoadingUIResourcesMsg: {
  1170. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1171. QueuePacket(app);
  1172. break;
  1173. }
  1174. case OP_DoneLoadingZoneResourcesMsg: {
  1175. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1176. SendZoneSpawns();
  1177. break;
  1178. }
  1179. case OP_DefaultGroupOptionsRequestMsg: {
  1180. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1181. SendDefaultGroupOptions();
  1182. break;
  1183. }
  1184. case OP_DoneLoadingEntityResourcesMsg: {
  1185. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1186. if (!IsReadyForSpawns())
  1187. SetReadyForSpawns(true);
  1188. SendCharInfo();
  1189. pos_update.Start();
  1190. quest_pos_timer.Start();
  1191. break;
  1192. }
  1193. case OP_LootItemsRequestMsg: {
  1194. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1195. HandleLoot(app);
  1196. break;
  1197. }
  1198. case OP_KnowledgeWindowSlotMappingMsg: {
  1199. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1200. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1201. if (packet) {
  1202. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1203. int num_updates = packet->getType_int16_ByName("spell_count");
  1204. int32 spell_id = 0;
  1205. int16 slot_id = 0;
  1206. char tmp_spell_id[15];
  1207. char tmp_slot[15];
  1208. for (int i = 0; i < num_updates; i++) {
  1209. memset(tmp_spell_id, 0, 15);
  1210. memset(tmp_slot, 0, 15);
  1211. sprintf(tmp_spell_id, "spell_id_%i", i);
  1212. sprintf(tmp_slot, "slot_id_%i", i);
  1213. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1214. if (spell_id > 0) {
  1215. slot_id = packet->getType_int16_ByName(tmp_slot);
  1216. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1217. if (spell && spell->slot != slot_id) {
  1218. spell->slot = slot_id;
  1219. spell->save_needed = true;
  1220. }
  1221. }
  1222. }
  1223. }
  1224. safe_delete(packet);
  1225. }
  1226. //SendKnowledgeWindowSlot();
  1227. break;
  1228. }
  1229. case OP_ReadyToZoneMsg: {
  1230. if (!IsReadyForSpawns())
  1231. {
  1232. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1233. }
  1234. else
  1235. {
  1236. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1237. if (client_zoning)
  1238. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1239. else
  1240. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1241. Disconnect();
  1242. }
  1243. break;
  1244. }
  1245. case OP_ClientFellMsg: {
  1246. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1247. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1248. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1249. float height = request->getType_float_ByName("height");
  1250. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1251. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1252. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1253. break;
  1254. }*/
  1255. float safe_height = 13.0f;
  1256. Skill* skill = GetPlayer()->GetSkillByName("Safe Fall", true);
  1257. if (skill)
  1258. safe_height += (skill->current_val + 1) / 5;
  1259. if (height > safe_height) {
  1260. int16 damage = (int16)ceil((height - safe_height) * 125);
  1261. if (height >= 80)
  1262. damage = 30000;
  1263. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1264. if (damage > 0) {
  1265. GetPlayer()->TakeDamage(damage);
  1266. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1267. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1268. if (!GetPlayer()->GetInvulnerable())
  1269. GetPlayer()->SetCharSheetChanged(true);
  1270. 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);
  1271. if (GetPlayer()->GetHP() == 0) {
  1272. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1273. }
  1274. }
  1275. }
  1276. safe_delete(request);
  1277. }
  1278. break;
  1279. }
  1280. case OP_MapFogDataUpdateMsg: {
  1281. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1282. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1283. break;
  1284. }
  1285. case OP_SelectZoneTeleporterDestinatio: {
  1286. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1287. ProcessTeleportLocation(app);
  1288. break;
  1289. }
  1290. case OP_SendLatestRequestMsg: {
  1291. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1292. uchar blah25[] = { 0x01 };
  1293. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1294. QueuePacket(app25);
  1295. break;
  1296. }
  1297. case OP_ShowCreateFromRecipeUIMsg: {
  1298. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1299. break;
  1300. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1301. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1302. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1303. QueuePacket(app);
  1304. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1305. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1306. QueuePacket(app);
  1307. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1308. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1309. ,0xff,0xff,0xff};
  1310. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1311. QueuePacket(app);
  1312. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1313. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1314. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1315. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1316. QueuePacket(app);
  1317. uchar blah5[] ={0x00,0x00};
  1318. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1319. QueuePacket(app);
  1320. break;*/
  1321. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1322. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1323. //QueuePacket(app);
  1324. }
  1325. case OP_BeginItemCreationMsg: {
  1326. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1327. //DumpPacket(app->pBuffer, app->size);
  1328. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1329. if (packet) {
  1330. packet->LoadPacketData(app->pBuffer, app->size);
  1331. int32 item = 0;
  1332. vector<int32> items;
  1333. char tmp_item_id[20];
  1334. item = packet->getType_int32_ByName("primary_component_id");
  1335. if (item > 0)
  1336. items.push_back(item);
  1337. item = 0;
  1338. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1339. for (int8 i = 0; i < build_components; i++) {
  1340. memset(tmp_item_id, 0, 20);
  1341. sprintf(tmp_item_id, "component_id_%i", i);
  1342. item = packet->getType_int32_ByName(tmp_item_id);
  1343. if (item > 0)
  1344. items.push_back(item);
  1345. item = 0;
  1346. }
  1347. item = packet->getType_int32_ByName("fuel_id");
  1348. if (item > 0)
  1349. items.push_back(item);
  1350. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1351. safe_delete(packet);
  1352. }
  1353. break;
  1354. }
  1355. case OP_StopItemCreationMsg: {
  1356. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1357. //DumpPacket(app->pBuffer, app->size);
  1358. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1359. break;
  1360. }
  1361. case OP_SignalMsg: {
  1362. PacketStruct* packet = configReader.getStruct("WS_Signal", GetVersion());
  1363. if (packet) {
  1364. packet->LoadPacketData(app->pBuffer, app->size);
  1365. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1366. if (str.size > 0) {
  1367. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1368. SetReadyForUpdates();
  1369. GetPlayer()->SendSpawnChanges(true);
  1370. }
  1371. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1372. if (zone_script && lua_interface)
  1373. {
  1374. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1375. }
  1376. }
  1377. }
  1378. break;
  1379. }
  1380. case OP_EntityVerbsRequestMsg: {
  1381. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1382. HandleVerbRequest(app);
  1383. break;
  1384. }
  1385. case OP_EntityVerbsVerbMsg: {
  1386. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1387. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1388. if (packet) {
  1389. packet->LoadPacketData(app->pBuffer, app->size);
  1390. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1391. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1392. Spawn* spawn = player->GetTarget();
  1393. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1394. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1395. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1396. {
  1397. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1398. if (spawn->IsGroundSpawn())
  1399. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1400. else if (spawn->IsObject())
  1401. ((Object*)spawn)->HandleUse(this, command);
  1402. else if (spawn->IsWidget())
  1403. ((Widget*)spawn)->HandleUse(this, command);
  1404. else if (spawn->IsSign())
  1405. ((Sign*)spawn)->HandleUse(this, command);
  1406. }
  1407. }
  1408. }
  1409. else {
  1410. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1411. if (command.size > 0) {
  1412. string command_name = command.data;
  1413. if (command_name.find(" ") < 0xFFFFFFFF)
  1414. command_name = command_name.substr(0, command_name.find(" "));
  1415. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1416. if (handler != 0xFFFFFFFF) {
  1417. if (command.data == command_name) {
  1418. command.data = "";
  1419. command.size = 0;
  1420. }
  1421. else {
  1422. command.data = command.data.substr(command.data.find(" ") + 1);
  1423. command.size = command.data.length();
  1424. }
  1425. commands.Process(handler, &command, this);
  1426. }
  1427. else {
  1428. if (spawn && spawn->IsNPC()) {
  1429. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1430. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1431. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1432. }
  1433. }
  1434. }
  1435. else
  1436. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1437. }
  1438. }
  1439. }
  1440. safe_delete(packet);
  1441. }
  1442. break;
  1443. }
  1444. case OP_SkillInfoRequest: {
  1445. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1446. HandleSkillInfoRequest(app);
  1447. break;
  1448. }
  1449. case OP_UpdateTargetMsg: {
  1450. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1451. int16 index = 0;
  1452. memcpy(&index, app->pBuffer, sizeof(int16));
  1453. if (index == 0xFFFF)
  1454. GetPlayer()->SetTarget(0);
  1455. else
  1456. GetPlayer()->SetTarget(GetPlayer()->GetSpawnByIndex(index));
  1457. if (GetPlayer()->GetTarget())
  1458. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1459. //player->SetTarget((int16*)app->pBuffer);
  1460. break;
  1461. }
  1462. case OP_ExamineInfoRequestMsg: {
  1463. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1464. HandleExamineInfoRequest(app);
  1465. break;
  1466. }
  1467. case OP_QuickbarUpdateMsg:
  1468. //case OP_QuickbarAddMsg:
  1469. {
  1470. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1471. HandleQuickbarUpdateRequest(app);
  1472. break;
  1473. }
  1474. case OP_PredictionUpdateMsg: {
  1475. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
  1476. if (version <= 546) {
  1477. int8 offset = 9;
  1478. if (app->pBuffer[0] == 0xFF)
  1479. offset += 2;
  1480. if (app->size > offset) {
  1481. if (player->IsCasting()) {
  1482. float distance = 0;
  1483. float x = player->GetX();
  1484. float y = player->GetY();
  1485. float z = player->GetZ();
  1486. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1487. distance = player->GetDistance(x, y, z, false);
  1488. if (distance > .5)
  1489. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1490. }
  1491. else
  1492. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1493. //DumpPacket(app);
  1494. }
  1495. }
  1496. else {
  1497. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1498. QueuePacket(app);
  1499. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1500. }
  1501. break;
  1502. }
  1503. case OP_RemoteCmdMsg: {
  1504. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1505. if (app->size > 0) {
  1506. EQ2_CommandString remote(app->pBuffer, app->size);
  1507. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1508. #if EQDEBUG >= 9
  1509. DumpPacket(app);
  1510. #endif
  1511. commands.Process(remote.handler, &remote.command, this);
  1512. }
  1513. else //bad client, disconnect
  1514. Disconnect();
  1515. break;
  1516. }
  1517. case OP_CancelSpellCast: {
  1518. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1519. current_zone->Interrupted(player, 0, 0, true);
  1520. SimpleMessage(CHANNEL_COLOR_SPELL_INTERRUPT, "You stop casting.");
  1521. break;
  1522. }
  1523. case OP_UpdatePositionMsg: {
  1524. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
  1525. int8 offset = 13;
  1526. if (app->pBuffer[0] == 0xFF)
  1527. offset += 2;
  1528. if (app->size > offset) {
  1529. if (player->IsCasting()) {
  1530. float distance = 0;
  1531. float x = player->GetX();
  1532. float y = player->GetY();
  1533. float z = player->GetZ();
  1534. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1535. distance = player->GetDistance(x, y, z, false);
  1536. if (distance > .5)
  1537. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1538. }
  1539. else
  1540. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1541. player_pos_changed = true;
  1542. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1543. //DumpPacket(app);
  1544. }
  1545. break;
  1546. }
  1547. case OP_MailSendMessageMsg: {
  1548. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1549. HandleSentMail(app);
  1550. break;
  1551. }
  1552. case OP_StopTrackingMsg: {
  1553. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1554. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1555. break;
  1556. }
  1557. case OP_BeginTrackingMsg: {
  1558. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1559. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1560. if (packet) {
  1561. packet->LoadPacketData(app->pBuffer, app->size);
  1562. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1563. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1564. if (spawn) {
  1565. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1566. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1567. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1568. }
  1569. safe_delete(packet);
  1570. }
  1571. break;
  1572. }
  1573. case OP_BioUpdateMsg: {
  1574. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1575. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1576. if (packet) {
  1577. packet->LoadPacketData(app->pBuffer, app->size);
  1578. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1579. safe_delete(packet);
  1580. }
  1581. break;
  1582. }
  1583. case OP_RewardPackMsg: {
  1584. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1585. /* 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
  1586. when we come across it (scatman) */
  1587. const char* name = app->GetOpcodeName();
  1588. if (name)
  1589. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1590. else
  1591. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1592. //DumpPacket(app);
  1593. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1594. if (packet) {
  1595. packet->LoadPacketData(app->pBuffer, app->size);
  1596. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1597. /* Player has contacted a guild recruiter */
  1598. if (recruiter_name.length() > 0) {
  1599. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1600. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1601. if (recruiter && guild) {
  1602. Message(CHANNEL_COLOR_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1603. recruiter->Message(CHANNEL_COLOR_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()));
  1604. recruiter->PlaySound("ui_guild_page");
  1605. }
  1606. }
  1607. /* New picture taken for guild recruiting */
  1608. else {
  1609. //DumpPacket(app->pBuffer, app->size);
  1610. int32 guild_id = 0;
  1611. int16 picture_data_size = 0;
  1612. unsigned char* recruiter_picture_data = 0;
  1613. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1614. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1615. Guild* guild = guild_list.GetGuild(guild_id);
  1616. if (guild) {
  1617. GuildMember* gm = guild->GetGuildMember(player);
  1618. if (gm) {
  1619. safe_delete_array(gm->recruiter_picture_data);
  1620. recruiter_picture_data = new unsigned char[picture_data_size];
  1621. for (int16 i = 0; i < picture_data_size; i++)
  1622. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1623. gm->recruiter_picture_data = recruiter_picture_data;
  1624. gm->recruiter_picture_data_size = picture_data_size;
  1625. guild->SetMemberSaveNeeded(true);
  1626. }
  1627. }
  1628. }
  1629. safe_delete(packet);
  1630. }
  1631. break;
  1632. }
  1633. case OP_PetOptions: {
  1634. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  1635. Spawn* target = player->GetTarget();
  1636. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  1637. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  1638. bool change = false;
  1639. packet->LoadPacketData(app->pBuffer, app->size);
  1640. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  1641. if (strlen(name.c_str()) != 0) {
  1642. target->SetName(name.c_str());
  1643. strcpy(player->GetInfoStruct()->pet_name, name.c_str());
  1644. GetCurrentZone()->SendUpdateTitles(target);
  1645. change = true;
  1646. }
  1647. // Check protect self setting and update if needed
  1648. if (packet->getType_int8_ByName("protect_self") == 1) {
  1649. if ((player->GetInfoStruct()->pet_behavior & 2) == 0) {
  1650. player->GetInfoStruct()->pet_behavior += 2;
  1651. change = true;
  1652. }
  1653. }
  1654. else {
  1655. if ((player->GetInfoStruct()->pet_behavior & 2) != 0) {
  1656. player->GetInfoStruct()->pet_behavior -= 2;
  1657. change = true;
  1658. }
  1659. }
  1660. // Check protect master setting and update if needed
  1661. if (packet->getType_int8_ByName("protect_master") == 1) {
  1662. if ((player->GetInfoStruct()->pet_behavior & 1) == 0) {
  1663. player->GetInfoStruct()->pet_behavior += 1;
  1664. change = true;
  1665. }
  1666. }
  1667. else {
  1668. if ((player->GetInfoStruct()->pet_behavior & 1) != 0) {
  1669. player->GetInfoStruct()->pet_behavior -= 1;
  1670. change = true;
  1671. }
  1672. }
  1673. // Check stay/follow setting and update if needed
  1674. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  1675. if (player->GetInfoStruct()->pet_movement != 2) {
  1676. player->GetInfoStruct()->pet_movement = 2;
  1677. change = true;
  1678. }
  1679. }
  1680. else {
  1681. if (player->GetInfoStruct()->pet_movement != 1) {
  1682. player->GetInfoStruct()->pet_movement = 1;
  1683. change = true;
  1684. }
  1685. }
  1686. // Ranged/Melee settings are not implemented yet
  1687. if (change)
  1688. player->SetCharSheetChanged(true);
  1689. safe_delete(packet);
  1690. }
  1691. break;
  1692. }
  1693. case OP_RecipeBook: {
  1694. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  1695. SendRecipeList();
  1696. break;
  1697. }
  1698. case OP_BuyPlayerHouseMsg: {
  1699. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  1700. DumpPacket(app);
  1701. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  1702. if (packet) {
  1703. packet->LoadPacketData(app->pBuffer, app->size);
  1704. HouseZone* hz = world.GetHouseZone(packet->getType_int64_ByName("house_id"));
  1705. if (hz) {
  1706. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  1707. if (houses.size() > 24)
  1708. {
  1709. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  1710. safe_delete(packet);
  1711. break;
  1712. }
  1713. 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
  1714. {
  1715. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id);
  1716. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  1717. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  1718. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  1719. //ClientPacketFunctions::SendHousingList(this);
  1720. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  1721. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1722. PlaySound("coin_cha_ching");
  1723. }
  1724. else
  1725. {
  1726. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  1727. PlaySound("buy_failed");
  1728. }
  1729. }
  1730. }
  1731. safe_delete(packet);
  1732. break;
  1733. }
  1734. case OP_EnterHouseMsg: {
  1735. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  1736. DumpPacket(app);
  1737. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  1738. if (packet) {
  1739. packet->LoadPacketData(app->pBuffer, app->size);
  1740. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(packet->getType_int64_ByName("house_id"));
  1741. if (ph) {
  1742. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1743. if (hz) {
  1744. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id);
  1745. if (house) {
  1746. Zone(house, true);
  1747. }
  1748. }
  1749. }
  1750. }
  1751. safe_delete(packet);
  1752. break;
  1753. }
  1754. case OP_PayHouseUpkeepMsg: {
  1755. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  1756. DumpPacket(app);
  1757. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  1758. if (packet) {
  1759. packet->LoadPacketData(app->pBuffer, app->size);
  1760. int64 houseID = packet->getType_int64_ByName("house_id");
  1761. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(houseID);
  1762. if (ph)
  1763. {
  1764. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1765. if (!hz)
  1766. {
  1767. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  1768. safe_delete(packet);
  1769. break;
  1770. }
  1771. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  1772. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  1773. {
  1774. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  1775. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  1776. {
  1777. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  1778. PlaySound("buy_failed");
  1779. safe_delete(packet);
  1780. break;
  1781. }
  1782. }
  1783. int64 coinReq = hz->upkeep_coin;
  1784. int64 tmpRecoverCoins = 0;
  1785. bool escrowChange = false;
  1786. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  1787. {
  1788. escrowChange = true;
  1789. tmpRecoverCoins = ph->escrow_coins;
  1790. coinReq -= ph->escrow_coins;
  1791. ph->escrow_coins = 0;
  1792. }
  1793. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  1794. {
  1795. escrowChange = true;
  1796. // more than enough in escrow, subtract and make our cost 0!
  1797. ph->escrow_coins -= coinReq;
  1798. coinReq = 0;
  1799. }
  1800. // TODO: Need support for upkeep_status, but alas status_points are not implemented!
  1801. if (!coinReq || coinReq && player->RemoveCoins(coinReq)) // TODO: Need option to take from bank if player does not have enough coin on them
  1802. {
  1803. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  1804. if (escrowChange)
  1805. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins);
  1806. ph->upkeep_due = upkeep_due;
  1807. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  1808. //ClientPacketFunctions::SendHousingList(this);
  1809. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1810. PlaySound("coin_cha_ching");
  1811. }
  1812. else
  1813. {
  1814. // recover the escrow we were going to use but could not spend due to lack of funds
  1815. if (tmpRecoverCoins)
  1816. ph->escrow_coins += tmpRecoverCoins;
  1817. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to pay for upkeep.");
  1818. PlaySound("buy_failed");
  1819. }
  1820. }
  1821. else
  1822. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", houseID);
  1823. }
  1824. safe_delete(packet);
  1825. break;
  1826. }
  1827. case OP_ExitHouseMsg: {
  1828. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  1829. int32 instance_id = GetCurrentZone()->GetInstanceID();
  1830. if (instance_id > 0) {
  1831. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  1832. if (ph) {
  1833. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1834. if (hz) {
  1835. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  1836. // determine if this is an instanced zone that already exists
  1837. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  1838. if (instance_zone || new_zone) {
  1839. GetPlayer()->SetX(hz->exit_x);
  1840. GetPlayer()->SetY(hz->exit_y);
  1841. GetPlayer()->SetZ(hz->exit_z);
  1842. GetPlayer()->SetHeading(hz->exit_heading);
  1843. if (instance_zone)
  1844. Zone(instance_zone->GetInstanceID(), false, true);
  1845. else
  1846. Zone(new_zone, false);
  1847. }
  1848. }
  1849. }
  1850. }
  1851. DumpPacket(app);
  1852. break;
  1853. }
  1854. case OP_QuestJournalWaypointMsg: {
  1855. //DumpPacket(app);
  1856. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  1857. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  1858. if (packet) {
  1859. packet->LoadPacketData(app->pBuffer, app->size);
  1860. int32 quests = packet->getType_int32_ByName("num_quests");
  1861. if (quests > 100) // just picking a number higher than max allowed
  1862. {
  1863. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  1864. break;
  1865. }
  1866. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  1867. for (int32 i = 0; i < quests; i++) {
  1868. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  1869. if (id == 0)
  1870. continue;
  1871. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  1872. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  1873. if (player->player_quests.count(id) > 0) {
  1874. player->player_quests[id]->SetTracked(tracked);
  1875. player->player_quests[id]->SetSaveNeeded(true);
  1876. }
  1877. }
  1878. safe_delete(packet);
  1879. }
  1880. break;
  1881. }
  1882. case OP_PaperdollImage: {
  1883. PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  1884. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1885. //First check if this is a new image... delete an existing partial image if one exists
  1886. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  1887. if (packet_index == 0) {
  1888. safe_delete_array(incoming_paperdoll.image_bytes);
  1889. incoming_paperdoll.last_received_packet_index = 0;
  1890. incoming_paperdoll.current_size_bytes = 0;
  1891. }
  1892. //return if this packet is not the one we are expecting...
  1893. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  1894. safe_delete(packet);
  1895. break;
  1896. }
  1897. //Check how many packets we're supposed to be receiving for this/these images
  1898. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  1899. //Check the image type, if this is a new type in the same series of packets we have a new image
  1900. int8 img_type = packet->getType_int8_ByName("image_type");
  1901. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  1902. //We have a new image. Save the old data and clear before continuing
  1903. SavePlayerImages();
  1904. }
  1905. incoming_paperdoll.image_type = img_type;
  1906. //Get the size of the image data in this packet
  1907. sint64 image_size = packet->getType_int32_ByName("imageSize");
  1908. if (image_size <= 0 || image_size > 1048576) {
  1909. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  1910. safe_delete(packet);
  1911. break;
  1912. }
  1913. //Create a new array
  1914. int32 new_image_size = image_size;
  1915. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  1916. if (incoming_paperdoll.image_bytes) {
  1917. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  1918. safe_delete_array(incoming_paperdoll.image_bytes);
  1919. }
  1920. //variable i should be the index in the packet of the first PNG file byte
  1921. vector<DataStruct*>* d_structs = packet->getStructs();
  1922. vector<DataStruct*>::iterator itr;
  1923. int32 i = 0;
  1924. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  1925. DataStruct* ds = (*itr);
  1926. if (strcmp(ds->GetName(), "pngData_0") != 0)
  1927. i += ds->GetDataSizeInBytes();
  1928. else
  1929. break;
  1930. }
  1931. //Return if this packet is bad and we would read out of bounds
  1932. if (app->size - i < new_image_size) {
  1933. safe_delete(packet);
  1934. safe_delete_array(new_image);
  1935. break;
  1936. }
  1937. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  1938. memcpy(tmp, app->pBuffer + i, new_image_size);
  1939. incoming_paperdoll.current_size_bytes += new_image_size;
  1940. incoming_paperdoll.image_bytes = new_image;
  1941. //Check if this is the last packet we're expecting for this image. Create a final image if so
  1942. if (incoming_paperdoll.image_num_packets == 1 ||
  1943. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  1944. SavePlayerImages();
  1945. }
  1946. incoming_paperdoll.last_received_packet_index = packet_index;
  1947. }
  1948. safe_delete(packet);
  1949. break;
  1950. }
  1951. case OP_ReadyForTakeOffMsg:
  1952. {
  1953. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  1954. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  1955. if (GetPendingFlightPath() > 0) {
  1956. if (index != -1) {
  1957. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  1958. if (packet) {
  1959. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  1960. packet->setDataByName("path_id", index);
  1961. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  1962. QueuePacket(packet->serialize());
  1963. safe_delete(packet);
  1964. on_auto_mount = true;
  1965. }
  1966. }
  1967. else {
  1968. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  1969. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  1970. EndAutoMount();
  1971. }
  1972. SetPendingFlightPath(0);
  1973. }
  1974. else
  1975. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  1976. break;
  1977. }
  1978. case OP_EarlyLandingRequestMsg:
  1979. {
  1980. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  1981. EndAutoMount();
  1982. break;
  1983. }
  1984. case OP_SubmitCharCust:
  1985. {
  1986. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  1987. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  1988. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1989. int8 type = packet->getType_int8_ByName("type");
  1990. if (type == 0) {
  1991. if (player->custNPC) {
  1992. player->custNPCTarget->CustomizeAppearance(packet);
  1993. current_zone->SendSpawnChanges(player->custNPCTarget);
  1994. }
  1995. else {
  1996. player->CustomizeAppearance(packet);
  1997. current_zone->SendSpawnChanges(player);
  1998. }
  1999. }
  2000. }
  2001. if (player->custNPC) {
  2002. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2003. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2004. if (player->custNPCTarget->IsBot())
  2005. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2006. player->custNPC = false;
  2007. player->custNPCTarget = 0;
  2008. player->changed = true;
  2009. player->info_changed = true;
  2010. current_zone->SendSpawnChanges(player, this);
  2011. }
  2012. break;
  2013. }
  2014. default: {
  2015. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2016. const char* name = app->GetOpcodeName();
  2017. if (name)
  2018. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2019. else
  2020. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2021. //DumpPacket(app);
  2022. }
  2023. }
  2024. if (!eqs || !eqs->CheckActive()) {
  2025. return false;
  2026. }
  2027. return ret;
  2028. }
  2029. bool Client::HandleLootItem(Spawn* entity, Item* item) {
  2030. if (!item) {
  2031. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2032. return false;
  2033. }
  2034. if (player->item_list.HasFreeSlot() || player->item_list.CanStack(item)) {
  2035. if (player->item_list.AssignItemToFreeSlot(item)) {
  2036. int8 type = CHANNEL_COLOR_LOOT;
  2037. if (GetVersion() >= 973 && GetVersion() <= 1000)
  2038. type = CHANNEL_COLOR_NEW_LOOT;
  2039. else if (GetVersion() >= 973)
  2040. type = CHANNEL_COLOR_NEWEST_LOOT;
  2041. if (entity)
  2042. Message(type, "You loot \\aITEM %u 0:%s\\/a from the corpse of %s", item->details.item_id, item->name.c_str(), entity->GetName());
  2043. else
  2044. Message(type, "You found a \\aITEM %u 0:%s\\/a", item->details.item_id, item->name.c_str());
  2045. Guild* guild = player->GetGuild();
  2046. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2047. char adjective[32];
  2048. int8 type;
  2049. memset(adjective, 0, sizeof(adjective));
  2050. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2051. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2052. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2053. }
  2054. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2055. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2056. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2057. }
  2058. else {
  2059. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2060. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2061. }
  2062. guild->AddNewGuildEvent(type, "%s has looted the %s \\aITEM %u 0:%s\\/a", Timer::GetUnixTimeStamp(), true, player->GetName(), adjective, item->details.item_id, item->name.c_str());
  2063. guild->SendMessageToGuild(type, "%s has looted the %s \\aITEM %u 0:%s\\/a", player->GetName(), adjective, item->details.item_id, item->name.c_str());
  2064. }
  2065. CheckPlayerQuestsItemUpdate(item);
  2066. return true;
  2067. }
  2068. else
  2069. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2070. }
  2071. else
  2072. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2073. return false;
  2074. }
  2075. bool Client::HandleLootItem(Spawn* entity, int32 item_id) {
  2076. if (!entity) {
  2077. return false;
  2078. }
  2079. return HandleLootItem(entity, entity->LootItem(item_id));
  2080. }
  2081. void Client::HandleLoot(EQApplicationPacket* app) {
  2082. PacketStruct* packet = configReader.getStruct("WS_LootType", GetVersion());
  2083. if (packet) {
  2084. packet->LoadPacketData(app->pBuffer, app->size);
  2085. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2086. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2087. safe_delete(packet);
  2088. int32 item_id = 0;
  2089. Item* item = 0;
  2090. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2091. if (player->HasPendingLootItems(loot_id)) {
  2092. Item* master_item = 0;
  2093. if (loot_all) {
  2094. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2095. if (items) {
  2096. for (int32 i = 0; loot_all && i < items->size(); i++) {
  2097. master_item = items->at(i);
  2098. if (master_item) {
  2099. item = new Item(master_item);
  2100. if (item) {
  2101. loot_all = HandleLootItem(0, item);
  2102. if (loot_all)
  2103. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2104. }
  2105. }
  2106. }
  2107. safe_delete(items);
  2108. }
  2109. }
  2110. else {
  2111. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2112. if (packet) {
  2113. packet->LoadPacketData(app->pBuffer, app->size);
  2114. item_id = packet->getType_int32_ByName("item_id");
  2115. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2116. if (items) {
  2117. for (int32 i = 0; i < items->size(); i++) {
  2118. master_item = items->at(i);
  2119. if (master_item && master_item->details.item_id == item_id) {
  2120. item = new Item(master_item);
  2121. if (item && HandleLootItem(0, item))
  2122. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2123. break;
  2124. }
  2125. }
  2126. safe_delete(items);
  2127. }
  2128. safe_delete(packet);
  2129. }
  2130. }
  2131. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2132. if (outapp)
  2133. QueuePacket(outapp);
  2134. Loot(0, player->GetPendingLootItems(loot_id), spawn);
  2135. }
  2136. else {
  2137. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2138. if (loot_all) {
  2139. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2140. loot_all = HandleLootItem(spawn, item_id);
  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. HandleLootItem(spawn, item_id);
  2149. safe_delete(packet);
  2150. }
  2151. }
  2152. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2153. if (outapp)
  2154. QueuePacket(outapp);
  2155. Loot(spawn);
  2156. if (!spawn->HasLoot()) {
  2157. CloseLoot();
  2158. if (spawn->IsNPC())
  2159. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2160. }
  2161. }
  2162. else {
  2163. if (!spawn) {
  2164. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2165. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2166. }
  2167. else
  2168. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2169. }
  2170. }
  2171. }
  2172. }
  2173. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2174. PacketStruct* request = 0;
  2175. // cout << "Request: \n";
  2176. // DumpPacket(app);
  2177. switch (app->pBuffer[0]) {
  2178. case 0: { //items
  2179. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2180. if (request) {
  2181. request->LoadPacketData(app->pBuffer, app->size);
  2182. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2183. if (!item)
  2184. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2185. if (item) {
  2186. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2187. if (response) {
  2188. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2189. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2190. response->setSmallStringByName("name", item->name.c_str());
  2191. EQ2Packet* app2 = response->serialize();
  2192. //DumpPacket(app2);
  2193. QueuePacket(app2);
  2194. safe_delete(response);
  2195. }
  2196. }
  2197. }
  2198. break;
  2199. }
  2200. case 2: {//spells
  2201. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2202. if (request) {
  2203. request->LoadPacketData(app->pBuffer, app->size);
  2204. int32 id = request->getType_int32_ByName("id");
  2205. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2206. Spell* spell = master_spell_list.GetSpell(id, tier);
  2207. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2208. if (response) {
  2209. response->setDataByName("request_type", 2);
  2210. response->setDataByName("unique_id", tier);
  2211. response->setDataByName("id", id);
  2212. if (spell)
  2213. response->setSmallStringByName("name", spell->GetName());
  2214. else
  2215. response->setSmallStringByName("name", "Unknown Spell");
  2216. EQ2Packet* app2 = response->serialize();
  2217. // DumpPacket(app2);
  2218. QueuePacket(app2);
  2219. safe_delete(response);
  2220. }
  2221. }
  2222. break;
  2223. }
  2224. default: {
  2225. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2226. }
  2227. }
  2228. safe_delete(request);
  2229. }
  2230. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2231. PacketStruct* request = 0;
  2232. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2233. //DumpPacket(app);
  2234. int8 type = app->pBuffer[0];
  2235. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2236. if (version <= 283) {
  2237. if (type == 1)
  2238. type = 4;
  2239. else if (type == 2)
  2240. type = 5;
  2241. }
  2242. if (type == 3) {
  2243. Spell* spell = 0;
  2244. bool trait_display;
  2245. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2246. if (!request) {
  2247. return;
  2248. }
  2249. request->LoadPacketData(app->pBuffer, app->size);
  2250. int32 id = request->getType_int32_ByName("id");
  2251. int32 tier = request->getType_int32_ByName("tier");
  2252. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2253. bool display = true;
  2254. if (version <= 283 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2255. display = false;
  2256. else if (version <= 546)
  2257. display = request->getType_int8_ByName("display");
  2258. //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
  2259. if (trait_tier != 0xFFFFFFFF) {
  2260. spell = master_spell_list.GetSpell(id, trait_tier);
  2261. if (!spell) {
  2262. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2263. }
  2264. trait_display = true;
  2265. }
  2266. else {
  2267. spell = master_spell_list.GetSpell(id, tier);
  2268. trait_display = false;
  2269. }
  2270. if (spell && sent_spell_details.count(id) == 0) {
  2271. sent_spell_details[id] = true;
  2272. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  2273. //DumpPacket(app);
  2274. QueuePacket(app);
  2275. }
  2276. }
  2277. else if (type == 0) {
  2278. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2279. if (!request) {
  2280. return;
  2281. }
  2282. request->LoadPacketData(app->pBuffer, app->size);
  2283. int32 id = request->getType_int32_ByName("id");
  2284. Item* item = 0;
  2285. // translate from unique id to spawn id for houses
  2286. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2287. bool wasSpawn = false;
  2288. if (spawn)
  2289. {
  2290. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2291. if (item)
  2292. {
  2293. wasSpawn = true;
  2294. item = new Item(item);
  2295. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2296. }
  2297. }
  2298. if (!item)
  2299. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2300. if (!item)
  2301. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2302. if (!item)
  2303. item = master_item_list.GetItem(id);
  2304. if (item) {// && sent_item_details.count(id) == 0){
  2305. sent_item_details[id] = true;
  2306. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2307. //DumpPacket(app);
  2308. QueuePacket(app);
  2309. if (wasSpawn)
  2310. delete item;
  2311. }
  2312. else {
  2313. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2314. DumpPacket(app);
  2315. }
  2316. }
  2317. else if (type == 1) {
  2318. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2319. if (!request) {
  2320. return;
  2321. }
  2322. request->LoadPacketData(app->pBuffer, app->size);
  2323. int32 id = request->getType_int32_ByName("id");
  2324. int32 unique_id = request->getType_int32_ByName("unique_id");
  2325. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  2326. if (!item)
  2327. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  2328. if (!item)
  2329. item = master_item_list.GetItem(id);
  2330. if (item) {
  2331. sent_item_details[id] = true;
  2332. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2333. //DumpPacket(app);
  2334. QueuePacket(app);
  2335. }
  2336. else {
  2337. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2338. DumpPacket(app);
  2339. }
  2340. }
  2341. else if (type == 2) {
  2342. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  2343. if (!request) {
  2344. return;
  2345. }
  2346. request->LoadPacketData(app->pBuffer, app->size);
  2347. int32 id = request->getType_int32_ByName("item_id");
  2348. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  2349. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  2350. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  2351. //int32 unique_id = request->getType_int32_ByName("unique_id");
  2352. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  2353. //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);
  2354. Item* item = master_item_list.GetItem(id);
  2355. if (item) {
  2356. //only display popup for non merchant links
  2357. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, true);
  2358. //DumpPacket(app);
  2359. QueuePacket(app);
  2360. }
  2361. else {
  2362. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2363. DumpPacket(app);
  2364. }
  2365. }
  2366. else if (type == 4) { //spell effect
  2367. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  2368. if (!request) {
  2369. return;
  2370. }
  2371. request->LoadPacketData(app->pBuffer, app->size);
  2372. int32 id = request->getType_int32_ByName("id");
  2373. int16 display = request->getType_int8_ByName("partial_info");
  2374. SpellEffects* effect = player->GetSpellEffect(id);
  2375. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  2376. if (effect) {
  2377. int8 tier = effect->tier;
  2378. Spell* spell = master_spell_list.GetSpell(id, tier);
  2379. if (spell && sent_spell_details.count(id) == 0) {
  2380. sent_spell_details[id] = true;
  2381. int8 type = 0;
  2382. if (version <= 283)
  2383. type = 1;
  2384. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  2385. //DumpPacket(app);
  2386. QueuePacket(app);
  2387. }
  2388. }
  2389. }
  2390. else if (type == 5) { // recipe info
  2391. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2392. if (!request)
  2393. return;
  2394. request->LoadPacketData(app->pBuffer, app->size);
  2395. int32 id = request->getType_int32_ByName("unknown_id");
  2396. Recipe* recipe = master_recipe_list.GetRecipe(id);
  2397. if (recipe) {
  2398. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  2399. //DumpPacket(app);
  2400. QueuePacket(app);
  2401. }
  2402. }
  2403. else if (type == 6) { // AA spell info
  2404. Spell* spell = 0;
  2405. //Spell* spell2 = 0;
  2406. //AltAdvanceData* data = 0;
  2407. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2408. if (!request)
  2409. return;
  2410. request->LoadPacketData(app->pBuffer, app->size);
  2411. int32 id = request->getType_int32_ByName("id");
  2412. int32 tier = GetPlayer()->GetSpellTier(id);
  2413. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  2414. //data = master_aa_list.GetAltAdvancement(id);
  2415. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  2416. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  2417. spell = master_spell_list.GetSpell(id, 1);
  2418. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  2419. sent_spell_details[spell->GetSpellID()] = true;
  2420. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  2421. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  2422. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  2423. //DumpPacket(app);
  2424. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  2425. QueuePacket(app);
  2426. //}
  2427. }
  2428. else {
  2429. LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
  2430. DumpPacket(app);
  2431. }
  2432. safe_delete(request);
  2433. }
  2434. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  2435. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  2436. if (request) {
  2437. request->LoadPacketData(app->pBuffer, app->size);
  2438. int32 id = request->getType_int32_ByName("id");
  2439. int32 bar = request->getType_int32_ByName("hotbar_number");
  2440. int32 slot = request->getType_int32_ByName("hotkey_slot");
  2441. int32 type = request->getType_int32_ByName("type");
  2442. int8 tier = request->getType_int32_ByName("unique_id");
  2443. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  2444. Spell* spell = 0;
  2445. if (type == 0xFFFFFFFF)
  2446. GetPlayer()->RemoveQuickbarItem(bar, slot);
  2447. else {
  2448. if (type == QUICKBAR_NORMAL)
  2449. spell = master_spell_list.GetSpell(id, tier);
  2450. if (spell)
  2451. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  2452. else
  2453. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  2454. }
  2455. safe_delete(request);
  2456. }
  2457. }
  2458. bool Client::Process(bool zone_process) {
  2459. if (!eqs) {
  2460. return false;
  2461. }
  2462. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  2463. return true;
  2464. }
  2465. if (new_client_login) {
  2466. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  2467. SendLoginInfo();
  2468. new_client_login = false;
  2469. }
  2470. bool ret = true;
  2471. sockaddr_in to;
  2472. memset((char*)&to, 0, sizeof(to));
  2473. to.sin_family = AF_INET;
  2474. to.sin_port = port;
  2475. to.sin_addr.s_addr = ip;
  2476. /************ Get all packets from packet manager out queue and process them ************/
  2477. EQApplicationPacket* app = 0;
  2478. if (eqs && !eqs->CheckActive()) {
  2479. num_active_failures++;
  2480. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  2481. if (num_active_failures > 100) {
  2482. return false;
  2483. }
  2484. return true;
  2485. }
  2486. while (ret && eqs && (app = eqs->PopPacket())) {
  2487. ret = HandlePacket(app);
  2488. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  2489. delete app;
  2490. }
  2491. if (GetCurrentZone() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  2492. player->ApplyPassiveSpells();
  2493. //database.LoadCharacterActiveSpells(player);
  2494. player->UnlockAllSpells(true);
  2495. should_load_spells = false;
  2496. }
  2497. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  2498. {
  2499. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  2500. return false;
  2501. }
  2502. if (quest_updates) {
  2503. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  2504. ProcessQuestUpdates();
  2505. }
  2506. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - 300)) {
  2507. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  2508. CheckQuestQueue();
  2509. }
  2510. if (pos_update.Check() && player_pos_changed && IsReadyForUpdates() && ( !disconnect_timer || !disconnect_timer->Enabled())) {
  2511. //GetPlayer()->CalculateLocation();
  2512. client_list.CheckPlayersInvisStatus(this);
  2513. GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
  2514. player_pos_changed = false;
  2515. GetCurrentZone()->CheckTransporters(this);
  2516. }
  2517. if (lua_interface && lua_debug && lua_debug_timer.Check())
  2518. lua_interface->UpdateDebugClients(this);
  2519. if (quest_pos_timer.Check())
  2520. CheckPlayerQuestsLocationUpdate();
  2521. if (camp_timer && camp_timer->Check() && getConnection()) {
  2522. getConnection()->SendDisconnect(false);
  2523. safe_delete(camp_timer);
  2524. disconnect_timer = new Timer(2000);
  2525. disconnect_timer->Start();
  2526. }
  2527. if (player->GetSkills()->HasSkillUpdates()) {
  2528. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  2529. if (skills) {
  2530. Skill* skill = 0;
  2531. vector<Skill*>::iterator itr;
  2532. for (itr = skills->begin(); itr != skills->end(); itr++) {
  2533. skill = *itr;
  2534. SkillChanged(skill, skill->previous_val, skill->current_val);
  2535. }
  2536. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  2537. if (app) QueuePacket(app);
  2538. safe_delete(skills);
  2539. }
  2540. }
  2541. if (disconnect_timer && disconnect_timer->Check()) {
  2542. safe_delete(disconnect_timer);
  2543. ret = false;
  2544. }
  2545. m_resurrect.writelock(__FUNCTION__, __LINE__);
  2546. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  2547. safe_delete(current_rez.expire_timer);
  2548. current_rez.expire_timer = 0;
  2549. current_rez.active = false;
  2550. current_rez.caster = 0;
  2551. current_rez.crit = false;
  2552. current_rez.crit_mod = 0;
  2553. current_rez.expire_timer = 0;
  2554. current_rez.heal_name = "";
  2555. current_rez.hp_perc = 0;
  2556. current_rez.mp_perc = 0;
  2557. current_rez.no_calcs = false;
  2558. current_rez.range = 0;
  2559. current_rez.should_delete = false;
  2560. current_rez.spell_name = "";
  2561. current_rez.spell_visual = 0;
  2562. current_rez.subspell = 0;
  2563. }
  2564. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  2565. // Quest timers
  2566. Quest* failed_step = 0;
  2567. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  2568. if (quest_timers.size() > 0) {
  2569. vector<int32>::iterator itr;
  2570. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  2571. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  2572. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  2573. Quest* quest = player_quests->at(*itr);
  2574. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  2575. failed_step = quest;
  2576. break;
  2577. }
  2578. }
  2579. else {
  2580. quest_timers.erase(itr);
  2581. break;
  2582. }
  2583. }
  2584. }
  2585. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  2586. if (failed_step)
  2587. failed_step->StepFailed(failed_step->GetTimerStep());
  2588. if (player->ControlFlagsChanged())
  2589. player->SendControlFlagUpdates(this);
  2590. if (!eqs || (eqs && !eqs->CheckActive()))
  2591. ret = false;
  2592. // redundant to client disconnect
  2593. // if(!ret)
  2594. // Save();
  2595. return ret;
  2596. }
  2597. ClientList::ClientList() {
  2598. MClients.SetName("ClientList::MClients");
  2599. }
  2600. ClientList::~ClientList() {
  2601. }
  2602. void ClientList::ReloadQuests() {
  2603. list<Client*>::iterator client_iter;
  2604. Client* client = 0;
  2605. MClients.readlock(__FUNCTION__, __LINE__);
  2606. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2607. client = *client_iter;
  2608. if (client)
  2609. client->ReloadQuests();
  2610. }
  2611. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2612. }
  2613. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  2614. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  2615. return;
  2616. list<Client*>::iterator client_iter;
  2617. Client* client = 0;
  2618. MClients.readlock(__FUNCTION__, __LINE__);
  2619. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2620. client = *client_iter;
  2621. if (client == owner || client->GetPlayer() == NULL)
  2622. continue;
  2623. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  2624. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  2625. }
  2626. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2627. }
  2628. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  2629. list<Client*>::iterator client_iter;
  2630. Client* client = 0;
  2631. MClients.readlock(__FUNCTION__, __LINE__);
  2632. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2633. client = *client_iter;
  2634. if (!client->GetPlayer())
  2635. continue;
  2636. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  2637. }
  2638. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2639. }
  2640. int32 ClientList::Count() {
  2641. return client_list.size();
  2642. }
  2643. void ClientList::Add(Client* client) {
  2644. MClients.writelock(__FUNCTION__, __LINE__);
  2645. client_list.push_back(client);
  2646. MClients.releasewritelock(__FUNCTION__, __LINE__);
  2647. }
  2648. Client* ClientList::FindByAccountID(int32 account_id) {
  2649. list<Client*>::iterator client_iter;
  2650. Client* client = 0;
  2651. Client* ret = 0;
  2652. MClients.readlock(__FUNCTION__, __LINE__);
  2653. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2654. client = *client_iter;
  2655. if (client->GetAccountID() == account_id) {
  2656. ret = client;
  2657. break;
  2658. }
  2659. }
  2660. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2661. return ret;
  2662. }
  2663. Client* ClientList::FindByName(char* charName) {
  2664. list<Client*>::iterator client_iter;
  2665. Client* client = 0;
  2666. Client* ret = 0;
  2667. MClients.readlock(__FUNCTION__, __LINE__);
  2668. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2669. client = *client_iter;
  2670. if (!client || !client->GetPlayer())
  2671. continue;
  2672. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  2673. ret = client;
  2674. break;
  2675. }
  2676. }
  2677. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2678. return ret;
  2679. }
  2680. Client* ClientList::Get(int32 ip, int16 port) {
  2681. list<Client*>::iterator client_iter;
  2682. Client* client = 0;
  2683. Client* ret = 0;
  2684. MClients.readlock(__FUNCTION__, __LINE__);
  2685. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2686. client = *client_iter;
  2687. if (client->GetIP() == ip && client->GetPort() == port) {
  2688. ret = client;
  2689. break;
  2690. }
  2691. }
  2692. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2693. return ret;
  2694. }
  2695. void ClientList::Process() {
  2696. list<Client*>::iterator client_iter;
  2697. list<Client*>::iterator erase_iter;
  2698. Client* client = 0;
  2699. MClients.readlock(__FUNCTION__, __LINE__);
  2700. erase_iter = client_list.end();
  2701. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2702. client = *client_iter;
  2703. // have a sanity check because the client list can sometimes obtain null client pointers
  2704. if (!client || (!client->Process() || client->remove_from_list)) {
  2705. erase_iter = client_iter;
  2706. break;
  2707. }
  2708. }
  2709. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2710. if (erase_iter != client_list.end()) {
  2711. client = *erase_iter;
  2712. MClients.writelock(__FUNCTION__, __LINE__);
  2713. client_list.erase(erase_iter);
  2714. MClients.releasewritelock(__FUNCTION__, __LINE__);
  2715. if (client && !client->remove_from_list) {
  2716. struct in_addr in;
  2717. in.s_addr = client->GetIP();
  2718. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  2719. safe_delete(client);
  2720. }
  2721. }
  2722. }
  2723. void ClientList::RemoveConnection(EQStream* eqs) {
  2724. Client* client;
  2725. if (eqs) {
  2726. list<Client*>::iterator client_iter;
  2727. MClients.readlock(__FUNCTION__, __LINE__);
  2728. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2729. client = *client_iter;
  2730. if (client->getConnection() == eqs)
  2731. client->Disconnect(false);
  2732. }
  2733. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2734. }
  2735. }
  2736. bool ClientList::ContainsStream(EQStream* eqs) {
  2737. if (!eqs) {
  2738. return false;
  2739. }
  2740. list<Client*>::iterator client_iter;
  2741. bool ret = false;
  2742. MClients.readlock(__FUNCTION__, __LINE__);
  2743. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2744. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  2745. ret = true;
  2746. break;
  2747. }
  2748. }
  2749. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2750. return ret;
  2751. }
  2752. void ClientList::Remove(Client* client, bool remove_data) {
  2753. client->remove_from_list = true;
  2754. if (remove_data) {
  2755. safe_delete(client);
  2756. }
  2757. }
  2758. void Client::SetCurrentZone(int32 id) {
  2759. if (current_zone) {
  2760. //current_zone->GetCombat()->RemoveHate(player);
  2761. current_zone->RemoveSpawn(false, player, false);
  2762. }
  2763. SetCurrentZone(zone_list.Get(id));
  2764. }
  2765. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  2766. if (current_zone) {
  2767. //current_zone->GetCombat()->RemoveHate(player);
  2768. current_zone->RemoveSpawn(false, player, false);
  2769. }
  2770. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  2771. }
  2772. ZoneServer* Client::GetCurrentZone() {
  2773. return current_zone;
  2774. }
  2775. void Client::SimpleMessage(int8 color, const char* message) {
  2776. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  2777. if (command_packet) {
  2778. command_packet->setDataByName("color", color);
  2779. command_packet->setMediumStringByName("text", message);
  2780. command_packet->setDataByName("unknown02", 0x00ff);
  2781. EQ2Packet* outapp = command_packet->serialize();
  2782. QueuePacket(outapp);
  2783. safe_delete(command_packet);
  2784. }
  2785. }
  2786. void Client::SendSpellUpdate(Spell* spell) {
  2787. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  2788. if (packet) {
  2789. int8 xxx = spell->GetSpellData()->is_aa;
  2790. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  2791. packet->setDataByName("spell_id", spell->GetSpellID());
  2792. packet->setDataByName("unique_id", spell->GetSpellTier());
  2793. packet->setDataByName("spell_name", spell->GetName());
  2794. packet->setDataByName("unknown", xxx);
  2795. packet->setDataByName("display_spell_tier", 1);
  2796. packet->setDataByName("unknown3", 1);
  2797. packet->setDataByName("tier", spell->GetSpellTier());
  2798. packet->setDataByName("icon", spell->GetSpellIcon());
  2799. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  2800. packet->setDataByName("unknown5", 0xFFFFFFFF);
  2801. //packet->PrintPacket();
  2802. EQ2Packet* outapp = packet->serialize();
  2803. //DumpPacket(outapp);
  2804. QueuePacket(outapp);
  2805. safe_delete(packet);
  2806. }
  2807. }
  2808. void Client::Message(int8 type, const char* message, ...) {
  2809. va_list argptr;
  2810. char buffer[4096];
  2811. va_start(argptr, message);
  2812. vsnprintf(buffer, sizeof(buffer), message, argptr);
  2813. va_end(argptr);
  2814. SimpleMessage(type, buffer);
  2815. }
  2816. void Client::Disconnect(bool send_disconnect)
  2817. {
  2818. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  2819. SetConnected(false);
  2820. if (send_disconnect && getConnection())
  2821. getConnection()->SendDisconnect(true);
  2822. this->Save();
  2823. this->GetPlayer()->WritePlayerStatistics();
  2824. eqs = 0;
  2825. }
  2826. bool Client::Summon(const char* search_name) {
  2827. Spawn* target = 0;
  2828. if (search_name || GetPlayer()->GetTarget()) {
  2829. Client* search_client = 0;
  2830. if (search_name) {
  2831. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  2832. if (target && target->IsPlayer())
  2833. search_client = GetCurrentZone()->GetClientBySpawn(target);
  2834. if (!target) {
  2835. search_client = zone_list.GetClientByCharName(string(search_name));
  2836. if (search_client)
  2837. target = search_client->GetPlayer();
  2838. }
  2839. }
  2840. else
  2841. target = GetPlayer()->GetTarget();
  2842. if (target && target != GetPlayer()) {
  2843. target->SetX(GetPlayer()->GetX());
  2844. target->SetY(GetPlayer()->GetY());
  2845. target->SetZ(GetPlayer()->GetZ());
  2846. target->SetHeading(GetPlayer()->GetHeading());
  2847. if (!target->IsPlayer()) {
  2848. target->SetSpawnOrigX(target->GetX());
  2849. target->SetSpawnOrigY(target->GetY());
  2850. target->SetSpawnOrigZ(target->GetZ());
  2851. target->SetSpawnOrigHeading(target->GetHeading());
  2852. }
  2853. target->SetLocation(GetPlayer()->GetLocation());
  2854. }
  2855. else if (target)
  2856. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  2857. if (search_client && search_client != this) {
  2858. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  2859. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  2860. if (search_client->GetCurrentZone() != GetCurrentZone())
  2861. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  2862. else {
  2863. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  2864. if (app)
  2865. search_client->QueuePacket(app);
  2866. }
  2867. }
  2868. }
  2869. if (!target)
  2870. return false;
  2871. else
  2872. return true;
  2873. }
  2874. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  2875. ZoneServer* instance_zone = NULL;
  2876. int8 instanceType = 0;
  2877. // determine if this is a group instanced zone that already exists
  2878. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  2879. if (instance_zone != NULL)
  2880. Zone(instance_zone->GetInstanceID(), zone_coords_valid, true);
  2881. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  2882. {
  2883. // best to check if we already have our own instance!
  2884. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  2885. if (data) {
  2886. // If lockout instances check to see if we are locked out
  2887. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  2888. int32 time = 0;
  2889. // Check success timer
  2890. if (data->last_success_timestamp > 0) {
  2891. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  2892. // Timer has not expired yet can't re enter
  2893. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  2894. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  2895. }
  2896. }
  2897. // Check failure timer
  2898. if (data->last_failure_timestamp > 0) {
  2899. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  2900. // Timer has not expired yet
  2901. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  2902. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  2903. }
  2904. }
  2905. // Time > 0 then we are locked out, make the message and send it and return true
  2906. if (time > 0) {
  2907. string time_msg = "";
  2908. int16 hour;
  2909. int8 min;
  2910. int8 sec;
  2911. hour = time / 3600;
  2912. time = time % 3600;
  2913. min = time / 60;
  2914. time = time % 60;
  2915. sec = time;
  2916. if (hour > 0) {
  2917. char temp[10];
  2918. sprintf(temp, " %i", hour);
  2919. time_msg.append(temp);
  2920. time_msg.append(" hour");
  2921. time_msg.append((hour > 1) ? "s" : "");
  2922. }
  2923. if (min > 0) {
  2924. char temp[5];
  2925. sprintf(temp, " %i", min);
  2926. time_msg.append(temp);
  2927. time_msg.append(" minute");
  2928. time_msg.append((min > 1) ? "s" : "");
  2929. }
  2930. // Only add seconds if minutes and hours are 0
  2931. if (hour == 0 && min == 0 && sec > 0) {
  2932. char temp[5];
  2933. sprintf(temp, " %i", sec);
  2934. time_msg.append(temp);
  2935. time_msg.append(" second");
  2936. time_msg.append((sec > 1) ? "s" : "");
  2937. }
  2938. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  2939. return true;
  2940. }
  2941. }
  2942. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  2943. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID);
  2944. // 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
  2945. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  2946. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  2947. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  2948. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  2949. }
  2950. else
  2951. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  2952. data->instance_id = instance_zone->GetInstanceID();
  2953. }
  2954. }
  2955. else {
  2956. switch (instanceType)
  2957. {
  2958. case SOLO_LOCKOUT_INSTANCE:
  2959. case GROUP_LOCKOUT_INSTANCE:
  2960. case RAID_LOCKOUT_INSTANCE:
  2961. {
  2962. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  2963. if (instance_zone) {
  2964. // 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
  2965. // so delete `instances` entry for the zone when it shuts down.
  2966. 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());
  2967. if (db_id > 0)
  2968. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  2969. }
  2970. break;
  2971. }
  2972. case SOLO_PERSIST_INSTANCE:
  2973. case GROUP_PERSIST_INSTANCE:
  2974. case RAID_PERSIST_INSTANCE:
  2975. {
  2976. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  2977. if (instance_zone) {
  2978. 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());
  2979. if (db_id > 0)
  2980. 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()));
  2981. }
  2982. break;
  2983. }
  2984. case PUBLIC_INSTANCE:
  2985. case TRADESKILL_INSTANCE:
  2986. {
  2987. // if its public/tradeskill, look for a public already setup
  2988. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  2989. if (instance_zone) {
  2990. // Check the current population against the max population, if greater or equal start a new version
  2991. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  2992. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  2993. }
  2994. else
  2995. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  2996. break;
  2997. }
  2998. case PERSONAL_HOUSE_INSTANCE:
  2999. case GUILD_HOUSE_INSTANCE:
  3000. {
  3001. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  3002. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  3003. // with the OP_EnterHouseMsg opcode
  3004. break;
  3005. }
  3006. case QUEST_INSTANCE:
  3007. {
  3008. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3009. break;
  3010. /*
  3011. 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`;
  3012. */
  3013. }
  3014. default:
  3015. {
  3016. // NONE
  3017. }
  3018. }
  3019. }
  3020. if (instance_zone != NULL)
  3021. Zone(instance_zone, zone_coords_valid);
  3022. }
  3023. if (instance_zone != NULL)
  3024. return true;
  3025. else
  3026. return false;
  3027. }
  3028. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  3029. Spawn* target = 0;
  3030. if (search_name || GetPlayer()->GetTarget()) {
  3031. Client* search_client = 0;
  3032. if (search_name) {
  3033. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3034. if (!target) {
  3035. search_client = zone_list.GetClientByCharName(search_name);
  3036. if (search_client)
  3037. target = search_client->GetPlayer();
  3038. }
  3039. if (target)
  3040. GetPlayer()->SetTarget(target);
  3041. }
  3042. else
  3043. target = GetPlayer()->GetTarget();
  3044. if (target && target != GetPlayer()) {
  3045. GetPlayer()->SetX(target->GetX());
  3046. GetPlayer()->SetY(target->GetY());
  3047. GetPlayer()->SetZ(target->GetZ());
  3048. GetPlayer()->SetHeading(target->GetHeading());
  3049. GetPlayer()->SetLocation(target->GetLocation());
  3050. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  3051. }
  3052. else if (target)
  3053. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  3054. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  3055. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  3056. else if (target) {
  3057. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion());
  3058. if (app)
  3059. QueuePacket(app);
  3060. }
  3061. }
  3062. if (!target)
  3063. return false;
  3064. else
  3065. return true;
  3066. }
  3067. bool Client::CheckZoneAccess(const char* zoneName) {
  3068. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  3069. ZoneServer* zone = zone_list.Get(zoneName, false);
  3070. // JA: implemented /zone lock|unlock commands (2012.07.28)
  3071. if (zone && zone->GetZoneLockState())
  3072. {
  3073. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  3074. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  3075. return false;
  3076. }
  3077. sint16 zoneMinStatus = 0;
  3078. int16 zoneMinLevel = 0;
  3079. int16 zoneMaxLevel = 0;
  3080. int16 zoneMinVersion = 0;
  3081. if (!zone)
  3082. {
  3083. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  3084. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  3085. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  3086. return true;
  3087. }
  3088. }
  3089. else
  3090. {
  3091. zoneMinStatus = zone->GetMinimumStatus();
  3092. zoneMinLevel = zone->GetMinimumLevel();
  3093. zoneMaxLevel = zone->GetMaximumLevel();
  3094. zoneMinVersion = zone->GetMinimumVersion();
  3095. }
  3096. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  3097. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  3098. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  3099. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  3100. {
  3101. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  3102. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  3103. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  3104. return false;
  3105. }
  3106. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  3107. {
  3108. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3109. {
  3110. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3111. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  3112. return false;
  3113. }
  3114. }
  3115. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  3116. {
  3117. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3118. {
  3119. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3120. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  3121. return false;
  3122. }
  3123. }
  3124. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  3125. {
  3126. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  3127. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  3128. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  3129. {
  3130. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  3131. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  3132. return false;
  3133. }
  3134. }
  3135. return true;
  3136. }
  3137. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID) {
  3138. Zone(zone_list.GetByInstanceID(instanceid), set_coords);
  3139. }
  3140. void Client::Zone(ZoneServer* new_zone, bool set_coords) {
  3141. if (!new_zone) {
  3142. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  3143. return;
  3144. }
  3145. client_zoning = true;
  3146. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  3147. player->SetResurrecting(true);
  3148. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  3149. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  3150. // Remove players pet from zone if there is one
  3151. player->DismissPet((NPC*)player->GetPet());
  3152. player->DismissPet((NPC*)player->GetCharmedPet());
  3153. player->DismissPet((NPC*)player->GetDeityPet());
  3154. player->DismissPet((NPC*)player->GetCosmeticPet());
  3155. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  3156. GetCurrentZone()->RemoveSpawn(false, player, false);
  3157. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  3158. SetCurrentZone(new_zone);
  3159. if (player->GetGroupMemberInfo())
  3160. {
  3161. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  3162. player->UpdateGroupMemberInfo();
  3163. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  3164. }
  3165. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  3166. if (set_coords)
  3167. {
  3168. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  3169. __FUNCTION__,
  3170. GetCurrentZone()->GetSafeX(),
  3171. GetCurrentZone()->GetSafeY(),
  3172. GetCurrentZone()->GetSafeZ(),
  3173. GetCurrentZone()->GetSafeHeading(),
  3174. new_zone->GetZoneName()
  3175. );
  3176. player->SetX(GetCurrentZone()->GetSafeX());
  3177. player->SetY(GetCurrentZone()->GetSafeY());
  3178. player->SetZ(GetCurrentZone()->GetSafeZ());
  3179. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3180. }
  3181. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  3182. Save();
  3183. char* new_zone_ip = 0;
  3184. struct in_addr in;
  3185. in.s_addr = this->GetIP();
  3186. if (strncmp(inet_ntoa(in), "192.168", 7) == 0 && strlen(net.GetInternalWorldAddress()) > 0)
  3187. new_zone_ip = net.GetInternalWorldAddress();
  3188. else
  3189. new_zone_ip = net.GetWorldAddress();
  3190. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  3191. int32 key = Timer::GetUnixTimeStamp();
  3192. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  3193. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  3194. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  3195. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  3196. }
  3197. void Client::Zone(const char* new_zone, bool set_coords)
  3198. {
  3199. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  3200. Zone(zone_list.Get(new_zone), set_coords);
  3201. }
  3202. float Client::DistanceFrom(Client* client) {
  3203. float ret = 0;
  3204. if (client && client != this) {
  3205. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  3206. ret = sqrt(ret);
  3207. }
  3208. return ret;
  3209. }
  3210. void Client::DetermineCharacterUpdates() {
  3211. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  3212. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  3213. cdu->account_id = GetAccountID();
  3214. cdu->char_id = GetCharacterID();
  3215. int32 timestamp = Timer::GetUnixTimeStamp();
  3216. int8 flag = GetTimeStampFlag();
  3217. if (flag & LEVEL_UPDATE_FLAG)
  3218. {
  3219. cdu->update_field = LEVEL_UPDATE_FLAG;
  3220. cdu->update_data = player->GetLevel();
  3221. loginserver.SendPacket(outpack);
  3222. }
  3223. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  3224. if (flag & CLASS_UPDATE_FLAG)
  3225. {
  3226. cdu->update_field = CLASS_UPDATE_FLAG;
  3227. cdu->update_data = player->GetAdventureClass();
  3228. loginserver.SendPacket(outpack);
  3229. }
  3230. if (flag & GENDER_UPDATE_FLAG)
  3231. {
  3232. cdu->update_field = GENDER_UPDATE_FLAG;
  3233. cdu->update_data = player->GetGender();
  3234. loginserver.SendPacket(outpack);
  3235. }
  3236. if (flag & DELETE_UPDATE_FLAG) {
  3237. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3238. }
  3239. safe_delete(outpack); // Zone, armor and name use a different structure
  3240. if (flag & RACE_UPDATE_FLAG)
  3241. {
  3242. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  3243. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  3244. ru->account_id = GetAccountID();
  3245. ru->char_id = GetCharacterID();
  3246. ru->race = player->GetRace();
  3247. ru->model_type = player->GetModelType();
  3248. loginserver.SendPacket(outpack);
  3249. safe_delete(outpack);
  3250. }
  3251. if (flag & ZONE_UPDATE_FLAG) {
  3252. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  3253. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  3254. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  3255. czu->account_id = GetAccountID();
  3256. czu->char_id = GetCharacterID();
  3257. czu->zone_id = GetCurrentZone()->GetZoneID();
  3258. const char* zone_file = GetCurrentZone()->GetZoneFile();
  3259. czu->zone_length = strlen(zone_file);
  3260. if (czu->zone_length > 64)
  3261. czu->zone_length = 64;
  3262. strncpy(czu->new_zone, zone_file, czu->zone_length);
  3263. loginserver.SendPacket(outpack);
  3264. safe_delete(outpack);
  3265. }
  3266. if (flag & ARMOR_UPDATE_FLAG) {
  3267. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3268. }
  3269. if (flag & NAME_UPDATE_FLAG) {
  3270. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3271. }
  3272. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  3273. }
  3274. void Client::Save() {
  3275. if (GetCharacterID() == 0)
  3276. return;
  3277. if (current_zone) {
  3278. DetermineCharacterUpdates();
  3279. UpdateCharacterInstances();
  3280. database.Save(this);
  3281. if (GetPlayer()->UpdateQuickbarNeeded()) {
  3282. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  3283. GetPlayer()->ResetQuickbarNeeded();
  3284. }
  3285. database.SaveItems(this);
  3286. database.SaveBuyBacks(this);
  3287. GetPlayer()->SaveHistory();
  3288. GetPlayer()->SaveLUAHistory();
  3289. }
  3290. }
  3291. void Client::UpdateCharacterInstances() {
  3292. if (GetPlayer() != NULL)
  3293. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  3294. /*if ( GetPlayer() != NULL )
  3295. {
  3296. // determine the last timestamp then get a new one, determine the difference in the timestamp
  3297. // to use for applying the update to each instances timer
  3298. int32 lastSaveTS = GetLastSavedTimeStamp();
  3299. int32 newSaveTS = Timer::GetUnixTimeStamp();
  3300. int32 diffTS = newSaveTS - lastSaveTS;
  3301. // update instance timers
  3302. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  3303. // update with the new timestamp and save the db
  3304. this->SetLastSavedTimeStamp(newSaveTS);
  3305. }*/
  3306. }
  3307. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  3308. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  3309. if (packet) {
  3310. packet->LoadPacketData(app->pBuffer, app->size);
  3311. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  3312. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  3313. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  3314. vector<EntityCommand*> commands;
  3315. vector<EntityCommand*> delete_commands;
  3316. if (out && spawn) {
  3317. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  3318. {
  3319. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  3320. if (!spawn->primary_command_list[i]->default_allow_list)
  3321. {
  3322. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3323. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  3324. continue;
  3325. }
  3326. else
  3327. {
  3328. // default is allow list, only deny if added to the list as deny (false itr second)
  3329. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3330. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  3331. continue;
  3332. }
  3333. commands.push_back(spawn->primary_command_list[i]);
  3334. }
  3335. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  3336. commands.push_back(spawn->secondary_command_list[i]);
  3337. if (spawn->IsPlayer()) {
  3338. if (player->IsFriend(spawn->GetName()))
  3339. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  3340. else
  3341. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  3342. if (player->IsIgnored(spawn->GetName()))
  3343. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  3344. else
  3345. {
  3346. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  3347. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  3348. }
  3349. if (((Player*)spawn)->GetGroupMemberInfo()) {
  3350. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  3351. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  3352. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  3353. }
  3354. }
  3355. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  3356. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  3357. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  3358. }
  3359. out->setDataByName("spawn_id", spawn_id);
  3360. out->setArrayLengthByName("num_verbs", commands.size());
  3361. for (int32 i = 0; i < commands.size(); i++) {
  3362. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  3363. out->setArrayDataByName("distance", commands[i]->distance, i);
  3364. if (commands[i]->error_text.length() == 0)
  3365. out->setArrayAddToPacketByName("error", false, i);
  3366. else {
  3367. out->setArrayDataByName("display_error", 1, i);
  3368. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  3369. }
  3370. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  3371. }
  3372. EQ2Packet* outapp = out->serialize();
  3373. //DumpPacket(outapp);
  3374. QueuePacket(outapp);
  3375. safe_delete(out);
  3376. for (int32 i = 0; i < delete_commands.size(); i++) {
  3377. safe_delete(delete_commands[i]);
  3378. }
  3379. }
  3380. safe_delete(packet);
  3381. }
  3382. }
  3383. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  3384. if (previous_value != new_value) {
  3385. Message(CHANNEL_COLOR_SKILL, "You get %s at %s (%i/%i).", new_value > previous_value ? "better" : "worse", skill->name.data.c_str(), new_value, skill->max_val);
  3386. char tmp[200] = { 0 };
  3387. 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);
  3388. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75, 0xFF, 0xFF, 0xFF);
  3389. }
  3390. }
  3391. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  3392. {
  3393. /* JA notes on the unknown:
  3394. 2 = ding glimmer
  3395. 16 = Achievement Unlocked
  3396. 6 no longer does anything
  3397. */
  3398. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  3399. if (packet) {
  3400. packet->setDataByName("unknown", unknown);
  3401. packet->setMediumStringByName("text", text);
  3402. if (type && strlen(type) > 0)
  3403. packet->setMediumStringByName("message_type", type);
  3404. packet->setDataByName("size", size);
  3405. packet->setDataByName("red", red);
  3406. packet->setDataByName("green", green);
  3407. packet->setDataByName("blue", blue);
  3408. QueuePacket(packet->serialize());
  3409. safe_delete(packet);
  3410. }
  3411. }
  3412. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  3413. if (new_level < 1) {
  3414. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  3415. return;
  3416. }
  3417. if (player->GetLevel() != new_level) {
  3418. player->SetLevel(new_level);
  3419. if (player->GetGroupMemberInfo()) {
  3420. player->UpdateGroupMemberInfo();
  3421. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  3422. }
  3423. }
  3424. if (new_level > old_level)
  3425. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  3426. if (player->GetPet()) {
  3427. NPC* pet = (NPC*)player->GetPet();
  3428. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  3429. pet->SetLevel(new_level);
  3430. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3431. if (command_packet) {
  3432. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  3433. command_packet->setDataByName("anim_type", 1753);
  3434. QueuePacket(command_packet->serialize());
  3435. safe_delete(command_packet);
  3436. }
  3437. }
  3438. }
  3439. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  3440. if (level_update) {
  3441. level_update->setDataByName("old_level", old_level);
  3442. level_update->setDataByName("new_level", new_level);
  3443. QueuePacket(level_update->serialize());
  3444. safe_delete(level_update);
  3445. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  3446. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  3447. }
  3448. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3449. if (command_packet) {
  3450. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  3451. command_packet->setDataByName("anim_type", 1753);
  3452. QueuePacket(command_packet->serialize());
  3453. safe_delete(command_packet);
  3454. }
  3455. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  3456. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  3457. SendNewSpells(player->GetAdventureClass());
  3458. SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  3459. SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  3460. GetPlayer()->ChangePrimaryWeapon();
  3461. GetPlayer()->ChangeSecondaryWeapon();
  3462. GetPlayer()->ChangeRangedWeapon();
  3463. GetPlayer()->GetInfoStruct()->level = new_level;
  3464. // GetPlayer()->SetLevel(new_level);
  3465. 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__);
  3466. GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
  3467. GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
  3468. GetPlayer()->CalculateBonuses();
  3469. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  3470. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  3471. InfoStruct* info = player->GetInfoStruct();
  3472. info->agi_base = new_level * 2 + 15;
  3473. info->intel_base = new_level * 2 + 15;
  3474. info->wis_base = new_level * 2 + 15;
  3475. info->str_base = new_level * 2 + 15;
  3476. info->sta_base = new_level * 2 + 15;
  3477. info->cold_base = (int16)(new_level * 1.5 + 10);
  3478. info->heat_base = (int16)(new_level * 1.5 + 10);
  3479. info->disease_base = (int16)(new_level * 1.5 + 10);
  3480. info->mental_base = (int16)(new_level * 1.5 + 10);
  3481. info->magic_base = (int16)(new_level * 1.5 + 10);
  3482. info->divine_base = (int16)(new_level * 1.5 + 10);
  3483. info->poison_base = (int16)(new_level * 1.5 + 10);
  3484. GetPlayer()->SetHPRegen((int)(new_level * .75) + (int)(new_level / 10) + 3);
  3485. GetPlayer()->SetPowerRegen(new_level + (int)(new_level / 10) + 4);
  3486. GetPlayer()->GetInfoStruct()->poison_base = (int16)(new_level * 1.5 + 10);
  3487. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  3488. GetPlayer()->SetCharSheetChanged(true);
  3489. Message(CHANNEL_COLOR_EXP, "You are now level %i!", new_level);
  3490. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  3491. int16 new_skill_cap = 5 * new_level;
  3492. PlayerSkillList* player_skills = player->GetSkills();
  3493. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  3494. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  3495. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  3496. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  3497. if (new_level > player->GetTSLevel())
  3498. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  3499. Guild* guild = GetPlayer()->GetGuild();
  3500. if (guild) {
  3501. int8 event_type = 0;
  3502. if (new_level < 10)
  3503. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  3504. else if (new_level == 10)
  3505. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  3506. else if (new_level >= 11 && new_level < 20)
  3507. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  3508. else if (new_level == 20)
  3509. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  3510. else if (new_level >= 21 && new_level < 30)
  3511. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  3512. else if (new_level == 30)
  3513. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  3514. else if (new_level >= 31 && new_level < 40)
  3515. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  3516. else if (new_level == 40)
  3517. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  3518. else if (new_level >= 41 && new_level < 50)
  3519. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  3520. else if (new_level == 50)
  3521. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  3522. else if (new_level >= 51 && new_level < 60)
  3523. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  3524. else if (new_level == 60)
  3525. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  3526. else if (new_level >= 61 && new_level < 70)
  3527. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  3528. else if (new_level == 70)
  3529. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  3530. else if (new_level >= 71 && new_level < 80)
  3531. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  3532. else if (new_level == 80)
  3533. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  3534. 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());
  3535. 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());
  3536. guild->UpdateGuildMemberInfo(GetPlayer());
  3537. guild->SendGuildMember(GetPlayer());
  3538. guild->SendGuildMemberList();
  3539. }
  3540. // Need to send the trait list every time the players level changes
  3541. // Also need to force the char sheet update or else there can be a large delay from when you level
  3542. // to when you are actually able to select traits.
  3543. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  3544. QueuePacket(master_trait_list.GetTraitListPacket(this));
  3545. if (version > 546)
  3546. master_aa_list.DisplayAA(this, 0, 0);
  3547. if (GetPlayer()->SpawnedBots.size() > 0) {
  3548. map<int32, int32>::iterator itr;
  3549. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  3550. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  3551. if (bot && bot->IsBot())
  3552. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  3553. }
  3554. }
  3555. }
  3556. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  3557. if (new_level < 1) {
  3558. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  3559. return;
  3560. }
  3561. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  3562. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  3563. return;
  3564. }
  3565. if (new_level > old_level)
  3566. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  3567. if (player->GetTSLevel() != new_level) {
  3568. player->SetTSLevel(new_level);
  3569. if (player->GetGroupMemberInfo()) {
  3570. player->UpdateGroupMemberInfo();
  3571. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  3572. }
  3573. }
  3574. // Only tradeskill skills should increace, and then only those related to your class
  3575. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  3576. if (level_update) {
  3577. level_update->setDataByName("old_level", old_level);
  3578. level_update->setDataByName("new_level", new_level);
  3579. level_update->setDataByName("type", 1);
  3580. QueuePacket(level_update->serialize());
  3581. safe_delete(level_update);
  3582. }
  3583. // Need to make tradeskill versions of the following
  3584. //SendNewSpells(player->GetAdventureClass());
  3585. //SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  3586. //SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  3587. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3588. if (command_packet) {
  3589. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  3590. command_packet->setDataByName("anim_type", 1753);
  3591. QueuePacket(command_packet->serialize());
  3592. safe_delete(command_packet);
  3593. }
  3594. GetPlayer()->GetInfoStruct()->tradeskill_level = new_level;
  3595. GetPlayer()->SetTSLevel(new_level);
  3596. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  3597. GetPlayer()->SetCharSheetChanged(true);
  3598. Message(CHANNEL_COLOR_WHITE, "Your tradeskill level is now %i!", new_level);
  3599. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  3600. PlayerSkillList* player_skills = player->GetSkills();
  3601. int16 specialize_skill_cap = new_level * 5;
  3602. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  3603. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  3604. int8 ts_class = player->GetTradeskillClass();
  3605. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  3606. int32 skill_id_1, skill_id_2, skill_id_3;
  3607. switch (base_ts_class) {
  3608. case ARTISAN:
  3609. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3610. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3611. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3612. break;
  3613. case OUTFITTER:
  3614. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3615. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3616. skill_id_1 = SKILL_ID_TAILORING;
  3617. skill_id_2 = SKILL_ID_METALSHAPING;
  3618. skill_id_3 = SKILL_ID_METALWORKING;
  3619. if (ts_class == TAILOR) {
  3620. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3621. skill_id_1 = 0;
  3622. }
  3623. else if (ts_class == ARMORER) {
  3624. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3625. skill_id_2 = 0;
  3626. }
  3627. else if (ts_class == WEAPONSMITH) {
  3628. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3629. skill_id_3 = 0;
  3630. }
  3631. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3632. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3633. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3634. break;
  3635. case SCHOLAR:
  3636. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3637. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3638. skill_id_1 = SKILL_ID_SCRIBING;
  3639. skill_id_2 = SKILL_ID_CHEMISTRY;
  3640. skill_id_3 = SKILL_ID_ARTIFICING;
  3641. if (ts_class == SAGE) {
  3642. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3643. skill_id_1 = 0;
  3644. }
  3645. else if (ts_class == ALCHEMIST) {
  3646. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3647. skill_id_2 = 0;
  3648. }
  3649. else if (ts_class == JEWELER) {
  3650. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3651. skill_id_3 = 0;
  3652. }
  3653. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3654. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3655. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3656. break;
  3657. case CRAFTSMAN:
  3658. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3659. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3660. skill_id_1 = SKILL_ID_ARTISTRY;
  3661. skill_id_2 = SKILL_ID_FLETCHING;
  3662. skill_id_3 = SKILL_ID_SCULPTING;
  3663. if (ts_class == PROVISIONER) {
  3664. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3665. skill_id_1 = 0;
  3666. }
  3667. else if (ts_class == WOODWORKER) {
  3668. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3669. skill_id_2 = 0;
  3670. }
  3671. else if (ts_class == CARPENTER) {
  3672. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3673. skill_id_3 = 0;
  3674. }
  3675. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3676. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3677. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3678. break;
  3679. default:
  3680. break;
  3681. }
  3682. if (new_level > player->GetAdventureClass())
  3683. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  3684. Guild* guild = GetPlayer()->GetGuild();
  3685. if (guild) {
  3686. int8 event_type = 0;
  3687. if (new_level < 10)
  3688. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  3689. else if (new_level == 10)
  3690. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  3691. else if (new_level >= 11 && new_level < 20)
  3692. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  3693. else if (new_level == 20)
  3694. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  3695. else if (new_level >= 21 && new_level < 30)
  3696. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  3697. else if (new_level == 30)
  3698. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  3699. else if (new_level >= 31 && new_level < 40)
  3700. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  3701. else if (new_level == 40)
  3702. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  3703. else if (new_level >= 41 && new_level < 50)
  3704. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  3705. else if (new_level == 50)
  3706. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  3707. else if (new_level >= 51 && new_level < 60)
  3708. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  3709. else if (new_level == 60)
  3710. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  3711. else if (new_level >= 61 && new_level < 70)
  3712. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  3713. else if (new_level == 70)
  3714. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  3715. else if (new_level >= 71 && new_level < 80)
  3716. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  3717. else if (new_level == 80)
  3718. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  3719. 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());
  3720. 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());
  3721. guild->UpdateGuildMemberInfo(GetPlayer());
  3722. guild->SendGuildMember(GetPlayer());
  3723. guild->SendGuildMemberList();
  3724. }
  3725. // Need to send the trait list every time the players level changes
  3726. // Also need to force the char sheet update or else there can be a large delay from when you level
  3727. // to when you are actually able to select traits.
  3728. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  3729. QueuePacket(master_trait_list.GetTraitListPacket(this));
  3730. }
  3731. void Client::SendPendingLoot(int32 total_coins, Spawn* entity) {
  3732. if (entity)
  3733. Loot(total_coins, player->GetPendingLootItems(entity->GetID()), entity);
  3734. }
  3735. void Client::CloseLoot() {
  3736. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  3737. packet->setDataByName("window_id", 4);
  3738. EQ2Packet* outapp = packet->serialize();
  3739. //DumpPacket(outapp);
  3740. QueuePacket(outapp);
  3741. safe_delete(packet);
  3742. }
  3743. string Client::GetCoinMessage(int32 total_coins) {
  3744. if (total_coins == 0) {
  3745. return " 0 Copper";
  3746. }
  3747. char tmp[64] = { 0 };
  3748. string message = "";
  3749. int32 val = 0;
  3750. if (total_coins >= 1000000) {
  3751. val = total_coins / 1000000;
  3752. total_coins -= 1000000 * val;
  3753. sprintf(tmp, " %u Platinum", val);
  3754. message.append(tmp);
  3755. memset(tmp, 0, 64);
  3756. }
  3757. if (total_coins >= 10000) {
  3758. val = total_coins / 10000;
  3759. total_coins -= 10000 * val;
  3760. sprintf(tmp, " %u Gold", val);
  3761. message.append(tmp);
  3762. memset(tmp, 0, 64);
  3763. }
  3764. if (total_coins >= 100) {
  3765. val = total_coins / 100;
  3766. total_coins -= 100 * val;
  3767. sprintf(tmp, " %u Silver", val);
  3768. message.append(tmp);
  3769. memset(tmp, 0, 64);
  3770. }
  3771. if (total_coins > 0) {
  3772. sprintf(tmp, " %u Copper", (int32)total_coins);
  3773. message.append(tmp);
  3774. }
  3775. return message;
  3776. }
  3777. void Client::Loot(int32 total_coins, vector<Item*>* items, Spawn* entity) {
  3778. if (!entity) {
  3779. CloseLoot();
  3780. return;
  3781. }
  3782. if (total_coins > 0) {
  3783. player->AddCoins(total_coins);
  3784. //PlaySound("coin_cha_ching");
  3785. string message = "";
  3786. if (entity->GetHP() == 0) {
  3787. message = "You loot ";
  3788. entity->SetLootCoins(0);
  3789. }
  3790. else
  3791. message = "You receive ";
  3792. message.append(GetCoinMessage(total_coins));
  3793. if (entity->GetHP() == 0)
  3794. message.append(" from the corpse of ").append(entity->GetName());
  3795. int8 type = CHANNEL_COLOR_LOOT;
  3796. if (GetVersion() >= 1208)
  3797. type = CHANNEL_LOOT;
  3798. else if (GetVersion() >= 973)
  3799. type = CHANNEL_COLOR_NEW_LOOT;
  3800. SimpleMessage(type, message.c_str());
  3801. }
  3802. if (!items || items->size() == 0)
  3803. CloseLoot();
  3804. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  3805. if (packet) {
  3806. vector<Item*>::iterator itr;
  3807. int32 packet_size = 0;
  3808. EQ2Packet* outapp = 0;
  3809. uchar* data = 0;
  3810. if (GetVersion() >= 284) {
  3811. if (GetVersion() > 546) {
  3812. if (items && items->size() > 0) {
  3813. packet->setDataByName("loot_count", items->size());
  3814. packet->setDataByName("display", 1);
  3815. }
  3816. packet->setDataByName("loot_type", 1);
  3817. if (version >= 1096)
  3818. packet->setDataByName("lotto_timeout", 0x78);
  3819. else
  3820. packet->setDataByName("lotto_timeout", 0x3C);
  3821. packet->setDataByName("loot_id", entity->GetID());
  3822. EQ2Packet* tmpPacket = packet->serialize();
  3823. packet_size += tmpPacket->size;
  3824. if (items && items->size() > 0) {
  3825. data = new uchar[items->size() * 1000 + packet_size];
  3826. memset(data, 0, items->size() * 1000 + packet_size);
  3827. }
  3828. else {
  3829. data = new uchar[packet_size];
  3830. memset(data, 0, packet_size);
  3831. }
  3832. uchar* ptr = data;
  3833. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  3834. ptr += tmpPacket->size;
  3835. safe_delete(tmpPacket);
  3836. Item* item = 0;
  3837. if (items && items->size() > 0) {
  3838. for (itr = items->begin(); itr != items->end(); itr++) {
  3839. item = *itr;
  3840. memcpy(ptr, &item->details.item_id, sizeof(int32));
  3841. ptr += sizeof(int32);
  3842. packet_size += sizeof(int32);
  3843. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  3844. int8 offset = 0;
  3845. if (GetVersion() >= 1188) {
  3846. offset = 13;
  3847. }
  3848. else if (GetVersion() >= 860) {
  3849. offset = 11;
  3850. }
  3851. else if (GetVersion() <= 546) {
  3852. offset = 19;
  3853. }
  3854. else {
  3855. offset = 10;
  3856. }
  3857. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  3858. ptr += tmpPacket->size - offset;
  3859. packet_size += tmpPacket->size - offset;
  3860. safe_delete(tmpPacket);
  3861. }
  3862. }
  3863. packet_size -= sizeof(int32);
  3864. memcpy(data, &packet_size, sizeof(int32));
  3865. packet_size += sizeof(int32);
  3866. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  3867. }
  3868. else {
  3869. if (items->size() > 0) {
  3870. packet->setArrayLengthByName("loot_count", items->size());
  3871. Item* item = 0;
  3872. if (items && items->size() > 0) {
  3873. int i = 0;
  3874. for (itr = items->begin(); itr != items->end(); itr++) {
  3875. item = *itr;
  3876. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  3877. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  3878. i++;
  3879. }
  3880. }
  3881. packet->setDataByName("display", 1);
  3882. }
  3883. packet->setDataByName("loot_type", 1); // normal
  3884. packet->setDataByName("lotto_timeout", 0x3c); // 60 seconds
  3885. packet->setDataByName("spawn_id", entity->GetID());
  3886. outapp = packet->serialize();
  3887. }
  3888. }
  3889. else {
  3890. if (items && items->size() > 0) {
  3891. packet->setArrayLengthByName("loot_count", items->size());
  3892. for (int i = 0; i < items->size(); i++) {
  3893. Item* item = (*items)[i];
  3894. packet->setArrayDataByName("name", item->name.c_str(), i);
  3895. packet->setArrayDataByName("item_id", item->details.item_id, i);
  3896. packet->setArrayDataByName("count", item->details.count, i);
  3897. packet->setArrayDataByName("icon", item->details.icon, i);
  3898. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  3899. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  3900. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  3901. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  3902. else
  3903. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  3904. }
  3905. }
  3906. packet->setDataByName("object_id", entity->GetID());
  3907. packet->setDataByName("unknown3", 1);
  3908. packet->setDataByName("unknown4", 1);
  3909. packet->setDataByName("unknown5", 60);
  3910. outapp = packet->serialize();
  3911. }
  3912. if (outapp) {
  3913. DumpPacket(outapp);
  3914. QueuePacket(outapp);
  3915. }
  3916. safe_delete_array(data);
  3917. safe_delete(packet);
  3918. }
  3919. }
  3920. void Client::Loot(Spawn* entity, bool attemptDisarm) {
  3921. if (entity->IsNPC() && ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  3922. int32 total_coins = entity->GetLootCoins();
  3923. entity->LockLoot();
  3924. Loot(total_coins, entity->GetLootItems(), entity);
  3925. entity->UnlockLoot();
  3926. OpenChest(entity, attemptDisarm);
  3927. }
  3928. else
  3929. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  3930. }
  3931. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  3932. {
  3933. if (!entity)
  3934. return;
  3935. int8 chest_difficulty = 0;
  3936. int32 state = 0;
  3937. // Check for the chest and set the action state
  3938. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  3939. string modelName;
  3940. if (entity->GetModelType() == 4034) {
  3941. // small chest, open with copper coins
  3942. // does not include traps, however can be disarmed
  3943. chest_difficulty = 1;
  3944. state = 11899;
  3945. modelName.append("Small Chest");
  3946. }
  3947. else if (entity->GetModelType() == 5864) {
  3948. // treasure chest, open with silver coins
  3949. chest_difficulty = 2;
  3950. state = 11901;
  3951. modelName.append("Treasure Chest");
  3952. }
  3953. else if (entity->GetModelType() == 5865) {
  3954. // ornate chest, open with gold coins
  3955. chest_difficulty = 3;
  3956. state = 11900;
  3957. modelName.append("Ornate Chest");
  3958. }
  3959. else if (entity->GetModelType() == 4015) {
  3960. // exquisite chest, open with gold coins and jewels as well as a glow effect
  3961. chest_difficulty = 5;
  3962. state = 11898;
  3963. modelName.append("Exquisite Chest");
  3964. }
  3965. bool firstChestOpen = false;
  3966. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  3967. {
  3968. ChestTrap::ChestTrapInfo nextTrap;
  3969. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  3970. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  3971. firstChestOpen = true;
  3972. entity->SetTrapTriggered(true);
  3973. if (ret)
  3974. {
  3975. if (disarmSkill && attemptDisarm)
  3976. {
  3977. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  3978. {
  3979. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  3980. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  3981. Message(CHANNEL_COLOR_WHITE, "You trigger the trap on %s!", modelName.c_str());
  3982. }
  3983. else
  3984. {
  3985. Message(CHANNEL_COLOR_WHITE, "You disarm the trap on %s", modelName.c_str());
  3986. }
  3987. // despite fail/succeed we should always try to increase skill if disarm is available
  3988. GetPlayer()->GetSkillByName("Disarm Trap", true);
  3989. }
  3990. else // no disarm skill, always fail
  3991. {
  3992. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  3993. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  3994. Message(CHANNEL_COLOR_WHITE, "You trigger the trap on %s!", modelName.c_str());
  3995. }
  3996. }
  3997. }
  3998. else if (!entity->HasTrapTriggered())
  3999. {
  4000. firstChestOpen = true;
  4001. entity->SetTrapTriggered(true);
  4002. }
  4003. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  4004. // for those in range the SendStateCommand will cause it to animate open.
  4005. // TODO: when player enters radius that does not have visual state, update visual state
  4006. if (firstChestOpen)
  4007. entity->SetVisualState(state, false);
  4008. GetCurrentZone()->SendStateCommand(entity, state);
  4009. }
  4010. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  4011. {
  4012. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  4013. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  4014. if (source == NULL)
  4015. source = (Entity*)GetPlayer();
  4016. if (spell)
  4017. {
  4018. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  4019. if (gmi && gmi->group_id)
  4020. {
  4021. deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(gmi->group_id);
  4022. for (int8 i = 0; i < members->size(); i++) {
  4023. Entity* member = members->at(i)->member;
  4024. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  4025. continue;
  4026. // if we have a radius provided then check if the group member is outside the radius or not
  4027. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  4028. continue;
  4029. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4030. }
  4031. }
  4032. else
  4033. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4034. }
  4035. }
  4036. Spawn* Client::GetBanker() {
  4037. return banker;
  4038. }
  4039. void Client::SetBanker(Spawn* in_banker) {
  4040. banker = in_banker;
  4041. }
  4042. void Client::Bank(Spawn* banker, bool cancel) {
  4043. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  4044. if (!cancel)
  4045. SetBanker(banker);
  4046. else
  4047. SetBanker(0);
  4048. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  4049. if (packet) {
  4050. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  4051. int64 coins = GetPlayer()->GetInfoStruct()->bank_coin_copper + GetPlayer()->GetInfoStruct()->bank_coin_silver * 100 +
  4052. GetPlayer()->GetInfoStruct()->bank_coin_gold * 10000 + (int64)GetPlayer()->GetInfoStruct()->bank_coin_plat * 1000000;
  4053. int32 coins1, coins2;
  4054. coins1 = ((int32*)&coins)[0];
  4055. coins2 = ((int32*)&coins)[1];
  4056. packet->setDataByName("bank_coins", coins1);
  4057. packet->setDataByName("bank_coins2", coins2);
  4058. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->coin_copper);
  4059. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->coin_silver);
  4060. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->coin_gold);
  4061. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->coin_plat);
  4062. if (!cancel)
  4063. packet->setDataByName("display", 1);
  4064. QueuePacket(packet->serialize());
  4065. safe_delete(packet);
  4066. }
  4067. }
  4068. }
  4069. void Client::BankWithdrawal(int64 amount) {
  4070. bool cheater = false;
  4071. if (GetBanker() && amount > 0) {
  4072. string withdrawal = "";
  4073. char withdrawal_data[512] = { 0 };
  4074. int32 tmp = 0;
  4075. if (amount >= 1000000) {
  4076. tmp = amount / 1000000;
  4077. if (tmp > GetPlayer()->GetBankCoinsPlat())
  4078. cheater = true;
  4079. else {
  4080. GetPlayer()->GetInfoStruct()->bank_coin_plat -= tmp;
  4081. GetPlayer()->GetInfoStruct()->coin_plat += tmp;
  4082. amount -= (int64)tmp * 1000000;
  4083. sprintf(withdrawal_data, "%u Platinum ", tmp);
  4084. withdrawal.append(withdrawal_data);
  4085. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4086. }
  4087. }
  4088. if (!cheater && amount >= 10000) {
  4089. tmp = amount / 10000;
  4090. if (tmp > GetPlayer()->GetBankCoinsGold())
  4091. cheater = true;
  4092. else {
  4093. GetPlayer()->GetInfoStruct()->bank_coin_gold -= tmp;
  4094. if ((GetPlayer()->GetInfoStruct()->coin_gold + tmp) > 100) {
  4095. GetPlayer()->GetInfoStruct()->coin_gold = (GetPlayer()->GetInfoStruct()->coin_gold + tmp) - 100;
  4096. GetPlayer()->GetInfoStruct()->coin_plat += 1;
  4097. }
  4098. else
  4099. GetPlayer()->GetInfoStruct()->coin_gold += tmp;
  4100. amount -= tmp * 10000;
  4101. sprintf(withdrawal_data, "%u Gold ", tmp);
  4102. withdrawal.append(withdrawal_data);
  4103. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4104. }
  4105. }
  4106. if (!cheater && amount >= 100) {
  4107. tmp = amount / 100;
  4108. if (tmp > GetPlayer()->GetBankCoinsSilver())
  4109. cheater = true;
  4110. else {
  4111. GetPlayer()->GetInfoStruct()->bank_coin_silver -= tmp;
  4112. if ((GetPlayer()->GetInfoStruct()->coin_silver + tmp) > 100) {
  4113. GetPlayer()->GetInfoStruct()->coin_silver = (GetPlayer()->GetInfoStruct()->coin_silver + tmp) - 100;
  4114. GetPlayer()->GetInfoStruct()->coin_gold += 1;
  4115. }
  4116. else
  4117. GetPlayer()->GetInfoStruct()->coin_silver += tmp;
  4118. amount -= tmp * 100;
  4119. sprintf(withdrawal_data, "%u Silver ", tmp);
  4120. withdrawal.append(withdrawal_data);
  4121. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4122. }
  4123. }
  4124. if (!cheater) {
  4125. if (amount > 0) {
  4126. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  4127. withdrawal.append(withdrawal_data);
  4128. GetPlayer()->GetInfoStruct()->bank_coin_copper -= amount;
  4129. if ((GetPlayer()->GetInfoStruct()->coin_copper + amount) > 100) {
  4130. GetPlayer()->GetInfoStruct()->coin_copper = (GetPlayer()->GetInfoStruct()->coin_copper + amount) - 100;
  4131. GetPlayer()->GetInfoStruct()->coin_silver += 1;
  4132. }
  4133. else
  4134. GetPlayer()->GetInfoStruct()->coin_copper += amount;
  4135. }
  4136. if (withdrawal.length() > 0) {
  4137. withdrawal.append("withdrawn ");
  4138. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->bank_coin_plat,
  4139. GetPlayer()->GetInfoStruct()->bank_coin_gold, GetPlayer()->GetInfoStruct()->bank_coin_silver, GetPlayer()->GetInfoStruct()->bank_coin_copper);
  4140. withdrawal.append(withdrawal_data);
  4141. SimpleMessage(CHANNEL_COLOR_REVIVE, withdrawal.c_str());
  4142. }
  4143. }
  4144. else
  4145. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4146. player->SetCharSheetChanged(true);
  4147. Bank(banker);
  4148. }
  4149. }
  4150. void Client::BankDeposit(int64 amount) {
  4151. bool cheater = false;
  4152. if (GetBanker() && amount > 0) {
  4153. int32 tmp = 0;
  4154. char deposit_data[512] = { 0 };
  4155. string deposit = "";
  4156. if (amount >= 1000000) {
  4157. tmp = amount / 1000000;
  4158. if (tmp > GetPlayer()->GetCoinsPlat())
  4159. cheater = true;
  4160. else {
  4161. GetPlayer()->GetInfoStruct()->bank_coin_plat += tmp;
  4162. GetPlayer()->GetInfoStruct()->coin_plat -= tmp;
  4163. amount -= (int64)tmp * 1000000;
  4164. sprintf(deposit_data, "%u Platinum ", tmp);
  4165. deposit.append(deposit_data);
  4166. memset(deposit_data, 0, sizeof(deposit_data));
  4167. }
  4168. }
  4169. if (!cheater && amount >= 10000) {
  4170. tmp = amount / 10000;
  4171. if (tmp > GetPlayer()->GetCoinsGold())
  4172. cheater = true;
  4173. else {
  4174. if ((GetPlayer()->GetInfoStruct()->bank_coin_gold + tmp) > 100) {
  4175. GetPlayer()->GetInfoStruct()->bank_coin_gold = (GetPlayer()->GetInfoStruct()->bank_coin_gold + tmp) - 100;
  4176. GetPlayer()->GetInfoStruct()->bank_coin_plat += 1;
  4177. }
  4178. else
  4179. GetPlayer()->GetInfoStruct()->bank_coin_gold += tmp;
  4180. GetPlayer()->GetInfoStruct()->coin_gold -= tmp;
  4181. amount -= tmp * 10000;
  4182. sprintf(deposit_data, "%u Gold ", tmp);
  4183. deposit.append(deposit_data);
  4184. memset(deposit_data, 0, sizeof(deposit_data));
  4185. }
  4186. }
  4187. if (!cheater && amount >= 100) {
  4188. tmp = amount / 100;
  4189. if (tmp > GetPlayer()->GetCoinsSilver())
  4190. cheater = true;
  4191. else {
  4192. if ((GetPlayer()->GetInfoStruct()->bank_coin_silver + tmp) > 100) {
  4193. GetPlayer()->GetInfoStruct()->bank_coin_silver = (GetPlayer()->GetInfoStruct()->bank_coin_silver + tmp) - 100;
  4194. GetPlayer()->GetInfoStruct()->bank_coin_gold += 1;
  4195. }
  4196. else
  4197. GetPlayer()->GetInfoStruct()->bank_coin_silver += tmp;
  4198. GetPlayer()->GetInfoStruct()->coin_silver -= tmp;
  4199. amount -= tmp * 100;
  4200. sprintf(deposit_data, "%u Silver ", tmp);
  4201. deposit.append(deposit_data);
  4202. memset(deposit_data, 0, sizeof(deposit_data));
  4203. }
  4204. }
  4205. if (!cheater) {
  4206. if (amount > 0) {
  4207. sprintf(deposit_data, "%u Copper ", (int32)amount);
  4208. deposit.append(deposit_data);
  4209. if ((GetPlayer()->GetInfoStruct()->bank_coin_copper + amount) > 100) {
  4210. GetPlayer()->GetInfoStruct()->bank_coin_copper = (GetPlayer()->GetInfoStruct()->bank_coin_copper + amount) - 100;
  4211. GetPlayer()->GetInfoStruct()->bank_coin_silver += 1;
  4212. }
  4213. else
  4214. GetPlayer()->GetInfoStruct()->bank_coin_copper += amount;
  4215. GetPlayer()->GetInfoStruct()->coin_copper -= amount;
  4216. }
  4217. if (deposit.length() > 0) {
  4218. deposit.append("deposited ");
  4219. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->bank_coin_plat,
  4220. GetPlayer()->GetInfoStruct()->bank_coin_gold, GetPlayer()->GetInfoStruct()->bank_coin_silver, GetPlayer()->GetInfoStruct()->bank_coin_copper);
  4221. deposit.append(deposit_data);
  4222. SimpleMessage(CHANNEL_COLOR_REVIVE, deposit.c_str());
  4223. }
  4224. }
  4225. else
  4226. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4227. player->SetCharSheetChanged(true);
  4228. Bank(banker);
  4229. }
  4230. }
  4231. void Client::AddPendingQuestReward(Quest* quest) {
  4232. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4233. quest_pending_reward.push_back(quest);
  4234. quest_updates = true;
  4235. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4236. }
  4237. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  4238. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4239. quest_pending_updates[quest_id][step_id] = progress;
  4240. quest_updates = true;
  4241. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4242. }
  4243. void Client::ProcessQuestUpdates() {
  4244. if (quest_pending_updates.size() > 0) {
  4245. map<int32, map<int32, int32> > tmp_quest_updates;
  4246. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4247. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  4248. quest_pending_updates.clear();
  4249. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4250. map<int32, map<int32, int32> >::iterator quest_itr;
  4251. map<int32, int32>::iterator step_itr;
  4252. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  4253. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  4254. if (step_itr->second == 0xFFFFFFFF) {
  4255. SetStepComplete(quest_itr->first, step_itr->first);
  4256. player->SendQuestRequiredSpawns(quest_itr->first);
  4257. }
  4258. else
  4259. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  4260. }
  4261. }
  4262. }
  4263. if (quest_pending_reward.size() > 0) {
  4264. vector<Quest*>::iterator itr;
  4265. vector<Quest*> tmp_quest_rewards;
  4266. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4267. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.end());
  4268. quest_pending_reward.clear();
  4269. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4270. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end(); itr++) {
  4271. GiveQuestReward(*itr);
  4272. }
  4273. }
  4274. quest_updates = false;
  4275. }
  4276. void Client::CheckQuestQueue() {
  4277. MQuestQueue.writelock();
  4278. last_update_time = 0;
  4279. vector<QueuedQuest*>::iterator itr;
  4280. QueuedQuest* queued_quest = 0;
  4281. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  4282. queued_quest = *itr;
  4283. SendQuestUpdateStepImmediately(queued_quest->quest, queued_quest->step, queued_quest->display_quest_helper);
  4284. safe_delete(queued_quest);
  4285. }
  4286. quest_queue.clear();
  4287. MQuestQueue.releasewritelock();
  4288. }
  4289. void Client::SetStepComplete(int32 quest_id, int32 step) {
  4290. Quest* quest = player->SetStepComplete(quest_id, step);
  4291. if (quest) {
  4292. SendQuestUpdate(quest);
  4293. GetCurrentZone()->SendQuestUpdates(this);
  4294. }
  4295. }
  4296. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  4297. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  4298. if (quest) {
  4299. SendQuestUpdate(quest);
  4300. GetCurrentZone()->SendQuestUpdates(this);
  4301. }
  4302. }
  4303. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  4304. bool hadUpdates = false;
  4305. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  4306. if (quest_updates) {
  4307. for (int32 i = 0; i < quest_updates->size(); i++)
  4308. {
  4309. SendQuestUpdate(quest_updates->at(i));
  4310. hadUpdates = true;
  4311. }
  4312. }
  4313. safe_delete(quest_updates);
  4314. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4315. if (quest_failures) {
  4316. for (int32 i = 0; i < quest_failures->size(); i++)
  4317. {
  4318. SendQuestFailure(quest_failures->at(i));
  4319. hadUpdates = true;
  4320. }
  4321. }
  4322. safe_delete(quest_failures);
  4323. if (hadUpdates)
  4324. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4325. }
  4326. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  4327. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  4328. if (quest_updates) {
  4329. for (int32 i = 0; i < quest_updates->size(); i++)
  4330. SendQuestUpdate(quest_updates->at(i));
  4331. GetCurrentZone()->SendQuestUpdates(this);
  4332. }
  4333. safe_delete(quest_updates);
  4334. }
  4335. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  4336. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  4337. if (quest_updates) {
  4338. for (int32 i = 0; i < quest_updates->size(); i++)
  4339. SendQuestUpdate(quest_updates->at(i));
  4340. }
  4341. safe_delete(quest_updates);
  4342. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4343. if (quest_failures) {
  4344. for (int32 i = 0; i < quest_failures->size(); i++)
  4345. SendQuestFailure(quest_failures->at(i));
  4346. }
  4347. safe_delete(quest_failures);
  4348. }
  4349. void Client::CheckPlayerQuestsLocationUpdate() {
  4350. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  4351. if (quest_updates) {
  4352. for (int32 i = 0; i < quest_updates->size(); i++)
  4353. SendQuestUpdate(quest_updates->at(i));
  4354. }
  4355. safe_delete(quest_updates);
  4356. }
  4357. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  4358. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  4359. if (quest_updates) {
  4360. for (int32 i = 0; i < quest_updates->size(); i++)
  4361. SendQuestUpdate(quest_updates->at(i));
  4362. }
  4363. safe_delete(quest_updates);
  4364. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4365. if (quest_failures) {
  4366. for (int32 i = 0; i < quest_failures->size(); i++)
  4367. SendQuestFailure(quest_failures->at(i));
  4368. }
  4369. safe_delete(quest_failures);
  4370. }
  4371. void Client::AddPendingQuest(Quest* quest) {
  4372. if (version <= 283) { //this client doesn't ask if you want the quest, so auto accept
  4373. AcceptQuest(quest->GetQuestID());
  4374. }
  4375. else {
  4376. player->pending_quests[quest->GetQuestID()] = quest;
  4377. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  4378. //DumpPacket(outapp);
  4379. QueuePacket(outapp);
  4380. }
  4381. }
  4382. Quest* Client::GetActiveQuest(int32 quest_id) {
  4383. if (player->player_quests.count(quest_id) > 0) {
  4384. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u active quests for char_id: %u", player->player_quests.count(quest_id), player->GetCharacterID());
  4385. return player->player_quests[quest_id];
  4386. }
  4387. return 0;
  4388. }
  4389. void Client::AcceptQuest(int32 id) {
  4390. Quest* quest = GetPendingQuest(id);
  4391. if (quest) {
  4392. RemovePendingQuest(quest);
  4393. AddPlayerQuest(quest);
  4394. GetCurrentZone()->SendQuestUpdates(this);
  4395. // If character has already completed this quest once update the given date in the database
  4396. if (GetPlayer()->GetCompletedPlayerQuests()->count(id) > 0) {
  4397. Quest* quest2 = GetPlayer()->GetCompletedQuest(id);
  4398. if (quest2)
  4399. quest->SetCompleteCount(quest2->GetCompleteCount());
  4400. database.SaveCharRepeatableQuest(this, id, quest->GetCompleteCount());
  4401. }
  4402. }
  4403. }
  4404. Quest* Client::GetPendingQuest(int32 id) {
  4405. if (player->pending_quests.count(id) > 0) {
  4406. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u pending quests for char_id: %u", player->pending_quests.count(id), player->GetCharacterID());
  4407. return player->pending_quests[id];
  4408. }
  4409. return 0;
  4410. }
  4411. void Client::RemovePendingQuest(Quest* quest) {
  4412. player->pending_quests.erase(quest->GetQuestID());
  4413. }
  4414. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  4415. if (!quest || !progress) {
  4416. return;
  4417. }
  4418. map<int32, int32>::iterator itr;
  4419. QuestStep* step = 0;
  4420. player->SetZone(GetCurrentZone());
  4421. for (itr = progress->begin(); itr != progress->end(); itr++) {
  4422. step = quest->GetQuestStep(itr->first);
  4423. if (step && itr->second > 0) {
  4424. step->SetStepProgress(itr->second);
  4425. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  4426. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  4427. }
  4428. }
  4429. }
  4430. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  4431. if (player->player_quests.count(quest->GetQuestID()) > 0) {
  4432. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  4433. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  4434. RemovePlayerQuest(quest->GetQuestID(), false, false);
  4435. }
  4436. player->player_quests[quest->GetQuestID()] = quest;
  4437. quest->SetPlayer(player);
  4438. current_quest_id = quest->GetQuestID();
  4439. if (send_packets && quest->GetQuestGiver() > 0)
  4440. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  4441. if (lua_interface && call_accepted)
  4442. lua_interface->CallQuestFunction(quest, "Accepted", player);
  4443. if (send_packets) {
  4444. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4445. //SendQuestJournal();
  4446. SendQuestJournalUpdate(quest);
  4447. // sent twice to match live
  4448. quest->SetTracked(false);
  4449. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  4450. quest->SetTracked(true);
  4451. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  4452. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4453. }
  4454. //This isn't during a load screen, so update spawns with required quests
  4455. if (call_accepted)
  4456. player->SendQuestRequiredSpawns(quest->GetQuestID());
  4457. }
  4458. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  4459. if (current_quest_id == id)
  4460. current_quest_id = 0;
  4461. if (player->player_quests.count(id) > 0) {
  4462. if (delete_quest) {
  4463. player->player_quests[id]->SetDeleted(true);
  4464. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  4465. }
  4466. if (send_update && player->player_quests[id]->GetQuestGiver() > 0)
  4467. GetCurrentZone()->SendSpawnChangesByDBID(player->player_quests[id]->GetQuestGiver(), this, false, true);
  4468. if (send_update) {
  4469. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4470. SendQuestJournal();
  4471. }
  4472. player->RemoveQuest(id, delete_quest);
  4473. if (send_update) {
  4474. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4475. SendQuestJournal();
  4476. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4477. }
  4478. }
  4479. }
  4480. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  4481. if (quest) {
  4482. QuestStep* quest_step = quest->GetQuestStep(step);
  4483. if (quest_step) {
  4484. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  4485. quest_step->WasUpdated(false);
  4486. }
  4487. }
  4488. }
  4489. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  4490. QueuedQuest* item = new QueuedQuest;
  4491. item->quest = quest;
  4492. item->step = step;
  4493. item->display_quest_helper = display_quest_helper;
  4494. MQuestQueue.writelock();
  4495. quest_queue.push_back(item);
  4496. last_update_time = Timer::GetCurrentTime2();
  4497. MQuestQueue.releasewritelock();
  4498. }
  4499. void Client::SendQuestFailure(Quest* quest) {
  4500. vector<QuestStep*>* failures = quest->GetQuestFailures();
  4501. if (failures) {
  4502. QuestStep* step = 0;
  4503. for (int32 i = 0; i < failures->size(); i++) {
  4504. step = failures->at(i);
  4505. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  4506. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4507. SendQuestJournal();
  4508. }
  4509. failures->clear();
  4510. }
  4511. }
  4512. void Client::SendQuestUpdate(Quest* quest) {
  4513. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  4514. if (updates) {
  4515. QuestStep* step = 0;
  4516. for (int32 i = 0; i < updates->size(); i++) {
  4517. step = updates->at(i);
  4518. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  4519. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  4520. if (step->WasUpdated()) {
  4521. SendQuestJournal();
  4522. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  4523. }
  4524. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4525. }
  4526. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction())
  4527. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  4528. if (quest->GetCompleted()) {
  4529. if (quest->GetQuestReturnNPC() > 0)
  4530. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  4531. if (quest->GetCompletedFlag())
  4532. quest->SetCompletedFlag(false);
  4533. }
  4534. updates->clear();
  4535. }
  4536. }
  4537. void Client::SendQuestJournal(bool all_quests, Client* client) {
  4538. if (!client)
  4539. client = this;
  4540. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id);
  4541. if (packet) {
  4542. EQ2Packet* outapp = packet->serialize();
  4543. //DumpPacket(outapp);
  4544. client->QueuePacket(outapp);
  4545. safe_delete(packet);
  4546. }
  4547. }
  4548. void Client::SendQuestJournalUpdate(Quest* quest) {
  4549. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC());
  4550. if (packet) {
  4551. QueuePacket(packet->serialize());
  4552. safe_delete(packet);
  4553. }
  4554. }
  4555. void Client::ReloadQuests() {
  4556. vector<int32> ids = player->GetQuestIDs();
  4557. Quest* quest = 0;
  4558. for (int32 i = 0; i < ids.size(); i++) {
  4559. quest = master_quest_list.GetQuest(ids[i]);
  4560. if (quest)
  4561. AddPlayerQuest(quest, false);
  4562. else
  4563. RemovePlayerQuest(ids[i]);
  4564. }
  4565. }
  4566. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  4567. bool found_quest = false;
  4568. vector<Quest*>::iterator itr;
  4569. vector<Item*>* items = 0;
  4570. Quest* quest = 0;
  4571. MPendingQuestAccept.lock();
  4572. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end(); itr++) {
  4573. quest = *itr;
  4574. items = quest->GetSelectableRewardItems();
  4575. if (items && items->size() > 0) {
  4576. for (int32 i = 0; i < items->size(); i++) {
  4577. if (items->at(i)->details.item_id == item_id) {
  4578. found_quest = true;
  4579. break;
  4580. }
  4581. }
  4582. }
  4583. else if (item_id == 0)
  4584. found_quest = true;
  4585. if (found_quest) {
  4586. pending_quest_accept.erase(itr);
  4587. break;
  4588. }
  4589. }
  4590. MPendingQuestAccept.unlock();
  4591. if (found_quest)
  4592. return quest;
  4593. return 0;
  4594. }
  4595. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  4596. int8 num_slots_needed = 0;
  4597. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  4598. Item* master_item = 0;
  4599. if (item_id > 0) {
  4600. num_slots_needed++;
  4601. master_item = master_item_list.GetItem(item_id);
  4602. }
  4603. vector<Item*>* items = quest->GetRewardItems();
  4604. if (items && items->size() > 0)
  4605. num_slots_needed += items->size();
  4606. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= items->size())) {
  4607. if (master_item)
  4608. AddItem(item_id);
  4609. if (items && items->size() > 0) {
  4610. for (int32 i = 0; i < items->size(); i++)
  4611. AddItem(new Item(items->at(i)));
  4612. }
  4613. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  4614. if (outapp)
  4615. QueuePacket(outapp);
  4616. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  4617. map<int32, sint32>::iterator itr;
  4618. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  4619. int32 faction_id = itr->first;
  4620. sint32 amount = itr->second;
  4621. if (amount > 0)
  4622. player->GetFactions()->IncreaseFaction(faction_id, amount);
  4623. else
  4624. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  4625. }
  4626. }
  4627. else {
  4628. MPendingQuestAccept.lock();
  4629. pending_quest_accept.push_back(quest);
  4630. MPendingQuestAccept.unlock();
  4631. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  4632. DisplayQuestComplete(quest);
  4633. }
  4634. }
  4635. void Client::DisplayQuestComplete(Quest* quest) {
  4636. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  4637. if (packet) {
  4638. packet->setDataByName("title", "Quest Reward!");
  4639. packet->setDataByName("name", quest->GetName());
  4640. packet->setDataByName("description", quest->GetDescription());
  4641. packet->setDataByName("level", quest->GetLevel());
  4642. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  4643. int8 difficulty = 0;
  4644. if ((string)quest->GetType() == "Tradeskill")
  4645. difficulty = player->GetTSArrowColor(quest->GetLevel());
  4646. else
  4647. difficulty = player->GetArrowColor(quest->GetLevel());
  4648. packet->setDataByName("difficulty", difficulty);
  4649. int64 rewarded_coin = 0;
  4650. if (quest->GetCoinsReward() > 0) {
  4651. if (quest->GetCoinsRewardMax() > 0)
  4652. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  4653. else
  4654. rewarded_coin = quest->GetCoinsReward();
  4655. }
  4656. quest->SetGeneratedCoin(rewarded_coin);
  4657. packet->setDataByName("max_coin", rewarded_coin);
  4658. packet->setDataByName("min_coin", rewarded_coin);
  4659. packet->setDataByName("status_points", quest->GetStatusPoints());
  4660. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  4661. vector<Item*>* items = quest->GetRewardItems();
  4662. if (items) {
  4663. packet->setArrayLengthByName("num_rewards", items->size());
  4664. for (int32 i = 0; i < items->size(); i++) {
  4665. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  4666. if (version < 860)
  4667. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  4668. else if (version < 1193)
  4669. packet->setItemArrayDataByName("item", items->at(i), player, i);
  4670. else
  4671. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  4672. }
  4673. }
  4674. if (items2 && items2->size() > 0) {
  4675. packet->setArrayLengthByName("num_select_rewards", items2->size());
  4676. for (int32 i = 0; i < items2->size(); i++) {
  4677. packet->setArrayDataByName("select_reward_id", items2->at(i)->details.item_id, i);
  4678. if (version < 860)
  4679. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, -1);
  4680. else if (version < 1193)
  4681. packet->setItemArrayDataByName("select_item", items2->at(i), player, i);
  4682. else
  4683. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, 2);
  4684. }
  4685. }
  4686. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  4687. if (reward_factions && reward_factions->size() > 0) {
  4688. packet->setArrayLengthByName("num_factions", reward_factions->size());
  4689. map<int32, sint32>::iterator itr;
  4690. int16 index = 0;
  4691. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  4692. int32 faction_id = itr->first;
  4693. sint32 amount = itr->second;
  4694. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  4695. if (faction_name) {
  4696. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  4697. packet->setArrayDataByName("amount", amount, index);
  4698. }
  4699. index++;
  4700. }
  4701. }
  4702. EQ2Packet* outapp = packet->serialize();
  4703. // DumpPacket(outapp);
  4704. QueuePacket(outapp);
  4705. safe_delete(packet);
  4706. }
  4707. }
  4708. void Client::DisplayRandomizeFeatures(int32 flags) {
  4709. SimpleMessage(CHANNEL_COLOR_WHITE, "Showing Active Randomize Features:");
  4710. if (flags > 0) {
  4711. if (flags & RANDOMIZE_GENDER)
  4712. SimpleMessage(CHANNEL_COLOR_WHITE, "- Gender");
  4713. if (flags & RANDOMIZE_RACE)
  4714. SimpleMessage(CHANNEL_COLOR_WHITE, "- Race");
  4715. if (flags & RANDOMIZE_MODEL_TYPE)
  4716. SimpleMessage(CHANNEL_COLOR_WHITE, "- Model");
  4717. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  4718. SimpleMessage(CHANNEL_COLOR_WHITE, "- Facial Hair");
  4719. if (flags & RANDOMIZE_HAIR_TYPE)
  4720. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair");
  4721. if (flags & RANDOMIZE_WING_TYPE)
  4722. SimpleMessage(CHANNEL_COLOR_WHITE, "- Wing");
  4723. if (flags & RANDOMIZE_CHEEK_TYPE)
  4724. SimpleMessage(CHANNEL_COLOR_WHITE, "- Cheek");
  4725. if (flags & RANDOMIZE_CHIN_TYPE)
  4726. SimpleMessage(CHANNEL_COLOR_WHITE, "- Chin");
  4727. if (flags & RANDOMIZE_EAR_TYPE)
  4728. SimpleMessage(CHANNEL_COLOR_WHITE, "- Ear");
  4729. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  4730. SimpleMessage(CHANNEL_COLOR_WHITE, "- Eyebrow");
  4731. if (flags & RANDOMIZE_EYE_TYPE)
  4732. SimpleMessage(CHANNEL_COLOR_WHITE, "- Eye");
  4733. if (flags & RANDOMIZE_LIP_TYPE)
  4734. SimpleMessage(CHANNEL_COLOR_WHITE, "- Lip");
  4735. if (flags & RANDOMIZE_NOSE_TYPE)
  4736. SimpleMessage(CHANNEL_COLOR_WHITE, "- Nose");
  4737. if (flags & RANDOMIZE_EYE_COLOR)
  4738. SimpleMessage(CHANNEL_COLOR_WHITE, "- Eye Color");
  4739. if (flags & RANDOMIZE_HAIR_COLOR1)
  4740. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair Color1");
  4741. if (flags & RANDOMIZE_HAIR_COLOR2)
  4742. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair Color2");
  4743. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  4744. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair Color Highlights");
  4745. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  4746. SimpleMessage(CHANNEL_COLOR_WHITE, "- Facial Hair Color");
  4747. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  4748. SimpleMessage(CHANNEL_COLOR_WHITE, "- Facial Hair Color Highlights");
  4749. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  4750. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair Type Color");
  4751. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  4752. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair Type Highlights");
  4753. if (flags & RANDOMIZE_SKIN_COLOR)
  4754. SimpleMessage(CHANNEL_COLOR_WHITE, "- Skin Color");
  4755. if (flags & RANDOMIZE_WING_COLOR1)
  4756. SimpleMessage(CHANNEL_COLOR_WHITE, "- Wing Color1");
  4757. if (flags & RANDOMIZE_WING_COLOR2)
  4758. SimpleMessage(CHANNEL_COLOR_WHITE, "- Wing Color2");
  4759. }
  4760. else
  4761. {
  4762. SimpleMessage(CHANNEL_COLOR_WHITE, "- No Randomization Set.");
  4763. }
  4764. }
  4765. void Client::GiveQuestReward(Quest* quest) {
  4766. current_quest_id = 0;
  4767. MPendingQuestAccept.lock();
  4768. pending_quest_accept.push_back(quest);
  4769. MPendingQuestAccept.unlock();
  4770. quest->IncrementCompleteCount();
  4771. player->AddCompletedQuest(quest);
  4772. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4773. SendQuestJournal();
  4774. player->RemoveQuest(quest->GetQuestID(), false);
  4775. DisplayQuestComplete(quest);
  4776. if (quest->GetExpReward() > 0) {
  4777. int16 level = player->GetLevel();
  4778. int32 xp = quest->GetExpReward();
  4779. if (player->AddXP(xp)) {
  4780. Message(CHANNEL_COLOR_EXP, "You gain %u experience!", (int32)xp);
  4781. if (player->GetLevel() != level)
  4782. ChangeLevel(level, player->GetLevel());
  4783. player->SetCharSheetChanged(true);
  4784. }
  4785. }
  4786. if (quest->GetTSExpReward() > 0) {
  4787. int8 ts_level = player->GetTSLevel();
  4788. int32 xp = quest->GetTSExpReward();
  4789. if (player->AddTSXP(xp)) {
  4790. Message(CHANNEL_COLOR_EXP, "You gain %u tradeskill experience!", (int32)xp);
  4791. if (player->GetTSLevel() != ts_level)
  4792. ChangeTSLevel(ts_level, player->GetTSLevel());
  4793. player->SetCharSheetChanged(true);
  4794. }
  4795. }
  4796. int64 total_coins = quest->GetGeneratedCoin();
  4797. if (total_coins > 0) {
  4798. player->AddCoins(total_coins);
  4799. PlaySound("coin_cha_ching");
  4800. char tmp[64] = { 0 };
  4801. string message = "You receive ";
  4802. int32 val = 0;
  4803. if (total_coins >= 1000000) {
  4804. val = total_coins / 1000000;
  4805. total_coins -= 1000000 * val;
  4806. sprintf(tmp, "%u Platinum ", val);
  4807. message.append(tmp);
  4808. memset(tmp, 0, 64);
  4809. }
  4810. if (total_coins >= 10000) {
  4811. val = total_coins / 10000;
  4812. total_coins -= 10000 * val;
  4813. sprintf(tmp, "%u Gold ", val);
  4814. message.append(tmp);
  4815. memset(tmp, 0, 64);
  4816. }
  4817. if (total_coins >= 100) {
  4818. val = total_coins / 100;
  4819. total_coins -= 100 * val;
  4820. sprintf(tmp, "%u Silver ", val);
  4821. message.append(tmp);
  4822. memset(tmp, 0, 64);
  4823. }
  4824. if (total_coins > 0) {
  4825. sprintf(tmp, "%u Copper ", (int32)total_coins);
  4826. message.append(tmp);
  4827. }
  4828. message.append("for completing ").append(quest->GetName());
  4829. int8 type = CHANNEL_COLOR_LOOT;
  4830. if (GetVersion() >= 973)
  4831. type = CHANNEL_COLOR_NEW_LOOT;
  4832. SimpleMessage(type, message.c_str());
  4833. }
  4834. if (quest->GetQuestGiver() > 0)
  4835. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  4836. RemovePlayerQuest(quest->GetQuestID(), true, false);
  4837. }
  4838. void Client::DisplayConversation(int32 conversation_id, int32 spawn_id, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  4839. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  4840. if (packet) {
  4841. packet->setDataByName("conversation_id", conversation_id);
  4842. packet->setDataByName("text", text);
  4843. packet->setDataByName("unknown2", 1);
  4844. conversation_map[conversation_id].clear();
  4845. if (conversations) {
  4846. packet->setArrayLengthByName("num_responses", conversations->size());
  4847. for (int32 i = 0; i < conversations->size(); i++) {
  4848. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  4849. if (conversations->at(i).function.length() > 0)
  4850. conversation_map[conversation_id][i] = conversations->at(i).function;
  4851. }
  4852. }
  4853. packet->setDataByName("spawn_id", spawn_id);
  4854. if (mp3) {
  4855. packet->setDataByName("voice", mp3);
  4856. packet->setDataByName("key1", key1);
  4857. packet->setDataByName("key2", key2);
  4858. }
  4859. QueuePacket(packet->serialize());
  4860. safe_delete(packet);
  4861. }
  4862. }
  4863. void Client::DisplayConversation(Item* item, vector<ConversationOption>* conversations, const char* text, int8 type, const char* mp3, int32 key1, int32 key2) {
  4864. if (!item || !text || !conversations || conversations->size() == 0) {
  4865. return;
  4866. }
  4867. int32 conversation_id = GetConversationID(0, item);
  4868. if (conversation_id == 0) {
  4869. next_conversation_id++;
  4870. conversation_id = next_conversation_id;
  4871. }
  4872. conversation_items[conversation_id] = item;
  4873. if (type == 4)
  4874. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  4875. else
  4876. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  4877. }
  4878. void Client::DisplayConversation(Entity* npc, int8 type, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  4879. if (!npc || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  4880. return;
  4881. }
  4882. int32 conversation_id = GetConversationID(npc, 0);
  4883. if (conversation_id == 0) {
  4884. next_conversation_id++;
  4885. conversation_id = next_conversation_id;
  4886. }
  4887. conversation_spawns[conversation_id] = npc;
  4888. /* NPCs can start two different types of conversations.
  4889. * Type 1: The chat type with bubbles.
  4890. * Type 2: The dialog type with the blue box. */
  4891. if (type == 1)
  4892. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(npc), conversations, text, mp3, key1, key2);
  4893. else if (type == 2)
  4894. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  4895. else //if (type == 3)
  4896. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  4897. }
  4898. void Client::CloseDialog(int32 conversation_id) {
  4899. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  4900. if (packet) {
  4901. packet->setDataByName("conversation_id", conversation_id);
  4902. QueuePacket(packet->serialize());
  4903. safe_delete(packet);
  4904. }
  4905. conversation_items.erase(conversation_id);
  4906. conversation_spawns.erase(conversation_id);
  4907. }
  4908. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  4909. int32 conversation_id = 0;
  4910. if (spawn) {
  4911. map<int32, Spawn*>::iterator itr;
  4912. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  4913. if (itr->second == spawn) {
  4914. conversation_id = itr->first;
  4915. break;
  4916. }
  4917. }
  4918. }
  4919. else if (item) {
  4920. map<int32, Item*>::iterator itr;
  4921. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  4922. if (itr->second == item) {
  4923. conversation_id = itr->first;
  4924. break;
  4925. }
  4926. }
  4927. }
  4928. return conversation_id;
  4929. }
  4930. Spawn* Client::GetCombineSpawn() {
  4931. return combine_spawn;
  4932. }
  4933. bool Client::ShouldTarget() {
  4934. return should_target;
  4935. }
  4936. void Client::TargetSpawn(Spawn* spawn) {
  4937. should_target = false;
  4938. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  4939. if (packet) {
  4940. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  4941. QueuePacket(packet->serialize());
  4942. safe_delete(packet);
  4943. }
  4944. }
  4945. void Client::CombineSpawns(float radius, Spawn* spawn) {
  4946. combine_spawn = spawn;
  4947. spawn->RemoveSpawnFromGroup(true);
  4948. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  4949. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  4950. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  4951. should_target = true;
  4952. }
  4953. void Client::AddCombineSpawn(Spawn* spawn) {
  4954. if (combine_spawn && combine_spawn != spawn && spawn) {
  4955. combine_spawn->AddSpawnToGroup(spawn);
  4956. spawn->AddSpawnToGroup(combine_spawn);
  4957. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  4958. }
  4959. else if (spawn)
  4960. combine_spawn = spawn;
  4961. should_target = true;
  4962. }
  4963. void Client::RemoveCombineSpawn(Spawn* spawn) {
  4964. if (combine_spawn && spawn)
  4965. spawn->RemoveSpawnFromGroup();
  4966. if (combine_spawn == spawn)
  4967. combine_spawn->RemoveSpawnFromGroup(true);
  4968. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  4969. if (combine_spawn == spawn)
  4970. combine_spawn = 0;
  4971. }
  4972. void Client::SaveCombineSpawns(const char* name) {
  4973. if (!combine_spawn) {
  4974. return;
  4975. }
  4976. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  4977. if (!spawns) {
  4978. return;
  4979. }
  4980. int32 count = spawns->size();
  4981. int32 spawnLocationID = 0;
  4982. if (count == 1)
  4983. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  4984. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  4985. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  4986. // we remove the spawn inside SaveCombinedSpawnLocation
  4987. //GetCurrentZone()->RemoveSpawn(false, combine_spawn);
  4988. }
  4989. else
  4990. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  4991. safe_delete(spawns);
  4992. combine_spawn = 0;
  4993. }
  4994. bool Client::AddItem(int32 item_id, int16 quantity) {
  4995. Item* master_item = master_item_list.GetItem(item_id);
  4996. Item* item = 0;
  4997. if (master_item)
  4998. item = new Item(master_item);
  4999. if (item) {
  5000. if (quantity > 0)
  5001. item->details.count = quantity;
  5002. return AddItem(item);
  5003. }
  5004. else
  5005. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  5006. return false;
  5007. }
  5008. bool Client::AddItem(Item* item) {
  5009. if (!item) {
  5010. return false;
  5011. }
  5012. if (item->IsBag()) {
  5013. if (GetVersion() <= 283 && item->details.num_slots > CLASSIC_EQ_MAX_BAG_SLOTS)
  5014. item->details.num_slots = CLASSIC_EQ_MAX_BAG_SLOTS;
  5015. item->details.bag_id = item->details.unique_id;
  5016. }
  5017. if (player->AddItem(item)) {
  5018. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5019. if (outapp) {
  5020. //DumpPacket(outapp);
  5021. QueuePacket(outapp);
  5022. //resend bag desc with new item name added
  5023. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  5024. if (outapp) {
  5025. //DumpPacket(outapp);
  5026. QueuePacket(outapp);
  5027. }
  5028. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  5029. DumpPacket(app);
  5030. client->QueuePacket(app);
  5031. */
  5032. }
  5033. CheckPlayerQuestsItemUpdate(item);
  5034. if (item->GetItemScript() && lua_interface)
  5035. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  5036. }
  5037. else {
  5038. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  5039. safe_delete(item);
  5040. return false;
  5041. }
  5042. return true;
  5043. }
  5044. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  5045. Item* master_item = master_item_list.GetItem(item_id);
  5046. Item* item = 0;
  5047. if (master_item)
  5048. item = new Item(master_item);
  5049. if (item) {
  5050. if (quantity > 0)
  5051. item->details.count = quantity;
  5052. return AddItemToBank(item);
  5053. }
  5054. else
  5055. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  5056. return false;
  5057. }
  5058. bool Client::AddItemToBank(Item* item) {
  5059. if (!item) {
  5060. return false;
  5061. }
  5062. if (item->IsBag())
  5063. item->details.bag_id = item->details.unique_id;
  5064. if (player->AddItemToBank(item)) {
  5065. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5066. if (outapp) {
  5067. QueuePacket(outapp);
  5068. //resend bag desc with new item name added
  5069. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  5070. if (outapp)
  5071. QueuePacket(outapp);
  5072. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  5073. DumpPacket(app);
  5074. client->QueuePacket(app);
  5075. */
  5076. }
  5077. CheckPlayerQuestsItemUpdate(item);
  5078. if (item->GetItemScript() && lua_interface)
  5079. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  5080. }
  5081. else {
  5082. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  5083. safe_delete(item);
  5084. return false;
  5085. }
  5086. return true;
  5087. }
  5088. bool Client::RemoveItem(Item* item, int16 quantity) {
  5089. EQ2Packet* outapp;
  5090. bool delete_item = false;
  5091. assert(item);
  5092. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  5093. item->details.count -= quantity;
  5094. item->save_needed = true;
  5095. }
  5096. else {
  5097. database.DeleteItem(character_id, item, 0);
  5098. player->GetPlayerItemList()->RemoveItem(item, false);
  5099. delete_item = true;
  5100. }
  5101. if ((outapp = player->SendInventoryUpdate(version))) {
  5102. QueuePacket(outapp);
  5103. if (item->GetItemScript() && lua_interface)
  5104. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  5105. if (delete_item)
  5106. safe_delete(item);
  5107. return true;
  5108. }
  5109. return false;
  5110. }
  5111. void Client::SetLuaDebugClient(bool val) {
  5112. if (val)
  5113. lua_debug_timer.Start();
  5114. lua_debug = val;
  5115. if (lua_interface && !val) {
  5116. lua_interface->RemoveDebugClients(this);
  5117. lua_debug_timer.Disable();
  5118. }
  5119. }
  5120. void Client::SetMerchantTransaction(Spawn* spawn) {
  5121. merchant_transaction = spawn;
  5122. }
  5123. Spawn* Client::GetMerchantTransaction() {
  5124. return merchant_transaction;
  5125. }
  5126. void Client::SetMailTransaction(Spawn* spawn) {
  5127. mail_transaction = spawn;
  5128. mail_window.coin_copper = 0;
  5129. mail_window.coin_silver = 0;
  5130. mail_window.coin_gold = 0;
  5131. mail_window.coin_plat = 0;
  5132. mail_window.char_item_id = 0;
  5133. }
  5134. Spawn* Client::GetMailTransaction() {
  5135. return mail_transaction;
  5136. }
  5137. void Client::PlaySound(const char* name) {
  5138. if (name) {
  5139. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  5140. if (packet) {
  5141. packet->setMediumStringByName("name", name);
  5142. QueuePacket(packet->serialize());
  5143. safe_delete(packet);
  5144. }
  5145. }
  5146. }
  5147. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  5148. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  5149. if(multiplier){
  5150. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  5151. float diff_low = faction_val - multiplier->faction_min;
  5152. if(diff_low < 0)
  5153. diff_low*=-1;
  5154. float total_diff = multiplier->faction_max - multiplier->faction_min;
  5155. if(total_diff < 0)
  5156. total_diff*=-1;
  5157. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  5158. float total1 = (diff_low/total_diff);
  5159. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  5160. return final_buy_multiplier;
  5161. }*/
  5162. return 1;
  5163. }
  5164. float Client::CalculateSellMultiplier(int32 merchant_id) {
  5165. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  5166. if(multiplier){
  5167. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  5168. float diff_low = faction_val - multiplier->faction_min;
  5169. if(diff_low < 0)
  5170. diff_low*=-1;
  5171. float total_diff = multiplier->faction_max - multiplier->faction_min;
  5172. if(total_diff < 0)
  5173. total_diff*=-1;
  5174. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  5175. float total1 = (diff_low/total_diff);
  5176. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  5177. return final_sell_multiplier;
  5178. }*/
  5179. return 1;
  5180. }
  5181. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  5182. Spawn* spawn = GetMerchantTransaction();
  5183. Guild* guild = GetPlayer()->GetGuild();
  5184. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5185. int32 total_sell_price = 0;
  5186. int32 total_status_sell_price = 0; //for status
  5187. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  5188. int32 sell_price = 0;
  5189. int32 status_sell_price = 0; //for status
  5190. Item* master_item = master_item_list.GetItem(item_id);
  5191. Item* item = 0;
  5192. if (unique_id == 0)
  5193. item = player->item_list.GetItemFromID(item_id, quantity);
  5194. else
  5195. item = player->item_list.GetItemFromUniqueID(unique_id);
  5196. if (!item)
  5197. player->item_list.GetItemFromID(item_id);
  5198. if (item && master_item) {
  5199. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  5200. if (sell_price > item->sell_price)
  5201. sell_price = item->sell_price;
  5202. if (quantity > item->details.count)
  5203. quantity = item->details.count;
  5204. total_sell_price = sell_price * quantity;
  5205. //------------------------------For Selling Status Items
  5206. status_sell_price = (int32)(master_item->sell_status * multiplier);
  5207. if (status_sell_price > item->sell_status)
  5208. status_sell_price = item->sell_status;
  5209. if (quantity > item->details.count)
  5210. quantity = item->details.count;
  5211. if (player->GetGuild()) {
  5212. total_status_sell_price = status_sell_price * quantity;
  5213. player->GetInfoStruct()->status_points += total_status_sell_price;
  5214. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  5215. guild->SendGuildMemberList();
  5216. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  5217. }
  5218. if (quantity > 1)
  5219. Message(CHANNEL_COLOR_MERCHANT, "You sell %i \\aITEM %u 0:%s\\/a to %s for %s.", quantity, master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
  5220. else
  5221. Message(CHANNEL_COLOR_MERCHANT, "You sell \\aITEM %u 0:%s\\/a to %s for %s.", master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
  5222. player->AddCoins(total_sell_price);
  5223. AddBuyBack(unique_id, item_id, quantity, sell_price);
  5224. if (quantity >= item->details.count) {
  5225. database.DeleteItem(GetCharacterID(), item, 0);
  5226. player->item_list.DestroyItem(item->details.index);
  5227. }
  5228. else {
  5229. item->details.count -= quantity;
  5230. item->save_needed = true;
  5231. }
  5232. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5233. if (outapp)
  5234. QueuePacket(outapp);
  5235. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY))
  5236. SendSellMerchantList();
  5237. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  5238. SendBuyBackList();
  5239. }
  5240. }
  5241. }
  5242. void Client::BuyBack(int32 item_id, int16 quantity) {
  5243. Spawn* spawn = GetMerchantTransaction();
  5244. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5245. deque<BuyBackItem*>::iterator itr;
  5246. BuyBackItem* buyback = 0;
  5247. BuyBackItem* closest = 0;
  5248. MBuyBack.readlock(__FUNCTION__, __LINE__);
  5249. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  5250. buyback = *itr;
  5251. if (buyback->unique_id == item_id) {
  5252. closest = buyback;
  5253. quantity = buyback->quantity;
  5254. break;
  5255. }
  5256. }
  5257. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  5258. if (closest) {
  5259. Item* item = 0;
  5260. Item* master_item = master_item_list.GetItem(closest->item_id);
  5261. if (master_item) {
  5262. item = new Item(master_item);
  5263. if (closest->quantity >= quantity)
  5264. item->details.count = quantity;
  5265. else
  5266. item->details.count = closest->quantity;
  5267. }
  5268. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  5269. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  5270. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  5271. bool removed = false;
  5272. if (closest->quantity == quantity) {
  5273. MBuyBack.writelock(__FUNCTION__, __LINE__);
  5274. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  5275. if (*itr == closest) {
  5276. buy_back_items.erase(itr);
  5277. removed = true;
  5278. break;
  5279. }
  5280. }
  5281. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  5282. }
  5283. else {
  5284. closest->quantity -= quantity;
  5285. closest->save_needed = true;
  5286. }
  5287. AddItem(item);
  5288. //EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5289. //if(outapp)
  5290. //QueuePacket(outapp);
  5291. if (removed) {
  5292. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  5293. safe_delete(closest);
  5294. }
  5295. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY))
  5296. SendSellMerchantList();
  5297. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  5298. SendBuyBackList();
  5299. }
  5300. else
  5301. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  5302. }
  5303. }
  5304. }
  5305. void Client::BuyItem(int32 item_id, int16 quantity) {
  5306. // Get the merchant we are buying from
  5307. Spawn* spawn = GetMerchantTransaction();
  5308. // Make sure the spawn has a merchant list
  5309. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5310. int32 total_buy_price = 0;
  5311. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  5312. int32 sell_price = 0;
  5313. Item* master_item = master_item_list.GetItem(item_id);
  5314. Item* item = 0;
  5315. int16 total_available = 0;
  5316. vector<MerchantItemInfo>* temp;
  5317. vector<MerchantItemInfo>::iterator itr;
  5318. MerchantItemInfo* ItemInfo = 0;
  5319. temp = world.GetMerchantList(spawn->GetMerchantID());
  5320. for (itr = temp->begin(); itr != temp->end(); itr++) {
  5321. if ((*itr).item_id == item_id) {
  5322. ItemInfo = &(*itr);
  5323. break;
  5324. }
  5325. }
  5326. if (master_item && ItemInfo) {
  5327. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  5328. quantity = 1;
  5329. total_available = 0xFFFF;
  5330. sell_price = master_item->sell_price;
  5331. }
  5332. else {
  5333. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  5334. sell_price = (int32)(master_item->sell_price * multiplier);
  5335. if (quantity > total_available)
  5336. quantity = total_available;
  5337. }
  5338. total_buy_price = sell_price * quantity;
  5339. item = new Item(master_item);
  5340. item->details.count = quantity;
  5341. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  5342. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  5343. safe_delete(item);
  5344. }
  5345. else {
  5346. // Price not set in the merchant_inventory table, use the old method
  5347. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  5348. if (player->RemoveCoins(total_buy_price)) {
  5349. item->SetMaxSellValue(sell_price);
  5350. if (quantity > 1)
  5351. Message(CHANNEL_COLOR_MERCHANT, "You buy %i \\aITEM %u 0:%s\\/a from %s for%s.", quantity, master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
  5352. else
  5353. Message(CHANNEL_COLOR_MERCHANT, "You buy \\aITEM %u 0:%s\\/a from %s for%s.", master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
  5354. AddItem(item);
  5355. CheckPlayerQuestsItemUpdate(item);
  5356. if (item && total_available < 0xFFFF) {
  5357. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  5358. SendBuyMerchantList();
  5359. }
  5360. //EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5361. //if(outapp)
  5362. // QueuePacket(outapp);
  5363. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) && !(spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  5364. SendSellMerchantList();
  5365. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  5366. PlayLotto(total_buy_price, item->details.item_id);
  5367. }
  5368. else {
  5369. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase \\aITEM %u 0:%s\\/a.", master_item->details.item_id, master_item->name.c_str());
  5370. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5371. PlaySound("buy_failed");
  5372. }
  5373. }
  5374. else {
  5375. // Price set in merchant_inventory table
  5376. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  5377. // TODO: need to add support for station cash
  5378. if (player->GetInfoStruct()->status_points >= ItemInfo->price_status && player->HasCoins(ItemInfo->price_coins * quantity)) {
  5379. // Check items
  5380. int16 item_quantity = 0;
  5381. // Default these to true in case price_item_id or price_item2_id was never set
  5382. bool hasItem1 = true;
  5383. bool hasItem2 = true;
  5384. Item* tempItem1 = 0;
  5385. Item* tempItem2 = 0;
  5386. if (ItemInfo->price_item_id != 0) {
  5387. // Same item for whatever reason lets add the quantities together
  5388. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  5389. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  5390. else
  5391. item_quantity = ItemInfo->price_item_qty;
  5392. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  5393. if (tempItem1) {
  5394. if (tempItem1->details.count < item_quantity)
  5395. hasItem1 = false;
  5396. }
  5397. else {
  5398. hasItem1 = false;
  5399. }
  5400. }
  5401. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  5402. // as item1 and we already checked for it so we can skip this check
  5403. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  5404. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  5405. if (tempItem2) {
  5406. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  5407. hasItem2 = false;
  5408. }
  5409. else {
  5410. hasItem2 = false;
  5411. }
  5412. }
  5413. // if we have every thing then remove the price and give the item
  5414. if (hasItem1 && hasItem2) {
  5415. player->GetInfoStruct()->status_points -= ItemInfo->price_status;
  5416. // TODO: station cash
  5417. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  5418. // so there is no need to send it more then that one time
  5419. if (tempItem1) {
  5420. if (tempItem1->details.count > item_quantity) {
  5421. tempItem1->details.count -= item_quantity;
  5422. tempItem1->save_needed = true;
  5423. }
  5424. else {
  5425. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  5426. player->item_list.DestroyItem(tempItem1->details.index);
  5427. }
  5428. }
  5429. if (tempItem2) {
  5430. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  5431. tempItem2->details.count -= ItemInfo->price_item2_qty;
  5432. tempItem2->save_needed = true;
  5433. }
  5434. else {
  5435. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  5436. player->item_list.DestroyItem(tempItem2->details.index);
  5437. }
  5438. }
  5439. // 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
  5440. player->RemoveCoins(ItemInfo->price_coins * quantity);
  5441. item->SetMaxSellValue(sell_price);
  5442. if (quantity > 1)
  5443. Message(CHANNEL_COLOR_MERCHANT, "You buy %i \\aITEM %u 0:%s\\/a from %s for%s.", quantity, master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
  5444. else
  5445. Message(CHANNEL_COLOR_MERCHANT, "You buy \\aITEM %u 0:%s\\/a from %s for%s.", master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
  5446. AddItem(item);
  5447. CheckPlayerQuestsItemUpdate(item);
  5448. if (item && total_available < 0xFFFF) {
  5449. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  5450. SendBuyMerchantList();
  5451. }
  5452. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) && !(spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  5453. SendSellMerchantList();
  5454. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  5455. PlayLotto(total_buy_price, item->details.item_id);
  5456. }
  5457. else {
  5458. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase \\aITEM %u 0:%s\\/a.", master_item->details.item_id, master_item->name.c_str());
  5459. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5460. PlaySound("buy_failed");
  5461. }
  5462. }
  5463. else {
  5464. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase \\aITEM %u 0:%s\\/a.", master_item->details.item_id, master_item->name.c_str());
  5465. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5466. PlaySound("buy_failed");
  5467. }
  5468. }
  5469. }
  5470. }
  5471. }
  5472. }
  5473. void Client::RepairItem(int32 item_id) {
  5474. Spawn* spawn = GetMerchantTransaction();
  5475. if (spawn) {
  5476. Item* item = player->item_list.GetItemFromID(item_id);
  5477. if (!item)
  5478. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  5479. if (item) {
  5480. int32 repair_cost = item->CalculateRepairCost();
  5481. if (player->RemoveCoins((int32)repair_cost)) {
  5482. item->generic_info.condition = 100;
  5483. item->save_needed = true;
  5484. QueuePacket(player->GetEquipmentList()->serialize(GetVersion()));
  5485. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  5486. QueuePacket(item->serialize(version, false, player));
  5487. Message(CHANNEL_COLOR_MERCHANT, "You give %s %s to repair your \\aITEM %u 0:%s\\/a.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->details.item_id, item->name.c_str());
  5488. PlaySound("coin_cha_ching");
  5489. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  5490. SendRepairList();
  5491. }
  5492. else {
  5493. LogWrite(MISC__TODO, 1, "TODO", " Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  5494. Message(CHANNEL_COLOR_MERCHANT, "You do not have enough coin to repair \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  5495. PlaySound("buy_failed");
  5496. }
  5497. }
  5498. }
  5499. }
  5500. void Client::RepairAllItems() {
  5501. Spawn* spawn = GetMerchantTransaction();
  5502. if (spawn) {
  5503. vector<Item*>* repairable_items = GetRepairableItems();
  5504. if (repairable_items && repairable_items->size() > 0) {
  5505. vector<Item*>::iterator itr;
  5506. int64 total_cost = 0;
  5507. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  5508. total_cost += (*itr)->CalculateRepairCost();
  5509. if (player->RemoveCoins((int32)total_cost)) {
  5510. Message(CHANNEL_COLOR_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  5511. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  5512. Item* item = *itr;
  5513. if (item) {
  5514. item->generic_info.condition = 100;
  5515. item->save_needed = true;
  5516. QueuePacket(item->serialize(version, false, player));
  5517. Message(CHANNEL_COLOR_YELLOW, "Repaired: \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  5518. }
  5519. }
  5520. QueuePacket(player->GetEquipmentList()->serialize(GetVersion()));
  5521. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  5522. PlaySound("coin_cha_ching");
  5523. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  5524. SendRepairList();
  5525. }
  5526. else {
  5527. LogWrite(MISC__TODO, 1, "TODO", "Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  5528. SimpleMessage(CHANNEL_COLOR_MERCHANT, "You do not have enough coin to repair all of your items.");
  5529. PlaySound("buy_failed");
  5530. }
  5531. }
  5532. safe_delete(repairable_items);
  5533. }
  5534. }
  5535. void Client::SendAchievementsList()
  5536. {
  5537. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  5538. map<int32, Achievement *>::iterator itr;
  5539. Achievement *achievement;
  5540. vector<AchievementRequirements *> *requirements = 0;
  5541. vector<AchievementRequirements *>::iterator itr2;
  5542. AchievementRequirements *requirement;
  5543. vector<AchievementRewards *> *rewards = 0;
  5544. vector<AchievementRewards *>::iterator itr3;
  5545. AchievementRewards *reward;
  5546. PacketStruct *packet;
  5547. int16 i = 0;
  5548. int16 j = 0;
  5549. int16 k = 0;
  5550. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  5551. return;
  5552. }
  5553. packet->setArrayLengthByName("num_achievements" , achievements->size());
  5554. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  5555. achievement = itr->second;
  5556. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  5557. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  5558. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  5559. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  5560. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  5561. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  5562. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  5563. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  5564. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  5565. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  5566. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  5567. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  5568. requirements = achievement->GetRequirements();
  5569. rewards = achievement->GetRewards();
  5570. j = 0;
  5571. k = 0;
  5572. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  5573. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  5574. requirement = *itr2;
  5575. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  5576. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  5577. j++;
  5578. }
  5579. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  5580. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  5581. reward = *itr3;
  5582. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  5583. k++;
  5584. }
  5585. i++;
  5586. }
  5587. //packet->PrintPacket();
  5588. EQ2Packet* data = packet->serialize();
  5589. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  5590. safe_delete(packet);
  5591. safe_delete(data);
  5592. //DumpPacket(app);
  5593. QueuePacket(app);*/
  5594. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  5595. SendAchievementUpdate(true);
  5596. }
  5597. void Client::SendAchievementUpdate(bool first_login) {
  5598. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  5599. map<int32, AchievementUpdate*>::iterator itr;
  5600. AchievementUpdate* update;
  5601. vector<AchievementUpdateItems*>* update_items = 0;
  5602. vector<AchievementUpdateItems*>::iterator itr2;
  5603. AchievementUpdateItems* update_item;
  5604. int16 i = 0;
  5605. int16 j = 0;
  5606. PacketStruct* packet;
  5607. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  5608. return;
  5609. }
  5610. packet->setDataByName("unknown1", first_login ? 1 : 0);
  5611. packet->setArrayLengthByName("num_achievements", updates->size());
  5612. for (itr = updates->begin(); itr != updates->end(); itr++) {
  5613. update = itr->second;
  5614. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  5615. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  5616. update_items = update->GetUpdateItems();
  5617. j = 0;
  5618. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  5619. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  5620. update_item = *itr2;
  5621. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  5622. j++;
  5623. }
  5624. i++;
  5625. }
  5626. //packet->PrintPacket();
  5627. EQ2Packet* data = packet->serialize();
  5628. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  5629. safe_delete(packet);
  5630. safe_delete(data);
  5631. //DumpPacket(app);
  5632. QueuePacket(app);
  5633. }
  5634. void Client::SendBuyMerchantList(bool sell) {
  5635. Spawn* spawn = GetMerchantTransaction();
  5636. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5637. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  5638. if (items) {
  5639. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5640. if (packet) {
  5641. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  5642. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5643. packet->setArrayLengthByName("num_items", items->size());
  5644. vector<MerchantItemInfo>::iterator itr;
  5645. sint8 item_difficulty = 0;
  5646. int32 sell_price = 0;
  5647. int i = 0;
  5648. int tmp_level = 0;
  5649. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  5650. MerchantItemInfo ItemInfo = *itr;
  5651. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  5652. if (!item)
  5653. continue;
  5654. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  5655. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5656. packet->setArrayDataByName("stack_size", item->stack_count, i);
  5657. packet->setArrayDataByName("icon", item->details.icon, i);
  5658. if (item->generic_info.adventure_default_level > 0)
  5659. tmp_level = item->generic_info.adventure_default_level;
  5660. else
  5661. tmp_level = item->generic_info.tradeskill_default_level;
  5662. packet->setArrayDataByName("level", tmp_level, i);
  5663. packet->setArrayDataByName("tier", item->details.tier, i);
  5664. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  5665. item_difficulty = player->GetArrowColor(tmp_level);
  5666. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  5667. item_difficulty = ARROW_COLOR_WHITE;
  5668. item_difficulty -= 6;
  5669. if (item_difficulty < 0)
  5670. item_difficulty *= -1;
  5671. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  5672. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  5673. packet->setArrayDataByName("unknown5", 255, i);
  5674. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  5675. if (GetVersion() <= 1096)
  5676. packet->setArrayDataByName("description", item->description.c_str(), i);
  5677. // If no price set in the merchant_inventory table then use the old method
  5678. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  5679. sell_price = (int32)(item->sell_price * multiplier);
  5680. packet->setArrayDataByName("price", sell_price, i);
  5681. }
  5682. else {
  5683. int8 count = 0;
  5684. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  5685. count++;
  5686. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  5687. count++;
  5688. if (count != 0) {
  5689. packet->setSubArrayLengthByName("num_tokens", count, i);
  5690. int8 index = 0;
  5691. Item* token = 0;
  5692. if (ItemInfo.price_item_id != 0) {
  5693. token = master_item_list.GetItem(ItemInfo.price_item_id);
  5694. if (item) {
  5695. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  5696. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  5697. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  5698. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  5699. }
  5700. token = 0;
  5701. index++;
  5702. }
  5703. if (ItemInfo.price_item2_id != 0) {
  5704. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  5705. if (item) {
  5706. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  5707. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  5708. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  5709. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  5710. }
  5711. }
  5712. }
  5713. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  5714. packet->setArrayDataByName("status", ItemInfo.price_status, i);
  5715. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  5716. }
  5717. }
  5718. if (sell)
  5719. packet->setDataByName("type", 130);
  5720. else
  5721. packet->setDataByName("type", 2);
  5722. EQ2Packet* outapp = packet->serialize();
  5723. // DumpPacket(outapp);
  5724. QueuePacket(outapp);
  5725. safe_delete(packet);
  5726. }
  5727. safe_delete(items);
  5728. }
  5729. else {
  5730. // Need to send an empty packet in the event there is no item list, otherwise the
  5731. // last item list sent to the player will show for this merchant
  5732. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5733. if (packet) {
  5734. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5735. if (sell)
  5736. packet->setDataByName("type", 130);
  5737. else
  5738. packet->setDataByName("type", 2);
  5739. EQ2Packet* outapp = packet->serialize();
  5740. QueuePacket(outapp);
  5741. safe_delete(packet);
  5742. }
  5743. }
  5744. }
  5745. }
  5746. void Client::SendSellMerchantList(bool sell) {
  5747. Spawn* spawn = GetMerchantTransaction();
  5748. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5749. map<int32, Item*>* items = player->GetItemList();
  5750. if (items) {
  5751. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5752. if (packet) {
  5753. vector<Item*> sellable_items;
  5754. map<int32, Item*>::iterator test_itr;
  5755. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  5756. if (test_itr->second && !test_itr->second->CheckFlag(NO_VALUE))
  5757. sellable_items.push_back(test_itr->second);
  5758. }
  5759. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5760. packet->setArrayLengthByName("num_items", sellable_items.size());
  5761. vector<Item*>::iterator itr;
  5762. Item* item = 0;
  5763. sint8 item_difficulty = 0;
  5764. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  5765. int32 sell_price = 0;
  5766. Item* master_item = 0;
  5767. int i = 0;
  5768. int tmp_level = 0;
  5769. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  5770. item = *itr;
  5771. master_item = master_item_list.GetItem(item->details.item_id);
  5772. if (master_item)
  5773. sell_price = (int32)(master_item->sell_price * multiplier);
  5774. else
  5775. sell_price = 0;
  5776. if (sell_price > item->sell_price)
  5777. sell_price = item->sell_price;
  5778. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  5779. string thename = item->name;
  5780. packet->setArrayDataByName("price", sell_price, i);
  5781. if (player->GetGuild()) {
  5782. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  5783. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  5784. }
  5785. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5786. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  5787. packet->setArrayDataByName("stack_size", item->details.count, i);
  5788. packet->setArrayDataByName("icon", item->details.icon, i);
  5789. if (item->generic_info.adventure_default_level > 0)
  5790. tmp_level = item->generic_info.adventure_default_level;
  5791. else
  5792. tmp_level = item->generic_info.tradeskill_default_level;
  5793. packet->setArrayDataByName("level", item->details.recommended_level, i);
  5794. packet->setArrayDataByName("tier", item->details.tier, i);
  5795. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  5796. item_difficulty = player->GetArrowColor(tmp_level);
  5797. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  5798. item_difficulty = ARROW_COLOR_WHITE;
  5799. item_difficulty -= 6;
  5800. if (item_difficulty < 0)
  5801. item_difficulty *= -1;
  5802. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  5803. if (item->details.count == 1)
  5804. packet->setArrayDataByName("quantity", 0xFFFF, i);
  5805. else
  5806. packet->setArrayDataByName("quantity", item->details.count, i);
  5807. packet->setArrayDataByName("stack_size2", item->details.count, i);
  5808. if (GetVersion() <= 1096)
  5809. packet->setArrayDataByName("description", item->description.c_str(), i);
  5810. }
  5811. if (sell)
  5812. packet->setDataByName("type", 129);
  5813. else
  5814. packet->setDataByName("type", 1);
  5815. packet->setDataByName("unknown8a", 16256, 6);
  5816. packet->setDataByName("unknown8a", 16256, 10);
  5817. //packet->PrintPacket();
  5818. EQ2Packet* outapp = packet->serialize();
  5819. //DumpPacket(outapp);
  5820. QueuePacket(outapp);
  5821. safe_delete(packet);
  5822. }
  5823. safe_delete(items);
  5824. }
  5825. }
  5826. }
  5827. void Client::SendBuyBackList(bool sell) {
  5828. Spawn* spawn = GetMerchantTransaction();
  5829. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5830. deque<BuyBackItem*>::iterator itr;
  5831. int i = 0;
  5832. Item* master_item = 0;
  5833. BuyBackItem* buyback = 0;
  5834. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5835. if (packet) {
  5836. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5837. packet->setArrayLengthByName("num_items", buy_back_items.size());
  5838. sint8 item_difficulty = 0;
  5839. MBuyBack.readlock(__FUNCTION__, __LINE__);
  5840. int tmp_level = 0;
  5841. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  5842. buyback = *itr;
  5843. master_item = master_item_list.GetItem(buyback->item_id);
  5844. if (master_item) {
  5845. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  5846. packet->setArrayDataByName("price", buyback->price, i);
  5847. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  5848. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  5849. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  5850. packet->setArrayDataByName("icon", master_item->details.icon, i);
  5851. if (master_item->generic_info.adventure_default_level > 0)
  5852. tmp_level = master_item->generic_info.adventure_default_level;
  5853. else
  5854. tmp_level = master_item->generic_info.tradeskill_default_level;
  5855. packet->setArrayDataByName("level", tmp_level, i);
  5856. packet->setArrayDataByName("tier", master_item->details.tier, i);
  5857. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  5858. item_difficulty = player->GetArrowColor(tmp_level);
  5859. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  5860. item_difficulty = ARROW_COLOR_WHITE;
  5861. item_difficulty -= 6;
  5862. if (item_difficulty < 0)
  5863. item_difficulty *= -1;
  5864. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  5865. if (buyback->quantity == 1)
  5866. packet->setArrayDataByName("quantity", 0xFFFF, i);
  5867. else
  5868. packet->setArrayDataByName("quantity", buyback->quantity, i);
  5869. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  5870. if (GetVersion() <= 1096)
  5871. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  5872. }
  5873. }
  5874. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  5875. if (sell)
  5876. packet->setDataByName("type", 640);
  5877. else
  5878. packet->setDataByName("type", 512);
  5879. EQ2Packet* outapp = packet->serialize();
  5880. // DumpPacket(outapp);
  5881. QueuePacket(outapp);
  5882. safe_delete(packet);
  5883. }
  5884. }
  5885. }
  5886. void Client::SendRepairList() {
  5887. Spawn* spawn = GetMerchantTransaction();
  5888. if (spawn) {
  5889. vector<Item*>* repairable_items = GetRepairableItems();
  5890. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5891. if (packet) {
  5892. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5893. packet->setArrayLengthByName("num_items", repairable_items->size());
  5894. Item* item = 0;
  5895. sint8 item_difficulty = 0;
  5896. int32 i = 0;
  5897. vector<Item*>::iterator itr;
  5898. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  5899. item = *itr;
  5900. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  5901. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  5902. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5903. packet->setArrayDataByName("stack_size", item->details.count, i);
  5904. packet->setArrayDataByName("icon", item->details.icon, i);
  5905. /*if (item->generic_info.adventure_default_level > 0)
  5906. tmp_level = item->generic_info.adventure_default_level;
  5907. else
  5908. tmp_level = item->generic_info.tradeskill_default_level;
  5909. packet->setArrayDataByName("level", tmp_level, i);*/
  5910. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  5911. packet->setArrayDataByName("tier", item->details.tier, i);
  5912. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  5913. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  5914. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  5915. item_difficulty = ARROW_COLOR_WHITE;
  5916. item_difficulty -= 6;
  5917. if (item_difficulty < 0)
  5918. item_difficulty *= -1;
  5919. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  5920. if (item->details.count == 1)
  5921. packet->setArrayDataByName("quantity", 0xFFFF, i);
  5922. else
  5923. packet->setArrayDataByName("quantity", item->details.count, i);
  5924. packet->setArrayDataByName("stack_size2", item->details.count, i);
  5925. if (GetVersion() <= 1096)
  5926. packet->setArrayDataByName("description", item->description.c_str(), i);
  5927. }
  5928. packet->setDataByName("type", 96);
  5929. EQ2Packet* outapp = packet->serialize();
  5930. QueuePacket(outapp);
  5931. safe_delete(packet);
  5932. }
  5933. safe_delete(repairable_items);
  5934. }
  5935. }
  5936. void Client::ShowLottoWindow() {
  5937. Spawn* spawn = GetMerchantTransaction();
  5938. if (spawn) {
  5939. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  5940. if (!item_id)
  5941. {
  5942. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  5943. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  5944. return;
  5945. }
  5946. else if (item_id == 0)
  5947. {
  5948. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  5949. return;
  5950. }
  5951. Item* item = master_item_list.GetItem(item_id);
  5952. if (!item) {
  5953. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  5954. return;
  5955. }
  5956. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  5957. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5958. if (packet) {
  5959. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5960. packet->setArrayLengthByName("num_items", 1);
  5961. packet->setArrayDataByName("item_name", item->name.c_str());
  5962. packet->setArrayDataByName("price", item->sell_price);
  5963. packet->setArrayDataByName("item_id", item->details.item_id);
  5964. packet->setArrayDataByName("stack_size", item->details.count);
  5965. packet->setArrayDataByName("icon", item->details.icon);
  5966. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  5967. packet->setArrayDataByName("tier", item->details.tier);
  5968. packet->setArrayDataByName("item_id2", item->details.item_id);
  5969. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  5970. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  5971. item_difficulty = ARROW_COLOR_WHITE;
  5972. item_difficulty -= 6;
  5973. if (item_difficulty < 0)
  5974. item_difficulty *= -1;
  5975. packet->setArrayDataByName("item_difficulty", item_difficulty);
  5976. //if(item->details.count == 1)
  5977. packet->setArrayDataByName("quantity", 0xFFFF);
  5978. //else
  5979. // packet->setArrayDataByName("quantity", item->details.count);
  5980. packet->setArrayDataByName("stack_size2", item->details.count);
  5981. packet->setArrayDataByName("description", item->description.c_str());
  5982. packet->setDataByName("type", 0x00000102);
  5983. QueuePacket(packet->serialize());
  5984. safe_delete(packet);
  5985. }
  5986. }
  5987. }
  5988. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  5989. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  5990. if (packet) {
  5991. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  5992. int32 rolls[6] = { 0 };
  5993. int32 lottery_digits[6] = { 0 };
  5994. int8 num_matches = 0;
  5995. int64 jackpot = 0;
  5996. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  5997. if (!item) {
  5998. return;
  5999. }
  6000. database.DeleteItem(GetCharacterID(), item, 0);
  6001. GetPlayer()->item_list.RemoveItem(item, true);
  6002. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  6003. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  6004. if (!winning_numbers) {
  6005. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  6006. variables.AddVariable(winning_numbers);
  6007. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6008. }
  6009. if (strlen(winning_numbers->GetValue()) != 12) {
  6010. winning_numbers->SetValue("231205182236");
  6011. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6012. }
  6013. try {
  6014. for (int32 i = 0; i < 12; i += 2) {
  6015. char num[4];
  6016. strncpy(num, winning_numbers->GetValue() + i, 2);
  6017. lottery_digits[i / 2] = atoi(num);
  6018. }
  6019. }
  6020. catch (...) {
  6021. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  6022. return;
  6023. }
  6024. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  6025. if (!jackpot_var) {
  6026. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  6027. variables.AddVariable(jackpot_var);
  6028. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6029. }
  6030. try {
  6031. jackpot = atoul(jackpot_var->GetValue());
  6032. if (jackpot < 10000)
  6033. jackpot = 10000;
  6034. }
  6035. catch (...) {
  6036. jackpot = 10000;
  6037. }
  6038. char new_jackpot[128] = { 0 };
  6039. sprintf(new_jackpot, "%llu", jackpot + price);
  6040. jackpot_var->SetValue(new_jackpot);
  6041. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6042. world.PickRandomLottoDigits(rolls);
  6043. packet->setDataByName("roll_digit1", rolls[0]);
  6044. packet->setDataByName("roll_digit2", rolls[1]);
  6045. packet->setDataByName("roll_digit3", rolls[2]);
  6046. packet->setDataByName("roll_digit4", rolls[3]);
  6047. packet->setDataByName("roll_digit5", rolls[4]);
  6048. packet->setDataByName("roll_digit6", rolls[5]);
  6049. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  6050. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  6051. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  6052. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  6053. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  6054. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  6055. QueuePacket(packet->serialize());
  6056. safe_delete(packet);
  6057. for (int32 i = 0; i < 6; i++) {
  6058. for (int32 j = 0; j < 6; j++) {
  6059. if (rolls[i] == lottery_digits[j]) {
  6060. num_matches++;
  6061. break;
  6062. }
  6063. }
  6064. }
  6065. char new_jackpot_str[16];
  6066. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  6067. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  6068. if (num_matches == 6) {
  6069. world.PickRandomLottoDigits(lottery_digits);
  6070. for (int32 i = 0; i < 12; i += 2)
  6071. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  6072. winning_numbers->SetValue(new_jackpot_str);
  6073. jackpot_var->SetValue("10000");
  6074. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6075. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6076. }
  6077. }
  6078. }
  6079. void Client::SendGuildCreateWindow() {
  6080. Spawn* spawn = GetPlayer()->GetTarget();
  6081. if (spawn) {
  6082. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6083. if (packet) {
  6084. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6085. packet->setArrayLengthByName("num_items", 0);
  6086. packet->setDataByName("type", 0x00008000);
  6087. QueuePacket(packet->serialize());
  6088. safe_delete(packet);
  6089. }
  6090. }
  6091. }
  6092. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  6093. BuyBackItem* item = new BuyBackItem;
  6094. item->item_id = item_id;
  6095. item->unique_id = unique_id;
  6096. item->price = price;
  6097. item->quantity = quantity;
  6098. item->save_needed = save_needed;
  6099. MBuyBack.writelock(__FUNCTION__, __LINE__);
  6100. buy_back_items.push_back(item);
  6101. if (buy_back_items.size() > 10) {
  6102. safe_delete(buy_back_items.front());
  6103. buy_back_items.pop_front();
  6104. }
  6105. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  6106. }
  6107. deque<BuyBackItem*>* Client::GetBuyBacks() {
  6108. return &buy_back_items;
  6109. }
  6110. vector<Item*>* Client::GetRepairableItems() {
  6111. vector<Item*>* repairable_items = new vector<Item*>;
  6112. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  6113. map<int32, Item*>* items = player->GetItemList();
  6114. if (equipped_items && equipped_items->size() > 0) {
  6115. for (int32 i = 0; i < equipped_items->size(); i++) {
  6116. Item* item = equipped_items->at(i);
  6117. if (item && item->generic_info.condition < 100)
  6118. repairable_items->push_back(item);
  6119. }
  6120. }
  6121. if (items && items->size() > 0) {
  6122. map<int32, Item*>::iterator itr;
  6123. for (itr = items->begin(); itr != items->end(); itr++) {
  6124. Item* item = itr->second;
  6125. if (item && item->generic_info.condition < 100)
  6126. repairable_items->push_back(item);
  6127. }
  6128. }
  6129. safe_delete(equipped_items);
  6130. safe_delete(items);
  6131. return repairable_items;
  6132. }
  6133. void Client::SendMailList() {
  6134. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  6135. if (kiosk_id > 0) {
  6136. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  6137. if (p) {
  6138. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  6139. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  6140. int16 i = 0;
  6141. p->setDataByName("kiosk_id", kiosk_id);
  6142. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  6143. while (itr.Next()) {
  6144. Mail* mail = itr->second;
  6145. p->setArrayDataByName("mail_id", mail->mail_id, i);
  6146. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  6147. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  6148. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  6149. p->setArrayDataByName("unknown1", 0x0000, i);
  6150. p->setArrayDataByName("already_read", mail->already_read, i);
  6151. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  6152. p->setArrayDataByName("mail_type", mail->mail_type, i);
  6153. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  6154. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  6155. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  6156. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  6157. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  6158. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  6159. p->setArrayDataByName("num_items", mail->stack, i);
  6160. p->setArrayDataByName("packettype", GetItemPacketType(GetVersion()));
  6161. p->setArrayDataByName("packetsubtype", 0xFF, i);
  6162. p->setArrayDataByName("unknown2", 0, i);
  6163. //p->setArrayDataByName("item_id", 5, i, 0);
  6164. //Item* item = master_item_list.GetItem(5);
  6165. //if (item)
  6166. // printf("%s\n", item->name.c_str());
  6167. //else
  6168. // printf("no item\n");
  6169. //p->setItemArrayDataByName("item", master_item_list.GetItem(5), i, 0);
  6170. i++;
  6171. }
  6172. // GMs send mail for free!
  6173. if (GetAdminStatus() > 0)
  6174. {
  6175. p->setDataByName("postage_cost", 0);
  6176. p->setDataByName("attachment_cost", 0);
  6177. }
  6178. else
  6179. {
  6180. p->setDataByName("postage_cost", 10);
  6181. p->setDataByName("attachment_cost", 50);
  6182. }
  6183. p->setDataByName("unknown3", 0x01F4);
  6184. p->setDataByName("unknown4", 0x01000000);
  6185. QueuePacket(p->serialize());
  6186. safe_delete(p);
  6187. }
  6188. }
  6189. else
  6190. SimpleMessage(CHANNEL_COLOR_MAIL, "You are currently not in a mail transaction.");
  6191. }
  6192. void Client::DisplayMailMessage(int32 mail_id) {
  6193. Mail* mail = player->GetMail(mail_id);
  6194. if (mail) {
  6195. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  6196. if (kiosk_id > 0) {
  6197. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6198. if (update) {
  6199. update->setDataByName("action", 0x03);
  6200. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  6201. update->setDataByName("packetsubtype", 0xFF);
  6202. QueuePacket(update->serialize());
  6203. safe_delete(update);
  6204. }
  6205. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  6206. if (packet) {
  6207. packet->setDataByName("kiosk_id", kiosk_id);
  6208. packet->setDataByName("mail_id", mail->mail_id);
  6209. packet->setDataByName("player_to_id", mail->player_to_id);
  6210. packet->setDataByName("player_from", mail->player_from.c_str());
  6211. packet->setDataByName("subject", mail->subject.c_str());
  6212. packet->setDataByName("mail_body", mail->mail_body.c_str());
  6213. packet->setDataByName("unknown1", 1);
  6214. packet->setDataByName("unknown2", 0);
  6215. packet->setDataByName("lock_report_button", 1);
  6216. packet->setDataByName("unknown3", 0xFFFFFFFF);
  6217. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  6218. packet->setDataByName("coin_copper", mail->coin_copper);
  6219. packet->setDataByName("coin_silver", mail->coin_silver);
  6220. packet->setDataByName("coin_gold", mail->coin_gold);
  6221. packet->setDataByName("coin_plat", mail->coin_plat);
  6222. packet->setDataByName("stack", mail->stack);
  6223. packet->setDataByName("packettype", GetItemPacketType(GetVersion()));
  6224. packet->setDataByName("packetsubtype", 0xFF);
  6225. packet->setDataByName("unknown4", 0);
  6226. packet->setDataByName("unknown5", 0);
  6227. packet->setDataByName("unknown6", 0);
  6228. packet->setDataByName("unknown7", 0);
  6229. mail->already_read = true;
  6230. mail->save_needed = true;
  6231. QueuePacket(packet->serialize());
  6232. safe_delete(packet);
  6233. //SendMailList();
  6234. }
  6235. }
  6236. else
  6237. SimpleMessage(CHANNEL_COLOR_MAIL, "You are currently not in a mail transaction.");
  6238. }
  6239. }
  6240. /* 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
  6241. packet back to the client before the mail actually sent. */
  6242. void Client::HandleSentMail(EQApplicationPacket* app) {
  6243. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  6244. if (packet) {
  6245. packet->LoadPacketData(app->pBuffer, app->size);
  6246. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  6247. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  6248. vector<int32>* ids = 0;
  6249. if (reply_packet) {
  6250. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  6251. if (player_to.length() == 0)
  6252. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  6253. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  6254. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  6255. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  6256. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  6257. else {
  6258. if (player_to.compare("<all>") == 0) {
  6259. if (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat == 0)
  6260. ids = database.GetAllPlayerIDs();
  6261. else
  6262. SimpleMessage(CHANNEL_COLOR_MAIL, "You may not mail gifts to multiple players.");
  6263. }
  6264. else {
  6265. ids = new vector<int32>;
  6266. ids->push_back(database.GetCharacterID(player_to.c_str()));
  6267. }
  6268. if (ids) {
  6269. for (int32 i = 0; i < ids->size(); i++) {
  6270. int32 player_to_id = ids->at(i);
  6271. if (player_to_id > 0) {
  6272. reply_type = MAIL_SEND_RESULT_SUCCESS;
  6273. Mail* mail = new Mail;
  6274. mail->mail_id = 0;
  6275. mail->player_to_id = player_to_id;
  6276. mail->player_from = string(GetPlayer()->GetName());
  6277. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  6278. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  6279. mail->already_read = 0;
  6280. mail->mail_type = MAIL_TYPE_REGULAR;
  6281. mail->coin_copper = mail_window.coin_copper;
  6282. mail->coin_silver = mail_window.coin_silver;
  6283. mail->coin_gold = mail_window.coin_gold;
  6284. mail->coin_plat = mail_window.coin_plat;
  6285. mail->stack = 0;
  6286. // GM's send mail for free!
  6287. if (GetAdminStatus() > 0)
  6288. {
  6289. mail->postage_cost = 0;
  6290. mail->attachment_cost = 0;
  6291. }
  6292. else
  6293. {
  6294. mail->postage_cost = 10;
  6295. mail->attachment_cost = 50;
  6296. }
  6297. mail->char_item_id = 0;
  6298. mail->time_sent = Timer::GetUnixTimeStamp();
  6299. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  6300. //int16 packettype = packet->getType_int16_ByName("packettype");
  6301. //int8 packetsubtype = packet->getType_int8_ByName("packetsubtype");
  6302. /*int32 postage_cost = packet->getType_int32_ByName("postage_cost");
  6303. int32 attachment_cost = packet->getType_int32_ByName("attachment_cost");
  6304. if (postage_cost > 0 || attachment_cost > 0)
  6305. PlaySoundA("coin_cha_ching");*/
  6306. mail->save_needed = false;
  6307. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  6308. if (to_client) {
  6309. to_client->GetPlayer()->AddMail(mail);
  6310. to_client->SimpleMessage(CHANNEL_COLOR_MAIL, "You've got mail! :)");
  6311. }
  6312. database.SavePlayerMail(mail);
  6313. mail_window.coin_copper = 0;
  6314. mail_window.coin_silver = 0;
  6315. mail_window.coin_gold = 0;
  6316. mail_window.coin_plat = 0;
  6317. }
  6318. else
  6319. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  6320. }
  6321. }
  6322. }
  6323. string players_to = "";
  6324. if (ids) {
  6325. for (int32 i = 0; i < ids->size(); i++) {
  6326. if (ids->at(i) != 0)
  6327. players_to.append(database.GetCharacterName(ids->at(i)));
  6328. if (i < (ids->size() - 1))
  6329. players_to.append(", ");
  6330. }
  6331. }
  6332. reply_packet->setDataByName("player_to", players_to.c_str());
  6333. reply_packet->setDataByName("reply_type", reply_type);
  6334. QueuePacket(reply_packet->serialize());
  6335. safe_delete(reply_packet);
  6336. safe_delete(ids);
  6337. }
  6338. safe_delete(packet);
  6339. }
  6340. }
  6341. void Client::DeleteMail(int32 mail_id, bool from_database) {
  6342. player->DeleteMail(mail_id, from_database);
  6343. }
  6344. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  6345. bool ret = false;
  6346. if (GetMailTransaction()) {
  6347. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6348. if (packet) {
  6349. if (copper > 0) {
  6350. if (player->RemoveCoins(copper)) {
  6351. mail_window.coin_copper += copper;
  6352. Message(CHANNEL_COLOR_MAIL, "You add %u copper to the mail window.", copper);
  6353. ret = true;
  6354. }
  6355. }
  6356. else if (silver > 0) {
  6357. if (player->RemoveCoins(silver * 100)) {
  6358. mail_window.coin_silver += silver;
  6359. Message(CHANNEL_COLOR_MAIL, "You add %u silver to the mail window.", silver);
  6360. ret = true;
  6361. }
  6362. }
  6363. else if (gold > 0) {
  6364. if (player->RemoveCoins(gold * 10000)) {
  6365. mail_window.coin_gold += gold;
  6366. Message(CHANNEL_COLOR_MAIL, "You add %u gold to the mail window.", gold);
  6367. ret = true;
  6368. }
  6369. }
  6370. else if (plat > 0) {
  6371. if (player->RemoveCoins(plat * 1000000)) {
  6372. mail_window.coin_plat += plat;
  6373. Message(CHANNEL_COLOR_MAIL, "You add %u platinum to the mail window.", plat);
  6374. ret = true;
  6375. }
  6376. }
  6377. if (ret) {
  6378. packet->setDataByName("coin_copper", mail_window.coin_copper);
  6379. packet->setDataByName("coin_silver", mail_window.coin_silver);
  6380. packet->setDataByName("coin_gold", mail_window.coin_gold);
  6381. packet->setDataByName("coin_plat", mail_window.coin_plat);
  6382. packet->setDataByName("stack", 0);
  6383. packet->setDataByName("packettype", GetItemPacketType(version));
  6384. packet->setDataByName("packetsubtype", 0xFF);
  6385. packet->setDataByName("unknown2", 0);
  6386. //packet->PrintPacket();
  6387. QueuePacket(packet->serialize());
  6388. }
  6389. else
  6390. SimpleMessage(CHANNEL_COLOR_MAIL, "You don't have that much money.");
  6391. safe_delete(packet);
  6392. }
  6393. }
  6394. else
  6395. SimpleMessage(CHANNEL_COLOR_MAIL, "You are currently not in a mail transaction.");
  6396. return ret;
  6397. }
  6398. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  6399. bool ret = false;
  6400. if (GetMailTransaction()) {
  6401. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6402. if (packet) {
  6403. if (copper > 0) {
  6404. player->AddCoins(copper);
  6405. mail_window.coin_copper -= copper;
  6406. Message(CHANNEL_COLOR_MAIL, "You remove %u copper from the mail window.", copper);
  6407. ret = true;
  6408. }
  6409. else if (silver > 0) {
  6410. player->AddCoins(silver * 100);
  6411. mail_window.coin_silver -= silver;
  6412. Message(CHANNEL_COLOR_MAIL, "You remove %u silver from the mail window.", silver);
  6413. ret = true;
  6414. }
  6415. else if (gold > 0) {
  6416. player->AddCoins(gold * 10000);
  6417. mail_window.coin_gold -= gold;
  6418. Message(CHANNEL_COLOR_MAIL, "You remove %u gold from the mail window.", gold);
  6419. ret = true;
  6420. }
  6421. else if (plat > 0) {
  6422. player->AddCoins(plat * 1000000);
  6423. mail_window.coin_plat -= plat;
  6424. Message(CHANNEL_COLOR_MAIL, "You remove %u platinum from the mail window.", plat);
  6425. ret = true;
  6426. }
  6427. if (ret) {
  6428. packet->setDataByName("coin_copper", mail_window.coin_copper);
  6429. packet->setDataByName("coin_silver", mail_window.coin_silver);
  6430. packet->setDataByName("coin_gold", mail_window.coin_gold);
  6431. packet->setDataByName("coin_plat", mail_window.coin_plat);
  6432. packet->setDataByName("stack", 0);
  6433. packet->setDataByName("packettype", 0x2BFE);
  6434. packet->setDataByName("packetsubtype", 0xFF);
  6435. packet->setDataByName("unknown2", 0);
  6436. QueuePacket(packet->serialize());
  6437. }
  6438. safe_delete(packet);
  6439. }
  6440. }
  6441. else
  6442. SimpleMessage(CHANNEL_COLOR_MAIL, "You are currently not in a mail transaction.");
  6443. return ret;
  6444. }
  6445. void Client::TakeMailAttachments(int32 mail_id) {
  6446. if (GetMailTransaction()) {
  6447. Mail* mail = player->GetMail(mail_id);
  6448. if (mail) {
  6449. int64 amount = 0;
  6450. if (mail->coin_copper > 0) {
  6451. amount += mail->coin_copper;
  6452. mail->coin_copper = 0;
  6453. }
  6454. if (mail->coin_silver > 0) {
  6455. amount += mail->coin_silver * 100;
  6456. mail->coin_silver = 0;
  6457. }
  6458. if (mail->coin_gold > 0) {
  6459. amount += mail->coin_gold * 10000;
  6460. mail->coin_gold = 0;
  6461. }
  6462. if (mail->coin_plat > 0) {
  6463. amount += mail->coin_plat * 1000000;
  6464. mail->coin_plat = 0;
  6465. }
  6466. if (mail->char_item_id > 0) {
  6467. LogWrite(MISC__TODO, 1, "TODO", "Items by Mail\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  6468. }
  6469. /* 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
  6470. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  6471. find it in any packet logs.*/
  6472. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6473. if (packet) {
  6474. packet->setDataByName("unknown", 0x03);
  6475. packet->setDataByName("coin_copper", mail->coin_copper);
  6476. packet->setDataByName("coin_silver", mail->coin_silver);
  6477. packet->setDataByName("coin_gold", mail->coin_gold);
  6478. packet->setDataByName("coin_plat", mail->coin_plat);
  6479. packet->setDataByName("stack", 0);
  6480. packet->setDataByName("packettype", 0x2BFE);
  6481. packet->setDataByName("packetsubtype", 0xFF);
  6482. packet->setDataByName("unknown2", 0);
  6483. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  6484. DumpPacket(packet->serialize());
  6485. QueuePacket(packet->serialize());
  6486. safe_delete(packet);
  6487. }*/
  6488. database.SavePlayerMail(mail);
  6489. if (amount > 0)
  6490. player->AddCoins(amount);
  6491. SendMailList();
  6492. }
  6493. }
  6494. else
  6495. SimpleMessage(CHANNEL_COLOR_MAIL, "You are currently not in a mail transaction.");
  6496. }
  6497. void Client::CancelSendMail() {
  6498. SimpleMessage(CHANNEL_COLOR_MAIL, "You cancel sending a letter.");
  6499. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  6500. mail_window.coin_copper = 0;
  6501. mail_window.coin_silver = 0;
  6502. mail_window.coin_gold = 0;
  6503. mail_window.coin_plat = 0;
  6504. mail_window.char_item_id = 0;
  6505. }
  6506. bool Client::GateAllowed() {
  6507. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  6508. 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__);
  6509. if (zone)
  6510. return true;
  6511. return false;
  6512. }
  6513. bool Client::BindAllowed() {
  6514. 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__);
  6515. return true;
  6516. }
  6517. bool Client::Bind() {
  6518. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  6519. player->GetPlayerInfo()->SetBindX(player->GetX());
  6520. player->GetPlayerInfo()->SetBindY(player->GetY());
  6521. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  6522. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  6523. return true;
  6524. }
  6525. bool Client::Gate() {
  6526. if (player->GetPlayerInfo()->GetBindZoneID() == 0)
  6527. return false;
  6528. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  6529. if (zone) {
  6530. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  6531. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  6532. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  6533. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  6534. Zone(zone, false);
  6535. return true;
  6536. }
  6537. return false;
  6538. }
  6539. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id) {
  6540. if (!destinations || !spawn) {
  6541. return;
  6542. }
  6543. bool has_map = false;
  6544. if (transport_id > 0)
  6545. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  6546. transport_spawn = spawn;
  6547. vector<TransportDestination*> transport_list;
  6548. vector<TransportDestination*>::iterator itr;
  6549. TransportDestination* destination = 0;
  6550. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  6551. destination = *itr;
  6552. 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)))
  6553. transport_list.push_back(destination);
  6554. }
  6555. if (transport_list.size() == 0 && destination) {
  6556. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  6557. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  6558. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  6559. else
  6560. {
  6561. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  6562. if (app)
  6563. QueuePacket(app);
  6564. }
  6565. }
  6566. else {
  6567. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  6568. // determine if this is an instanced zone that already exists
  6569. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  6570. if (instance_zone || new_zone) {
  6571. GetPlayer()->SetX(destination->destination_x);
  6572. GetPlayer()->SetY(destination->destination_y);
  6573. GetPlayer()->SetZ(destination->destination_z);
  6574. GetPlayer()->SetHeading(destination->destination_heading);
  6575. if (instance_zone)
  6576. Zone(instance_zone->GetInstanceID(), false, true);
  6577. else
  6578. Zone(new_zone, false);
  6579. }
  6580. }
  6581. if (destination->message.length() > 0)
  6582. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  6583. }
  6584. else if (transport_list.size() > 0) {
  6585. if (!spawn->IsSoundsDisabled())
  6586. PlaySound("mariner_bell");
  6587. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  6588. if (packet) {
  6589. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  6590. // Put all the destinations the player can go in a new vector
  6591. vector<TransportDestination*> destinations;
  6592. for (int32 i = 0; i < transport_list.size(); i++) {
  6593. destination = transport_list.at(i);
  6594. // Check min level
  6595. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  6596. continue;
  6597. // Check max level
  6598. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  6599. continue;
  6600. // Check quest complete
  6601. if (destination->req_quest_complete > 0 && GetPlayer()->GetCompletedQuest(destination->req_quest_complete) == 0)
  6602. continue;
  6603. // Check req quest and step
  6604. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  6605. continue;
  6606. // 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
  6607. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  6608. packet->setDataByName("current_zone", destination->display_name.c_str());
  6609. packet->setDataByName("current_map_x", destination->map_x);
  6610. packet->setDataByName("current_map_y", destination->map_y);
  6611. }
  6612. else {
  6613. destinations.push_back(destination);
  6614. }
  6615. }
  6616. // Use the new vector to create the packet
  6617. destination = 0;
  6618. packet->setArrayLengthByName("num_destinations", destinations.size());
  6619. for (int32 i = 0; i < destinations.size(); i++) {
  6620. destination = destinations.at(i);
  6621. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  6622. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  6623. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  6624. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  6625. packet->setArrayDataByName("cost", destination->cost, i);
  6626. if (has_map) {
  6627. packet->setArrayDataByName("map_x", destination->map_x, i);
  6628. packet->setArrayDataByName("map_y", destination->map_y, i);
  6629. }
  6630. }
  6631. if (has_map)
  6632. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  6633. EQ2Packet* app = packet->serialize();
  6634. //DumpPacket(app);
  6635. if (destinations.size() > 0)
  6636. QueuePacket(app);
  6637. safe_delete(packet);
  6638. }
  6639. }
  6640. }
  6641. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  6642. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  6643. if (packet) {
  6644. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  6645. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  6646. int32 unique_id = packet->getType_int32_ByName("unique_id");
  6647. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  6648. int32 cost = packet->getType_int32_ByName("cost");
  6649. vector<TransportDestination*> destinations;
  6650. TransportDestination* destination = 0;
  6651. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  6652. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  6653. vector<TransportDestination*>::iterator itr;
  6654. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  6655. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  6656. destination = *itr;
  6657. break;
  6658. }
  6659. }
  6660. SetTemporaryTransportID(0);
  6661. if (!destination)
  6662. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  6663. else {
  6664. if (cost == 0 || player->RemoveCoins(cost)) {
  6665. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  6666. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  6667. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  6668. else
  6669. {
  6670. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  6671. if (outapp)
  6672. QueuePacket(outapp);
  6673. }
  6674. }
  6675. else {
  6676. GetPlayer()->SetX(destination->destination_x);
  6677. GetPlayer()->SetY(destination->destination_y);
  6678. GetPlayer()->SetZ(destination->destination_z);
  6679. GetPlayer()->SetHeading(destination->destination_heading);
  6680. // Test if where we're going is an Instanced zone
  6681. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  6682. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  6683. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  6684. Zone(new_zone, false);
  6685. }
  6686. }
  6687. if (destination->message.length() > 0)
  6688. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  6689. }
  6690. else
  6691. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  6692. }
  6693. }
  6694. safe_delete(packet);
  6695. }
  6696. }
  6697. void Client::SendNewSpells(int8 class_id) {
  6698. if (class_id > 0) {
  6699. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  6700. vector<Spell*>::iterator itr;
  6701. Spell* spell = 0;
  6702. bool send_updates = false;
  6703. for (itr = spells->begin(); itr != spells->end(); itr++) {
  6704. spell = *itr;
  6705. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  6706. send_updates = true;
  6707. SendSpellUpdate(spell);
  6708. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  6709. player->UnlockSpell(spell);
  6710. }
  6711. }
  6712. if (send_updates) {
  6713. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  6714. if (outapp)
  6715. QueuePacket(outapp);
  6716. }
  6717. safe_delete(spells);
  6718. }
  6719. }
  6720. void Client::SetItemSearch(vector<Item*>* items) {
  6721. if (items) {
  6722. safe_delete(search_items);
  6723. search_items = items;
  6724. }
  6725. }
  6726. vector<Item*>* Client::GetSearchItems() {
  6727. return search_items;
  6728. }
  6729. void Client::SearchStore(int32 page) {
  6730. if (search_items) {
  6731. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  6732. if (packet) {
  6733. int32 x = page * 8;
  6734. if (search_items->size() > 8) {
  6735. if ((search_items->size() - x) > 8)
  6736. packet->setArrayLengthByName("num_items", 8);
  6737. else
  6738. packet->setArrayLengthByName("num_items", search_items->size() - x);
  6739. }
  6740. else
  6741. packet->setArrayLengthByName("num_items", search_items->size());
  6742. if (search_items->size() > 0) {
  6743. packet->setArrayLengthByName("num_sellers", 1);
  6744. packet->setArrayDataByName("seller_seller_id", 1);
  6745. packet->setArrayDataByName("seller_name", "EQ2EmuDevs");
  6746. packet->setDataByName("per_page", 8);
  6747. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  6748. packet->setDataByName("page", page);
  6749. Item* item = 0;
  6750. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  6751. for (int32 i = 0; i < limit; i++, x++) {
  6752. if (x >= search_items->size())
  6753. break;
  6754. item = search_items->at(x);
  6755. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6756. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6757. packet->setArrayDataByName("icon", item->details.icon, i);
  6758. //packet->setArrayDataByName("unknown2b", i, i);
  6759. packet->setArrayDataByName("item_seller_id", 1, i);
  6760. if (item->stack_count == 0)
  6761. packet->setArrayDataByName("quantity", 1, i);
  6762. else
  6763. packet->setArrayDataByName("quantity", item->stack_count, i);
  6764. packet->setArrayDataByName("stack_size", item->stack_count, i);
  6765. std::string tmpStr("");
  6766. tmpStr.append(item->name.c_str());
  6767. tmpStr.append(" (");
  6768. tmpStr.append(std::to_string(item->details.item_id));
  6769. tmpStr.append(")");
  6770. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  6771. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  6772. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  6773. }
  6774. }
  6775. /*EQ2Packet* outapp = packet->serialize();
  6776. DumpPacket(outapp);
  6777. QueuePacket(outapp);*/
  6778. QueuePacket(packet->serialize());
  6779. safe_delete(packet);
  6780. }
  6781. }
  6782. }
  6783. void Client::SetReadyForUpdates() {
  6784. GetPlayer()->SetFullyLoggedIn(true);
  6785. if (!ready_for_updates)
  6786. database.loadCharacterProperties(this);
  6787. ready_for_updates = true;
  6788. }
  6789. void Client::SetReadyForSpawns(bool val) {
  6790. ready_for_spawns = val;
  6791. if (GetPlayer()->GetActivityStatus() > 0) {
  6792. GetPlayer()->SetActivityStatus(0);
  6793. if (GetPlayer()->GetGroupMemberInfo()) {
  6794. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  6795. }
  6796. }
  6797. zone_list.CheckFriendZoned(this);
  6798. }
  6799. void Client::SendChatRelationship(int8 type, const char* name) {
  6800. if (!name) {
  6801. return;
  6802. }
  6803. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  6804. if (packet) {
  6805. packet->setDataByName("account_id", GetAccountID());
  6806. packet->setDataByName("type", type);
  6807. packet->setArrayLengthByName("num_names", 1);
  6808. packet->setArrayDataByName("name", name);
  6809. if (type == 0) {
  6810. Client* client = zone_list.GetClientByCharName(name);
  6811. if (client) {
  6812. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  6813. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  6814. }
  6815. }
  6816. QueuePacket(packet->serialize());
  6817. safe_delete(packet);
  6818. }
  6819. }
  6820. void Client::SendFriendList() {
  6821. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  6822. if (packet) {
  6823. packet->setDataByName("account_id", GetAccountID());
  6824. map<string, int8>::iterator itr;
  6825. map<string, int8>* friends = player->GetFriends();
  6826. if (friends && friends->size() > 0) {
  6827. Client* client = 0;
  6828. vector<string> names;
  6829. for (itr = friends->begin(); itr != friends->end(); itr++) {
  6830. if (itr->second == 2)
  6831. continue;
  6832. names.push_back(itr->first);
  6833. }
  6834. packet->setArrayLengthByName("num_names", names.size());
  6835. for (int32 i = 0; i < names.size(); i++) {
  6836. client = zone_list.GetClientByCharName(names[i]);
  6837. packet->setArrayDataByName("name", names[i].c_str(), i);
  6838. if (client) {
  6839. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  6840. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  6841. }
  6842. }
  6843. }
  6844. QueuePacket(packet->serialize());
  6845. safe_delete(packet);
  6846. }
  6847. }
  6848. void Client::SendIgnoreList() {
  6849. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  6850. if (packet) {
  6851. packet->setDataByName("account_id", GetAccountID());
  6852. packet->setDataByName("type", 2);
  6853. map<string, int8>::iterator itr;
  6854. map<string, int8>* ignored = player->GetIgnoredPlayers();
  6855. if (ignored && ignored->size() > 0) {
  6856. vector<string> names;
  6857. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  6858. if (itr->second == 2)
  6859. continue;
  6860. names.push_back(itr->first);
  6861. }
  6862. packet->setArrayLengthByName("num_names", names.size());
  6863. for (int32 i = 0; i < names.size(); i++)
  6864. packet->setArrayDataByName("name", names[i].c_str(), i);
  6865. }
  6866. QueuePacket(packet->serialize());
  6867. safe_delete(packet);
  6868. }
  6869. }
  6870. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  6871. if (waypoint_name) {
  6872. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  6873. if (packet) {
  6874. packet->setArrayLengthByName("num_updates", 1);
  6875. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  6876. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  6877. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  6878. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  6879. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  6880. QueuePacket(packet->serialize());
  6881. safe_delete(packet);
  6882. }
  6883. }
  6884. }
  6885. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  6886. if (waypoint_name) {
  6887. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  6888. if (packet) {
  6889. packet->setArrayLengthByName("num_points", 1);
  6890. packet->setArrayDataByName("x", x, 0);
  6891. packet->setArrayDataByName("y", y, 0);
  6892. packet->setArrayDataByName("z", z, 0);
  6893. packet->setDataByName("waypoint_x", x);
  6894. packet->setDataByName("waypoint_y", y);
  6895. packet->setDataByName("waypoint_z", z);
  6896. packet->setDataByName("waypoint_name", waypoint_name);
  6897. packet->setDataByName("unknown", 0);
  6898. QueuePacket(packet->serialize());
  6899. safe_delete(packet);
  6900. }
  6901. }
  6902. }
  6903. void Client::InspectPlayer(Player* player_to_inspect) {
  6904. if (player_to_inspect) {
  6905. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  6906. if (packet) {
  6907. packet->setDataByName("unknown", 0);
  6908. packet->setSmallStringByName("name", player_to_inspect->GetName());
  6909. packet->setDataByName("race", player_to_inspect->GetRace());
  6910. packet->setDataByName("gender", player_to_inspect->GetGender());
  6911. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  6912. LogWrite(MISC__TODO, 1, "TODO", "Put mentored level here (adventure_level_effective)\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  6913. packet->setDataByName("adventure_level_effective", player_to_inspect->GetLevel());
  6914. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  6915. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  6916. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  6917. packet->setDataByName("health", player_to_inspect->GetHP());
  6918. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  6919. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  6920. packet->setDataByName("power", player_to_inspect->GetPower());
  6921. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  6922. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  6923. packet->setDataByName("mitigation", 0);
  6924. packet->setDataByName("unknown1", 0);
  6925. packet->setDataByName("avoidance", 0);
  6926. packet->setDataByName("unknown2", 0);
  6927. packet->setDataByName("mitigation_percentage", 0);
  6928. packet->setDataByName("strength", player_to_inspect->GetStr());
  6929. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  6930. packet->setDataByName("stamina", player_to_inspect->GetSta());
  6931. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  6932. packet->setDataByName("agility", player_to_inspect->GetAgi());
  6933. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  6934. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  6935. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  6936. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  6937. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  6938. packet->setDataByName("unknown4", 0);
  6939. packet->setDataByName("unknown5", 0);
  6940. packet->setDataByName("unknown6", 0);
  6941. packet->setDataByName("unknown7", 0);
  6942. packet->setDataByName("unknown8", 0);
  6943. packet->setDataByName("unknown9", 0);
  6944. packet->setDataByName("unknown10", 0);
  6945. packet->setDataByName("unknown11", 0);
  6946. packet->setDataByName("unknown12", 0);
  6947. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  6948. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  6949. packet->setDataByName("heat_resist_percentage", 0);
  6950. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  6951. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  6952. packet->setDataByName("cold_resist_percentage", 0);
  6953. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  6954. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  6955. packet->setDataByName("magic_resist_percentage", 0);
  6956. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  6957. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  6958. packet->setDataByName("mental_resist_percentage", 0);
  6959. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  6960. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  6961. packet->setDataByName("divine_resist_percentage", 0);
  6962. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  6963. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  6964. packet->setDataByName("disease_resist_percentage", 0);
  6965. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  6966. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  6967. packet->setDataByName("poison_resist_percentage", 0);
  6968. packet->setArrayLengthByName("num_chars", 0x01FF);
  6969. string biography = player_to_inspect->GetBiography();
  6970. for (size_t i = 0; i < biography.length(); i++)
  6971. packet->setArrayDataByName("biography_char", biography[i], i);
  6972. LogWrite(MISC__TODO, 0, "TODO", "Why is inspect player weapons commented out? in func: %s, line: %i", __FUNCTION__, __LINE__);
  6973. /*Item* pw = player_to_inspect->GetEquipmentList()->GetItem(0);
  6974. if (pw)
  6975. packet->setItemByName("primary", pw, player_to_inspect, 0);
  6976. Item* sw = player_to_inspect->GetEquipmentList()->GetItem(1);
  6977. if (sw)
  6978. packet->setItemByName("secondary", sw, player_to_inspect, 0);*/
  6979. //DumpPacket(packet->serialize());
  6980. QueuePacket(packet->serialize());
  6981. safe_delete(packet);
  6982. }
  6983. }
  6984. }
  6985. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  6986. pending_guild_invite.guild = guild;
  6987. pending_guild_invite.invited_by = invited_by;
  6988. }
  6989. void Client::ShowClaimWindow() {
  6990. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  6991. if (packet) {
  6992. map<int32, Item*>* items = &master_item_list.items;
  6993. map<int32, Item*>::iterator itr;
  6994. int32 i = 0;
  6995. if (items->size() > 10)
  6996. packet->setArrayLengthByName("num_claim_items", 10);
  6997. else
  6998. packet->setArrayLengthByName("num_claim_items", items->size());
  6999. for (itr = items->begin(); itr != items->end(); itr++) {
  7000. if (i == 10)
  7001. break;
  7002. Item* item = itr->second;
  7003. packet->setArrayDataByName("id", i, i);
  7004. packet->setArrayDataByName("not_yet_claimed", 1, i);
  7005. packet->setArrayDataByName("num_remaining", 5, i);
  7006. packet->setArrayDataByName("one_per_character", 1, i);
  7007. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  7008. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7009. packet->setArrayDataByName("text", "If you ever see this text, let Scatman know, thanks! :)", i);
  7010. packet->setArrayDataByName("category", "Scott's Shit", i);
  7011. packet->setArrayDataByName("icon", item->details.icon, i);
  7012. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7013. i++;
  7014. }
  7015. packet->setDataByName("unknown3", 1);
  7016. QueuePacket(packet->serialize());
  7017. safe_delete(packet);
  7018. }
  7019. }
  7020. void Client::ShowGuildSearchWindow() {
  7021. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  7022. if (packet) {
  7023. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  7024. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  7025. packet->setArrayLengthByName("num_guilds", guilds->size());
  7026. int32 i = 0;
  7027. while (itr.Next()) {
  7028. Guild* guild = itr.second;
  7029. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  7030. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  7031. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  7032. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  7033. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  7034. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  7035. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  7036. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  7037. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  7038. packet->setArrayDataByName("unknown7", 0x02, i);
  7039. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  7040. i++;
  7041. }
  7042. QueuePacket(packet->serialize());
  7043. safe_delete(packet);
  7044. }
  7045. }
  7046. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  7047. PacketStruct* packet;
  7048. vector<int8>* slot_data;
  7049. vector<int8>::iterator itr;
  7050. int32 slots = 0;
  7051. assert(item);
  7052. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  7053. return;
  7054. }
  7055. slot_data = &item->slot_data;
  7056. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  7057. if (version >= 1188)
  7058. slots = *itr;
  7059. else
  7060. slots += (int8)pow(2.0, *itr);
  7061. }
  7062. packet->setDataByName("slot", slots);
  7063. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  7064. if (slots == 2) {
  7065. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  7066. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  7067. }
  7068. else {
  7069. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  7070. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  7071. }
  7072. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  7073. if (slots == 4) {
  7074. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  7075. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  7076. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  7077. }
  7078. else if (slots == 7) {
  7079. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  7080. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  7081. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  7082. }
  7083. else {
  7084. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  7085. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  7086. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  7087. }
  7088. packet->setDataByName("icon", item->details.icon);
  7089. packet->setDataByName("item_id", item->details.item_id);
  7090. packet->setDataByName("item_crc", crc);
  7091. packet->setDataByName("unknown2", 0xFFFFFFFF);
  7092. packet->setDataByName("unknown4", 0xFFFFFFFF);
  7093. packet->setDataByName("unknown5", 0xFF, 9);
  7094. packet->setDataByName("unknown5", 0xFF, 10);
  7095. QueuePacket(packet->serialize());
  7096. safe_delete(packet);
  7097. }
  7098. void Client::SendCollectionList() {
  7099. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  7100. map<int32, Collection*>::iterator itr;
  7101. vector<struct CollectionItem*>* collection_items;
  7102. Collection* collection;
  7103. struct CollectionItem* collection_item;
  7104. PacketStruct* packet = 0;
  7105. int16 i = 0, j;
  7106. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  7107. return;
  7108. packet->setArrayLengthByName("num_collections", collections->size());
  7109. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7110. collection = itr->second;
  7111. collection_items = collection->GetCollectionItems();
  7112. packet->setArrayDataByName("unknown", 1, i);
  7113. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  7114. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  7115. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  7116. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  7117. packet->setArrayDataByName("level", collection->GetLevel(), i);
  7118. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  7119. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  7120. for (j = 0; j < collection_items->size(); j++) {
  7121. collection_item = collection_items->at(j);
  7122. Item* item = master_item_list.GetItem(collection_item->item);
  7123. if (item) {
  7124. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  7125. if (version < 955)
  7126. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  7127. else
  7128. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  7129. }
  7130. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  7131. }
  7132. i++;
  7133. }
  7134. packet->setDataByName("new_collection_flag", 1);
  7135. QueuePacket(packet->serialize());
  7136. safe_delete(packet);
  7137. }
  7138. bool Client::SendCollectionsForItem(Item* item) {
  7139. map<int32, Collection*> collections_to_send;
  7140. map<int32, Collection*>* collections;
  7141. map<int32, Collection*>::iterator itr;
  7142. vector<struct CollectionItem*>* collection_items;
  7143. Collection* collection;
  7144. struct CollectionItem* collection_item;
  7145. PacketStruct* packet;
  7146. int16 i;
  7147. assert(item);
  7148. /* get any collections required by this item that the player already has */
  7149. collections = player->GetCollectionList()->GetCollections();
  7150. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7151. collection = itr->second;
  7152. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  7153. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  7154. collections_to_send[collection->GetID()] = collection;
  7155. }
  7156. }
  7157. /* get any collections required by this item that the player does not have and send it to the client */
  7158. collections = master_collection_list.GetCollections();
  7159. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7160. collection = itr->second;
  7161. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  7162. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  7163. return false;
  7164. }
  7165. packet->setArrayLengthByName("num_collections", 1);
  7166. packet->setArrayDataByName("unknown", 1, 0);
  7167. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  7168. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  7169. packet->setArrayDataByName("completed", 0, 0);
  7170. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  7171. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  7172. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  7173. packet->setArrayDataByName("unknown3", 0x28, 0);
  7174. collection_items = collection->GetCollectionItems();
  7175. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  7176. for (i = 0; i < collection_items->size(); i++) {
  7177. collection_item = collection_items->at(i);
  7178. Item* item2 = master_item_list.GetItem(collection_item->item);
  7179. if (item2) {
  7180. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  7181. if (version < 955)
  7182. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  7183. else
  7184. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  7185. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  7186. }
  7187. }
  7188. packet->setDataByName("new_collection_flag", 0);
  7189. QueuePacket(packet->serialize());
  7190. safe_delete(packet);
  7191. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  7192. collections_to_send[collection->GetID()] = collection;
  7193. }
  7194. }
  7195. /* send the client a list of collections that should be filtered for this item */
  7196. if (collections_to_send.size() > 0) {
  7197. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  7198. return false;
  7199. }
  7200. i = 0;
  7201. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  7202. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  7203. collection = itr->second;
  7204. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  7205. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  7206. i++;
  7207. }
  7208. packet->setDataByName("item_icon", item->details.icon);
  7209. packet->setDataByName("item_name", item->name.c_str());
  7210. packet->setDataByName("item_id", item->details.item_id);
  7211. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  7212. QueuePacket(packet->serialize());
  7213. safe_delete(packet);
  7214. }
  7215. return collections_to_send.size() > 0;
  7216. }
  7217. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  7218. Collection* collection;
  7219. struct CollectionItem* collection_item;
  7220. PacketStruct* packet;
  7221. char tmp[200] = { 0 };
  7222. assert(item);
  7223. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  7224. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  7225. /* get the item struct that represents the item for this collection */
  7226. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  7227. SendCollectionList();
  7228. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  7229. return;
  7230. }
  7231. /* sanity check */
  7232. if (collection_item->found) {
  7233. SendCollectionList();
  7234. 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());
  7235. return;
  7236. }
  7237. }
  7238. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  7239. collection = new Collection(collection);
  7240. /* get the item struct that represents the item for this collection */
  7241. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  7242. SendCollectionList();
  7243. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  7244. safe_delete(collection);
  7245. return;
  7246. }
  7247. /* add the new collection to the player's collection list */
  7248. if (!player->GetCollectionList()->AddCollection(collection)) {
  7249. SendCollectionList();
  7250. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  7251. safe_delete(collection);
  7252. return;
  7253. }
  7254. }
  7255. else {
  7256. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  7257. return;
  7258. }
  7259. collection_item->found = 1;
  7260. collection->SetSaveNeeded(true);
  7261. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  7262. SendCollectionList();
  7263. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  7264. return;
  7265. }
  7266. packet->setDataByName("collection_id", collection_id);
  7267. packet->setDataByName("collection_item_num", collection_item->index);
  7268. packet->setDataByName("add", 1);
  7269. QueuePacket(packet->serialize());
  7270. Item* item2 = master_item_list.GetItem(collection_item->item);
  7271. if (item2) {
  7272. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  7273. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  7274. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  7275. }
  7276. safe_delete(packet);
  7277. RemoveItem(item, 1);
  7278. SendCollectionList();
  7279. }
  7280. void Client::DisplayCollectionComplete(Collection* collection) {
  7281. vector<struct CollectionRewardItem*>* reward_items;
  7282. vector<struct CollectionRewardItem*>* selectable_reward_items;
  7283. struct CollectionRewardItem* reward_item;
  7284. PacketStruct* packet;
  7285. int32 i;
  7286. assert(collection);
  7287. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  7288. return;
  7289. }
  7290. reward_items = collection->GetRewardItems();
  7291. selectable_reward_items = collection->GetSelectableRewardItems();
  7292. packet->setDataByName("title", "Quest Reward!");
  7293. packet->setDataByName("name", collection->GetName());
  7294. packet->setDataByName("description", collection->GetCategory());
  7295. packet->setDataByName("level", collection->GetLevel());
  7296. packet->setDataByName("max_coin", collection->GetRewardCoin());
  7297. packet->setDataByName("min_coin", collection->GetRewardCoin());
  7298. //packet->setDataByName("status_points", quest->GetStatusPoints());
  7299. packet->setArrayLengthByName("num_rewards", reward_items->size());
  7300. for (i = 0; i < reward_items->size(); i++) {
  7301. reward_item = reward_items->at(i);
  7302. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  7303. if (version < 860)
  7304. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
  7305. else if (version < 1193)
  7306. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  7307. else
  7308. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  7309. }
  7310. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  7311. for (i = 0; i < selectable_reward_items->size(); i++) {
  7312. reward_item = selectable_reward_items->at(i);
  7313. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  7314. if (version < 860)
  7315. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
  7316. else if (version < 1193)
  7317. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  7318. else
  7319. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  7320. }
  7321. QueuePacket(packet->serialize());
  7322. safe_delete(packet);
  7323. }
  7324. void Client::HandInCollections() {
  7325. map<int32, Collection*>* collections;
  7326. map<int32, Collection*>::iterator itr;
  7327. Collection* collection;
  7328. /* only show 1 collection reward dialog at a time */
  7329. if (player->GetPendingCollectionReward()) {
  7330. return;
  7331. }
  7332. collections = player->GetCollectionList()->GetCollections();
  7333. /* 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
  7334. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  7335. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7336. collection = itr->second;
  7337. if (collection->GetIsReadyToTurnIn()) {
  7338. player->SetPendingCollectionReward(collection);
  7339. DisplayCollectionComplete(collection);
  7340. return;
  7341. }
  7342. }
  7343. }
  7344. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  7345. vector<struct CollectionRewardItem*>* reward_items;
  7346. vector<struct CollectionRewardItem*>::iterator itr;
  7347. struct CollectionRewardItem* reward_item;
  7348. int16 num_slots_needed;
  7349. int16 num_slots;
  7350. assert(collection);
  7351. reward_items = collection->GetRewardItems();
  7352. num_slots_needed = (int16)reward_items->size();
  7353. if (selectable_item_id > 0)
  7354. num_slots_needed++;
  7355. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  7356. if (num_slots < num_slots_needed) {
  7357. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  7358. HandInCollections();
  7359. return;
  7360. }
  7361. /* add manditory items */
  7362. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  7363. reward_item = *itr;
  7364. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  7365. }
  7366. /* find and add the selectable item if there's one */
  7367. if (selectable_item_id > 0) {
  7368. reward_items = collection->GetSelectableRewardItems();
  7369. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  7370. reward_item = *itr;
  7371. if (reward_item->item->details.item_id == selectable_item_id) {
  7372. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  7373. break;
  7374. }
  7375. }
  7376. }
  7377. if (collection->GetRewardXP() > 0) {
  7378. player->AddXP((int32)collection->GetRewardXP());
  7379. SimpleMessage(CHANNEL_COLOR_YELLOW, "You gain experience!");
  7380. }
  7381. if (collection->GetRewardCoin() > 0) {
  7382. player->AddCoins(collection->GetRewardCoin());
  7383. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  7384. }
  7385. collection->SetCompleted(true);
  7386. //update achievements for completeing collection here
  7387. collection->SetSaveNeeded(true);
  7388. SendCollectionList();
  7389. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  7390. player->SetPendingCollectionReward(0);
  7391. HandInCollections();
  7392. }
  7393. void Client::SendRecipeList() {
  7394. PacketStruct* packet = 0;
  7395. if (GetRecipeListSent()) {
  7396. return;
  7397. }
  7398. if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  7399. return;
  7400. }
  7401. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  7402. map<int32, Recipe*>::iterator itr;
  7403. Recipe* recipe;
  7404. int16 i = 0;
  7405. packet->setArrayLengthByName("num_recipes", recipes->size());
  7406. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  7407. recipe = itr->second;
  7408. packet->setArrayDataByName("id", recipe->GetID(), i);
  7409. packet->setArrayDataByName("tier", recipe->GetTier(), i);
  7410. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  7411. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  7412. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  7413. packet->setArrayDataByName("skill", recipe->GetSkill(), i);
  7414. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  7415. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  7416. packet->setArrayDataByName("unknown2", recipe->GetUnknown2(), i);
  7417. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  7418. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  7419. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  7420. i++;
  7421. }
  7422. //packet->PrintPacket();
  7423. //DumpPacket(packet->serialize());
  7424. QueuePacket(packet->serialize());
  7425. safe_delete(packet);
  7426. SetRecipeListSent(true);
  7427. }
  7428. void Client::ShowRecipeBook() {
  7429. PacketStruct* packet = 0;
  7430. Spawn* target = 0;
  7431. if (!(target = player->GetTarget())) {
  7432. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  7433. return;
  7434. }
  7435. if (!target->IsObject()) {
  7436. return;
  7437. }
  7438. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  7439. return;
  7440. }
  7441. packet->setDataByName("device", target->GetName());
  7442. packet->setDataByName("unknown1", 1);
  7443. if (((Object*)target)->GetDeviceID() > 0) {
  7444. int32 deviceID = (int32)pow(2.0, (double)((Object*)target)->GetDeviceID());
  7445. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  7446. packet->setDataByName("unknown2", 8);
  7447. packet->setDataByName("unknown3", deviceID);
  7448. }
  7449. //packet->PrintPacket();
  7450. QueuePacket(packet->serialize());
  7451. safe_delete(packet);
  7452. }
  7453. void Client::SendTitleUpdate() {
  7454. list<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  7455. list<Title*>::iterator itr;
  7456. Title* title;
  7457. int16 i = 0;
  7458. sint16 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  7459. sint16 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  7460. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  7461. if (packet) {
  7462. packet->setArrayLengthByName("num_titles", titles->size());
  7463. for (itr = titles->begin(); itr != titles->end(); itr++) {
  7464. title = *itr;
  7465. packet->setArrayDataByName("title", title->GetName(), i);
  7466. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  7467. i++;
  7468. }
  7469. packet->setDataByName("current_prefix", prefix_index);
  7470. packet->setDataByName("current_suffix", suffix_index);
  7471. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  7472. #if EQDEBUG >= 9
  7473. packet->PrintPacket();
  7474. #endif
  7475. QueuePacket(packet->serialize());
  7476. safe_delete(packet);
  7477. SendUpdateTitles(prefix_index, suffix_index);
  7478. }
  7479. }
  7480. void Client::SendUpdateTitles(sint16 prefix, sint16 suffix) {
  7481. Title* suffix_title = 0;
  7482. Title* prefix_title = 0;
  7483. if (suffix != -1) {
  7484. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  7485. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  7486. }
  7487. else
  7488. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  7489. if (prefix != -1) {
  7490. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  7491. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  7492. }
  7493. else
  7494. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  7495. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  7496. }
  7497. void Client::SendLanguagesUpdate(int32 id) {
  7498. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  7499. list<Language*>::iterator itr;
  7500. Language* language;
  7501. int32 i = 0;
  7502. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  7503. if (packet) {
  7504. packet->setArrayLengthByName("num_languages", languages->size());
  7505. for (itr = languages->begin(); itr != languages->end(); itr++) {
  7506. language = *itr;
  7507. packet->setArrayDataByName("language_id", language->GetID(), i);
  7508. i++;
  7509. }
  7510. packet->setDataByName("current_language", id);
  7511. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  7512. #if EQDEBUG >= 9
  7513. packet->PrintPacket();
  7514. #endif
  7515. QueuePacket(packet->serialize());
  7516. safe_delete(packet);
  7517. }
  7518. }
  7519. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  7520. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  7521. if (packet) {
  7522. if (pet_name)
  7523. packet->setDataByName("pet_name", pet_name);
  7524. if (player->GetInfoStruct()->pet_behavior & 1)
  7525. packet->setDataByName("protect_master", 1);
  7526. if (player->GetInfoStruct()->pet_behavior & 2)
  7527. packet->setDataByName("protect_self", 1);
  7528. if (player->GetInfoStruct()->pet_movement == 2)
  7529. packet->setDataByName("stay_follow_toggle", 1);
  7530. packet->setDataByName("pet_type", type);
  7531. QueuePacket(packet->serialize());
  7532. }
  7533. safe_delete(packet);
  7534. }
  7535. bool Client::IsCrafting() {
  7536. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  7537. }
  7538. void Client::SendBiography() {
  7539. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  7540. if (packet) {
  7541. if (strlen(player->GetInfoStruct()->biography) > 0)
  7542. packet->setDataByName("biography", player->GetInfoStruct()->biography);
  7543. QueuePacket(packet->serialize());
  7544. }
  7545. safe_delete(packet);
  7546. }
  7547. PendingResurrection* Client::GetCurrentRez() {
  7548. return &current_rez;
  7549. }
  7550. Mutex* Client::GetResurrectMutex() {
  7551. return &m_resurrect;
  7552. }
  7553. void Client::SendResurrectionWindow() {
  7554. Spawn* caster = current_rez.caster;
  7555. if (!caster || !player)
  7556. return;
  7557. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  7558. if (!packet)
  7559. return;
  7560. char* tmp = new char[512];
  7561. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  7562. packet->setMediumStringByName("text", tmp);
  7563. packet->setMediumStringByName("accept_text", "Yes");
  7564. packet->setMediumStringByName("cancel_text", "No");
  7565. sprintf(tmp, "accept_resurrection %u", player->GetID());
  7566. packet->setMediumStringByName("accept_command", tmp);
  7567. sprintf(tmp, "decline_resurrection %u", player->GetID());
  7568. packet->setMediumStringByName("cancel_command", tmp);
  7569. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  7570. QueuePacket(packet->serialize());
  7571. safe_delete(packet);
  7572. safe_delete_array(tmp);
  7573. }
  7574. void Client::AcceptResurrection() {
  7575. Spawn* caster = current_rez.caster;
  7576. if (!player || !caster)
  7577. return;
  7578. if (player->Alive())
  7579. return;
  7580. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  7581. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  7582. SendResurrectionWindow();
  7583. return;
  7584. }
  7585. player->GetZone()->ResurrectSpawn(player, this);
  7586. current_rez.should_delete = true;
  7587. }
  7588. void Client::SetPendingLastName(string last_name) {
  7589. pending_last_name = new string;
  7590. pending_last_name->assign(last_name);
  7591. }
  7592. string* Client::GetPendingLastName() {
  7593. return pending_last_name;
  7594. }
  7595. void Client::RemovePendingLastName() {
  7596. safe_delete(pending_last_name);
  7597. }
  7598. void Client::SendLastNameConfirmation() {
  7599. if (!pending_last_name)
  7600. return;
  7601. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  7602. if (packet) {
  7603. char* text = new char[128];
  7604. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  7605. packet->setDataByName("text", text);
  7606. packet->setDataByName("accept_text", "Yes");
  7607. packet->setDataByName("accept_command", "confirmedlastname");
  7608. packet->setDataByName("cancel_text", "No");
  7609. packet->setDataByName("max_length", 50);
  7610. packet->setDataByName("unknown4", 1);
  7611. packet->setDataByName("unknown5", 1);
  7612. QueuePacket(packet->serialize());
  7613. safe_delete(packet);
  7614. safe_delete_array(text);
  7615. }
  7616. }
  7617. void Client::AddQuestTimer(int32 quest_id) {
  7618. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  7619. quest_timers.push_back(quest_id);
  7620. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  7621. }
  7622. void Client::RemoveQuestTimer(int32 quest_id) {
  7623. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  7624. vector<int32>::iterator itr;
  7625. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  7626. if ((*itr) == quest_id) {
  7627. quest_timers.erase(itr);
  7628. break;
  7629. }
  7630. }
  7631. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  7632. }
  7633. void Client::SavePlayerImages() {
  7634. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  7635. // Save the paperdoll image if the server allows it
  7636. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  7637. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  7638. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  7639. // Save the head shot if the server allows it
  7640. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  7641. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  7642. // Send the head shot to the login server
  7643. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  7644. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  7645. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  7646. memset(packet->pBuffer, 0, size);
  7647. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  7648. pic->account_id = GetAccountID();
  7649. pic->char_id = GetCharacterID();
  7650. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  7651. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  7652. loginserver.SendPacket(packet);
  7653. safe_delete(packet);
  7654. }
  7655. }
  7656. safe_delete_array(incoming_paperdoll.image_bytes);
  7657. incoming_paperdoll.current_size_bytes = 0;
  7658. }
  7659. void Client::EndAutoMount() {
  7660. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  7661. if (packet) {
  7662. packet->setDataByName("parameter1", 128);
  7663. packet->setDataByName("parameter2", 64);
  7664. packet->setDataByName("value", 1);
  7665. QueuePacket(packet->serialize());
  7666. safe_delete(packet);
  7667. }
  7668. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  7669. if (packet) {
  7670. packet->setDataByName("parameter3", 4);
  7671. packet->setDataByName("parameter5", 2);
  7672. packet->setDataByName("value", 0);
  7673. QueuePacket(packet->serialize());
  7674. safe_delete(packet);
  7675. }
  7676. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  7677. if (packet) {
  7678. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  7679. QueuePacket(packet->serialize());
  7680. safe_delete(packet);
  7681. }
  7682. on_auto_mount = false;
  7683. player->SetMount(((Player*)player)->GetTempMount());
  7684. EQ2_Color mount_color = player->GetTempMountColor();
  7685. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  7686. player->SetMountColor(&mount_color);
  7687. player->SetMountSaddleColor(&saddle_color);
  7688. player->SetTempMount(0);
  7689. }
  7690. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  7691. const char* spawn_script = spawn->GetSpawnScript();
  7692. bool should_use_spawn = true;
  7693. if (spawn_script) {
  7694. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  7695. if (state) {
  7696. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  7697. if (state_mutex)
  7698. state_mutex->writelock(__FUNCTION__, __LINE__);
  7699. lua_getglobal(state, "can_use_command");
  7700. if (lua_isfunction(state, -1)) {
  7701. lua_interface->SetSpawnValue(state, spawn);
  7702. lua_interface->SetSpawnValue(state, GetPlayer());
  7703. lua_interface->SetStringValue(state, command ? command : "");
  7704. if (lua_pcall(state, 3, 1, 0) == 0) {
  7705. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  7706. }
  7707. }
  7708. lua_interface->ResetFunctionStack(state);
  7709. if (state_mutex)
  7710. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  7711. }
  7712. }
  7713. return should_use_spawn;
  7714. }
  7715. bool Client::IsCurrentTransmuteID(int32 req_id) {
  7716. return req_id == transmuteID;
  7717. }
  7718. void Client::SetTransmuteID(int32 trans_id) {
  7719. transmuteID = trans_id;
  7720. }
  7721. int32 Client::GetTransmuteID() {
  7722. return transmuteID;
  7723. }
  7724. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  7725. {
  7726. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  7727. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  7728. if (zar)
  7729. {
  7730. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  7731. if (database.IsActiveQuery(charID))
  7732. {
  7733. delayedLogin = true;
  7734. delayedAccountID = account_id;
  7735. delayedAccessKey = access_code;
  7736. delayTimer.Start(500);
  7737. 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);
  7738. return true;
  7739. }
  7740. delayedLogin = false;
  7741. delayTimer.Disable();
  7742. firstlogin = zar->isFirstLogin();
  7743. 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);
  7744. if (database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  7745. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  7746. if (pvp_allowed)
  7747. this->GetPlayer()->SetAttackable(1);
  7748. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  7749. Client* client = zone_list.GetClientByCharName(player->GetName());
  7750. if (client) {
  7751. if (client->getConnection())
  7752. client->getConnection()->SendDisconnect();
  7753. if (client->GetCurrentZone() && !client->IsZoning()) {
  7754. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  7755. if (client->GetVersion() == version) {
  7756. Player* current_player = GetPlayer();
  7757. SetPlayer(client->GetPlayer());
  7758. client->SetPlayer(current_player);
  7759. client->GetPlayer()->SetPendingDeletion(true);
  7760. GetPlayer()->SetPendingDeletion(false);
  7761. GetPlayer()->ResetSavedSpawns();
  7762. GetPlayer()->SetReturningFromLD(true);
  7763. GetPlayer()->GetZone()->RemoveDelayedSpawnRemove(GetPlayer());
  7764. }
  7765. client->GetCurrentZone()->RemoveClientImmediately(client);
  7766. }
  7767. }
  7768. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  7769. if (!GetCurrentZone()) {
  7770. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  7771. ClientPacketFunctions::SendLoginDenied(this);
  7772. }
  7773. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  7774. getConnection()->SetClientVersion(version);
  7775. GetCurrentZone()->SetSpawnStructs(this);
  7776. connected_to_zone = true;
  7777. client_list.Remove(this); //remove from master client list
  7778. new_client_login = true;
  7779. GetCurrentZone()->AddClient(this); //add to zones client list
  7780. world.RejoinGroup(this);
  7781. zone_list.AddClientToMap(player->GetName(), this);
  7782. }
  7783. else {
  7784. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  7785. ClientPacketFunctions::SendLoginDenied(this);
  7786. return false;
  7787. }
  7788. }
  7789. else {
  7790. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  7791. ClientPacketFunctions::SendLoginDenied(this);
  7792. }
  7793. zone_auth.RemoveAuth(zar);
  7794. }
  7795. else
  7796. {
  7797. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  7798. Disconnect();
  7799. }
  7800. return true;
  7801. }
  7802. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  7803. if (!IsReadyForUpdates())
  7804. return;
  7805. map<int32, SpawnData> info_changes;
  7806. map<int32, SpawnData> pos_changes;
  7807. map<int32, SpawnData> vis_changes;
  7808. map<int32, SpawnData> empty_changes;
  7809. int32 info_size = 0;
  7810. int32 pos_size = 0;
  7811. int32 vis_size = 0;
  7812. int count = 0;
  7813. for (const auto& spawn : spawns) {
  7814. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  7815. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()) || GetPlayer()->NeedsSpawnResent(spawn) || GetPlayer()->GetDistance(spawn) >= SEND_SPAWN_DISTANCE)
  7816. continue;
  7817. if (spawn->vis_changed)
  7818. {
  7819. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  7820. if (vis_change) {
  7821. SpawnData data;
  7822. data.spawn = spawn;
  7823. data.data = vis_change;
  7824. data.size = spawn->vis_packet_size;
  7825. map<int32, SpawnData> tmp_vis_changes;
  7826. tmp_vis_changes[index] = data;
  7827. map<int32, SpawnData> tmp_info_changes;
  7828. map<int32, SpawnData> tmp_pos_changes;
  7829. int32 tmp_info_size = 0;
  7830. int32 tmp_pos_size = 0;
  7831. if (spawn->info_changed) {
  7832. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  7833. if (info_change) {
  7834. SpawnData data;
  7835. data.spawn = spawn;
  7836. data.data = info_change;
  7837. data.size = spawn->info_packet_size;
  7838. tmp_info_size = data.size;
  7839. tmp_info_changes[index] = data;
  7840. }
  7841. }
  7842. if (spawn->position_changed) {
  7843. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  7844. if (pos_change) {
  7845. SpawnData data;
  7846. data.spawn = spawn;
  7847. data.data = pos_change;
  7848. data.size = spawn->pos_packet_size;
  7849. tmp_pos_size = data.size;
  7850. tmp_pos_changes[index] = data;
  7851. }
  7852. }
  7853. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  7854. continue;
  7855. }
  7856. }
  7857. if (spawn->info_changed) {
  7858. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  7859. if (info_change) {
  7860. SpawnData data;
  7861. data.spawn = spawn;
  7862. data.data = info_change;
  7863. data.size = spawn->info_packet_size;
  7864. info_size += spawn->info_packet_size;
  7865. info_changes[index] = data;
  7866. }
  7867. count++;
  7868. }
  7869. if (spawn->position_changed) {
  7870. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  7871. if (pos_change) {
  7872. SpawnData data;
  7873. data.spawn = spawn;
  7874. data.data = pos_change;
  7875. data.size = spawn->pos_packet_size;
  7876. pos_size += spawn->pos_packet_size;
  7877. pos_changes[index] = data;
  7878. }
  7879. count++;
  7880. }
  7881. if (spawn->vis_changed) {
  7882. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  7883. if (vis_change) {
  7884. SpawnData data;
  7885. data.spawn = spawn;
  7886. data.data = vis_change;
  7887. data.size = spawn->vis_packet_size;
  7888. vis_size += spawn->vis_packet_size;
  7889. vis_changes[index] = data;
  7890. }
  7891. count++;
  7892. }
  7893. }
  7894. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  7895. return;
  7896. }
  7897. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  7898. for (auto& kv : info_changes) {
  7899. safe_delete_array(kv.second.data);
  7900. }
  7901. for (auto& kv : pos_changes) {
  7902. safe_delete_array(kv.second.data);
  7903. }
  7904. for (auto& kv : vis_changes) {
  7905. safe_delete_array(kv.second.data);
  7906. }
  7907. }
  7908. 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)
  7909. {
  7910. static const int8 oversized = 255;
  7911. int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  7912. int32 size = info_size + pos_size + vis_size + 8;
  7913. if (version > 283) //version 283 and below uses an overload for size, not always 4 bytes
  7914. size += 3;
  7915. size += CheckOverLoadSize(info_size);
  7916. size += CheckOverLoadSize(pos_size);
  7917. size += CheckOverLoadSize(vis_size);
  7918. if (version <= 283 && size >= 255) {//1 byte to 3 for overloaded val
  7919. size += 2;
  7920. }
  7921. uchar* tmp = new uchar[size];
  7922. uchar* ptr = tmp;
  7923. memset(tmp, 0, size);
  7924. if (version <= 283) {
  7925. if (size >= 255) {
  7926. size -= 3;
  7927. memcpy(ptr, &oversized, sizeof(int8));
  7928. ptr += sizeof(int8);
  7929. memcpy(ptr, &size, sizeof(int16));
  7930. ptr += sizeof(int16);
  7931. size += 3;
  7932. }
  7933. else {
  7934. size -= 1;
  7935. memcpy(ptr, &size, sizeof(int8));
  7936. ptr += sizeof(int8);
  7937. size += 1;
  7938. }
  7939. }
  7940. else {
  7941. size -= 4;
  7942. memcpy(ptr, &size, sizeof(int32));
  7943. ptr += sizeof(int32);
  7944. size += 4;
  7945. }
  7946. memcpy(ptr, &oversized, sizeof(int8));
  7947. ptr += sizeof(int8);
  7948. memcpy(ptr, &opcode_val, sizeof(int16));
  7949. ptr += sizeof(int16);
  7950. int32 current_time = Timer::GetCurrentTime2();
  7951. memcpy(ptr, &current_time, sizeof(int32));
  7952. ptr += sizeof(int32);
  7953. ptr += DoOverLoad(info_size, ptr);
  7954. for (const auto& kv : info_changes) {
  7955. auto info = kv.second;
  7956. memcpy(ptr, info.data, info.size);
  7957. ptr += info.size;
  7958. }
  7959. ptr += DoOverLoad(pos_size, ptr);
  7960. for (const auto& kv : pos_changes) {
  7961. auto pos = kv.second;
  7962. memcpy(ptr, pos.data, pos.size);
  7963. ptr += pos.size;
  7964. }
  7965. ptr += DoOverLoad(vis_size, ptr);
  7966. for (const auto& kv : vis_changes) {
  7967. auto vis = kv.second;
  7968. memcpy(ptr, vis.data, vis.size);
  7969. ptr += vis.size;
  7970. }
  7971. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  7972. if (packet) {
  7973. /*char blah[64];
  7974. snprintf(blah, 64, "Sending %i", current_time);
  7975. SimpleMessage(4, blah);*/
  7976. QueuePacket(packet);
  7977. }
  7978. delete[] tmp;
  7979. }
  7980. void Client::SendHailCommand(Spawn* spawn)
  7981. {
  7982. // hardcoded 'hail' entity commands
  7983. switch (spawn->secondary_command_list_id)
  7984. {
  7985. case 9:
  7986. case 1262:
  7987. case 1265:
  7988. case 1267:
  7989. {
  7990. EQ2_16BitString* command = new EQ2_16BitString();
  7991. command->data = "";
  7992. command->size = 0;
  7993. commands.Process(COMMAND_HAIL, command, this, spawn);
  7994. safe_delete(command);
  7995. break;
  7996. }
  7997. }
  7998. }
  7999. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  8000. {
  8001. if (GetPlayer()->WasSentSpawn(spawn->GetID()) && GetPlayer()->WasSpawnRemoved(spawn) == false) {
  8002. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  8003. if (packet) {
  8004. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  8005. packet->setMediumStringByName("command_name", command);
  8006. packet->setDataByName("distance", distance);
  8007. QueuePacket(packet->serialize());
  8008. safe_delete(packet);
  8009. }
  8010. }
  8011. }
  8012. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  8013. {
  8014. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  8015. return false;
  8016. if (command == "house_spawn_examine")
  8017. {
  8018. uint32 itemID = spawn->GetPickupItemID();
  8019. if (itemID)
  8020. {
  8021. Item* item = master_item_list.GetItem(itemID);
  8022. if (item)
  8023. {
  8024. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  8025. //DumpPacket(app);
  8026. QueuePacket(app);
  8027. }
  8028. }
  8029. return true;
  8030. }
  8031. return false;
  8032. }
  8033. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  8034. {
  8035. if (GetTempPlacementSpawn())
  8036. {
  8037. Spawn* tmp = GetTempPlacementSpawn();
  8038. int32 spawn_group_id = database.GetNextSpawnLocation();
  8039. tmp->SetSpawnLocationID(spawn_group_id);
  8040. float newHeading = place_object->getType_float_ByName("heading") + 180;
  8041. int32 spawnDBID = 0;
  8042. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  8043. {
  8044. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  8045. tmp->SetDatabaseID(spawnDBID);
  8046. }
  8047. else
  8048. {
  8049. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  8050. if (spawnDBID)
  8051. {
  8052. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  8053. tmp->SetDatabaseID(spawnDBID);
  8054. }
  8055. }
  8056. tmp->SetX(place_object->getType_float_ByName("x"));
  8057. tmp->SetY(place_object->getType_float_ByName("y"));
  8058. tmp->SetZ(place_object->getType_float_ByName("z"));
  8059. tmp->SetHeading(newHeading);
  8060. tmp->SetSpawnOrigX(tmp->GetX());
  8061. tmp->SetSpawnOrigY(tmp->GetY());
  8062. tmp->SetSpawnOrigZ(tmp->GetZ());
  8063. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  8064. database.SaveSpawnInfo(tmp);
  8065. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  8066. if (!spawnDBID)
  8067. {
  8068. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  8069. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), (Object*)tmp);
  8070. }
  8071. return true;
  8072. }
  8073. return false;
  8074. }
  8075. bool Client::PopulateHouseSpawnFinalize()
  8076. {
  8077. if (GetTempPlacementSpawn())
  8078. {
  8079. Spawn* tmp = GetTempPlacementSpawn();
  8080. GetCurrentZone()->AddSpawn(tmp);
  8081. GetCurrentZone()->SendSpawnChanges(tmp, this);
  8082. SetTempPlacementSpawn(nullptr);
  8083. int32 uniqueID = GetPlacementUniqueItemID();
  8084. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  8085. tmp->SetPickupItemID(uniqueItem->details.item_id);
  8086. tmp->SetPickupUniqueItemID(uniqueID);
  8087. if (uniqueItem)
  8088. {
  8089. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  8090. {
  8091. Query query;
  8092. 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);
  8093. }
  8094. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  8095. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  8096. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  8097. SetPlacementUniqueItemID(0);
  8098. }
  8099. return true;
  8100. }
  8101. return false;
  8102. }
  8103. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  8104. {
  8105. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  8106. packet->setDataByName("placement_mode", placementMode);
  8107. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  8108. packet->setDataByName("model_type", spawn->GetModelType());
  8109. packet->setDataByName("unknown", 1); //size
  8110. packet->setDataByName("unknown2", 1); //size 2
  8111. packet->setDataByName("unknown2", .5, 1); //size 3
  8112. packet->setDataByName("unknown2", 3, 2);
  8113. packet->setDataByName("unknown2", unknown2_3, 3);
  8114. packet->setDataByName("max_distance", 500);
  8115. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  8116. QueuePacket(packet->serialize());
  8117. safe_delete(packet);
  8118. }
  8119. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  8120. {
  8121. SetPendingFlightPath(path_id);
  8122. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  8123. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  8124. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  8125. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  8126. if (packet) {
  8127. QueuePacket(packet->serialize());
  8128. safe_delete(packet);
  8129. }
  8130. if (mount_id)
  8131. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  8132. }