9
3

client.cpp 298 KB

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