client.cpp 309 KB

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