client.cpp 310 KB

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