123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837 |
- /*
- EQ2Emulator: Everquest II Server Emulator
- Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
- This file is part of EQ2Emulator.
- EQ2Emulator is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- EQ2Emulator is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "../common/debug.h"
- #include "../common/Log.h"
- #include <iostream>
- #include <iomanip>
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <zlib.h>
- #include <assert.h>
- #include <algorithm>
- #include "Player.h"
- #include "Commands/Commands.h"
- #include "ClientPacketFunctions.h"
- #include "../common/ConfigReader.h"
- #include "Guilds/Guild.h"
- #include "Variables.h"
- #include "Rules/Rules.h"
- #include "Titles.h"
- #include "Chat/Chat.h"
- #include "SpellProcess.h"
- #include "Zone/ChestTrap.h"
- #include "../../common/GlobalHeaders.h"
- //#include "Quests.h"
- #ifdef WIN32
- #include <WinSock2.h>
- #include <windows.h>
- #define snprintf _snprintf
- #define vsnprintf _vsnprintf
- #define strncasecmp _strnicmp
- #define strcasecmp _stricmp
- #else
- #include <sys/socket.h>
- #ifdef FREEBSD
- #include <sys/types.h>
- #endif
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <unistd.h>
- #endif
- #if defined(__GNUC__)
- #define _snprintf snprintf
- #endif
- #include "client.h"
- #include "../common/emu_opcodes.h"
- #include "../common/packet_dump.h"
- #include "WorldDatabase.h"
- #include "races.h"
- #include "classes.h"
- #include "LoginServer.h"
- #include "World.h"
- #include "../common/EQ2_Common_Structs.h"
- #include "net.h"
- #include "../common/MiscFunctions.h"
- #include "Skills.h"
- #include "LuaInterface.h"
- #include "Quests.h"
- #include "Collections/Collections.h"
- #include "Achievements/Achievements.h"
- #include "Traits/Traits.h"
- #include "Recipes/Recipe.h"
- #include "Tradeskills/Tradeskills.h"
- #include "AltAdvancement/AltAdvancement.h"
- #include "Bots/Bot.h"
- #include "VisualStates.h"
- extern WorldDatabase database;
- extern const char* ZONE_NAME;
- extern LoginServer loginserver;
- extern sint32 numclients;
- extern NetConnection net;
- extern Commands commands;
- extern ClientList client_list;
- extern ZoneList zone_list;
- extern ZoneAuth zone_auth;
- extern MasterItemList master_item_list;
- extern MasterSkillList master_skill_list;
- extern MasterSpellList master_spell_list;
- extern MasterTraitList master_trait_list;
- extern MasterQuestList master_quest_list;
- extern MasterFactionList master_faction_list;
- extern MasterRecipeList master_recipe_list;
- extern volatile bool RunLoops;
- extern ConfigReader configReader;
- extern LuaInterface* lua_interface;
- extern World world;
- extern Variables variables;
- extern Classes classes;
- extern Races races;
- extern GuildList guild_list;
- extern MasterCollectionList master_collection_list;
- extern MasterAchievementList master_achievement_list;
- extern RuleManager rule_manager;
- extern Chat chat;
- extern MasterAAList master_aa_list;
- extern MasterAAList master_tree_nodes;
- extern ChestTrapList chest_trap_list;
- extern MasterRecipeBookList master_recipebook_list;
- extern VisualStates visual_states;
- using namespace std;
- Client::Client(EQStream* ieqs) : underworld_cooldown_timer(5000), pos_update(125), quest_pos_timer(2000), lua_debug_timer(30000), delayTimer(500), transmuteID(0), temp_placement_timer(10), spawn_removal_timer(250) {
- eqs = ieqs;
- ip = eqs->GetrIP();
- port = ntohs(eqs->GetrPort());
- merchant_transaction = nullptr;
- mail_window.item = nullptr; // don't want this to be set(loose ptr) when using ResetSendMail to provide rest of the defaults
- ResetSendMail(false);
- timestamp_flag = 0;
- current_quest_id = 0;
- last_update_time = 0;
- quest_updates = false;
- //autobootup_timeout = new Timer(10000);
- //autobootup_timeout->Disable();
- CLE_keepalive_timer = new Timer(15000);
- connect = new Timer(1000);
- connect->Disable();
- zoneID = 0;
- account_name[0] = 0;
- character_id = 0;
- account_id = 0;
- pwaitingforbootup = 0;
- current_zone = 0;
- connected_to_zone = false;
- connected = false;
- camp_timer = 0;
- linkdead_timer = 0;
- client_zoning = false;
- zoning_id = 0;
- zoning_x = 0;
- zoning_y = 0;
- zoning_z = 0;
- zoning_instance_id = 0;
- player_pos_changed = false;
- ++numclients;
- if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
- world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
- remove_from_list = false;
- new_client_login = NewLoginState::LOGIN_NONE;
- UpdateWindowTitle(0);
- num_active_failures = 0;
- player = new Player();
- player->SetClient(this);
- combine_spawn = 0;
- lua_debug = false;
- ready_for_spawns = false;
- ready_for_updates = false;
- lua_debug_timer.Disable();
- transport_spawn = 0;
- MBuyBack.SetName("Client::MBuyBack");
- MDeletePlayer.SetName("Client::MDeletePlayer");
- MQuestPendingUpdates.SetName("Client::MQuestPendingUpdates");
- search_items = 0;
- version = 0;
- next_conversation_id = 0;
- pending_guild_invite.guild = 0;
- pending_guild_invite.invited_by = 0;
- m_recipeListSent = false;
- m_resurrect.SetName("Client::m_resurrect");
- current_rez.expire_timer = 0;
- current_rez.should_delete = true;
- pending_last_name = 0;
- should_target = false;
- initial_spawns_sent = false;
- MQuestTimers.SetName("Client::quest_timers");
- memset(&incoming_paperdoll, 0, sizeof(incoming_paperdoll));
- on_auto_mount = false;
- should_load_spells = true;
- spawnPlacementMode = ServerSpawnPlacementMode::DEFAULT;
- delayedLogin = false;
- delayedAccountID = 0;
- delayedAccessKey = 0;
- delayTimer.Disable();
- tempPlacementSpawn = nullptr;
- placement_unique_item_id = 0;
- SetHasOwnerOrEditAccess(false);
- temporary_transport_id = 0;
- rejoin_group_id = 0;
- lastRegionRemapTime = 0;
- regionDebugMessaging = false;
- client_reloading_zone = false;
- last_saved_timestamp = 0;
- MQueueStateCmds.SetName("Client::MQueueStateCmds");
- save_spell_state_timer.Disable();
- save_spell_state_time_bucket = 0;
- player_loading_complete = false;
- MItemDetails.SetName("Client::MItemDetails");
- MSpellDetails.SetName("Client::MSpellDetails");
- hasSentTempPlacementSpawn = false;
- spawn_removal_timer.Start();
- disable_save = false;
- SetZoningDestination(nullptr);
- underworld_cooldown_timer.Disable();
- player_pos_change_count = 0;
- pov_ghost_spawn_id = 0;
- recipe_orig_packet = nullptr;
- recipe_xor_packet = nullptr;
- recipe_packet_count = 0;
- recipe_orig_packet_size = 0;
- }
- Client::~Client() {
- RemoveClientFromZone();
- //let the stream factory know were done with this stream
- if (eqs) {
- eqs->Close();
- try {
- eqs->ReleaseFromUse();
- }
- catch (...) {}
- }
- eqs = NULL;
- //safe_delete(autobootup_timeout);
- safe_delete(linkdead_timer);
- vector<QueuedQuest*>::iterator itr;
- QueuedQuest* queued_quest = 0;
- for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
- queued_quest = *itr;
- safe_delete(queued_quest);
- }
- quest_queue.clear();
-
- vector<QuestRewardData*>::iterator rwd_itr;
- QuestRewardData* quest_rwd_data = 0;
- for (rwd_itr = quest_pending_reward.begin(); rwd_itr != quest_pending_reward.end(); rwd_itr++) {
- quest_rwd_data = *rwd_itr;
- safe_delete(quest_rwd_data);
- }
- quest_pending_reward.clear();
-
- safe_delete(CLE_keepalive_timer);
- safe_delete(connect);
- --numclients;
- UpdateWindowTitle(0);
- }
- void Client::RemoveClientFromZone() {
- if(player && player->GetZone())
- player->GetZone()->GetSpellProcess()->RemoveSpellTimersFromSpawn(player, true, false, true, true);
-
- if (GetTempPlacementSpawn() && GetCurrentZone()) {
- Spawn* tmp = GetTempPlacementSpawn();
- SetTempPlacementSpawn(nullptr);
- GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
- }
- if (current_zone && player) {
- if (player->GetGroupMemberInfo()) {
- TempRemoveGroup();
- }
- world.GetGroupManager()->ClearPendingInvite(player);
- }
- if (lua_interface)
- lua_interface->RemoveDebugClients(this);
- if (player)
- zone_list.RemoveClientFromMap(player->GetName(), this);
- safe_delete(camp_timer);
- safe_delete(search_items);
- safe_delete(current_rez.expire_timer);
- safe_delete(pending_last_name);
- safe_delete_array(incoming_paperdoll.image_bytes);
- MDeletePlayer.writelock(__FUNCTION__, __LINE__);
- player = nullptr;
- MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
-
- deque<BuyBackItem*>::iterator itr;
- MBuyBack.writelock(__FUNCTION__, __LINE__);
- for (itr = buy_back_items.begin(); itr != buy_back_items.end();) {
- safe_delete(*itr);
- itr = buy_back_items.erase(itr);
- }
- MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
- }
- void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
- if (eqs) {
- if (!eqs->CheckActive()) {
- client_list.Remove(this);
- eqs = 0;
- }
- }
- if (app && eqs && version > 0)
- eqs->EQ2QueuePacket(app, attemptedCombine);
- else {
- safe_delete(app);
- }
- }
- void Client::PopulateSkillMap() {
- EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
- if (app)
- QueuePacket(app);
- else {
- LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
- Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
- }
- }
- void Client::SendLoginInfo() {
- if(GetPlayer()->IsReturningFromLD())
- firstlogin = true;
- if (firstlogin) {
- LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
- world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
- PopulateSkillMap();
- // 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!
- LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
- }
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
- database.ToggleCharacterOnline(this, 1);
- int32 count = 0;
- if(!GetPlayer()->IsReturningFromLD())
- {
- count = database.LoadCharacterTitles(GetCharacterID(), player);
- if (count == 0) {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
- database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
- }
- }
- if(!GetPlayer()->IsReturningFromLD())
- {
- count = database.LoadCharacterLanguages(GetCharacterID(), player);
- if (count == 0)
- LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
- count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
- if (count == 0)
- LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
- }
- ClientPacketFunctions::SendLoginAccepted(this);
- ClientPacketFunctions::SendAbilities ( this );
- ClientPacketFunctions::SendCommandNamePacket(this);
- ClientPacketFunctions::SendQuickBarInit(this);
- // we only need to send the MOTD if it is the first time the person is logging in.
- if (firstlogin) {
- ClientPacketFunctions::SendMOTD(this);
- ClientPacketFunctions::SendCharacterMacros(this);
- zone_list.CheckFriendList(this);
- }
- if(!GetPlayer()->IsReturningFromLD())
- {
- database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
- if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
- {
- LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
- database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
- database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
- }
- GetPlayer()->item_list.SetMaxItemIndex();
- database.LoadPlayerFactions(this);
- database.LoadCharacterQuests(this);
- database.LoadCharacterQuestRewards(this);
- database.LoadPlayerMail(this);
- }
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
- SendQuestJournal(true, 0, false);
- if (version > 546) // right version? possibly not!
- master_aa_list.DisplayAA(this, 0, 3);
- if (version > 283)
- SendCollectionList();
- SendBiography();
- map<int32, Quest*>::iterator itr;
- Quest* quest = 0;
- GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
- for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
- quest = itr->second;
- if (quest->IsTracked()) {
- quest->SetTracked(false);
- QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
- quest->SetTracked(true);
- QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
- }
- }
- GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
- // SendAchievementsList();
- /*Guild* guild = player->GetGuild();
- if (guild) {
- guild->UpdateGuildMemberInfo(GetPlayer());
- if (firstlogin)
- guild->SendGuildMOTD(this);
- guild->SendGuildUpdate(this);
- guild->SendGuildMember(GetPlayer(), firstlogin);
- guild->SendGuildEventList(this);
- guild->SendGuildBankEventList(this);
- guild->SendAllGuildEvents(this);
- guild->SendGuildMemberList(this);
- }*/
- if (version > 283) {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
- EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
- if (outapp) {
- LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
- //DumpPacket(outapp);
- QueuePacket(outapp);
- }
- }
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
- ClientPacketFunctions::SendCommandList(this);
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
- SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
- ClientPacketFunctions::SendInstanceList(this);
- SendZoneInfo();
- /*Spell* spell = 0;
- vector<QuickBarItem*>::iterator itr;
- for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
- if((*itr)->type == 1){
- spell = master_spell_list.GetSpell((*itr)->id);
- if(spell)
- QueuePacket(spell->serialize(this, false, 0x20));
- }
- }*/
- }
- void Client::SendPlayerDeathWindow()
- {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
- vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
- vector<RevivePoint*>::iterator itr;
- if (results && results->size() > 0)
- {
- PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
- if (packet)
- {
- packet->setArrayLengthByName("location_count", results->size());
- RevivePoint* point = 0;
- int32 i = 0;
- for (itr = results->begin(); itr != results->end(); itr++, i++)
- {
- point = *itr;
- if (point)
- {
- packet->setArrayDataByName("location_id", point->id, i);
- //zone_name = database.GetZoneName(point->zone_id);
- string zone_name = database.GetZoneDescription(point->zone_id);
- if (zone_name.length() > 0)
- packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
- packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
- packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
- }
- if (point->id == 0xFFFFFFFF)//tmp location
- safe_delete(point);
- }
- #if EQDEBUG >= 3
- LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
- packet->PrintPacket();
- #endif
- EQ2Packet* outapp = packet->serialize();
- QueuePacket(outapp);
- safe_delete(packet);
- }
- // done with the revive points so lets free up the pointer
- safe_delete(results);
- }
- }
- void Client::DisplayDeadWindow()
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
- player->SetHP(0);
- player->SetPower(0);
- GetCurrentZone()->TriggerCharSheetTimer();
- if(GetVersion() <= 546) {
- ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 1);
- ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 1);
- }
- else {
- ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 1);
- ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 1);
- }
- PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
- if (packet)
- {
- packet->setDataByName("spawn_id", 0xFFFFFFFF);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- SendPlayerDeathWindow();
- }
- void Client::HandlePlayerRevive(int32 point_id)
- {
- if(GetVersion() <= 546) {
- ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 0);
- ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 0);
- }
- else {
- ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 0);
- ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 0);
- }
- SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
- PacketStruct* packet = configReader.getStruct("WS_Resurrected", GetVersion());
- if (packet)
- {
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- float origX, origY, origZ, origHeading = 0.0f;
- origX = player->GetX();
- origY = player->GetY();
- origZ = player->GetZ();
- origHeading = player->GetHeading();
- ZoneServer* originalZone = GetCurrentZone();
- int32 origGridID = GetPlayer()->GetLocation();
- float x, y, z, heading;
- RevivePoint* revive_point = 0;
- if (point_id != 0xFFFFFFFF)
- revive_point = GetCurrentZone()->GetRevivePoint(point_id);
- string zone_desc;
- const char* location_name = "Unknown";
- player->SetAlive(true);
- player->SetResurrecting(true);
- player->SetHP(player->GetTotalHP());
- player->SetPower(player->GetTotalPower());
-
- //revive at zone safe coords
- if (!revive_point)
- {
- LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
- x = GetCurrentZone()->GetSafeX();
- y = GetCurrentZone()->GetSafeY();
- z = GetCurrentZone()->GetSafeZ();
- heading = GetCurrentZone()->GetSafeHeading();
- zone_desc = GetCurrentZone()->GetZoneDescription();
- location_name = "Zone Safe Point";
- Zone(GetCurrentZone()->GetZoneName(), false);
- }
- else
- {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
- x = revive_point->x;
- y = revive_point->y;
- z = revive_point->z;
- heading = revive_point->heading;
- zone_desc = database.GetZoneDescription(revive_point->zone_id);
- location_name = revive_point->location_name.c_str();
- Zone(GetCurrentZone()->GetZoneName(), false);
- }
- player->SetX(x);
- player->SetY(y);
- player->SetZ(z);
- player->SetHeading(heading);
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
- zone_desc.c_str(),
- player->GetX(),
- player->GetY(),
- player->GetZ(),
- player->GetHeading(),
- player->GetHP(),
- player->GetPower(),
- location_name);
- //player->ClearEverything();
- Save();
- if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
- {
- string zone_name = database.GetZoneName(revive_point->zone_id);
- if (zone_name.length() == 0)
- {
- LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
- x = GetCurrentZone()->GetSafeX();
- y = GetCurrentZone()->GetSafeY();
- z = GetCurrentZone()->GetSafeZ();
- heading = GetCurrentZone()->GetSafeHeading();
- location_name = "Zone Safe Point";
- }
- else
- {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
- location_name = revive_point->location_name.c_str();
- //player->ClearEverything();
- Save();
- Zone(zone_name.c_str(), false);
- }
- }
- zone_desc = GetCurrentZone()->GetZoneDescription();
- Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
- player->SetSpawnType(4);
- if (version > 283) {
- packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
- if (packet)
- {
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
- if (packet)
- {
- packet->setDataByName("x", x);
- packet->setDataByName("y", y);
- packet->setDataByName("z", z);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- SendControlGhost();
- packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
- if (packet)
- {
- packet->setDataByName("spawn_id", 0xFFFFFFFF);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
-
- if(rule_manager.GetGlobalRule(R_Combat, EnableSpiritShards)->GetBool())
- {
- NPC* shard = player->InstantiateSpiritShard(origX, origY, origZ, origHeading, origGridID, originalZone);
- if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
- originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_PRESPAWN);
- originalZone->RemoveSpawn(player, false, true, true, true, true);
- originalZone->AddSpawn(shard);
-
- if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
- originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_SPAWN);
- }
- m_resurrect.writelock(__FUNCTION__, __LINE__);
- if (current_rez.active)
- current_rez.should_delete = true;
- m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
- }
- void Client::SendControlGhost(int32 send_id, int8 unknown2) {
- PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", send_id);
- packet->setDataByName("speed", GetPlayer()->GetSpeed());
- packet->setDataByName("size", 0.51);
- packet->setDataByName("unknown2", unknown2);
- packet->setDataByName("air_speed", player->GetAirSpeed());
- EQ2Packet* app = packet->serialize();
- QueuePacket(app);
- safe_delete(packet);
- }
- }
- void Client::SendCharInfo() {
- EQ2Packet* app;
-
- player->SetEquippedItemAppearances();
- ClientPacketFunctions::SendCharacterData(this);
- SendCharPOVGhost();
- SendControlGhost(player->GetIDWithPlayerSpawn(player), 255);
-
- if (version <= 283) {
- //le: hack to allow client time to zone in, it gets stuck on Loading UI Resources if we go too fast, need to figure it out. Probably something it doesnt like with ExamineInfo packets
- Sleep(2000);
- }
- //sending bad spawn packet?
- //SendAchievementsList();
- //if (version > 546)
- //ClientPacketFunctions::SendHousingList(this);
-
- ClientPacketFunctions::SendCharacterSheet(this);
- ClientPacketFunctions::SendTraitList(this);// moved from below
- ClientPacketFunctions::SendAbilities(this);
- ClientPacketFunctions::SendSkillBook(this);
- if (!IsReloadingZone() && !player->IsResurrecting() && GetVersion() >= 546) {
- ClientPacketFunctions::SendUpdateSpellBook(this);
- }
- else {
- player->SetResurrecting(false);
- }
- GetCurrentZone()->AddSpawn(player);
- if(IsReloadingZone() && (zoning_x || zoning_y || zoning_z)) {
- GetPlayer()->SetX(zoning_x);
- GetPlayer()->SetY(zoning_y);
- GetPlayer()->SetZ(zoning_z);
- GetPlayer()->SetHeading(zoning_h);
- EQ2Packet* packet = GetPlayer()->Move(zoning_x, zoning_y, zoning_z, GetVersion(), zoning_h);
- QueuePacket(packet);
- }
- //SendCollectionList();
- Guild* guild = player->GetGuild();
- if (guild)
- guild->GuildMemberLogin(this, firstlogin);
- app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
- if (app) {
- LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
- //DumpPacket(app);
- QueuePacket(app);
- }
- app = player->GetEquipmentList()->serialize(GetVersion(), player);
- if (app) {
- QueuePacket(app);
- }
- app = player->GetAppearanceEquipmentList()->serialize(GetVersion(), player);
- if (app) {
- QueuePacket(app);
- }
- vector<Item*>* items = player->GetPlayerItemList()->GetItemsFromBagID(-3); // bank items
- if (items && items->size() > 0) {
- for (int32 i = 0; i < items->size(); i++) {
- EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
- LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
- //DumpPacket(outapp);
- QueuePacket(outapp);
- }
- }
- if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
- QueuePacket(app);
- safe_delete(items);
- items = player->GetPlayerItemList()->GetItemsFromBagID(-4); //shared bank items
- if (items && items->size() > 0) {
- for (int32 i = 0; i < items->size(); i++)
- QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
- }
- safe_delete(items);
- if (version > 283) {
- SendTitleUpdate();
- }
- GetPlayer()->UpdateWeapons();
- if(!GetPlayer()->IsReturningFromLD()) {
- database.LoadBuyBacks(this);
- }
- if (version > 546)
- master_aa_list.DisplayAA(this, 0, 0);
- string zone_motd = GetCurrentZone()->GetZoneMOTD();
- if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
- string zone_motd_send = "Zone MOTD: " + zone_motd;
- SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
- }
- const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
- if (zone_script && lua_interface)
- lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
- this->client_zoning = false;
- this->zoning_id = 0;
- this->zoning_instance_id = 0;
- SetZoningDestination(nullptr);
-
- if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
- GetCurrentZone()->AddDamagedSpawn(player);
- if (firstlogin)
- firstlogin = false;
- player->ClearProcs();
- items = player->GetEquippedItemList();
- if (items && items->size() > 0) {
- for (int32 i = 0; i < items->size(); i++) {
- Item* item = items->at(i);
- if (item && item->GetItemScript() && lua_interface)
- lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
- }
- }
- //Allow this player to change their last name if they meet the level requirement
- if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
- player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
- safe_delete(items);
- if (!player->Alive())
- DisplayDeadWindow();
- ClientPacketFunctions::SendLocalizedTextMessage(this);
- if (GetCurrentZone()->GetInstanceID())
- {
- PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
- if (ph) {
- //HouseZone* hz = world.GetHouseZone(ph->house_id);
- string name = string(GetPlayer()->GetName());
- if (name.compare(ph->player_name) == 0)
- SetHasOwnerOrEditAccess(true);
- }
- }
-
- bool groupMentor = false;
- GetPlayer()->group_id = rejoin_group_id;
- if(!world.RejoinGroup(this, rejoin_group_id))
- GetPlayer()->group_id = 0;
- else
- {
- Entity* ent = world.GetGroupManager()->IsPlayerInGroup(rejoin_group_id, GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id);
- if(ent && ent->IsPlayer())
- {
- GetPlayer()->SetMentorStats(ent->GetLevel(), ent->GetID(), false);
- groupMentor = true;
- }
- }
- if(!groupMentor)
- GetPlayer()->SetMentorStats(GetPlayer()->GetLevel(), 0, false);
- if(!GetPlayer()->IsReturningFromLD()) {
- database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_MAINTAINEDEFFECTS);
- database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_SPELLEFFECTS);
- }
- else {
- Spawn* pet_spawn = nullptr;
- if(GetPlayer()->GetPet())
- pet_spawn = GetPlayer()->GetPet();
- else if(GetPlayer()->GetCharmedPet())
- pet_spawn = GetPlayer()->GetCharmedPet();
- else if(GetPlayer()->GetCosmeticPet())
- pet_spawn = GetPlayer()->GetCosmeticPet();
- else if(GetPlayer()->GetDeityPet())
- pet_spawn = GetPlayer()->GetDeityPet();
-
- if(pet_spawn) {
- GetPlayer()->GetInfoStruct()->set_pet_id(GetPlayer()->GetIDWithPlayerSpawn(pet_spawn));
- }
- }
- GetPlayer()->SetSaveSpellEffects(false);
- GetPlayer()->SetCharSheetChanged(true);
- GetPlayer()->SetReturningFromLD(false);
- }
- void Client::SendZoneSpawns() {
- //Allows us to place spawns almost anywhere
- if (version > 283) {
- uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
- EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
- QueuePacket(app);
- }
- ClientPacketFunctions::SendSkillSlotMappings(this);
- ClientPacketFunctions::SendGameWorldTime(this);
- GetCurrentZone()->StartZoneInitialSpawnThread(this);
- }
- void Client::SendCharPOVGhost() {
- bool use_ghost_pov = false;
- PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
- int32 ghost_id = 0;
- if (set_pov) {
- if(pov_ghost_spawn_id) {
- Spawn* spawn = GetCurrentZone()->GetSpawnByID(pov_ghost_spawn_id);
- ghost_id = player->GetIDWithPlayerSpawn(spawn);
- if(spawn) {
- use_ghost_pov = true;
- }
- }
- if(use_ghost_pov) {
- set_pov->setDataByName("spawn_id", ghost_id);
- }
- else {
- set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
- }
- EQ2Packet* app_pov = set_pov->serialize();
- QueuePacket(app_pov);
- safe_delete(set_pov);
- }
- }
- void Client::SendZoneInfo() {
- ZoneServer* zone = GetCurrentZone();
- if (zone) {
- EQ2Packet* packet = zone->GetZoneInfoPacket(this);
- QueuePacket(packet);
- if (version > 283) {
- PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
- LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
- #if EQDEBUG >= 9
- fog_packet->PrintPacket();
- #endif
- if (fog_packet) {
- database.LoadFogInit(zone->GetZoneFile(), fog_packet);
- QueuePacket(fog_packet->serialize());
- safe_delete(fog_packet);
- }
- zone->SendFlightPathsPackets(this);
- }
- }
- /*
- uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
- ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
- ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
- EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
- QueuePacket(appA);
- uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
- ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
- ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
- EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
- QueuePacket(appB);
- */
- LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
- SendFriendList();
- LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
- SendIgnoreList();
- }
- void Client::SendDefaultGroupOptions() {
- /*
- 0 - loot method
- 1 - loot items rarity
- 2 - Auto split coin
- 4 - default yell method
- 6 - group autolock
- 7 - solo autolock
- */
- PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
- if (default_options) {
- default_options->setDataByName("loot_method", GetPlayer()->GetInfoStruct()->get_group_loot_method());
- default_options->setDataByName("loot_items_rarity", GetPlayer()->GetInfoStruct()->get_group_loot_items_rarity());
- default_options->setDataByName("auto_split_coin", GetPlayer()->GetInfoStruct()->get_group_auto_split());
- default_options->setDataByName("default_yell_method", GetPlayer()->GetInfoStruct()->get_group_default_yell());
- default_options->setDataByName("group_autolock", GetPlayer()->GetInfoStruct()->get_group_autolock());
- default_options->setDataByName("default_group_lock_method", GetPlayer()->GetInfoStruct()->get_group_lock_method());
- if(GetVersion() > 561) {
- default_options->setDataByName("solo_autolock", GetPlayer()->GetInfoStruct()->get_group_solo_autolock());
- default_options->setDataByName("auto_loot_method", GetPlayer()->GetInfoStruct()->get_group_auto_loot_method());
- }
- EQ2Packet* app7 = default_options->serialize();
- QueuePacket(app7);
- safe_delete(default_options);
- }
- }
- bool Client::HandlePacket(EQApplicationPacket* app) {
- bool ret = true;
- //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
- //DumpPacket(app);
- #if EQDEBUG >= 9
- LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
- DumpPacket(app, true);
- #endif
- EmuOpcode opcode = app->GetOpcode();
- #if EQDEBUG >= 9
- const char* name = app->GetOpcodeName();
- if (name)
- cout << name;
- else
- cout << "Unknown";
- cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
- DumpPacket(app);
- #endif
- //if (opcode != OP_UpdatePositionMsg) {
- // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
- //}
- if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
- {
- opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
- }
- switch (opcode) {
- case _maxEmuOpcode:
- break;
- case OP_LoginByNumRequestMsg: {
- LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
- PacketStruct* request;
- request = configReader.getStruct("LoginByNumRequest", 1);
- if (request) {
- if(request->LoadPacketData(app->pBuffer, app->size)) {
- // test the original location of Version for clients older than 1212
- version = request->getType_int16_ByName("version");
- if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
- // must be new client data version method, re-fetch the packet
- safe_delete(request);
- request = configReader.getStruct("LoginByNumRequest", 1208);
- if (request && request->LoadPacketData(app->pBuffer, app->size)) {
- // Xinux suggests using an INT16 here. Our first new version = 57000
- version = request->getType_int16_ByName("version");
- }
- else {
- LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
- break;
- }
- }
- if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
- LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
- ClientPacketFunctions::SendLoginDenied(this);
-
- /* reset version and protect server from trying to send packets out to a bad client
- ** cause of Dec 6th/Dec 7th 2023 crash
- ** Client::MakeSpawnChangePacket
- ** int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd); <-- crashes pulling opcode with bad version
- */
- version = 546;
- ready_for_updates = false;
- ready_for_spawns = false;
- return false;
- }
- int32 account_id = request->getType_int32_ByName("account_id");
- int32 access_code = request->getType_int32_ByName("access_code");
- if (!HandleNewLogin(account_id, access_code))
- return false;
- }
- }
- safe_delete(request);
- break;
- }
- case OP_DefaultGroupOptionsMsg: {
- PacketStruct* packet = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
- if (packet) {
- if (packet->LoadPacketData(app->pBuffer, app->size)) {
- packet->PrintPacket();
- int8 loot_method = packet->getType_int8_ByName("loot_method");
- int8 loot_items_rarity = packet->getType_int8_ByName("loot_items_rarity");
- int8 auto_split_coin = packet->getType_int8_ByName("auto_split_coin");
- int8 default_yell_method = packet->getType_int8_ByName("default_yell_method");
- int8 autolock = packet->getType_int8_ByName("group_autolock");
- int8 group_lock_method = packet->getType_int8_ByName("default_group_lock_method");
- int8 solo_autolock = packet->getType_int8_ByName("solo_autolock");
- int8 auto_loot_method = 0;
- if (GetVersion() > 561) {
- auto_loot_method = packet->getType_int8_ByName("auto_loot_method");
- if (auto_loot_method > AutoLootMode::METHOD_DECLINE)
- auto_loot_method = AutoLootMode::METHOD_DECLINE;
- }
- GetPlayer()->GetInfoStruct()->set_group_loot_method(loot_method);
- GetPlayer()->GetInfoStruct()->set_group_loot_items_rarity(loot_items_rarity);
- GetPlayer()->GetInfoStruct()->set_group_auto_split(auto_split_coin);
- GetPlayer()->GetInfoStruct()->set_group_default_yell(default_yell_method);
- GetPlayer()->GetInfoStruct()->set_group_autolock(autolock);
- GetPlayer()->GetInfoStruct()->set_group_lock_method(group_lock_method);
- GetPlayer()->GetInfoStruct()->set_group_solo_autolock(solo_autolock);
- GetPlayer()->GetInfoStruct()->set_group_auto_loot_method(auto_loot_method);
- database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTMETHOD, (char*)std::to_string(loot_method).c_str());
- database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTITEMRARITY, (char*)std::to_string(loot_items_rarity).c_str());
- database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOSPLIT, (char*)std::to_string(auto_split_coin).c_str());
- database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPDEFAULTYELL, (char*)std::to_string(default_yell_method).c_str());
- database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOLOCK, (char*)std::to_string(autolock).c_str());
- database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOCKMETHOD, (char*)std::to_string(group_lock_method).c_str());
- database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPSOLOAUTOLOCK, (char*)std::to_string(solo_autolock).c_str());
- database.insertCharacterProperty(this, CHAR_PROPERTY_AUTOLOOTMETHOD, (char*)std::to_string(auto_loot_method).c_str());
- if (this->GetPlayer()->GetGroupMemberInfo() && this->GetPlayer()->GetGroupMemberInfo()->leader)
- {
- world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
- PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
- if (group)
- {
- GroupOptions goptions;
- goptions.loot_method = loot_method;
- goptions.loot_items_rarity = loot_items_rarity;
- goptions.auto_split = auto_split_coin;
- goptions.default_yell = default_yell_method;
- goptions.group_autolock = autolock;
- goptions.solo_autolock = solo_autolock;
- goptions.auto_loot_method = auto_loot_method;
- group->SetDefaultGroupOptions(&goptions);
- }
- world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
- }
- }
- safe_delete(packet);
- }
- break;
- }
- case OP_MapRequest: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
- PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
- if (packet && app->size > 2 && GetCurrentZone()) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
- if (fog_packet) {
- LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
- database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
- fog_packet->setDataByName("unknown1", 1);
- fog_packet->setDataByName("unknown3", 1);
- LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
- //fog_packet->PrintPacket();
- QueuePacket(fog_packet->serialize());
- safe_delete(fog_packet);
- }
- }
- safe_delete(packet);
- }
- break;
- }
- case OP_RequestCampMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
- PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
- if (request && request->LoadPacketData(app->pBuffer, app->size)) {
- LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
- LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
- request->getType_int8_ByName("quit"),
- request->getType_int8_ByName("camp_desktop"),
- request->getType_int16_ByName("camp_char_select"),
- (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
- //DumpPacket(app->pBuffer, app->size);
- //request->PrintPacket();
- if (!camp_timer) {
- int16 camp_time = 20; // default if rule cannot be found
- if (GetAdminStatus() >= 100)
- camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
- else
- camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
- PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
- if (response) {
- bool disconnect = false;
- if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
- // Command: /camp desktop
- // Command: /quit
- response->setDataByName("camp_desktop", 1);
- disconnect = true;
- }
- else {
- // Command: /camp
- response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
- response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
- response->setDataByName("seconds", camp_time);
- }
- camp_timer = new Timer(camp_time * 1000);
- camp_timer->Enable();
- if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
- // /camp {char_name}
- response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
- }
- else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
- // /camp (go back to char selection screen)
- response->setDataByName("char_name", " ");
- response->setDataByName("camp_char_select", 1);
- }
- LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
- response->getType_int8_ByName("seconds"),
- response->getType_int8_ByName("camp_desktop"),
- response->getType_int8_ByName("camp_char_select"),
- (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
-
- // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
- if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
- player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
- //response->PrintPacket();
- QueuePacket(response->serialize());
- safe_delete(response);
- if (disconnect)
- Disconnect();
- }
- }
- }
- safe_delete(request);
- break;
- }
- case OP_StoodMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
- if (camp_timer)
- {
- // JA: clear camping flag
- if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
- player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
- safe_delete(camp_timer);
- EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
- QueuePacket(outapp);
- }
- player->SetTempVisualState(0);
- break;
- }
- case OP_StandMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
- if (camp_timer)
- {
- // JA: clear camping flag
- if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
- player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
- safe_delete(camp_timer);
- EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
- QueuePacket(outapp);
- }
- player->SetTempVisualState(539);
- break;
- }
- case OP_SitMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
- player->SetTempVisualState(538);
- break;
- }
- case OP_SatMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
- player->SetTempVisualState(540);
- break;
- }
- case OP_QuestJournalOpenMsg:
- case OP_QuestJournalInspectMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
- if (app->size < sizeof(int32))
- break;
- int32 quest_id = 0;
- memcpy(&quest_id, app->pBuffer, sizeof(int32));
- GetPlayer()->SendQuest(quest_id);
- break;
- }
- case OP_QuestJournalSetVisibleMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
- PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
- if (packet) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- int32 quest_id = packet->getType_int32_ByName("quest_id");
- bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
- GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
- map<int32, Quest*>* player_quests = player->GetPlayerQuests();
- if (player_quests) {
- if (player_quests->count(quest_id) > 0)
- player_quests->at(quest_id)->SetHidden(hidden);
- else
- LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
- }
- else
- LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
- GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
- }
- safe_delete(packet);
- }
- break;
- }
- case OP_MacroUpdateMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
- PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
- if (macro_update) {
- if(macro_update->LoadPacketData(app->pBuffer, app->size)) {
- vector<string>* update = new vector<string>;
- int8 number = macro_update->getType_int8_ByName("number");
- int16 icon = macro_update->getType_int16_ByName("icon");
- string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
- int8 count = macro_update->getType_int8_ByName("macro_count");
- if (GetVersion() <= 283) {
- update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
- }
- else {
- for (int8 i = 0; i < count; i++) {
- char tmp_command[15] = { 0 };
- sprintf(tmp_command, "command_%i", i);
- update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
- }
- }
- if (name.length() == 0)
- database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
- else
- database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
- safe_delete(update);
- }
- safe_delete(macro_update);
- }
- break;
- }
- case OP_DialogSelectMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
- PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
- if (packet) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- int32 conversation_id = packet->getType_int32_ByName("conversation_id");
- int32 response_index = packet->getType_int32_ByName("response");
- HandleDialogSelectMsg(conversation_id, response_index);
- }
- }
- safe_delete(packet);
- break;
- }
- case OP_CancelMoveObjectModeMsg: {
- SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
- if (GetTempPlacementSpawn())
- {
- Spawn* tmp = GetTempPlacementSpawn();
- SetTempPlacementSpawn(nullptr);
- SetPlacementUniqueItemID(0);
- GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
- break; // break out early if we are tied to a temp spawn
- }
- // if we are moving some other object? other use-cases not covered
- break;
- }
- case OP_PositionMoveableObject: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
- PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
- if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
- Spawn* spawn = 0;
- if (GetTempPlacementSpawn())
- spawn = GetTempPlacementSpawn();
- else
- spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
- if (!spawn) {
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
- break;
- }
- else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
- {
- SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
- break;
- }
-
-
- int32 uniqueID = spawn->GetPickupUniqueItemID();
- if(uniqueID) {
- Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
- if(uniqueItem && uniqueItem->CheckFlag2(HOUSE_LORE) && GetCurrentZone()->HouseItemSpawnExists(uniqueItem->details.item_id)) {
- Message(CHANNEL_COLOR_RED, "Item %s is house lore and you cannot place another.", uniqueItem->name.c_str());
- break;
- }
- }
- // handles instantiation logic + adding to zone of a new house object
- PopulateHouseSpawn(place_object);
- float newHeading = place_object->getType_float_ByName("heading") + 180;
- char query[256];
- switch (GetSpawnPlacementMode())
- {
- case ServerSpawnPlacementMode::OPEN_HEADING:
- {
- if (spawn && spawn->IsWidget())
- {
- Widget* widget = (Widget*)spawn;
- widget->SetOpenHeading(newHeading);
- widget->SetIncludeHeading(true);
- spawn->position_changed = true;
- _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
- if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
- }
- else
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
- break;
- }
- case ServerSpawnPlacementMode::CLOSE_HEADING:
- {
- if (spawn && spawn->IsWidget())
- {
- Widget* widget = (Widget*)spawn;
- widget->SetClosedHeading(newHeading);
- widget->SetIncludeHeading(true);
- spawn->position_changed = true;
- _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
- if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
- if (spawn->GetSpawnLocationID())
- {
- Query query;
- query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
- }
- }
- else
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
- break;
- }
- default:
- {
- spawn->SetX(place_object->getType_float_ByName("x"));
- spawn->SetY(place_object->getType_float_ByName("y"));
- spawn->SetZ(place_object->getType_float_ByName("z"));
- spawn->SetHeading(newHeading);
- spawn->SetSpawnOrigX(spawn->GetX());
- spawn->SetSpawnOrigY(spawn->GetY());
- spawn->SetSpawnOrigZ(spawn->GetZ());
- spawn->SetSpawnOrigHeading(spawn->GetHeading());
- if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
- else if (spawn->GetSpawnLocationID() > 0)
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
- }
- }
- PopulateHouseSpawnFinalize();
- SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
- }
- safe_delete(place_object);
- break;
- }
- case OP_CampAbortedMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
- if (camp_timer)
- {
- // JA: clear camping flag
- if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
- player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
- safe_delete(camp_timer);
- EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
- QueuePacket(outapp);
- }
- break;
- }
- case OP_DoneLoadingUIResourcesMsg: {
- if(GetVersion() < 546) {
- ClientPacketFunctions::SendUpdateSpellBook(this);
- }
- EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
- QueuePacket(app);
- if(!player_loading_complete)
- {
- const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
- if (zone_script && lua_interface)
- lua_interface->RunZoneScript(zone_script, "player_loadcomplete", GetCurrentZone(), GetPlayer());
- player_loading_complete = true;
- }
- break;
- }
- case OP_DoneLoadingZoneResourcesMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
- SendZoneSpawns();
- break;
- }
- case OP_DefaultGroupOptionsRequestMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
- SendDefaultGroupOptions();
- break;
- }
- case OP_DoneLoadingEntityResourcesMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
- if (!IsReadyForSpawns())
- SetReadyForSpawns(true);
- player->CalculateApplyWeight();
- SendCharInfo();
- pos_update.Start();
- quest_pos_timer.Start();
- break;
- }
- case OP_LootItemsRequestMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
- HandleLootItemRequestPacket(app);
- break;
- }
- case OP_StoppedLootingMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoppedLootingMsg", opcode, opcode);
- if (app->size < sizeof(int32))
- break;
-
- int32 loot_id = 0;
- memcpy(&loot_id, app->pBuffer, sizeof(int32));
- Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
- if(spawn) {
- spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
- spawn->SetLooterSpawnID(0);
- }
- break;
- }
- case OP_WaypointSelectMsg: {
- PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
- if (packet) {
- if (packet->LoadPacketData(app->pBuffer, app->size)) {
- int32 selection = packet->getType_int32_ByName("selection");
- if (selection > 0) {
- SelectWaypoint(selection);
- }
- }
- }
- safe_delete(packet);
- break;
- }
- case OP_KnowledgeWindowSlotMappingMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
- PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
- if (packet) {
- if (packet->LoadPacketData(app->pBuffer, app->size)) {
- int num_updates = packet->getType_int16_ByName("spell_count");
- int32 spell_id = 0;
- int16 slot_id = 0;
- char tmp_spell_id[15];
- char tmp_slot[15];
- for (int i = 0; i < num_updates; i++) {
- memset(tmp_spell_id, 0, 15);
- memset(tmp_slot, 0, 15);
- sprintf(tmp_spell_id, "spell_id_%i", i);
- sprintf(tmp_slot, "slot_id_%i", i);
- spell_id = packet->getType_int32_ByName(tmp_spell_id);
- if (spell_id > 0) {
- slot_id = packet->getType_int16_ByName(tmp_slot);
- SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
- if (spell && spell->slot != slot_id) {
- spell->slot = slot_id;
- spell->save_needed = true;
- }
- }
- }
- }
- safe_delete(packet);
- }
- //SendKnowledgeWindowSlot();
- break;
- }
- case OP_ReadyToZoneMsg: {
- if (!IsReadyForSpawns())
- {
- LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
- }
- else
- {
- if(zoning_destination) {
- SetCurrentZone(zoning_destination);
- }
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
- bool succeed_override_zone = true;
- if(!GetCurrentZone()) {
- LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone and zone is not there! Emergency boot!", player->GetName());
- if(zoning_instance_id) {
- ZoneServer* zone = zone_list.GetByInstanceID(zoning_instance_id, zoning_id, true);
- if(!zone) {
- LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver instance id %u zone id %u.", player->GetName(), zoning_instance_id, zoning_id);
- succeed_override_zone = false;
- }
- else {
- SetCurrentZone(zone);
- LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique instance has been created for %s through emergency boot!", player->GetName());
- }
- }
- else if(zoning_id) {
-
- ZoneServer* zone = zone_list.Get(zoning_id, true, true);
- if(!zone) {
- LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver zone id %u.", player->GetName(), zoning_id);
- succeed_override_zone = false;
- }
- else {
- SetCurrentZone(zone);
- LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique zone has been created for %s through emergency boot!", player->GetName());
- }
- }
- }
-
- if (client_zoning)
- LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
- else
- LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
- Disconnect();
- }
- break;
- }
- case OP_ClientFellMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
- PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
- if (request && request->LoadPacketData(app->pBuffer, app->size)) {
- float height = request->getType_float_ByName("height");
- /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
- if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
- cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
- break;
- }*/
- float safe_height = 13.0f;
- float safe_skill_with_bonus = GetPlayer()->CalculateSkillWithBonus("Safe Fall", ITEM_STAT_SAFE_FALL, true);
- if (safe_skill_with_bonus > 0.0f)
- safe_height += (1 + safe_skill_with_bonus) / 5;
- if (height > safe_height) {
- int16 damage = (int16)ceil((height - safe_height) * 125);
- if (height >= 80)
- damage = 30000;
- //cout << "Detected fall height:" << height << " damage:" << damage << endl;
- if (damage > 0) {
- GetPlayer()->TakeDamage(damage);
- if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
- GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
- if (!GetPlayer()->GetInvulnerable())
- GetPlayer()->SetCharSheetChanged(true);
- 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);
- if (GetPlayer()->GetHP() == 0) {
- GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
- }
- }
- }
- }
- safe_delete(request);
- break;
- }
- case OP_MapFogDataUpdateMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
- LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
- break;
- }
- case OP_SelectZoneTeleporterDestinatio: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
- ProcessTeleportLocation(app);
- break;
- }
- case OP_SendLatestRequestMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
- if(GetVersion() < 60085) {
- // this does not exist in newer clients like AoM, confirmed to exist in DoF, other clients will need review at a later time
- uchar blah25[] = { 0x01 };
- EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
- QueuePacket(app25);
- }
- break;
- }
- case OP_RequestRecipeDetailsMsg: {
- PacketStruct* packet = configReader.getStruct("WS_RequestRecipeDetail", GetVersion());
- if (packet) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- vector<int32> recipes;
- int32 recipe_id = 0;
- char recipe_prop_name[30];
- int32 num_recipes = packet->getType_int32_ByName("num_recipes");
- // WS_RecipeDetails
- for (int32 i = 0; i < num_recipes; i++) {
- memset(recipe_prop_name, 0, 30);
- snprintf(recipe_prop_name, 30, "recipe_id_%i", i);
- recipe_id = packet->getType_int32_ByName(recipe_prop_name);
- if(recipe_id > 0) {
- recipes.push_back(recipe_id);
- }
- }
- SendRecipeDetails(&recipes);
- }
-
- safe_delete(packet);
- }
- break;
- }
- case OP_ShowCreateFromRecipeUIMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
- break;
- /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
- ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
- EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
- QueuePacket(app);
- uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
- app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
- QueuePacket(app);
- uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
- ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
- ,0xff,0xff,0xff};
- app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
- QueuePacket(app);
- uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
- ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
- ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
- app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
- QueuePacket(app);
- uchar blah5[] ={0x00,0x00};
- app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
- QueuePacket(app);
- break;*/
- //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
- //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
- //QueuePacket(app);
- }
- case OP_BeginItemCreationMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
- //DumpPacket(app->pBuffer, app->size);
- PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
- if (packet) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- int32 item = 0;
- int8 qty = 0;
- vector<pair<int32, int16>> items;
- char tmp_item_id[30];
- int8 num_primary_selected_items = packet->getType_int8_ByName("num_primary_selected_items");
- for (int8 i = 0; i < num_primary_selected_items; i++) {
- memset(tmp_item_id, 0, 30);
- sprintf(tmp_item_id, "primary_selected_item_id_%i", i);
- item = packet->getType_int32_ByName(tmp_item_id);
- sprintf(tmp_item_id, "primary_selected_item_qty_%i", i);
- qty = packet->getType_int16_ByName(tmp_item_id);
- if (item > 0)
- items.push_back(make_pair(item,qty));
- item = 0;
- }
- int8 build_components = packet->getType_int8_ByName("num_build_components");
- for (int8 i = 0; i < build_components; i++) {
- memset(tmp_item_id, 0, 30);
- sprintf(tmp_item_id, "num_selected_items_%i", i);
- int8 num_selected_items = packet->getType_int8_ByName(tmp_item_id);
- for (int8 j = 0; j < num_selected_items; j++) {
- memset(tmp_item_id, 0, 30);
- sprintf(tmp_item_id, "selected_id%i_%i", i,j);
- item = packet->getType_int32_ByName(tmp_item_id);
- sprintf(tmp_item_id, "selected_qty%i_%i", i, j);
- qty = packet->getType_int16_ByName(tmp_item_id);
- if (item > 0)
- items.push_back(make_pair(item, qty));
- item = 0;
- }
- }
- int8 num_fuel_items = packet->getType_int8_ByName("num_fuel_items");
- for (int8 i = 0; i < num_fuel_items; i++) {
- memset(tmp_item_id, 0, 30);
- sprintf(tmp_item_id, "fuel_id_%i", i);
- item = packet->getType_int32_ByName(tmp_item_id);
- sprintf(tmp_item_id, "fuel_qty_%i", i);
- qty = packet->getType_int16_ByName(tmp_item_id);
- if (item > 0)
- items.push_back(make_pair(item, qty));
- item = 0;
- }
-
- GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
- }
- safe_delete(packet);
- }
- break;
- }
- case OP_StopItemCreationMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
- //DumpPacket(app->pBuffer, app->size);
- GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
- break;
- }
- case OP_SysClient:
- case OP_SignalMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient/OP_SignalMsg", opcode, opcode);
- PacketStruct* packet = configReader.getStruct("WS_Signal", 1);
- if (packet) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
- if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
- SetReloadingZone(false);
- if(GetPlayer()->IsDeletedSpawn()) {
- GetPlayer()->SetDeletedSpawn(false);
- }
- ResetZoningCoords();
- SetReadyForUpdates();
- GetPlayer()->SendSpawnChanges(true);
- ProcessStateCommands();
- GetPlayer()->changed = true;
- GetPlayer()->info_changed = true;
- GetPlayer()->vis_changed = true;
- player_pos_changed = true;
- GetPlayer()->AddChangedZoneSpawn();
- ProcessZoneIgnoreWidgets();
- }
- else {
- LogWrite(CCLIENT__WARNING, 0, "Client", "Player %s reported SysClient/SignalMsg state %s.", GetPlayer()->GetName(), str.data.c_str());
- }
- const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
- if (zone_script && lua_interface)
- {
- lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
- }
- }
- safe_delete(packet);
- }
- break;
- }
- case OP_EntityVerbsRequestMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
- HandleVerbRequest(app);
- break;
- }
- case OP_EntityVerbsVerbMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
- PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
- if (packet) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- int32 spawn_id = packet->getType_int32_ByName("spawn_id");
- player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
- Spawn* spawn = player->GetTarget();
- if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
- string command = packet->getType_EQ2_16BitString_ByName("command").data;
- if (!HandleHouseEntityCommands(spawn, spawn_id, command))
- {
- if (EntityCommandPrecheck(spawn, command.c_str())) {
- if (spawn->IsGroundSpawn())
- ((GroundSpawn*)spawn)->HandleUse(this, command);
- else if (spawn->IsObject())
- ((Object*)spawn)->HandleUse(this, command);
- else if (spawn->IsWidget())
- ((Widget*)spawn)->HandleUse(this, command);
- else if (spawn->IsSign())
- ((Sign*)spawn)->HandleUse(this, command);
- }
- }
- }
- else {
- EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
- if (command.size > 0) {
- string command_name = command.data;
- if (command_name.find(" ") < 0xFFFFFFFF) {
- if (GetVersion() <= 546) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
- string::size_type pos = command_name.find(" ");
- while(pos != string::npos){
- command_name.replace(pos, 1, "_");
- pos = command_name.find(" ");
- }
- }
- else
- command_name = command_name.substr(0, command_name.find(" "));
- }
- int32 handler = commands.GetCommandHandler(command_name.c_str());
- if (handler != 0xFFFFFFFF) {
- if (command.data == command_name) {
- command.data = "";
- command.size = 0;
- }
- else {
- command.data = command.data.substr(command.data.find(" ") + 1);
- command.size = command.data.length();
- }
- commands.Process(handler, &command, this);
- }
- else {
- if (spawn && spawn->IsNPC()) {
- if (EntityCommandPrecheck(spawn, command.data.c_str())) {
- if (!((NPC*)spawn)->HandleUse(this, command.data)) {
- command_name = command.data;
- string::size_type pos = command_name.find(" ");
- while (pos != string::npos) {
- command_name.replace(pos, 1, "_");
- pos = command_name.find(" ");
- }
- if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
- LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
- }
- }
- }
- }
- else
- LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
- }
- }
- }
- }
- safe_delete(packet);
- }
- break;
- }
- case OP_SkillInfoRequest: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
- HandleSkillInfoRequest(app);
- break;
- }
- case OP_UpdateTargetMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
- int16 index = 0;
- memcpy(&index, app->pBuffer, sizeof(int16));
- if (index == 0xFFFF)
- GetPlayer()->SetTarget(0);
- else {
- Spawn* spawn = GetPlayer()->GetSpawnByIndex(index);
- if(spawn)
- GetPlayer()->SetTarget(spawn);
- else {
- LogWrite(PLAYER__ERROR, 1, "Player", "Player %s tried to target %u index, but that index was not valid.", GetPlayer()->GetName(), index);
- }
- }
- if (GetPlayer()->GetTarget())
- GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
- //player->SetTarget((int16*)app->pBuffer);
- break;
- }
- case OP_ExamineInfoRequestMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
- HandleExamineInfoRequest(app);
- break;
- }
- case OP_QuickbarUpdateMsg:
- //case OP_QuickbarAddMsg:
- {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
- HandleQuickbarUpdateRequest(app);
- break;
- }
- case OP_PredictionUpdateMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
- if (version <= 546) {
- int8 offset = 9;
- if (app->pBuffer[0] == 0xFF)
- offset += 2;
- if (app->size > offset) {
- if (player->IsCasting()) {
- float distance = 0;
- float x = player->GetX();
- float y = player->GetY();
- float z = player->GetZ();
- player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
- distance = player->GetDistance(x, y, z, false);
- if (distance > .5)
- current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
- }
- else
- player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
- player_pos_changed = true;
- //DumpPacket(app);
- }
- }
- else {
- EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
- QueuePacket(app);
- LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
- }
- break;
- }
- case OP_RemoteCmdMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
- if (app->size > 0) {
- EQ2_CommandString remote(app->pBuffer, app->size);
- LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
- #if EQDEBUG >= 9
- DumpPacket(app);
- #endif
- commands.Process(remote.handler, &remote.command, this);
- }
- else //bad client, disconnect
- Disconnect();
- break;
- }
- case OP_CancelSpellCast: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
- current_zone->Interrupted(player, 0, 0, true);
- SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
- break;
- }
- case OP_UpdatePositionMsg: {
- LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
- int8 offset = 13;
- if (app->pBuffer[0] == 0xFF)
- offset += 2;
- if (app->size > offset) {
- if (player->IsCasting()) {
- float distance = 0;
- float x = player->GetX();
- float y = player->GetY();
- float z = player->GetZ();
- player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
- distance = player->GetDistance(x, y, z, false);
- if (distance > .5)
- current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
- }
- else
- player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
- player_pos_changed = true;
- LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
- //DumpPacket(app);
- }
- break;
- }
- case OP_MailSendMessageMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
- HandleSentMail(app);
- break;
- }
- case OP_StopTrackingMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
- player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
- break;
- }
- case OP_BeginTrackingMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
- PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
- if (packet) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- int32 spawn_id = packet->getType_int32_ByName("spawn_id");
- Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
- if (spawn) {
- AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
- BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
- player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
- }
- }
- safe_delete(packet);
- }
- break;
- }
- case OP_BioUpdateMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
- PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
- if (packet) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
- }
- safe_delete(packet);
- }
- break;
- }
- case OP_RewardPackMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
- /* 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
- when we come across it (scatman) */
- const char* name = app->GetOpcodeName();
- if (name)
- LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
- else
- LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
- //DumpPacket(app);
- PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
- if (packet) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
- /* Player has contacted a guild recruiter */
- if (recruiter_name.length() > 0) {
- Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
- Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
- if (recruiter && guild) {
- Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
- recruiter->Message(CHANNEL_GUILD_EVENT, "%s [%u %s], [0 Unskilled] (%s) is requesting to speak to YOU about joining the guild.", player->GetName(), player->GetLevel(), classes.GetClassNameCase(player->GetAdventureClass()).c_str(), races.GetRaceNameCase(player->GetRace()));
- recruiter->PlaySound("ui_guild_page");
- }
- }
- /* New picture taken for guild recruiting */
- else {
- //DumpPacket(app->pBuffer, app->size);
- int32 guild_id = 0;
- int16 picture_data_size = 0;
- unsigned char* recruiter_picture_data = 0;
- memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
- memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
- Guild* guild = guild_list.GetGuild(guild_id);
- if (guild) {
- GuildMember* gm = guild->GetGuildMember(player);
- if (gm) {
- safe_delete_array(gm->recruiter_picture_data);
- recruiter_picture_data = new unsigned char[picture_data_size];
- for (int16 i = 0; i < picture_data_size; i++)
- memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
- gm->recruiter_picture_data = recruiter_picture_data;
- gm->recruiter_picture_data_size = picture_data_size;
- guild->SetMemberSaveNeeded(true);
- }
- }
- }
- }
- safe_delete(packet);
- }
- break;
- }
- case OP_PetOptions: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
- Spawn* target = player->GetTarget();
- PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
- if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
- bool change = false;
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
- if (strlen(name.c_str()) != 0 && SetPetName(name.c_str())) {
- target->SetName(name.c_str());
- GetCurrentZone()->SendUpdateTitles(target);
- change = true;
- }
- int8 pet_behavior = player->GetInfoStruct()->get_pet_behavior();
- // Check protect self setting and update if needed
- if (packet->getType_int8_ByName("protect_self") == 1) {
- if ((pet_behavior & 2) == 0) {
- player->GetInfoStruct()->set_pet_behavior(pet_behavior + 2);
- change = true;
- }
- }
- else {
- if ((pet_behavior & 2) != 0) {
- player->GetInfoStruct()->set_pet_behavior(pet_behavior - 2);
- change = true;
- }
- }
- // Check protect master setting and update if needed
- if (packet->getType_int8_ByName("protect_master") == 1) {
- if ((pet_behavior & 1) == 0) {
- player->GetInfoStruct()->set_pet_behavior(pet_behavior + 1);
- change = true;
- }
- }
- else {
- if ((pet_behavior & 1) != 0) {
- player->GetInfoStruct()->set_pet_behavior(pet_behavior - 1);
- change = true;
- }
- }
- int8 pet_movement = player->GetInfoStruct()->get_pet_movement();
- // Check stay/follow setting and update if needed
- if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
- if (pet_movement != 2) {
- player->GetInfoStruct()->set_pet_movement(2);
- change = true;
- }
- }
- else {
- if (pet_movement != 1) {
- player->GetInfoStruct()->set_pet_movement(1);
- change = true;
- }
- }
- // Ranged/Melee settings are not implemented yet
- if (change)
- player->SetCharSheetChanged(true);
- }
- safe_delete(packet);
- }
- break;
- }
- case OP_RecipeBook: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
- SendRecipeList();
- break;
- }
- case OP_BuyPlayerHouseMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
- //DumpPacket(app);
- int64 bank_money = GetPlayer()->GetBankCoinsPlat();
- PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
- if (packet) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- int64 house_id = 0;
- if(GetVersion() <= 546) {
- house_id = packet->getType_int32_ByName("house_id");
- }
- else {
- house_id = packet->getType_int64_ByName("house_id");
- }
- HouseZone* hz = world.GetHouseZone(house_id);
- if (hz) {
- bool got_bank_money = BankHasCoin(hz->cost_coin);
- int8 disable_alignment_req = rule_manager.GetGlobalRule(R_Player, DisableHouseAlignmentRequirement)->GetInt8();
- std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
- if (houses.size() > 24)
- {
- SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
- safe_delete(packet);
- break;
- }
- if(disable_alignment_req && hz->alignment > 0 && hz->alignment != GetPlayer()->GetAlignment())
- {
- std::string req = "You must be of ";
- if (hz->alignment == 1)
- req.append("Good");
- else
- req.append("Evil");
- req.append(" alignment to purchase this house");
- SimpleMessage(CHANNEL_COLOR_YELLOW, req.c_str());
- safe_delete(packet);
- break;
- }
- int32 status_req = hz->cost_status;
- int32 available_status = player->GetInfoStruct()->get_status_points();
- if (status_req <= available_status && (!hz->cost_coin || (hz->cost_coin && player->RemoveCoins(hz->cost_coin))))
- {
- player->GetInfoStruct()->subtract_status_points(status_req);
- ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id, false, false);
- int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
- int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
- world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
- //ClientPacketFunctions::SendHousingList(this);
- PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
- ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
- PlaySound("coin_cha_ching");
- }
- else if (status_req <= available_status && got_bank_money == 1) {
- player->GetInfoStruct()->subtract_status_points(status_req);
- bool bankwithdrawl = BankWithdrawalNoBanker(hz->cost_coin);
-
- //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
- if (bankwithdrawl == 0) {
- PlaySound("buy_failed");
- SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
- safe_delete(packet);
- break;
- }
- ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id, false, false);
- int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
- int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
- world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
- PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
- ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
- PlaySound("coin_cha_ching");
- }
- else
- {
- SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
- PlaySound("buy_failed");
- }
- }
- }
- }
- safe_delete(packet);
- break;
- }
- case OP_EnterHouseMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
- //DumpPacket(app);
- PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
- if (packet) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- PlayerHouse* ph = nullptr;
- HouseZone* hz = nullptr;
- int64 house_id = 0;
- int32 spawn_index = 0;
-
- if(GetVersion() <= 546) {
- spawn_index = packet->getType_int32_ByName("house_id");
- }
- else {
- house_id = packet->getType_int64_ByName("house_id");
- }
-
- ZoneServer* house = GetHouseZoneServer(spawn_index, house_id);
- if (house) {
- Zone(house, true);
- }
- }
- }
- safe_delete(packet);
- break;
- }
- case OP_PayHouseUpkeepMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
-
- PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
- if (packet) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- int64 house_id = 0;
-
- if(GetVersion() <= 546) {
- house_id = packet->getType_int32_ByName("house_id");
- }
- else {
- house_id = packet->getType_int64_ByName("house_id");
- }
- HouseZone* hz = nullptr;
- PlayerHouse* ph = world.GetPlayerHouse(this, GetVersion() <= 546 ? house_id : 0, GetVersion() > 546 ? house_id : 0, &hz);
- if (ph)
- {
- if (!hz)
- {
- Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
- safe_delete(packet);
- break;
- }
- int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
- if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
- {
- upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
- if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
- {
- Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
- PlaySound("buy_failed");
- safe_delete(packet);
- break;
- }
- }
- bool escrowChange = false;
- int64 statusReq = hz->upkeep_status;
- int64 tmpRecoverStatus = 0;
- if(ph->escrow_status && statusReq >= ph->escrow_status )
- {
- escrowChange = true;
- tmpRecoverStatus = ph->escrow_status;
- statusReq -= ph->escrow_status;
- ph->escrow_status = 0;
- }
- else if (ph->escrow_status && statusReq && statusReq <= ph->escrow_status)
- {
- escrowChange = true;
- ph->escrow_status -= statusReq;
- tmpRecoverStatus = statusReq;
- statusReq = 0;
- }
- int64 coinReq = hz->upkeep_coin;
- int64 tmpRecoverCoins = 0;
- if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
- {
- escrowChange = true;
- tmpRecoverCoins = ph->escrow_coins;
- coinReq -= ph->escrow_coins;
- ph->escrow_coins = 0;
- }
- else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
- {
- escrowChange = true;
- // more than enough in escrow, subtract and make our cost 0!
- ph->escrow_coins -= coinReq;
- tmpRecoverCoins = coinReq;
- coinReq = 0;
- }
- int32 available_status_points = player->GetInfoStruct()->get_status_points();
- if(!statusReq || (statusReq && statusReq <= available_status_points))
- {
- if(coinReq && player->RemoveCoins(coinReq))
- coinReq = 0;
-
- if(!coinReq && statusReq && player->GetInfoStruct()->subtract_status_points(statusReq))
- statusReq = 0;
- }
- bool got_bank_money = BankHasCoin(hz->upkeep_coin);
- if (!coinReq && !statusReq) // TODO: Need option to take from bank if player does not have enough coin on them
- {
- database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
- if (escrowChange)
- database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
- ph->upkeep_due = upkeep_due;
- database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
- //ClientPacketFunctions::SendHousingList(this);
- ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
- PlaySound("coin_cha_ching");
- }
- else if (!statusReq && got_bank_money == 1) {
- bool bankwithdrawl = BankWithdrawalNoBanker(hz->upkeep_coin);
- //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
- if (bankwithdrawl == 0) {
- PlaySound("buy_failed");
- SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
- safe_delete(packet);
- break;
- }
- database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
- if (escrowChange)
- database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
- ph->upkeep_due = upkeep_due;
- database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
- ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
- PlaySound("coin_cha_ching");
- }
- else
- {
- // recover the escrow we were going to use but could not spend due to lack of funds
- if (tmpRecoverCoins)
- ph->escrow_coins += tmpRecoverCoins;
- if(tmpRecoverStatus)
- ph->escrow_status += tmpRecoverStatus;
- SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money or status to pay for upkeep.");
- PlaySound("buy_failed");
- }
- }
- else
- Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", house_id);
- }
- }
- safe_delete(packet);
- break;
- }
- case OP_ExitHouseMsg: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
- int32 instance_id = GetCurrentZone()->GetInstanceID();
- if (instance_id > 0) {
- PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
- if (ph) {
- HouseZone* hz = world.GetHouseZone(ph->house_id);
- if (hz) {
- ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
- // determine if this is an instanced zone that already exists
- ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
- if (instance_zone || new_zone) {
- GetPlayer()->SetX(hz->exit_x);
- GetPlayer()->SetY(hz->exit_y);
- GetPlayer()->SetZ(hz->exit_z);
- GetPlayer()->SetHeading(hz->exit_heading);
- if (instance_zone)
- Zone(instance_zone->GetInstanceID(), false, true);
- else
- Zone(new_zone, false);
- }
- }
- }
- }
- break;
- }
- case OP_QuestJournalWaypointMsg: {
- //DumpPacket(app);
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
- PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
- if (packet) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- int32 quests = packet->getType_int32_ByName("num_quests");
- if (quests > 100) // just picking a number higher than max allowed
- {
- LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
- break;
- }
- LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
- for (int32 i = 0; i < quests; i++) {
- int32 id = packet->getType_int32_ByName("quest_id_0", i);
- if (id == 0)
- continue;
- LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
- bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
- GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
- if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
- player->player_quests[id]->SetTracked(tracked);
- player->player_quests[id]->SetSaveNeeded(true);
- }
- GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
- }
- }
- safe_delete(packet);
- }
- break;
- }
- case OP_PaperdollImage: {
- /* PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
- if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
- //First check if this is a new image... delete an existing partial image if one exists
- int8 packet_index = packet->getType_int8_ByName("packetIndex");
- if (packet_index == 0) {
- safe_delete_array(incoming_paperdoll.image_bytes);
- incoming_paperdoll.last_received_packet_index = 0;
- incoming_paperdoll.current_size_bytes = 0;
- }
- //return if this packet is not the one we are expecting...
- else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
- safe_delete(packet);
- break;
- }
- //Check how many packets we're supposed to be receiving for this/these images
- incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
- //Check the image type, if this is a new type in the same series of packets we have a new image
- int8 img_type = packet->getType_int8_ByName("image_type");
- if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
- //We have a new image. Save the old data and clear before continuing
- SavePlayerImages();
- }
- incoming_paperdoll.image_type = img_type;
- //Get the size of the image data in this packet
- sint64 image_size = packet->getType_int32_ByName("imageSize");
- if (image_size <= 0 || image_size > 1048576) {
- //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
- safe_delete(packet);
- break;
- }
- //Create a new array
- int32 new_image_size = image_size;
- uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
- if (incoming_paperdoll.image_bytes) {
- memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
- safe_delete_array(incoming_paperdoll.image_bytes);
- }
- //variable i should be the index in the packet of the first PNG file byte
- vector<DataStruct*>* d_structs = packet->getStructs();
- vector<DataStruct*>::iterator itr;
- int32 i = 0;
- for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
- DataStruct* ds = (*itr);
- if (strcmp(ds->GetName(), "pngData_0") != 0)
- i += ds->GetDataSizeInBytes();
- else
- break;
- }
- //Return if this packet is bad and we would read out of bounds
- if (app->size - i < new_image_size) {
- safe_delete(packet);
- safe_delete_array(new_image);
- break;
- }
- uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
- memcpy(tmp, app->pBuffer + i, new_image_size);
- incoming_paperdoll.current_size_bytes += new_image_size;
- incoming_paperdoll.image_bytes = new_image;
- //Check if this is the last packet we're expecting for this image. Create a final image if so
- if (incoming_paperdoll.image_num_packets == 1 ||
- incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
- SavePlayerImages();
- }
- incoming_paperdoll.last_received_packet_index = packet_index;
- }
- safe_delete(packet);
- */
- break;
- }
- case OP_ReadyForTakeOffMsg:
- {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
- int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
- if (GetPendingFlightPath() > 0) {
- if (index != -1) {
- PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
- packet->setDataByName("path_id", index);
- packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
- QueuePacket(packet->serialize());
- safe_delete(packet);
- on_auto_mount = true;
- }
- }
- else {
- LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
- Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
- EndAutoMount();
- }
- SetPendingFlightPath(0);
- }
- else
- LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
- break;
- }
- case OP_EarlyLandingRequestMsg:
- {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
- EndAutoMount();
- break;
- }
- case OP_SubmitCharCust:
- {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
- PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
- if (packet && packet->LoadPacketData(app->pBuffer, app->size, GetVersion() <= 546 ? false : true)) {
- int8 type = packet->getType_int8_ByName("type");
- if (type == 0) {
- /*if (player->custNPC) {
- player->custNPCTarget->CustomizeAppearance(packet);
- current_zone->SendSpawnChanges(player->custNPCTarget);
- }
- else {*/
- player->CustomizeAppearance(packet);
- current_zone->SendSpawnChanges(player);
- //}
- }
- }
- safe_delete(packet);
- /*
- if (player->custNPC) {
- memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
- memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
- if (player->custNPCTarget->IsBot())
- database.SaveBotAppearance((Bot*)player->custNPCTarget);
- player->custNPC = false;
- player->custNPCTarget = 0;
- player->changed = true;
- player->info_changed = true;
- current_zone->SendSpawnChanges(player, this);
- }*/
- break;
- }
- default: {
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
- const char* name = app->GetOpcodeName();
- if (name)
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
- else
- LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
- // keeping this around for debugging purposes
- DumpPacket(app);
- }
- }
- if (!eqs || !eqs->CheckActive()) {
- return false;
- }
- return ret;
- }
- bool Client::HandleLootItem(Spawn* entity, Item* item, Spawn* target, bool overrideLootRestrictions) {
- if (!item) {
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
- return false;
- }
- int32 conflictItemList = 0, conflictequipmentList = 0, conflictAppearanceEquipmentList = 0;
- int16 lore_stack_count = 0;
- Player* lootingPlayer = player;
- Client* lootingClient = this;
- if (target != nullptr && target != lootingPlayer && target->IsPlayer()) {
- lootingPlayer = (Player*)target;
- lootingClient = lootingPlayer->GetClient();
- }
- // needs to only be checked before expiration of loot restrictions
- if (entity && !overrideLootRestrictions) {
- if (entity->GetLootGroupID() > 0 && (!lootingPlayer->GetGroupMemberInfo() || lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID())) {
- LogWrite(LOOT__ERROR, 0, "Loot", "%s: Loot Group ID from %s did not match Item: %s (%u), expected group id %u.", entity->GetName(), lootingPlayer->GetName(), item->name.c_str(), item->details.item_id, entity->GetLootGroupID());
- return false;
- }
- if (entity->GetLootMethod() != GroupLootMethod::METHOD_FFA) {
- switch (entity->GetLootMethod()) {
- case GroupLootMethod::METHOD_LEADER: {
- if (entity->GetLootGroupID() > 0 && (!lootingPlayer->GetGroupMemberInfo() || (lootingPlayer->GetGroupMemberInfo() && (lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID() || !lootingPlayer->GetGroupMemberInfo()->leader)))) {
- LogWrite(LOOT__ERROR, 0, "Loot", "%s: Loot Attempt from %s was not allowed with Item: %s (%u), must be group leader.", entity->GetName(), lootingPlayer->GetName(), item->name.c_str(), item->details.item_id);
- return false;
- }
- break;
- }
- case GroupLootMethod::METHOD_LOTTO:
- case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
- if (entity->IsLootTimerRunning()) {
- LogWrite(LOOT__INFO, 0, "Loot", "%s: Loot Timer is still running, flag player %s to lotto Item: %s (%u).", entity->GetName(), lootingPlayer->GetName(), item->name.c_str(), item->details.item_id);
- return false;
- }
- break;
- }
- }
- }
- }
- if (((conflictItemList = lootingPlayer->item_list.CheckSlotConflict(item, true, true, &lore_stack_count)) == LORE ||
- (conflictequipmentList = lootingPlayer->equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE ||
- (conflictAppearanceEquipmentList = lootingPlayer->appearance_equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE) && !item->CheckFlag(STACK_LORE)) {
- Message(CHANNEL_COLOR_RED, "You cannot loot %s due to lore conflict.", item->name.c_str());
- return false;
- }
- else if (conflictItemList == STACK_LORE || conflictequipmentList == STACK_LORE || conflictAppearanceEquipmentList == STACK_LORE) {
- Message(CHANNEL_COLOR_RED, "You cannot loot %s due to stack lore conflict.", item->name.c_str());
- return false;
- }
- if (lootingPlayer->item_list.HasFreeSlot() || lootingPlayer->item_list.CanStack(item)) {
- if (lootingPlayer->item_list.AssignItemToFreeSlot(item)) {
- if (item->CheckFlag2(HEIRLOOM)) { // TODO: RAID Support
- GroupMemberInfo* gmi = lootingClient->GetPlayer()->GetGroupMemberInfo();
- if (gmi && gmi->group_id)
- {
- PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
- if (group)
- {
- group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>* members = group->GetMembers();
- if (members) {
- for (int8 i = 0; i < members->size(); i++) {
- Entity* member = members->at(i)->member;
- if (!member)
- continue;
- if ((member->GetZone() != lootingClient->GetPlayer()->GetZone()))
- continue;
- if (member->IsPlayer()) {
- item->grouped_char_ids.insert(std::make_pair(((Player*)member)->GetCharacterID(), true));
- item->save_needed = true;
- }
- }
- }
- group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- }
- int8 type = CHANNEL_LOOT;
- if (entity) {
- lootingClient->Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
- }
- else {
- lootingClient->Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
- }
- Guild* guild = lootingPlayer->GetGuild();
- if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
- char adjective[32];
- int8 type;
- memset(adjective, 0, sizeof(adjective));
- if (item->details.tier >= ITEM_TAG_MYTHICAL) {
- strncpy(adjective, "Mythical", sizeof(adjective) - 1);
- type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
- }
- else if (item->details.tier >= ITEM_TAG_FABLED) {
- strncpy(adjective, "Fabled", sizeof(adjective) - 1);
- type = GUILD_EVENT_LOOTS_FABELED_ITEM;
- }
- else {
- strncpy(adjective, "Legendary", sizeof(adjective) - 1);
- type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
- }
- guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
- guild->SendMessageToGuild(type, "%s has looted the %s %s", lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
- }
- if (item->GetItemScript() && lua_interface)
- lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, lootingPlayer);
- lootingClient->CheckPlayerQuestsItemUpdate(item);
- if (GetVersion() <= 546) {
- EQ2Packet* outapp = lootingPlayer->SendInventoryUpdate(GetVersion());
- if (outapp)
- lootingClient->QueuePacket(outapp);
- }
- return true;
- }
- else
- lootingClient->SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
- }
- else
- lootingClient->SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
- return false;
- }
- bool Client::HandleLootItemByID(Spawn* entity, int32 item_id, Spawn* target) {
- if (!entity) {
- return false;
- }
- Item* item = entity->LootItem(item_id);
- bool success = false;
- success = HandleLootItem(entity, item, target);
- if (!success)
- entity->AddLootItem(item);
- return success;
- }
- void Client::HandleLootItemRequestPacket(EQApplicationPacket* app) {
- PacketStruct* packet = configReader.getStruct("WS_LootItem", GetVersion());
- if (packet) {
- if (packet->LoadPacketData(app->pBuffer, app->size)) {
- int32 loot_id = packet->getType_int32_ByName("loot_id");
- bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
- int32 target_id = packet->getType_int32_ByName("target_id");
- int8 button_clicked = packet->getType_int8_ByName("button_clicked");
- Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
- if(!spawn) {
- safe_delete(packet);
- return;
- }
- Item* item = nullptr;
- vector<Item*>* items = player->GetPendingLootItems(loot_id);
- if (items) {
- int32 item_id = packet->getType_int32_ByName("item_id_0");
- for (int32 i = 0; i < items->size(); i++) {
- Item* master_item = items->at(i);
- if (master_item && (loot_all || master_item->details.item_id == item_id)) {
- item = new Item(master_item);
- if (item) {
- loot_all = HandleLootItem(0, item);
- if (loot_all) {
- player->RemovePendingLootItem(loot_id, item->details.item_id);
- if (GetVersion() <= 546) {
- EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
- if (outapp)
- QueuePacket(outapp);
- }
- }
- }
- if (!loot_all)
- break;
- }
- }
- safe_delete(items);
- safe_delete(packet);
- return;
- }
- spawn->LockLoot();
- bool unlockedLoot = false;
- if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
- if (loot_all) {
- switch (spawn->GetLootMethod()) {
- case GroupLootMethod::METHOD_LOTTO: {
- spawn->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
- break;
- }
- case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
- spawn->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
- }
- default: {
- if (!unlockedLoot) {
- spawn->UnlockLoot();
- unlockedLoot = true;
- }
- int32 item_id = 0;
- while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
- loot_all = HandleLootItemByID(spawn, item_id, GetPlayer());
- }
- break;
- }
- }
- spawn->UnlockLoot();
- if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
- CloseLoot(loot_id);
- }
- }
- else {
- int8 item_count = packet->getType_int8_ByName("item_count");
- for (int8 cur = 0; cur < item_count; cur++) {
- char item_field_name[64];
- snprintf(item_field_name, 64, "item_id_%u", cur);
- int32 item_id = packet->getType_int32_ByName(item_field_name);
- Spawn* target = this->GetPlayer();
- if (target_id != 0xFFFFFFFF && GetPlayer()->GetGroupMemberInfo()) {
- Spawn* destTarget = GetPlayer()->GetSpawnWithPlayerID(target_id);
- if (destTarget && (!destTarget->IsPlayer() || !world.GetGroupManager()->IsInGroup(GetPlayer()->GetGroupMemberInfo()->group_id, ((Player*)destTarget)))) {
- SimpleMessage(CHANNEL_COMMAND_TEXT, "HACKS!!");
- safe_delete(packet);
- spawn->UnlockLoot();
- return;
- }
- target = destTarget;
- }
- bool breakLoopAllLooted = false;
- switch (spawn->GetLootMethod()) {
- case GroupLootMethod::METHOD_LOTTO: {
- spawn->AddLottoItemRequest(item_id, GetPlayer()->GetID());
- break;
- }
- case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
- if (button_clicked == 3) { // decline
- break;
- }
- if (GetVersion() <= 546) {
- button_clicked = 1; // selecting is need
- }
- spawn->AddNeedGreedItemRequest(item_id, GetPlayer()->GetID(), (button_clicked == 1));
- break;
- }
- default: {
- if (!unlockedLoot) {
- spawn->UnlockLoot();
- unlockedLoot = true;
- }
- if (!loot_all) {
- HandleLootItemByID(spawn, item_id, target);
- }
- else {
- while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
- loot_all = HandleLootItemByID(spawn, item_id, target);
- }
- breakLoopAllLooted = true;
- }
- break;
- }
- }
- if (breakLoopAllLooted) {
- break;
- }
- }
- if (!unlockedLoot) {
- spawn->UnlockLoot();
- }
- if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO ||
- (spawn->GetLootMethod() == GroupLootMethod::METHOD_NEED_BEFORE_GREED && item_count >= spawn->GetLootCount())) {
- CloseLoot(loot_id);
- }
- }
- if (GetVersion() > 546) {
- EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
- if (outapp)
- QueuePacket(outapp);
- }
- if (spawn->GetLootMethod() != GroupLootMethod::METHOD_LOTTO && spawn->GetLootMethod() != GroupLootMethod::METHOD_NEED_BEFORE_GREED) {
- LootSpawnRequest(spawn);
- }
- else {
- spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
- }
- if (!spawn->HasLoot()) {
- CloseLoot(loot_id);
- if (spawn->IsNPC())
- GetCurrentZone()->RemoveDeadSpawn(spawn);
- }
- }
- else {
- spawn->UnlockLoot();
- if (!spawn) {
- LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
- }
- else
- SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
- }
- }
- safe_delete(packet);
- }
- }
- void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
- PacketStruct* request = 0;
- // cout << "Request: \n";
- // DumpPacket(app);
- switch (app->pBuffer[0]) {
- case 0: { //items
- request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
- if (request) {
- if(request->LoadPacketData(app->pBuffer, app->size)) {
- Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
- if (!item)
- item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
- if (item) {
- PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
- if (response) {
- response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
- response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
- response->setSmallStringByName("name", item->name.c_str());
- EQ2Packet* app2 = response->serialize();
- //DumpPacket(app2);
- QueuePacket(app2);
- safe_delete(response);
- }
- }
- }
- safe_delete(request);
- }
- break;
- }
- case 2: {//spells
- request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
- if (request) {
- if(request->LoadPacketData(app->pBuffer, app->size)) {
- int32 id = request->getType_int32_ByName("id");
- int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
- Spell* spell = master_spell_list.GetSpell(id, tier);
- PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
- if (response) {
- response->setDataByName("request_type", 2);
- response->setDataByName("unique_id", tier);
- response->setDataByName("id", id);
- if (spell)
- response->setSmallStringByName("name", spell->GetName());
- else
- response->setSmallStringByName("name", "Unknown Spell");
- EQ2Packet* app2 = response->serialize();
- // DumpPacket(app2);
- QueuePacket(app2);
- safe_delete(response);
- }
- }
- safe_delete(request);
- }
- break;
- }
- default: {
- LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
- }
- }
- safe_delete(request);
- }
- void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
- PacketStruct* request = 0;
- if (!app || app->size == 0)
- return;
- //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
- //DumpPacket(app);
- int8 type = app->pBuffer[0];
- //283: item: 0, effect: 1, recipe: 2, spell: 3
- if (version <= 283) {
- if (type == 1)
- type = 4;
- else if (type == 2)
- type = 5;
- }
- if (type == 3) {
- Spell* spell = 0;
- bool trait_display;
-
- request = configReader.getStruct((GetVersion() <= 283) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
- if (!request) {
- return;
- }
- if(!request->LoadPacketData(app->pBuffer, app->size)) {
- safe_delete(request);
- return;
- }
-
- int32 id = request->getType_int32_ByName("id");
- int32 tier = request->getType_int32_ByName("tier");
- int32 trait_tier = request->getType_int32_ByName("unknown_id");
- bool display = true;
- if (version <= 283 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
- display = false;
- else if (version <= 546)
- display = request->getType_int8_ByName("display");
- else if (version > 546)
- display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
- //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
- if (trait_tier != 0xFFFFFFFF) {
- spell = master_spell_list.GetSpell(id, trait_tier);
- if (!spell) {
- spell = master_spell_list.GetSpell(id, trait_tier + 1);
- }
- trait_display = true;
- }
- else {
- spell = master_spell_list.GetSpell(id, tier);
- trait_display = false;
- }
- // if we can't find it on the master spell list, see if it is a custom spell
- if (!spell)
- {
- lua_interface->FindCustomSpellLock();
- LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
- if (tmpSpell)
- spell = tmpSpell->spell;
- lua_interface->FindCustomSpellUnlock();
- }
-
- if (spell && !CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
- if (!spell->IsCopiedSpell())
- SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
- EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
- //DumpPacket(app);
- QueuePacket(app);
- }
- else if(spell && GetVersion() <=546 && CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
- EQ2Packet* app = spell->SerializeSpell(this, display, trait_display, GetVersion() <= 546 ? true : false);
- //DumpPacket(app);
- QueuePacket(app);
- }
- }
- else if (type == 0) {
- request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
- if (!request) {
- return;
- }
- if(!request->LoadPacketData(app->pBuffer, app->size)) {
- safe_delete(request);
- return;
- }
- int32 id = request->getType_int32_ByName("id");
- Item* item = 0;
- // translate from unique id to spawn id for houses
- Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
- bool wasSpawn = false;
- if (spawn)
- {
- item = master_item_list.GetItem(spawn->GetPickupItemID());
- if (item)
- {
- wasSpawn = true;
- item = new Item(item);
- item->details.unique_id = spawn->GetPickupUniqueItemID();
- }
- }
- if (!item)
- item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
- if (!item)
- item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
- if (!item)
- item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(id);
- if (!item)
- item = master_item_list.GetItem(id);
- if (item) {// && sent_item_details.count(id) == 0){
- MItemDetails.writelock(__FUNCTION__, __LINE__);
- sent_item_details[id] = true;
- MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
- EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
-
- QueuePacket(app);
- if (wasSpawn)
- delete item;
- }
- else {
- LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
- DumpPacket(app);
- }
- }
- else if (type == 1) {
- request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
- if (!request) {
- return;
- }
- if(!request->LoadPacketData(app->pBuffer, app->size)) {
- safe_delete(request);
- return;
- }
- int32 id = request->getType_int32_ByName("id");
- int32 unique_id = request->getType_int32_ByName("unique_id");
- Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
- if (!item)
- item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
- if (!item)
- item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(unique_id);
- if (!item)
- item = master_item_list.GetItem(id);
- if (item) {
- MItemDetails.writelock(__FUNCTION__, __LINE__);
- sent_item_details[id] = true;
- MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
- EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
- QueuePacket(app);
- }
- else {
- LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
- DumpPacket(app);
- }
- }
- else if (type == 2) {
- request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
- if (!request) {
- return;
- }
- if(!request->LoadPacketData(app->pBuffer, app->size)) {
- safe_delete(request);
- return;
- }
- int32 id = request->getType_int32_ByName("item_id");
- //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
- //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
- //int8 unknown2 = request->getType_int8_ByName("unknown2");
- //int32 unique_id = request->getType_int32_ByName("unique_id");
- //int16 unknown5 = request->getType_sint16_ByName("unknown5");
- //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);
- Item* item = master_item_list.GetItem(id);
- if (item) {
- //only display popup for non merchant links
- EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, GetVersion() > 546 ? true : false);
-
- QueuePacket(app);
- }
- else {
- LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
- DumpPacket(app);
- }
- }
- else if (type == 4) { //spell effect
- request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
- if (!request) {
- return;
- }
- if(!request->LoadPacketData(app->pBuffer, app->size)) {
- safe_delete(request);
- return;
- }
- int32 id = request->getType_int32_ByName("id");
- int16 display = request->getType_int8_ByName("partial_info");
- SpellEffects* effect = player->GetSpellEffect(id);
- //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
- if (effect) {
- int8 tier = effect->tier;
- Spell* spell = master_spell_list.GetSpell(id, tier);
- // if we can't find it on the master spell list, see if it is a custom spell
- if (!spell)
- {
- lua_interface->FindCustomSpellLock();
- LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
- EQ2Packet* pack = 0;
- if (tmpSpell)
- spell = tmpSpell->spell;
- lua_interface->FindCustomSpellUnlock();
- }
- if (spell && !CountSentSpell(id, tier)) {
- if (!spell->IsCopiedSpell())
- SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
- int8 type = 0;
- if (version <= 283)
- type = 1;
- EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
- //DumpPacket(app);
- QueuePacket(app);
- }
- }
- }
- else if (type == 5) { // recipe info
- request = configReader.getStruct((GetVersion() <= 283) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
- if (!request)
- return;
- if(!request->LoadPacketData(app->pBuffer, app->size)) {
- safe_delete(request);
- return;
- }
-
- int32 id = 0;
- if(GetVersion() < 546) {
- id = request->getType_int32_ByName("id");
- }
- else if(GetVersion() == 546) {
- id = request->getType_int32_ByName("unique_id");
- }
- else {
- id = request->getType_int32_ByName("unknown_id");
- }
- Recipe* recipe = master_recipe_list.GetRecipe(id);
- if (recipe) {
- EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
- //DumpPacket(app);
- QueuePacket(app);
- }
- }
- else if (type == 6) { // AA spell info
- Spell* spell = 0;
- //Spell* spell2 = 0;
- //AltAdvanceData* data = 0;
- request = configReader.getStruct((GetVersion() <= 283) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
- if (!request)
- return;
- if(!request->LoadPacketData(app->pBuffer, app->size)) {
- safe_delete(request);
- return;
- }
- int32 id = request->getType_int32_ByName("id");
- int32 tier = GetPlayer()->GetSpellTier(id);
- LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
- //data = master_aa_list.GetAltAdvancement(id);
- //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
- //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
- spell = master_spell_list.GetSpell(id, tier);
- if (!spell)
- spell = master_spell_list.GetSpell(id, 1);
- if (!spell)
- {
- lua_interface->FindCustomSpellLock();
- LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
- if (tmpSpell)
- spell = tmpSpell->spell;
- lua_interface->FindCustomSpellUnlock();
- }
- if (!spell)
- {
- LogWrite(WORLD__ERROR, 0, "WORLD", "FAILED Examine Info Request-> Spell ID: %u, tier: %i", id, tier);
- return;
- }
- //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
- if (!spell->IsCopiedSpell())
- SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
- // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
- LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
- if(GetVersion() > 546) {
- EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
- /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
- //DumpPacket(app);
- QueuePacket(app);
- }
- //}
- }
- else {
- LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
- DumpPacket(app);
- }
- safe_delete(request);
- }
- void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
- PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
- if (request) {
- if(request->LoadPacketData(app->pBuffer, app->size)) {
- int32 id = request->getType_int32_ByName("id");
- int32 bar = request->getType_int32_ByName("hotbar_number");
- int32 slot = request->getType_int32_ByName("hotkey_slot");
- int32 type = request->getType_int32_ByName("type");
- int8 tier = request->getType_int32_ByName("unique_id");
- EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
- Spell* spell = 0;
- if (type == 0xFFFFFFFF)
- GetPlayer()->RemoveQuickbarItem(bar, slot);
- else {
- if (type == QUICKBAR_NORMAL)
- spell = master_spell_list.GetSpell(id, tier);
- if (spell)
- GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
- else
- GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
- }
- }
- safe_delete(request);
- }
- }
- bool Client::Process(bool zone_process) {
-
- bool ret = true;
- // EQS can become null if player is linkdead, we want to always be able to process the camp/linkdead timers when active
- if ((camp_timer && camp_timer->Check()) || (linkdead_timer && linkdead_timer->Check())) {
- ResetSendMail();
- if(getConnection())
- getConnection()->SendDisconnect(false);
- safe_delete(camp_timer);
- if(linkdead_timer) {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Player %s triggered linkdead timer, disconnecting", GetPlayer()->GetName());
- // we remove the linkdead status and force a camp out immediately
- if((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0) {
- GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() - ACTIVITY_STATUS_LINKDEAD);
- }
- if ((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0) {
- GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
- }
- }
- safe_delete(linkdead_timer);
- ret = false;
- }
-
- if (!eqs) {
- return false;
- }
- if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
- return true;
- }
- switch(new_client_login) {
- case NewLoginState::LOGIN_SEND: {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
- SendLoginInfo();
-
- new_client_login = NewLoginState::LOGIN_NONE;
- break;
- }
- case NewLoginState::LOGIN_INITIAL_LOAD: {
- bool isDBActive = database.IsActiveQuery(GetCharacterID());
-
- // wait for starting skills/spells to load and reload from DB.
- if(!isDBActive) {
- if (GetPlayer()->GetInfoStruct()->get_reload_player_spells()) {
- database.LoadCharacterSpells(GetCharacterID(), GetPlayer());
- GetPlayer()->GetInfoStruct()->set_reload_player_spells(0);
- }
- new_client_login = NewLoginState::LOGIN_SEND;
- }
- break;
- }
- case NewLoginState::LOGIN_ALLOWED: {
- int32 count = 0;
- if(!GetPlayer()->IsReturningFromLD())
- {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
- count = database.LoadCharacterSkills(GetCharacterID(), player);
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
- count = database.LoadCharacterSpells(GetCharacterID(), player);
- }
- else
- {
- LogWrite(CCLIENT__INFO, 0, "Client", "Player is returning from linkdead status (Player does not need reload) thus skipping database loading for '%s'...", player->GetName());
- }
-
- // get the latest character starting skills / spells, may have been updated after character creation
- if(GetPlayer()->GetInfoStruct()->get_first_world_login()) {
- world.SyncCharacterAbilities(this);
- Query query;
- query.AddQueryAsync(GetCharacterID(), &database, Q_UPDATE, "UPDATE characters set first_world_login = 0 where id=%u", GetCharacterID());
- GetPlayer()->GetInfoStruct()->set_first_world_login(0);
- }
-
- new_client_login = NewLoginState::LOGIN_INITIAL_LOAD;
- break;
- }
- case NewLoginState::LOGIN_DELAYED: {
- if(!delay_msg_timer.Enabled() || delay_msg_timer.Check()) {
- LogWrite(CCLIENT__INFO, 0, "Client", "Wait for zone %s to load for new client %s...", GetCurrentZone()->GetZoneName(), GetPlayer()->GetName());
- delay_msg_timer.Start(1000, true);
- }
- if(!GetCurrentZone()->IsLoading()) {
- new_client_login = NewLoginState::LOGIN_ALLOWED;
- }
-
- return true;
- break;
- }
- }
-
- delay_msg_timer.Disable();
-
- sockaddr_in to;
- memset((char*)&to, 0, sizeof(to));
- to.sin_family = AF_INET;
- to.sin_port = port;
- to.sin_addr.s_addr = ip;
- /************ Get all packets from packet manager out queue and process them ************/
- EQApplicationPacket* app = 0;
- if (eqs && !eqs->CheckActive()) {
- num_active_failures++;
- LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
- if (num_active_failures > 100) {
- return false;
- }
- return true;
- }
- while (ret && eqs && (app = eqs->PopPacket())) {
- ret = HandlePacket(app);
- LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
- delete app;
- }
- if (GetCurrentZone() && !GetCurrentZone()->IsLoading() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
- //database.LoadCharacterActiveSpells(player);
- player->UnlockAllSpells(true);
- should_load_spells = false;
- }
- if(spawn_removal_timer.Check() && GetPlayer()) {
- GetPlayer()->ProcessSpawnRangeUpdates();
- GetPlayer()->CheckSpawnStateQueue();
- }
- if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
- {
- if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
- return false;
- }
- if (quest_updates) {
- LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
- ProcessQuestUpdates();
- }
- int32 queue_timer_delay = rule_manager.GetGlobalRule(R_Client, QuestQueueTimer)->GetInt32();
- if(queue_timer_delay < 10) {
- queue_timer_delay = 10;
- }
- if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - queue_timer_delay)) {
- LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
- CheckQuestQueue();
- }
- MSaveSpellStateMutex.lock();
- if(save_spell_state_timer.Check())
- {
- save_spell_state_timer.Disable();
- GetPlayer()->SaveSpellEffects();
- }
- MSaveSpellStateMutex.unlock();
- if (temp_placement_timer.Check()) {
- if(GetTempPlacementSpawn() && GetPlayer()->WasSentSpawn(GetTempPlacementSpawn()->GetID()) && !hasSentTempPlacementSpawn) {
- SendMoveObjectMode(GetTempPlacementSpawn(), 0);
- hasSentTempPlacementSpawn = true;
- temp_placement_timer.Disable();
- }
- }
- if (pos_update.Check())
- {
- ProcessStateCommands();
-
- GetPlayer()->ResetMentorship(); // check if we need to asynchronously reset mentorship
- if(GetPlayer()->GetRegionMap())
- GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
-
- if(player_pos_changed && IsReadyForUpdates()) {
- if(!underworld_cooldown_timer.Enabled() || (underworld_cooldown_timer.Enabled() && underworld_cooldown_timer.Check())) {
- bool underworld = false;
- if(rule_manager.GetGlobalRule(R_Zone, UseMapUnderworldCoords)->GetBool()) {
- if(GetCurrentZone()->GetUnderWorld() != -1000000.0f) {
- if(GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld())
- underworld = true;
- }
- else if(GetPlayer()->GetMap() && GetPlayer()->GetMap()->GetMinY() != 9999999.0f && GetPlayer()->GetY() < (GetPlayer()->GetMap()->GetMinY() + rule_manager.GetGlobalRule(R_Zone, MapUnderworldCoordOffset)->GetFloat())) {
- underworld = true;
- }
- }
- else if(GetPlayer()->GetMap() && GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld()) {
- underworld = true;
- }
- if(underworld) {
- player->SetX(GetCurrentZone()->GetSafeX());
- player->SetY(GetCurrentZone()->GetSafeY());
- player->SetZ(GetCurrentZone()->GetSafeZ());
- player->SetHeading(GetCurrentZone()->GetSafeHeading());
- EQ2Packet* app = GetPlayer()->Move(player->GetX(), player->GetY(), player->GetZ(), GetVersion(), player->GetHeading());
- if(app){
- QueuePacket(app);
- }
- SimpleMessage(CHANNEL_COLOR_RED, "You have been teleported to a safe location in the zone, because you appeared to have fallen through the world.");
- }
- underworld_cooldown_timer.Start();
- }
- //GetPlayer()->CalculateLocation();
- client_list.CheckPlayersInvisStatus(this);
- GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
-
- player_pos_changed = false;
-
- GetCurrentZone()->CheckTransporters(this);
-
- if(GetPlayer()->GetRegionMap())
- {
- GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
- }
- }
- else if (IsReadyForUpdates() && GetPlayer()->GetRegionMap()) {
- GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
- }
- }
- if (lua_interface && lua_debug && lua_debug_timer.Check())
- lua_interface->UpdateDebugClients(this);
- if (quest_pos_timer.Check())
- CheckPlayerQuestsLocationUpdate();
- if (player->GetSkills()->HasSkillUpdates()) {
- vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
- if (skills) {
- Skill* skill = 0;
- vector<Skill*>::iterator itr;
- for (itr = skills->begin(); itr != skills->end(); itr++) {
- skill = *itr;
- SkillChanged(skill, skill->previous_val, skill->current_val);
- }
- EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
- if (app) QueuePacket(app);
- safe_delete(skills);
- }
- }
- m_resurrect.writelock(__FUNCTION__, __LINE__);
- if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
- safe_delete(current_rez.expire_timer);
- current_rez.expire_timer = 0;
- current_rez.active = false;
- current_rez.caster = 0;
- current_rez.crit = false;
- current_rez.crit_mod = 0;
- current_rez.expire_timer = 0;
- current_rez.heal_name = "";
- current_rez.hp_perc = 0;
- current_rez.mp_perc = 0;
- current_rez.no_calcs = false;
- current_rez.range = 0;
- current_rez.should_delete = false;
- current_rez.spell_name = "";
- current_rez.spell_visual = 0;
- current_rez.subspell = 0;
- }
- m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
- // Quest timers
- Quest* failed_step = 0;
- MQuestTimers.writelock(__FUNCTION__, __LINE__);
- if (quest_timers.size() > 0) {
- vector<int32>::iterator itr;
- GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
- map<int32, Quest*>* player_quests = player->GetPlayerQuests();
- for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
- if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
- Quest* quest = player_quests->at(*itr);
- if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
- failed_step = quest;
- break;
- }
- }
- else {
- itr = quest_timers.erase(itr);
- break;
- }
- }
- GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
- }
- MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
- if (failed_step)
- failed_step->StepFailed(failed_step->GetTimerStep());
- if (player->ControlFlagsChanged())
- player->SendControlFlagUpdates(this);
- if (!eqs || (eqs && !eqs->CheckActive()))
- ret = false;
- // redundant to client disconnect
- // if(!ret)
- // Save();
- return ret;
- }
- ClientList::ClientList() {
- MClients.SetName("ClientList::MClients");
- }
- ClientList::~ClientList() {
- }
- void ClientList::ReloadQuests() {
- list<Client*>::iterator client_iter;
- Client* client = 0;
- MClients.readlock(__FUNCTION__, __LINE__);
- for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
- client = *client_iter;
- if (client)
- client->ReloadQuests();
- }
- MClients.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ClientList::CheckPlayersInvisStatus(Client* owner) {
- if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
- return;
- list<Client*>::iterator client_iter;
- Client* client = 0;
- MClients.readlock(__FUNCTION__, __LINE__);
- for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
- client = *client_iter;
- if (client == owner || client->GetPlayer() == NULL)
- continue;
- if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
- client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
- }
- MClients.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
- list<Client*>::iterator client_iter;
- Client* client = 0;
- MClients.readlock(__FUNCTION__, __LINE__);
- for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
- client = *client_iter;
- if (!client->GetPlayer())
- continue;
- client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
- }
- MClients.releasereadlock(__FUNCTION__, __LINE__);
- }
- int32 ClientList::Count() {
- return client_list.size();
- }
- void ClientList::Add(Client* client) {
- MClients.writelock(__FUNCTION__, __LINE__);
- client_list.push_back(client);
- MClients.releasewritelock(__FUNCTION__, __LINE__);
- }
- Client* ClientList::FindByAccountID(int32 account_id) {
- list<Client*>::iterator client_iter;
- Client* client = 0;
- Client* ret = 0;
- MClients.readlock(__FUNCTION__, __LINE__);
- for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
- client = *client_iter;
- if (client->GetAccountID() == account_id) {
- ret = client;
- break;
- }
- }
- MClients.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- Client* ClientList::FindByName(char* charName) {
- list<Client*>::iterator client_iter;
- Client* client = 0;
- Client* ret = 0;
- MClients.readlock(__FUNCTION__, __LINE__);
- for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
- client = *client_iter;
- if (!client || !client->GetPlayer())
- continue;
- if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
- ret = client;
- break;
- }
- }
- MClients.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- Client* ClientList::Get(int32 ip, int16 port) {
- list<Client*>::iterator client_iter;
- Client* client = 0;
- Client* ret = 0;
- MClients.readlock(__FUNCTION__, __LINE__);
- for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
- client = *client_iter;
- if (client->GetIP() == ip && client->GetPort() == port) {
- ret = client;
- break;
- }
- }
- MClients.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ClientList::Process() {
- list<Client*>::iterator client_iter;
- list<Client*>::iterator erase_iter;
- Client* client = 0;
- MClients.readlock(__FUNCTION__, __LINE__);
- erase_iter = client_list.end();
- for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
- client = *client_iter;
- // have a sanity check because the client list can sometimes obtain null client pointers
- if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
- erase_iter = client_iter;
- break;
- }
- }
- MClients.releasereadlock(__FUNCTION__, __LINE__);
- if (erase_iter != client_list.end()) {
- client = *erase_iter;
- MClients.writelock(__FUNCTION__, __LINE__);
- client_list.erase(erase_iter);
- MClients.releasewritelock(__FUNCTION__, __LINE__);
- if (client && !client->remove_from_list) {
- struct in_addr in;
- in.s_addr = client->GetIP();
- LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
- safe_delete(client);
- }
- }
- }
- void ClientList::RemoveConnection(EQStream* eqs) {
- Client* client;
- if (eqs) {
- list<Client*>::iterator client_iter;
- MClients.readlock(__FUNCTION__, __LINE__);
- for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
- client = *client_iter;
- if (client->getConnection() == eqs)
- client->Disconnect(true);
- }
- MClients.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- bool ClientList::ContainsStream(EQStream* eqs) {
- if (!eqs) {
- return false;
- }
- list<Client*>::iterator client_iter;
- bool ret = false;
- MClients.readlock(__FUNCTION__, __LINE__);
- for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
- if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
- ret = true;
- break;
- }
- }
- MClients.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ClientList::Remove(Client* client, bool remove_data) {
- client->remove_from_list = true;
- if (remove_data) {
- safe_delete(client);
- }
- }
- void Client::SetCurrentZone(ZoneServer* zone) {
- current_zone = zone;
- if(player) {
- player->SetZone(zone, GetVersion());
- }
- }
- void Client::SetCurrentZone(int32 id) {
- if (current_zone) {
- //current_zone->GetCombat()->RemoveHate(player);
- current_zone->RemoveSpawn(player, false, true, true, true, true);
- }
- SetCurrentZone(zone_list.Get(id));
- }
- void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
- if (current_zone) {
- //current_zone->GetCombat()->RemoveHate(player);
- current_zone->RemoveSpawn(player, false, true, true, true, true);
- }
- SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
- }
- ZoneServer* Client::GetCurrentZone() {
- return current_zone;
- }
- int8 Client::GetMessageChannelColor(int8 channel_type) {
- if (GetVersion() >= 973 && GetVersion() <= 1000) {
- if (channel_type == CHANNEL_LOOT)
- return CHANNEL_COLOR_NEW_LOOT;
- }
- else if (GetVersion() >= 973) {
- if (channel_type == CHANNEL_LOOT)
- return CHANNEL_COLOR_NEWEST_LOOT;
- }
- if (GetVersion() <= 283) {
- if (channel_type <=12)
- return channel_type;
- switch (channel_type) {
- case CHANNEL_GROUP_CHAT:
- case CHANNEL_GROUP_SAY:
- case CHANNEL_RAID_SAY:
- case CHANNEL_GUILD_CHAT:
- case CHANNEL_GUILD_SAY:
- case CHANNEL_OFFICER_SAY:
- case CHANNEL_GUILD_MOTD:
- return channel_type - 1;
- case CHANNEL_PRIVATE_CHAT:
- case CHANNEL_NONPLAYER_TELL:
- return channel_type - 5;
- case CHANNEL_PRIVATE_TELL:
- case CHANNEL_TELL_FROM_CS:
- return channel_type - 6;
- case CHANNEL_CHAT_CHANNEL_TEXT:
- case CHANNEL_OUT_OF_CHARACTER:
- case CHANNEL_AUCTION:
- case CHANNEL_CUSTOM_CHANNEL:
- case CHANNEL_CHARACTER_TEXT:
- case CHANNEL_REWARD:
- case CHANNEL_DEATH:
- case CHANNEL_PET_CHAT:
- case CHANNEL_SKILL:
- return channel_type - 7;
- case CHANNEL_SPELLS:
- case CHANNEL_YOU_CAST:
- case CHANNEL_YOU_FAIL:
- return channel_type - 8;
- case CHANNEL_FRIENDLY_CAST:
- case CHANNEL_FRIENDLY_FAIL:
- case CHANNEL_OTHER_CAST:
- case CHANNEL_OTHER_FAIL:
- case CHANNEL_HOSTILE_CAST:
- case CHANNEL_HOSTILE_FAIL:
- case CHANNEL_WORN_OFF:
- case CHANNEL_SPELLS_OTHER:
- return channel_type - 9;
- case CHANNEL_COMBAT:
- return channel_type - 15;
- case CHANNEL_HEROIC_OPPORTUNITY:
- case CHANNEL_NON_MELEE_DAMAGE:
- case CHANNEL_DAMAGE_SHIELD:
- return channel_type - 16;
- case CHANNEL_MELEE_COMBAT:
- case CHANNEL_WARNINGS:
- case CHANNEL_YOU_HIT:
- case CHANNEL_YOU_MISS:
- case CHANNEL_ATTACKER_HITS:
- case CHANNEL_ATTACKER_MISSES:
- return channel_type - 18;
- case CHANNEL_OTHER_HIT:
- case CHANNEL_OTHER_MISSES:
- case CHANNEL_CRITICAL_HIT:
- return channel_type - 22;
- case CHANNEL_OTHER:
- case CHANNEL_MONEY_SPLIT:
- case CHANNEL_LOOT:
- return channel_type - 30;
- case CHANNEL_COMMAND_TEXT:
- case CHANNEL_BROADCAST:
- case CHANNEL_WHO:
- case CHANNEL_COMMANDS:
- case CHANNEL_MERCHANT:
- case CHANNEL_MERCHANT_BUY_SELL:
- case CHANNEL_CONSIDER_MESSAGE:
- case CHANNEL_CON_MINUS_2:
- case CHANNEL_CON_MINUS_1:
- case CHANNEL_CON_0:
- case CHANNEL_CON_1:
- case CHANNEL_CON_2:
- return channel_type - 31;
- default: {
- return CHANNEL_DEFAULT;
- }
- }
- }
- else if (GetVersion() <= 546) {
- if (channel_type < 20)
- return channel_type;
- switch (channel_type) {
- case CHANNEL_GUILD_MOTD:
- case CHANNEL_GUILD_MEMBER_ONLINE:
- case CHANNEL_GUILD_EVENT:
- return channel_type + 1;
- case CHANNEL_PRIVATE_CHAT:
- case CHANNEL_NONPLAYER_TELL:
- return channel_type - 1;
- case CHANNEL_PRIVATE_TELL:
- case CHANNEL_TELL_FROM_CS:
- case CHANNEL_ARENA:
- case CHANNEL_CHAT_CHANNEL_TEXT:
- case CHANNEL_OUT_OF_CHARACTER:
- case CHANNEL_AUCTION:
- case CHANNEL_CUSTOM_CHANNEL:
- case CHANNEL_CHARACTER_TEXT:
- case CHANNEL_REWARD:
- case CHANNEL_DEATH:
- case CHANNEL_PET_CHAT:
- case CHANNEL_SKILL:
- case CHANNEL_FACTION:
- case CHANNEL_SPELLS:
- case CHANNEL_YOU_CAST:
- case CHANNEL_YOU_FAIL:
- return channel_type - 2;
- case CHANNEL_FRIENDLY_CAST:
- case CHANNEL_FRIENDLY_FAIL:
- case CHANNEL_OTHER_CAST:
- case CHANNEL_OTHER_FAIL:
- case CHANNEL_HOSTILE_CAST:
- case CHANNEL_HOSTILE_FAIL:
- case CHANNEL_WORN_OFF:
- case CHANNEL_SPELLS_OTHER:
- case CHANNEL_HEAL_SPELLS:
- case CHANNEL_HEALS:
- case CHANNEL_FRIENDLY_HEALS:
- case CHANNEL_OTHER_HEALS:
- case CHANNEL_HOSTILE_HEALS:
- return channel_type - 3;
- case CHANNEL_COMBAT:
- case CHANNEL_GENERAL_COMBAT:
- case CHANNEL_HEROIC_OPPORTUNITY:
- case CHANNEL_NON_MELEE_DAMAGE:
- case CHANNEL_DAMAGE_SHIELD:
- case CHANNEL_WARD:
- return channel_type - 4;
- case CHANNEL_MELEE_COMBAT:
- case CHANNEL_WARNINGS:
- case CHANNEL_YOU_HIT:
- case CHANNEL_YOU_MISS:
- case CHANNEL_ATTACKER_HITS:
- case CHANNEL_ATTACKER_MISSES:
- case CHANNEL_YOUR_PET_HITS:
- case CHANNEL_YOUR_PET_MISSES:
- case CHANNEL_ATTACKER_HITS_PET:
- case CHANNEL_ATTACKER_MISSES_PET:
- case CHANNEL_OTHER_HIT:
- case CHANNEL_OTHER_MISSES:
- return channel_type - 5;
- case CHANNEL_OTHER:
- case CHANNEL_MONEY_SPLIT:
- case CHANNEL_LOOT:
- return channel_type - 14;
- case CHANNEL_COMMAND_TEXT:
- case CHANNEL_BROADCAST:
- case CHANNEL_WHO:
- case CHANNEL_COMMANDS:
- case CHANNEL_MERCHANT:
- case CHANNEL_MERCHANT_BUY_SELL:
- case CHANNEL_CONSIDER_MESSAGE:
- case CHANNEL_CON_MINUS_2:
- case CHANNEL_CON_MINUS_1:
- case CHANNEL_CON_0:
- case CHANNEL_CON_1:
- case CHANNEL_CON_2:
- case CHANNEL_TRADESKILLS:
- case CHANNEL_HARVESTING:
- case CHANNEL_HARVESTING_WARNINGS:
- return channel_type - 15;
- default: {
- return CHANNEL_DEFAULT;
- }
- }
- }
- else {
- switch (channel_type) {
- default: {
- return channel_type;
- }
- }
- }
- return channel_type;
- }
- void Client::HandleTellMessage(Client* from, const char* message, const char* to, int32 current_language_id) {
- if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
- return;
- PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
- if (packet) {
- packet->setDataByName("from", from->GetPlayer()->GetName());
- packet->setDataByName("to", to);
- packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
- packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
- packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
- packet->setDataByName("unknown2", 1, 1);
- packet->setDataByName("show_bubble", 1);
-
- if (current_language_id == 0 || GetPlayer()->HasLanguage(current_language_id)) {
- packet->setDataByName("understood", 1);
- }
-
- packet->setDataByName("time", 2);
- packet->setDataByName("language", current_language_id);
- packet->setMediumStringByName("message", message);
- EQ2Packet* outpacket = packet->serialize();
- QueuePacket(outpacket);
- safe_delete(packet);
- }
- }
- void Client::SimpleMessage(int8 color, const char* message) {
- PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
- if (command_packet) {
- command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
- command_packet->setMediumStringByName("text", message);
- command_packet->setDataByName("unknown02", 0x00ff);
- EQ2Packet* outapp = command_packet->serialize();
- QueuePacket(outapp);
- safe_delete(command_packet);
- }
- }
- void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
- PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
- if (packet) {
- int8 xxx = spell->GetSpellData()->is_aa;
- packet->setDataByName("spell_type", spell->GetSpellData()->type);
- packet->setDataByName("spell_id", spell->GetSpellID());
- packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
- packet->setDataByName("spell_name", spell->GetName());
- if(add_silently)
- packet->setDataByName("add_silently", 1);
- if(add_to_hotbar)
- packet->setDataByName("add_to_hotbar", 1);
- packet->setDataByName("unknown", xxx);
- packet->setDataByName("display_spell_tier", 1);
- packet->setDataByName("unknown3", 1);
- packet->setDataByName("tier", spell->GetSpellTier());
- packet->setDataByName("icon", spell->GetSpellIcon());
- packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
- packet->setDataByName("unknown5", 0xFFFFFFFF);
- //packet->PrintPacket();
- EQ2Packet* outapp = packet->serialize();
- //DumpPacket(outapp);
- QueuePacket(outapp);
- safe_delete(packet);
- }
- }
- void Client::Message(int8 type, const char* message, ...) {
- va_list argptr;
- char buffer[4096];
- va_start(argptr, message);
- vsnprintf(buffer, sizeof(buffer), message, argptr);
- va_end(argptr);
- SimpleMessage(type, buffer);
- }
- void Client::Disconnect(bool send_disconnect)
- {
- LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
- this->Save();
- this->GetPlayer()->WritePlayerStatistics();
- SetConnected(false);
- if (send_disconnect && getConnection())
- getConnection()->SendDisconnect(true);
- eqs = 0;
- }
- bool Client::Summon(const char* search_name) {
- Spawn* target = 0;
- if (search_name || GetPlayer()->GetTarget()) {
- Client* search_client = 0;
- if (search_name) {
- target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
- if (target && target->IsPlayer())
- search_client = target->GetClient();
- if (!target) {
- search_client = zone_list.GetClientByCharName(string(search_name));
- if (search_client)
- target = search_client->GetPlayer();
- }
- }
- else
- target = GetPlayer()->GetTarget();
- if (target && target != GetPlayer()) {
- target->SetX(GetPlayer()->GetX());
- target->SetY(GetPlayer()->GetY());
- target->SetZ(GetPlayer()->GetZ());
- target->SetHeading(GetPlayer()->GetHeading());
- if (!target->IsPlayer()) {
- target->SetSpawnOrigX(target->GetX());
- target->SetSpawnOrigY(target->GetY());
- target->SetSpawnOrigZ(target->GetZ());
- target->SetSpawnOrigHeading(target->GetHeading());
- }
- target->SetLocation(GetPlayer()->GetLocation());
- if(target->IsNPC()) {
- ((NPC*)target)->HaltMovement();
- }
- }
- else if (target)
- Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
- if (search_client && search_client != this) {
- search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
- Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
- if (search_client->GetCurrentZone() != GetCurrentZone())
- search_client->Zone(GetCurrentZone()->GetZoneName(), false);
- else {
- EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
- if (app)
- search_client->QueuePacket(app);
- }
- }
- }
- if (!target)
- return false;
- else
- return true;
- }
- std::string Client::IdentifyInstanceLockout(int32 zoneID, bool displayClient) {
- int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
- if(instanceType < 1)
- return std::string("");
-
- ZoneServer* instance_zone = nullptr;
- InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
- if (data) {
- // If lockout instances check to see if we are locked out
- if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
- int32 time = 0;
- // Check success timer
- if (data->last_success_timestamp > 0) {
- if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
- // Timer has not expired yet can't re enter
- LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
- time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
- }
- }
- // Check failure timer
- if (data->last_failure_timestamp > 0) {
- if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
- // Timer has not expired yet
- LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
- time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
- }
- }
- // Time > 0 then we are locked out, make the message and send it and return true
- if (time > 0) {
- string time_msg = "";
- int16 hour;
- int8 min;
- int8 sec;
- hour = time / 3600;
- time = time % 3600;
- min = time / 60;
- time = time % 60;
- sec = time;
- if (hour > 0) {
- char temp[10];
- snprintf(temp, 9," %i", hour);
- time_msg.append(temp);
- time_msg.append(" hour");
- time_msg.append((hour > 1) ? "s" : "");
- }
- if (min > 0) {
- char temp[5];
- snprintf(temp, 4," %i", min);
- time_msg.append(temp);
- time_msg.append(" minute");
- time_msg.append((min > 1) ? "s" : "");
- }
- // Only add seconds if minutes and hours are 0
- if (hour == 0 && min == 0 && sec > 0) {
- char temp[5];
- snprintf(temp, 4," %i", sec);
- time_msg.append(temp);
- time_msg.append(" second");
- time_msg.append((sec > 1) ? "s" : "");
- }
- if(displayClient)
- Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
- return time_msg;
- }
- }
- }
- return std::string("");
- }
- ZoneServer* Client::IdentifyInstance(int32 zoneID) {
- int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
- if(instanceType < 1)
- return nullptr;
- ZoneServer* instance_zone = nullptr;
- InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
- if (data) {
- std::string lockoutTime = IdentifyInstanceLockout(zoneID);
- // If lockout instances check to see if we are locked out
- if (lockoutTime.length() > 0) {
- return nullptr;
- }
- // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
- instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID, false, false);
- // 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
- if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
- if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
- database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
- data->last_success_timestamp = Timer::GetUnixTimeStamp();
- }
- else
- database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
- data->instance_id = instance_zone->GetInstanceID();
- }
- }
- return instance_zone;
- }
- bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
- ZoneServer* instance_zone = NULL;
- int8 instanceType = 0;
- // determine if this is a group instanced zone that already exists
- instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
- if (instance_zone != NULL)
- Zone(instance_zone->GetInstanceID(), zone_coords_valid);
- else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
- {
- // best to check if we already have our own instance!
- if((instance_zone = IdentifyInstance(zoneID)) == nullptr)
- {
- switch (instanceType)
- {
- case SOLO_LOCKOUT_INSTANCE:
- case GROUP_LOCKOUT_INSTANCE:
- case RAID_LOCKOUT_INSTANCE:
- {
- instance_zone = zone_list.GetByInstanceID(0, zoneID);
- if (instance_zone) {
- // 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
- // so delete `instances` entry for the zone when it shuts down.
- 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());
- if (db_id > 0)
- GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
- }
- break;
- }
- case SOLO_PERSIST_INSTANCE:
- case GROUP_PERSIST_INSTANCE:
- case RAID_PERSIST_INSTANCE:
- {
- instance_zone = zone_list.GetByInstanceID(0, zoneID);
- if (instance_zone) {
- 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());
- if (db_id > 0)
- 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()));
- }
- break;
- }
- case PUBLIC_INSTANCE:
- case TRADESKILL_INSTANCE:
- {
- // if its public/tradeskill, look for a public already setup
- instance_zone = zone_list.GetByLowestPopulation(zoneID);
- if (instance_zone) {
- // Check the current population against the max population, if greater or equal start a new version
- if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
- instance_zone = zone_list.GetByInstanceID(0, zoneID);
- }
- else
- instance_zone = zone_list.GetByInstanceID(0, zoneID);
- break;
- }
- case PERSONAL_HOUSE_INSTANCE:
- case GUILD_HOUSE_INSTANCE:
- {
- // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
- // use this function without some rework, so it will all be handled in Client::HandlePacket()
- // with the OP_EnterHouseMsg opcode
- break;
- }
- case QUEST_INSTANCE:
- {
- instance_zone = zone_list.GetByInstanceID(0, zoneID);
- break;
- /*
- 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`;
- */
- }
- default:
- {
- // NONE
- }
- }
- }
- if (instance_zone != NULL)
- Zone(instance_zone, zone_coords_valid);
- }
- if (instance_zone != NULL)
- return true;
- else
- return false;
- }
- bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
- Spawn* target = 0;
- if (search_name || GetPlayer()->GetTarget()) {
- Client* search_client = 0;
- if (search_name) {
- target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
- if (!target) {
- search_client = zone_list.GetClientByCharName(search_name);
- if (search_client)
- target = search_client->GetPlayer();
- }
- if (target)
- GetPlayer()->SetTarget(target);
- }
- else
- target = GetPlayer()->GetTarget();
- if (target && target != GetPlayer()) {
- GetPlayer()->SetX(target->GetX());
- GetPlayer()->SetY(target->GetY());
- GetPlayer()->SetZ(target->GetZ());
- GetPlayer()->SetHeading(target->GetHeading());
- GetPlayer()->SetLocation(target->GetLocation());
- Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
- }
- else if (target)
- Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
- if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
- Zone(search_client->GetCurrentZone()->GetZoneName(), false);
- else if (target) {
- EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion(), (target->GetHeading() + 180.0f));
- if (app)
- QueuePacket(app);
- }
- }
- if (!target)
- return false;
- else
- return true;
- }
- bool Client::CheckZoneAccess(const char* zoneName) {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
- ZoneServer* zone = zone_list.Get(zoneName, false, false, false);
- // JA: implemented /zone lock|unlock commands (2012.07.28)
- if (zone && zone->GetZoneLockState())
- {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
- Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
- return false;
- }
- sint16 zoneMinStatus = 0;
- int16 zoneMinLevel = 0;
- int16 zoneMaxLevel = 0;
- int16 zoneMinVersion = 0;
- if (!zone)
- {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
- bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
- if (!success) { // couldn't even find the zone, this shouldn't happen though..
- return true;
- }
- }
- else
- {
- zoneMinStatus = zone->GetMinimumStatus();
- zoneMinLevel = zone->GetMinimumLevel();
- zoneMaxLevel = zone->GetMaximumLevel();
- zoneMinVersion = zone->GetMinimumVersion();
- }
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
- // use ZoneLevelOverrideStatus in both min_level and max_level checks
- sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
- if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
- {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
- Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
- return false;
- }
- if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
- {
- if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
- {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
- Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
- return false;
- }
- }
- if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
- {
- if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
- {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
- Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
- return false;
- }
- }
- if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
- {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
- sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
- if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
- {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
- Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
- return false;
- }
- }
- return true;
- }
- void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID, bool is_spell) {
- Zone(zone_list.GetByInstanceID(instanceid, 0, false, true), set_coords, is_spell);
- }
- void Client::Zone(ZoneServer* new_zone, bool set_coords, bool is_spell) {
- if (!new_zone) {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
- return;
- }
-
- client_zoning = true;
- zoning_id = new_zone->GetZoneID();
- zoning_instance_id = new_zone->GetInstanceID();
-
- LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
- player->SetResurrecting(true);
- LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
- //GetCurrentZone()->GetCombat()->RemoveHate(player);
- SaveSpells();
-
- ResetSendMail();
- // Remove players pet from zone if there is one
- ((Entity*)player)->DismissAllPets();
- LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
- GetCurrentZone()->RemoveSpawn(player, false, true, true, true, !is_spell);
-
- GetPlayer()->DeleteSpellEffects(true);
-
- LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
- SetZoningDestination(new_zone);
- SetCurrentZone(new_zone);
-
- if (player->GetGroupMemberInfo())
- {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
- player->UpdateGroupMemberInfo();
- world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
- }
- // block out the member info for the group
- TempRemoveGroup();
- UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
- if (set_coords)
- {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
- __FUNCTION__,
- GetCurrentZone()->GetSafeX(),
- GetCurrentZone()->GetSafeY(),
- GetCurrentZone()->GetSafeZ(),
- GetCurrentZone()->GetSafeHeading(),
- new_zone->GetZoneName()
- );
- player->SetX(GetCurrentZone()->GetSafeX());
- player->SetY(GetCurrentZone()->GetSafeY());
- player->SetZ(GetCurrentZone()->GetSafeZ());
- player->SetHeading(GetCurrentZone()->GetSafeHeading());
-
- SetZoningCoords(GetCurrentZone()->GetSafeX(), GetCurrentZone()->GetSafeY(),
- GetCurrentZone()->GetSafeZ(), GetCurrentZone()->GetSafeHeading());
- }
- else {
- ResetZoningCoords();
- }
- LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
- Save();
- char* new_zone_ip = 0;
- if (IsPrivateAddress(this->GetIP()) && strlen(net.GetInternalWorldAddress()) > 0)
- new_zone_ip = net.GetInternalWorldAddress();
- else
- new_zone_ip = net.GetWorldAddress();
- LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
- int32 key = Timer::GetUnixTimeStamp();
- LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
- ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
- LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
- zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
- if (version > 283) {
- PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
- if (packet)
- {
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- void Client::Zone(const char* new_zone, bool set_coords, bool is_spell)
- {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
- Zone(zone_list.Get(new_zone), set_coords, is_spell);
- }
- float Client::DistanceFrom(Client* client) {
- float ret = 0;
- if (client && client != this) {
- ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
- ret = sqrt(ret);
- }
- return ret;
- }
- void Client::DetermineCharacterUpdates() {
- ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
- CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
- cdu->account_id = GetAccountID();
- cdu->char_id = GetCharacterID();
- int32 timestamp = Timer::GetUnixTimeStamp();
- int8 flag = GetTimeStampFlag();
- if (flag & LEVEL_UPDATE_FLAG)
- {
- cdu->update_field = LEVEL_UPDATE_FLAG;
- cdu->update_data = player->GetLevel();
- loginserver.SendPacket(outpack);
- }
- //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
- if (flag & CLASS_UPDATE_FLAG)
- {
- cdu->update_field = CLASS_UPDATE_FLAG;
- cdu->update_data = player->GetAdventureClass();
- loginserver.SendPacket(outpack);
- }
- if (flag & GENDER_UPDATE_FLAG)
- {
- cdu->update_field = GENDER_UPDATE_FLAG;
- cdu->update_data = player->GetGender();
- loginserver.SendPacket(outpack);
- }
- if (flag & DELETE_UPDATE_FLAG) {
- LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
- }
- safe_delete(outpack); // Zone, armor and name use a different structure
- if (flag & RACE_UPDATE_FLAG)
- {
- outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
- RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
- ru->account_id = GetAccountID();
- ru->char_id = GetCharacterID();
- ru->race = player->GetRace();
- ru->model_type = player->GetModelType();
- loginserver.SendPacket(outpack);
- safe_delete(outpack);
- }
- if (flag & ZONE_UPDATE_FLAG) {
- ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
- memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
- CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
- czu->account_id = GetAccountID();
- czu->char_id = GetCharacterID();
- czu->zone_id = GetCurrentZone()->GetZoneID();
- const char* zone_file = GetCurrentZone()->GetZoneFile();
- czu->zone_length = strlen(zone_file);
- if (czu->zone_length > 64)
- czu->zone_length = 64;
- strncpy(czu->new_zone, zone_file, czu->zone_length);
- loginserver.SendPacket(outpack);
- safe_delete(outpack);
- }
- if (flag & ARMOR_UPDATE_FLAG) {
- LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
- }
- if (flag & NAME_UPDATE_FLAG) {
- LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
- }
- database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
- }
- void Client::Save() {
- if (GetCharacterID() == 0 || IsSaveDisabled())
- return;
- if (current_zone) {
- DetermineCharacterUpdates();
- UpdateCharacterInstances();
- this->SetLastSavedTimeStamp(Timer::GetCurrentTime2());
- database.Save(this);
- if (GetPlayer()->UpdateQuickbarNeeded()) {
- database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
- GetPlayer()->ResetQuickbarNeeded();
- }
- database.SaveItems(this);
- database.SaveBuyBacks(this);
- GetPlayer()->SaveHistory();
- GetPlayer()->SaveLUAHistory();
- MSaveSpellStateMutex.lock();
- GetPlayer()->SaveSpellEffects();
- MSaveSpellStateMutex.unlock();
- }
- }
- void Client::UpdateCharacterInstances() {
- if (GetPlayer() != NULL)
- GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
- /*if ( GetPlayer() != NULL )
- {
- // determine the last timestamp then get a new one, determine the difference in the timestamp
- // to use for applying the update to each instances timer
- int32 lastSaveTS = GetLastSavedTimeStamp();
- int32 newSaveTS = Timer::GetUnixTimeStamp();
- int32 diffTS = newSaveTS - lastSaveTS;
- // update instance timers
- GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
- // update with the new timestamp and save the db
- this->SetLastSavedTimeStamp(newSaveTS);
- }*/
- }
- void Client::HandleVerbRequest(EQApplicationPacket* app) {
- PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
- if (packet) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- int32 spawn_id = packet->getType_int32_ByName("spawn_id");
- PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
- Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
- vector<EntityCommand*> commands;
- vector<EntityCommand*> delete_commands;
- if (out && spawn) {
- for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
- {
- // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
- if (!spawn->primary_command_list[i]->default_allow_list)
- {
- map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
- if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
- continue;
- }
- else
- {
- // default is allow list, only deny if added to the list as deny (false itr second)
- map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
- if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
- continue;
- }
- commands.push_back(spawn->primary_command_list[i]);
- }
- for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
- commands.push_back(spawn->secondary_command_list[i]);
- if (spawn->IsPlayer()) {
- if (player->IsFriend(spawn->GetName()))
- delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
- else
- delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
- if (player->IsIgnored(spawn->GetName()))
- delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
- else
- {
- delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
- delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
- }
- if (((Player*)spawn)->GetGroupMemberInfo()) {
- if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
- delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
- delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
- }
- if(spawn->IsPlayer() && player->GetGroupMemberInfo() && !player->GetGroupMemberInfo()->mentor_target_char_id)
- delete_commands.push_back(player->CreateEntityCommand("Mentor", 10000, "mentor", "", 0, 0));
- else if(spawn->IsPlayer() && player->GetGroupMemberInfo() && player->GetGroupMemberInfo()->mentor_target_char_id == ((Player*)spawn)->GetCharacterID())
- delete_commands.push_back(player->CreateEntityCommand("Stop Mentoring", 10000, "unmentor", "", 0, 0));
- }
- else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
- delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
- commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
- }
- out->setDataByName("spawn_id", spawn_id);
- out->setArrayLengthByName("num_verbs", commands.size());
- for (int32 i = 0; i < commands.size(); i++) {
- out->setArrayDataByName("command", commands[i]->command.c_str(), i);
- out->setArrayDataByName("distance", commands[i]->distance, i);
- if (commands[i]->error_text.length() == 0)
- out->setArrayAddToPacketByName("error", false, i);
- else {
- out->setArrayDataByName("display_error", 1, i);
- out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
- }
- out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
- }
- EQ2Packet* outapp = out->serialize();
- //DumpPacket(outapp);
- QueuePacket(outapp);
- safe_delete(out);
- for (int32 i = 0; i < delete_commands.size(); i++) {
- safe_delete(delete_commands[i]);
- }
- }
- }
- safe_delete(packet);
- }
- }
- void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
- if (previous_value != new_value) {
- Message(CHANNEL_SKILL, "You get %s at %s (%i/%i).", new_value > previous_value ? "better" : "worse", skill->name.data.c_str(), new_value, skill->max_val);
- char tmp[200] = { 0 };
- 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);
- SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
- }
- }
- void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
- {
- /* JA notes on the unknown:
- 2 = ding glimmer
- 16 = Achievement Unlocked
- 6 no longer does anything
- */
- PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
- if (packet) {
- packet->setDataByName("unknown", unknown);
- packet->setMediumStringByName("text", text);
- if (type && strlen(type) > 0)
- packet->setMediumStringByName("message_type", type);
- packet->setDataByName("size", size);
- packet->setDataByName("red", red);
- packet->setDataByName("green", green);
- packet->setDataByName("blue", blue);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- void Client::ChangeLevel(int16 old_level, int16 new_level) {
- if (new_level < 1) {
- SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
- return;
- }
- if (player->GetLevel() != new_level) {
- player->SetLevel(new_level);
- if (player->GetGroupMemberInfo()) {
- player->UpdateGroupMemberInfo();
- world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
- }
- }
- if (new_level > old_level) {
- player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
- }
- if (player->GetPet()) {
- NPC* pet = (NPC*)player->GetPet();
- if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
- pet->SetLevel(new_level);
- pet->UpdateWeapons();
- PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
- if (command_packet) {
- command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
- command_packet->setDataByName("anim_type", 1753);
- QueuePacket(command_packet->serialize());
- safe_delete(command_packet);
- }
- }
- }
- PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
- if (level_update) {
- level_update->setDataByName("old_level", old_level);
- level_update->setDataByName("new_level", new_level);
- QueuePacket(level_update->serialize());
- safe_delete(level_update);
- GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
- GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
- //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
- }
- PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
- if (command_packet) {
- command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
- command_packet->setDataByName("anim_type", 1753);
- QueuePacket(command_packet->serialize());
- safe_delete(command_packet);
- }
- if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
- player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
- SendNewAdventureSpells();
- GetPlayer()->GetInfoStruct()->set_level(new_level);
- GetPlayer()->UpdateWeapons();
- // GetPlayer()->SetLevel(new_level);
- 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__);
- GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
- GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
- GetPlayer()->CalculateBonuses();
- GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
- GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
- /*InfoStruct* info = player->GetInfoStruct();
- info->set_agi_base(new_level * 2 + 15);
- info->set_intel_base(new_level * 2 + 15);
- info->set_wis_base(new_level * 2 + 15);
- info->set_str_base(new_level * 2 + 15);
- info->set_sta_base(new_level * 2 + 15);
- info->set_cold_base((int16)(new_level * 1.5 + 10));
- info->set_heat_base((int16)(new_level * 1.5 + 10));
- info->set_disease_base((int16)(new_level * 1.5 + 10));
- info->set_mental_base((int16)(new_level * 1.5 + 10));
- info->set_magic_base((int16)(new_level * 1.5 + 10));
- info->set_divine_base((int16)(new_level * 1.5 + 10));
- info->set_poison_base((int16)(new_level * 1.5 + 10));
- GetPlayer()->GetInfoStruct()->set_poison_base((int16)(new_level * 1.5 + 10));*/
- UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
- GetPlayer()->SetCharSheetChanged(true);
- Message(CHANNEL_REWARD, "You are now level %i!", new_level);
- LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
- int16 new_skill_cap = 5 * new_level;
- PlayerSkillList* player_skills = player->GetSkills();
- player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
- player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
-
- if(rule_manager.GetGlobalRule(R_Player, AutoSkillUpBaseSkills)->GetBool()) {
- //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
- player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
- player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
- }
-
- player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
- player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
-
- if(rule_manager.GetGlobalRule(R_Player, AutoSkillUpBaseSkills)->GetBool()) {
- //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
- player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
- player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
- }
-
- player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
- player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
- player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
- player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
- player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPONRY, new_skill_cap);
-
- if (new_level > player->GetTSLevel())
- player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
- //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
- if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
- player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
- if (player_skills->HasSkill(SKILL_ID_FISTS))
- player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
- if (player_skills->HasSkill(SKILL_ID_DESTROYING))
- player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
- if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
- player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
- Guild* guild = GetPlayer()->GetGuild();
- if (guild) {
- int8 event_type = 0;
- if (new_level < 10)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
- else if (new_level == 10)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
- else if (new_level >= 11 && new_level < 20)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
- else if (new_level == 20)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
- else if (new_level >= 21 && new_level < 30)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
- else if (new_level == 30)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
- else if (new_level >= 31 && new_level < 40)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
- else if (new_level == 40)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
- else if (new_level >= 41 && new_level < 50)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
- else if (new_level == 50)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
- else if (new_level >= 51 && new_level < 60)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
- else if (new_level == 60)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
- else if (new_level >= 61 && new_level < 70)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
- else if (new_level == 70)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
- else if (new_level >= 71 && new_level < 80)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
- else if (new_level == 80)
- event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
- 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());
- 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());
- guild->UpdateGuildMemberInfo(GetPlayer());
- guild->SendGuildMember(GetPlayer());
- guild->SendGuildMemberList();
- }
- // Need to send the trait list every time the players level changes
- // Also need to force the char sheet update or else there can be a large delay from when you level
- // to when you are actually able to select traits.
- QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
- QueuePacket(master_trait_list.GetTraitListPacket(this));
- if (version > 546)
- master_aa_list.DisplayAA(this, 0, 0);
- if (GetPlayer()->SpawnedBots.size() > 0) {
- map<int32, int32>::iterator itr;
- for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
- Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
- if (bot && bot->IsBot())
- ((Bot*)bot)->ChangeLevel(old_level, new_level);
- }
- }
- }
- void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
- if (new_level < 1) {
- SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
- return;
- }
- if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
- SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
- return;
- }
- if (new_level > old_level)
- player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
- if (player->GetTSLevel() != new_level) {
- player->SetTSLevel(new_level);
- if (player->GetGroupMemberInfo()) {
- player->UpdateGroupMemberInfo();
- world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
- }
- }
- // Only tradeskill skills should increace, and then only those related to your class
- PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
- if (level_update) {
- level_update->setDataByName("old_level", old_level);
- level_update->setDataByName("new_level", new_level);
- level_update->setDataByName("type", 1);
- QueuePacket(level_update->serialize());
- safe_delete(level_update);
- }
-
- // provide new spells upon levelling
- SendNewTradeskillSpells();
-
- PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
- if (command_packet) {
- command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
- command_packet->setDataByName("anim_type", 1753);
- QueuePacket(command_packet->serialize());
- safe_delete(command_packet);
- }
- GetPlayer()->GetInfoStruct()->set_tradeskill_level(new_level);
- GetPlayer()->SetTSLevel(new_level);
- UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
- GetPlayer()->SetCharSheetChanged(true);
- Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
- LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
- PlayerSkillList* player_skills = player->GetSkills();
- int16 specialize_skill_cap = new_level * 5;
- int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
- int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
- int8 ts_class = player->GetTradeskillClass();
- int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
- int32 skill_id_1, skill_id_2, skill_id_3;
- switch (base_ts_class) {
- case ARTISAN:
- player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
- player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
- player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
- break;
- case OUTFITTER:
- player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
- player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
- skill_id_1 = SKILL_ID_TAILORING;
- skill_id_2 = SKILL_ID_METALSHAPING;
- skill_id_3 = SKILL_ID_METALWORKING;
- if (ts_class == TAILOR) {
- player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
- skill_id_1 = 0;
- }
- else if (ts_class == ARMORER) {
- player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
- skill_id_2 = 0;
- }
- else if (ts_class == WEAPONSMITH) {
- player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
- skill_id_3 = 0;
- }
- if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
- if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
- if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
- break;
- case SCHOLAR:
- player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
- player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
- skill_id_1 = SKILL_ID_SCRIBING;
- skill_id_2 = SKILL_ID_CHEMISTRY;
- skill_id_3 = SKILL_ID_ARTIFICING;
- if (ts_class == SAGE) {
- player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
- skill_id_1 = 0;
- }
- else if (ts_class == ALCHEMIST) {
- player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
- skill_id_2 = 0;
- }
- else if (ts_class == JEWELER) {
- player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
- skill_id_3 = 0;
- }
- if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
- if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
- if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
- break;
- case CRAFTSMAN:
- player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
- player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
- skill_id_1 = SKILL_ID_ARTISTRY;
- skill_id_2 = SKILL_ID_FLETCHING;
- skill_id_3 = SKILL_ID_SCULPTING;
- if (ts_class == PROVISIONER) {
- player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
- skill_id_1 = 0;
- }
- else if (ts_class == WOODWORKER) {
- player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
- skill_id_2 = 0;
- }
- else if (ts_class == CARPENTER) {
- player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
- skill_id_3 = 0;
- }
- if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
- if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
- if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
- break;
- default:
- break;
- }
- if (new_level > player->GetAdventureClass())
- player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
- Guild* guild = GetPlayer()->GetGuild();
- if (guild) {
- int8 event_type = 0;
- if (new_level < 10)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
- else if (new_level == 10)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
- else if (new_level >= 11 && new_level < 20)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
- else if (new_level == 20)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
- else if (new_level >= 21 && new_level < 30)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
- else if (new_level == 30)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
- else if (new_level >= 31 && new_level < 40)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
- else if (new_level == 40)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
- else if (new_level >= 41 && new_level < 50)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
- else if (new_level == 50)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
- else if (new_level >= 51 && new_level < 60)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
- else if (new_level == 60)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
- else if (new_level >= 61 && new_level < 70)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
- else if (new_level == 70)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
- else if (new_level >= 71 && new_level < 80)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
- else if (new_level == 80)
- event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
- 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());
- 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());
- guild->UpdateGuildMemberInfo(GetPlayer());
- guild->SendGuildMember(GetPlayer());
- guild->SendGuildMemberList();
- }
- // Need to send the trait list every time the players level changes
- // Also need to force the char sheet update or else there can be a large delay from when you level
- // to when you are actually able to select traits.
- QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
- QueuePacket(master_trait_list.GetTraitListPacket(this));
- }
- void Client::CloseLoot(int32 spawn_id) {
- if (GetVersion() > 546) {
- PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
- if (packet) {
- packet->setDataByName("window_id", 4);
- EQ2Packet* outapp = packet->serialize();
- if (outapp) {
- //DumpPacket(outapp);
- QueuePacket(outapp);
- }
- safe_delete(packet);
- }
- }
-
- if(spawn_id > 0){
- PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", spawn_id);
- EQ2Packet* outapp = packet->serialize();
- if (outapp)
- QueuePacket(outapp);
- safe_delete(packet);
- }
-
- Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
- if(spawn) {
- spawn->CloseLoot(GetPlayer());
- }
- }
- }
- string Client::GetCoinMessage(int32 total_coins) {
- if (total_coins == 0) {
- return " 0 Copper";
- }
- char tmp[64] = { 0 };
- string message = "";
- int32 val = 0;
- if (total_coins >= 1000000) {
- val = total_coins / 1000000;
- total_coins -= 1000000 * val;
- sprintf(tmp, " %u Platinum", val);
- message.append(tmp);
- memset(tmp, 0, 64);
- }
- if (total_coins >= 10000) {
- val = total_coins / 10000;
- total_coins -= 10000 * val;
- sprintf(tmp, " %u Gold", val);
- message.append(tmp);
- memset(tmp, 0, 64);
- }
- if (total_coins >= 100) {
- val = total_coins / 100;
- total_coins -= 100 * val;
- sprintf(tmp, " %u Silver", val);
- message.append(tmp);
- memset(tmp, 0, 64);
- }
- if (total_coins > 0) {
- sprintf(tmp, " %u Copper", (int32)total_coins);
- message.append(tmp);
- }
- return message;
- }
- void Client::SendLootResponsePacket(int32 total_coins, vector<Item*>* items, Spawn* entity, bool ignore_loot_tier) {
- if (!entity) {
- CloseLoot(0);
- return;
- }
- if (total_coins > 0) {
- player->AddCoins(total_coins);
- //PlaySound("coin_cha_ching");
- string message = "";
- if (entity->GetHP() == 0) {
- message = "You loot ";
- entity->SetLootCoins(0, false);
- }
- else
- message = "You receive ";
- message.append(GetCoinMessage(total_coins));
- if (entity->GetHP() == 0)
- message.append(" from the corpse of ").append(entity->GetName());
- int8 type = CHANNEL_LOOT;
- SimpleMessage(type, message.c_str());
- }
- if (!items || items->size() == 0)
- CloseLoot(entity->GetID());
- entity->StartLootTimer(GetPlayer());
- PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
- if (packet) {
- entity->AddSpawnLootWindowCompleted(GetPlayer()->GetID(), false);
- vector<Item*>::iterator itr;
- int32 packet_size = 0;
- EQ2Packet* outapp = 0;
- uchar* data = 0;
- vector<Item*> send_items;
- if (items && items->size() > 0) {
- for (int i = 0; i < items->size(); i++) {
- Item* item = (*items)[i];
- if (entity->GetLootMethod() > GroupLootMethod::METHOD_FFA && !ignore_loot_tier) {
- bool skipItem = entity->IsItemInLootTier(item);
- if (!skipItem) {
- send_items.push_back(item);
- }
- }
- else {
- send_items.push_back(item);
- }
- }
- }
- if (GetVersion() >= 284) {
- if (GetVersion() > 561) {
- if (send_items.size() > 0) {
- packet->setDataByName("loot_count", send_items.size());
- packet->setDataByName("display", 1);
- }
- packet->setDataByName("loot_type", entity->GetLootMethod());
- packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000);
- packet->setDataByName("loot_id", entity->GetID());
- EQ2Packet* tmpPacket = packet->serialize();
- packet_size += tmpPacket->size;
- if (send_items.size() > 0) {
- data = new uchar[send_items.size() * 1000 + packet_size];
- memset(data, 0, send_items.size() * 1000 + packet_size);
- }
- else {
- data = new uchar[packet_size];
- memset(data, 0, packet_size);
- }
- uchar* ptr = data;
- memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
- ptr += tmpPacket->size;
- safe_delete(tmpPacket);
- Item* item = 0;
- if (send_items.size() > 0) {
- for (itr = send_items.begin(); itr != send_items.end(); itr++) {
- item = *itr;
- memcpy(ptr, &item->details.item_id, sizeof(int32));
- ptr += sizeof(int32);
- packet_size += sizeof(int32);
- tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
- int8 offset = 0;
- if (GetVersion() >= 1188) {
- offset = 13;
- }
- else if (GetVersion() >= 860) {
- offset = 11;
- }
- else if (GetVersion() <= 561) {
- offset = 19;
- }
- else {
- offset = 10;
- }
- memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
- ptr += tmpPacket->size - offset;
- packet_size += tmpPacket->size - offset;
- safe_delete(tmpPacket);
- }
- }
- packet_size -= sizeof(int32);
- memcpy(data, &packet_size, sizeof(int32));
- packet_size += sizeof(int32);
- outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
- }
- else {
- if (send_items.size() > 0) {
- packet->setArrayLengthByName("loot_count", send_items.size());
- Item* item = 0;
- if (send_items.size() > 0) {
- int i = 0;
- for (itr = send_items.begin(); itr != send_items.end(); itr++) {
- item = *itr;
- packet->setArrayDataByName("loot_id", item->details.item_id, i);
- packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
- i++;
- }
- }
- packet->setDataByName("display", 1);
- }
- packet->setDataByName("loot_type", entity->GetLootMethod()); // normal
- packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000); // 60 seconds
- packet->setDataByName("spawn_id", entity->GetID());
- outapp = packet->serialize();
- }
- }
- else {
- if (send_items.size() > 0) {
- packet->setArrayLengthByName("loot_count", send_items.size());
- for (int i = 0; i < send_items.size(); i++) {
- Item* item = (send_items)[i];
- packet->setArrayDataByName("name", item->name.c_str(), i);
- packet->setArrayDataByName("item_id", item->details.item_id, i);
- packet->setArrayDataByName("count", item->details.count, i);
- packet->setArrayDataByName("icon", item->details.icon, i);
- if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
- packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
- else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
- packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
- else
- packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
- }
- }
- packet->setDataByName("object_id", entity->GetID());
- packet->setDataByName("unknown3", 1);
- packet->setDataByName("unknown4", 1);
- packet->setDataByName("unknown5", 60);
- outapp = packet->serialize();
- }
- if (outapp) {
- QueuePacket(outapp);
- }
- safe_delete_array(data);
- safe_delete(packet);
- }
- }
- bool Client::LootSpawnByMethod(Spawn* entity) {
- bool sentLoot = false;
- world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
- GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
- if (gmi && gmi->group_id)
- {
- PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
- if (group)
- {
- int8 auto_split_coin = group->GetGroupOptions()->auto_split;
- group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>* members = group->GetMembers();
- int32 split_coin_per_player = 0;
- int32 coins_remain_after_split = entity->GetLootCoins();
- int32 total_coins = entity->GetLootCoins();
- if (auto_split_coin) {
- int8 members_in_zone = 0;
- for (int8 i = 0; i < members->size(); i++) {
- Entity* member = members->at(i)->member;
- if (!member || !member->IsPlayer())
- continue;
- if (member->GetZone() != GetPlayer()->GetZone())
- continue;
- members_in_zone++;
- }
- if (members_in_zone < 1) // this should not happen, but divide by zero checked
- members_in_zone = 0;
- split_coin_per_player = entity->GetLootCoins() / members_in_zone;
- coins_remain_after_split = entity->GetLootCoins() - (split_coin_per_player * members_in_zone);
- entity->SetLootCoins(0, false);
- }
- LogWrite(LOOT__INFO, 0, "Loot", "%s: Group LootSpawnByMethod %u, auto coin split %u, split coin per player %u, remaining coin after split %u", entity->GetName(), entity->GetLootMethod(), auto_split_coin, split_coin_per_player, coins_remain_after_split);
- bool startWithLooter = true;
- for (int8 i = 0; i < members->size(); i++) {
- Entity* member = members->at(i)->member;
- if (!member || !member->IsPlayer())
- continue;
- if (member->GetZone() != GetPlayer()->GetZone())
- continue;
- // this will make sure we properly send the loot window to the initial requester if there is no item rarity matches
- if (startWithLooter && member != GetPlayer())
- continue;
- else if (!startWithLooter && member == GetPlayer())
- continue;
- else if (startWithLooter) {
- i = 0;
- startWithLooter = false;
- }
- if (auto_split_coin && (split_coin_per_player + coins_remain_after_split) > 0) {
- player->AddCoins(split_coin_per_player + coins_remain_after_split);
- if (((Player*)member)->GetClient()) {
- ((Player*)member)->GetClient()->Message(CHANNEL_MONEY_SPLIT, "Your share of %s from the corpse of %s is %s.", GetCoinMessage(total_coins).c_str(), entity->GetLootName(), GetCoinMessage(split_coin_per_player + coins_remain_after_split).c_str());
- }
- if (coins_remain_after_split > 0) // overflow of coin division went to the first player
- coins_remain_after_split = 0;
- }
- switch (entity->GetLootMethod()) {
- case GroupLootMethod::METHOD_LOTTO:
- case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
- if (((Player*)member)->GetClient()) {
- switch (member->GetInfoStruct()->get_group_auto_loot_method()) {
- case 1: { // lotto, need
- if (entity->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
- entity->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
- }
- else { // *need* before greed
- entity->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
- }
- entity->AddSpawnLootWindowCompleted(member->GetID(), true);
- // if it already exists we have to override the setting
- entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
- break;
- }
- case 2: { // decline
- entity->AddSpawnLootWindowCompleted(member->GetID(), true);
- // if it already exists we have to override the setting
- entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
- break;
- }
- default: { // presume 0 or higher than 2
- ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity, true);
- break;
- }
- }
- sentLoot = true;
- }
- break;
- }
- case GroupLootMethod::METHOD_ROUND_ROBIN: {
- entity->AddSpawnLootWindowCompleted(member->GetID(), true);
- sentLoot = true;
- break;
- }
- case GroupLootMethod::METHOD_LEADER: {
- if (member->GetGroupMemberInfo()->leader)
- ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
- break;
- }
- case GroupLootMethod::METHOD_FFA: {
- if(member == GetPlayer()) {
- ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
- }
- break;
- }
- }
- }
- group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
- return sentLoot;
- }
- void Client::LootSpawnRequest(Spawn* entity, bool attemptDisarm) {
- bool lootAllowed = false;
- bool sentLoot = false;
- std::vector<int32> item_list;
- if (entity->IsNPC()) {
- entity->LockLoot();
- lootAllowed = ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer());
- entity->UnlockLoot();
- if (lootAllowed) {
- OpenChest(entity, attemptDisarm);
- }
- else {
- SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
- return;
- }
- entity->LockLoot();
- if (((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
- lootAllowed = true;
- if ((sentLoot = LootSpawnByMethod(entity))) {
- entity->GetLootItemsList(&item_list);
- }
- else {
- SendLootResponsePacket(entity->GetLootCoins(), entity->GetLootItems(), entity);
- }
- }
- entity->UnlockLoot();
- if (lootAllowed) {
- entity->DistributeGroupLoot_RoundRobin(&item_list, true);
- }
- }
- }
- void Client::OpenChest(Spawn* entity, bool attemptDisarm)
- {
- if (!entity)
- return;
- int8 chest_difficulty = 0;
- int32 state = 0;
- // Check for the chest and set the action state
- /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
- string modelName;
- if (entity->GetModelType() == 4034) {
- // small chest, open with copper coins
- // does not include traps, however can be disarmed
- chest_difficulty = 1;
- state = 11899;
- modelName.append("Small Chest");
- }
- else if (entity->GetModelType() == 5864) {
- // treasure chest, open with silver coins
- chest_difficulty = 2;
- state = 11901;
- modelName.append("Treasure Chest");
- }
- else if (entity->GetModelType() == 5865) {
- // ornate chest, open with gold coins
- chest_difficulty = 3;
- state = 11900;
- modelName.append("Ornate Chest");
- }
- else if (entity->GetModelType() == 4015) {
- // exquisite chest, open with gold coins and jewels as well as a glow effect
- chest_difficulty = 5;
- state = 11898;
- modelName.append("Exquisite Chest");
- }
- bool firstChestOpen = false;
- if (chest_difficulty > 0 && !entity->HasTrapTriggered())
- {
- ChestTrap::ChestTrapInfo nextTrap;
- bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
- Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
- firstChestOpen = true;
- entity->SetTrapTriggered(true, state);
- if (ret)
- {
- if (disarmSkill && attemptDisarm)
- {
- if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
- {
- CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
- rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
- Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
- }
- else
- {
- Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
- }
- // despite fail/succeed we should always try to increase skill if disarm is available
- GetPlayer()->GetSkillByName("Disarm Trap", true);
- }
- else // no disarm skill, always fail
- {
- CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
- rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
- Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
- }
- }
- }
- else if (!entity->HasTrapTriggered())
- {
- firstChestOpen = true;
- entity->SetTrapTriggered(true, state);
- }
- // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
- // for those in range the SendStateCommand will cause it to animate open.
- // players not currently in radius will have it queued with client->QueueStateCommand when SendSpawn takes place
- if (firstChestOpen)
- GetCurrentZone()->SendStateCommand(entity, state);
- }
- void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
- {
- Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
- SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
- if (source == NULL)
- source = (Entity*)GetPlayer();
- if (spell)
- {
- GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
- if (gmi && gmi->group_id)
- {
- PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
- if (group)
- {
- group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>* members = group->GetMembers();
- for (int8 i = 0; i < members->size(); i++) {
- Entity* member = members->at(i)->member;
- if(!member)
- continue;
-
- if (!member->Alive() || (member->GetZone() != source->GetZone()))
- continue;
- // if we have a radius provided then check if the group member is outside the radius or not
- if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
- continue;
- spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
- }
- group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- else
- spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
- }
- }
- Spawn* Client::GetBanker() {
- return banker;
- }
- void Client::SetBanker(Spawn* in_banker) {
- banker = in_banker;
- }
- void Client::Bank(Spawn* banker, bool cancel) {
- if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
- if (!cancel)
- SetBanker(banker);
- else
- SetBanker(0);
- PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
- int64 coins = GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + GetPlayer()->GetInfoStruct()->get_bank_coin_silver() * 100 +
- GetPlayer()->GetInfoStruct()->get_bank_coin_gold() * 10000 + (int64)GetPlayer()->GetInfoStruct()->get_bank_coin_plat() * 1000000;
- int32 coins1, coins2;
- coins1 = ((int32*)&coins)[0];
- coins2 = ((int32*)&coins)[1];
- packet->setDataByName("bank_coins", coins1);
- packet->setDataByName("bank_coins2", coins2);
- packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->get_coin_copper());
- packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->get_coin_silver());
- packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->get_coin_gold());
- packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->get_coin_plat());
- if (!cancel)
- packet->setDataByName("display", 1);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- bool Client::BankHasCoin(int64 amount){
- int32 tmp = 0;
-
- if(amount <= 0)
- return 0;
- //plat
- if (amount >= 1000000) {
- tmp = amount / 1000000;
- int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
-
- if(bank_coins_plat >= tmp)
- return 1;
- }
- //gold
- if (amount >= 10000) {
- tmp = amount / 10000;
- int32 bank_coins_gold = GetPlayer()->GetBankCoinsGold();
-
- if(bank_coins_gold >= tmp)
- return 1;
- }
- //silver
- if (amount >= 100) {
- tmp = amount / 100;
- int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
- if(bank_coins_silver >= tmp)
- return 1;
- }
- //copper
- if (amount > 0) {
- int32 bank_coins_copper = GetPlayer()->GetBankCoinsCopper();
-
- if(bank_coins_copper >= amount)
- return 1;
- }
- return 0;
- }
- bool Client::BankWithdrawalNoBanker(int64 amount) {
- bool cheater = false;
- if (amount > 0) {
- string withdrawal = "";
- char withdrawal_data[512] = { 0 };
- int32 tmp = 0;
- if (amount >= 1000000) {
- tmp = amount / 1000000;
- int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
- if (tmp > bank_coins_plat)
- cheater = true;
- else {
- GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
- GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
- amount -= (int64)tmp * 1000000;
- sprintf(withdrawal_data, "%u Platinum ", tmp);
- withdrawal.append(withdrawal_data);
- memset(withdrawal_data, 0, sizeof(withdrawal_data));
- }
- }
- if (!cheater && amount >= 10000) {
- tmp = amount / 10000;
- if (tmp > GetPlayer()->GetBankCoinsGold())
- cheater = true;
- else {
- int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
- bank_coins_gold -= tmp;
- if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
- GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
- GetPlayer()->GetInfoStruct()->add_coin_plat(1);
- }
- else
- GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
- amount -= tmp * 10000;
- sprintf(withdrawal_data, "%u Gold ", tmp);
- withdrawal.append(withdrawal_data);
- memset(withdrawal_data, 0, sizeof(withdrawal_data));
- }
- }
- if (!cheater && amount >= 100) {
- tmp = amount / 100;
- int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
- if (tmp > bank_coins_silver)
- cheater = true;
- else {
- GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
- if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
- GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
- GetPlayer()->GetInfoStruct()->add_coin_gold(1);
- }
- else
- GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
- amount -= tmp * 100;
- sprintf(withdrawal_data, "%u Silver ", tmp);
- withdrawal.append(withdrawal_data);
- memset(withdrawal_data, 0, sizeof(withdrawal_data));
- }
- }
- if (!cheater) {
- if (amount > 0) {
- sprintf(withdrawal_data, "%u Copper ", (int32)amount);
- withdrawal.append(withdrawal_data);
- int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
- GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
- if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
- GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
- GetPlayer()->GetInfoStruct()->add_coin_silver(1);
- }
- else
- GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
- }
- if (withdrawal.length() > 0) {
- withdrawal.append("withdrawn ");
- sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
- GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
- withdrawal.append(withdrawal_data);
- SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
- return 1;
- }
- }
- else
- Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
- return 0;
- }
- return 0;
- }
- void Client::BankWithdrawal(int64 amount) {
- bool cheater = false;
- if (GetBanker() && amount > 0) {
- string withdrawal = "";
- char withdrawal_data[512] = { 0 };
- int32 tmp = 0;
- if (amount >= 1000000) {
- tmp = amount / 1000000;
- int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
- if (tmp > bank_coins_plat)
- cheater = true;
- else {
- GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
- GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
- amount -= (int64)tmp * 1000000;
- sprintf(withdrawal_data, "%u Platinum ", tmp);
- withdrawal.append(withdrawal_data);
- memset(withdrawal_data, 0, sizeof(withdrawal_data));
- }
- }
- if (!cheater && amount >= 10000) {
- tmp = amount / 10000;
- if (tmp > GetPlayer()->GetBankCoinsGold())
- cheater = true;
- else {
- int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
- bank_coins_gold -= tmp;
- if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
- GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
- GetPlayer()->GetInfoStruct()->add_coin_plat(1);
- }
- else
- GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
- amount -= tmp * 10000;
- sprintf(withdrawal_data, "%u Gold ", tmp);
- withdrawal.append(withdrawal_data);
- memset(withdrawal_data, 0, sizeof(withdrawal_data));
- }
- }
- if (!cheater && amount >= 100) {
- tmp = amount / 100;
- int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
- if (tmp > bank_coins_silver)
- cheater = true;
- else {
- GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
- if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
- GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
- GetPlayer()->GetInfoStruct()->add_coin_gold(1);
- }
- else
- GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
- amount -= tmp * 100;
- sprintf(withdrawal_data, "%u Silver ", tmp);
- withdrawal.append(withdrawal_data);
- memset(withdrawal_data, 0, sizeof(withdrawal_data));
- }
- }
- if (!cheater) {
- if (amount > 0) {
- sprintf(withdrawal_data, "%u Copper ", (int32)amount);
- withdrawal.append(withdrawal_data);
- int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
- GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
- if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
- GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
- GetPlayer()->GetInfoStruct()->add_coin_silver(1);
- }
- else
- GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
- }
- if (withdrawal.length() > 0) {
- withdrawal.append("withdrawn ");
- sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
- GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
- withdrawal.append(withdrawal_data);
- SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
- }
- }
- else
- Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
- player->SetCharSheetChanged(true);
- Bank(banker);
- }
- }
- void Client::BankDeposit(int64 amount) {
- bool cheater = false;
- if (GetBanker() && amount > 0) {
- int32 tmp = 0;
- char deposit_data[512] = { 0 };
- string deposit = "";
- if (amount >= 1000000) {
- tmp = amount / 1000000;
- if (tmp > GetPlayer()->GetCoinsPlat())
- cheater = true;
- else {
- GetPlayer()->GetInfoStruct()->add_bank_coin_plat(tmp);
- GetPlayer()->GetInfoStruct()->set_coin_plat(GetPlayer()->GetInfoStruct()->get_coin_plat() - tmp);
- amount -= (int64)tmp * 1000000;
- sprintf(deposit_data, "%u Platinum ", tmp);
- deposit.append(deposit_data);
- memset(deposit_data, 0, sizeof(deposit_data));
- }
- }
- if (!cheater && amount >= 10000) {
- tmp = amount / 10000;
- if (tmp > GetPlayer()->GetCoinsGold())
- cheater = true;
- else {
- if ((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) > 100) {
- GetPlayer()->GetInfoStruct()->set_bank_coin_gold((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) - 100);
- GetPlayer()->GetInfoStruct()->add_bank_coin_plat(1);
- }
- else
- GetPlayer()->GetInfoStruct()->add_bank_coin_gold(tmp);
- GetPlayer()->GetInfoStruct()->set_coin_gold(GetPlayer()->GetInfoStruct()->get_coin_gold() - tmp);
- amount -= tmp * 10000;
- sprintf(deposit_data, "%u Gold ", tmp);
- deposit.append(deposit_data);
- memset(deposit_data, 0, sizeof(deposit_data));
- }
- }
- if (!cheater && amount >= 100) {
- tmp = amount / 100;
- if (tmp > GetPlayer()->GetCoinsSilver())
- cheater = true;
- else {
- if ((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) > 100) {
- GetPlayer()->GetInfoStruct()->set_bank_coin_silver((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) - 100);
- GetPlayer()->GetInfoStruct()->add_bank_coin_gold(1);
- }
- else
- GetPlayer()->GetInfoStruct()->add_bank_coin_silver(tmp);
- GetPlayer()->GetInfoStruct()->set_coin_silver(GetPlayer()->GetInfoStruct()->get_coin_silver() - tmp);
- amount -= tmp * 100;
- sprintf(deposit_data, "%u Silver ", tmp);
- deposit.append(deposit_data);
- memset(deposit_data, 0, sizeof(deposit_data));
- }
- }
- if (!cheater) {
- if (amount > 0) {
- sprintf(deposit_data, "%u Copper ", (int32)amount);
- deposit.append(deposit_data);
- if ((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) > 100) {
- GetPlayer()->GetInfoStruct()->set_bank_coin_copper((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) - 100);
- GetPlayer()->GetInfoStruct()->add_bank_coin_silver(1);
- }
- else
- GetPlayer()->GetInfoStruct()->add_bank_coin_copper(amount);
- GetPlayer()->GetInfoStruct()->set_coin_copper(GetPlayer()->GetInfoStruct()->get_coin_copper() - amount);
- }
- if (deposit.length() > 0) {
- deposit.append("deposited ");
- sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
- GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
- deposit.append(deposit_data);
- SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
- }
- }
- else
- Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
- player->SetCharSheetChanged(true);
- Bank(banker);
- }
- }
- void Client::AddPendingQuestAcceptReward(Quest* quest)
- {
- std::unique_lock lock(MPendingQuestAccept);
- pending_quest_accept.push_back(quest->GetQuestID());
- }
- void Client::AddPendingQuestReward(Quest* quest, bool update, bool is_temporary, std::string description) {
- QueueQuestReward(quest->GetQuestID(), is_temporary, false, false, (is_temporary ? quest->GetCoinTmpReward() : 0),
- (is_temporary ? quest->GetStatusTmpReward() : 0), description, false, 0);
- quest_updates = update;
- if(quest_updates) {
- SaveQuestRewardData(true);
- }
- }
- void Client::QueueQuestReward(int32 quest_id, bool is_temporary, bool is_collection, bool has_displayed, int64 tmp_coin, int32 tmp_status, std::string description, bool db_saved, int32 index) {
- if(HasQuestRewardQueued(quest_id, is_temporary, is_collection))
- return;
-
- QuestRewardData* data = new QuestRewardData;
- data->quest_id = quest_id;
- data->is_temporary = is_temporary;
- data->is_collection = is_collection;
- data->has_displayed = has_displayed;
- data->tmp_coin = tmp_coin;
- data->tmp_status = tmp_status;
- data->description = std::string(description);
- data->db_saved = db_saved;
- data->db_index = index;
- MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
- quest_pending_reward.push_back(data);
- MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
- }
- bool Client::HasQuestRewardQueued(int32 quest_id, bool is_temporary, bool is_collection) {
-
- bool success = false;
- MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
- if (quest_pending_reward.size() > 0) {
- vector<QuestRewardData*>::iterator itr;
-
- for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
- int32 questID = (*itr)->quest_id;
- bool temporary = (*itr)->is_temporary;
- bool collection = (*itr)->is_collection;
- if( questID == quest_id && is_temporary == temporary && is_collection == collection ) {
- success = true;
- break;
- }
- }
- }
- MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
-
- return success;
- }
- void Client::RemoveQueuedQuestReward() {
- MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
- if(quest_pending_reward.size() > 0) {
- QuestRewardData* data = quest_pending_reward.at(0);
- if(data->db_saved) {
- Query query;
- query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_rewards where char_id = %u and indexed = %u", GetCharacterID(), data->db_index);
- if(data->is_temporary && data->quest_id) {
- query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_temporary_rewards where char_id = %u and quest_id = %u", GetCharacterID(), data->quest_id);
- }
- }
- quest_pending_reward.erase(quest_pending_reward.begin());
- }
- MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
-
- SaveQuestRewardData(true);
- }
- void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
- MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
- quest_pending_updates[quest_id][step_id] = progress;
- quest_updates = true;
- MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
- }
- void Client::ProcessQuestUpdates() {
- if(!IsReadyForUpdates())
- return;
- if (quest_pending_updates.size() > 0) {
- map<int32, map<int32, int32> > tmp_quest_updates;
- MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
- tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
- quest_pending_updates.clear();
- MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
- map<int32, map<int32, int32> >::iterator quest_itr;
- map<int32, int32>::iterator step_itr;
- for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
- for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
- if (step_itr->second == 0xFFFFFFFF) {
- SetStepComplete(quest_itr->first, step_itr->first);
- player->SendQuestRequiredSpawns(quest_itr->first);
- }
- else
- AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
- }
- }
- }
- MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
- if (quest_pending_reward.size() > 0) {
- MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
-
- // only able to display one reward at a time
- if(GetPlayer()->IsActiveReward())
- return;
-
- Query query;
- vector<QuestRewardData*>::iterator itr;
- vector<QuestRewardData*> tmp_quest_rewards;
- MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
- tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.begin()+1);
- MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
-
- bool delete_first = false;
- for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end();) {
- int32 questID = (*itr)->quest_id;
- if((*itr)->is_collection && GetPlayer()->GetPendingCollectionReward()) {
- DisplayCollectionComplete(GetPlayer()->GetPendingCollectionReward());
- GetPlayer()->SetActiveReward(true);
- (*itr)->has_displayed = true;
-
- UpdateCharacterRewardData((*itr));
- break;
- }
- else if(questID > 0 && GetPlayer()->UpdateQuestReward(questID, (*itr))) {
- (*itr)->has_displayed = true;
- UpdateCharacterRewardData((*itr));
- // only able to display one reward at a time
- break;
- } else {
- delete_first = true;
- LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, deleting quest id from tmp_quest_rewards.", questID, GetPlayer()->GetName());
- break;
- }
- }
-
- if(delete_first) {
- RemoveQueuedQuestReward();
- }
- } else {
- MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
- }
-
- MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
- if (quest_pending_reward.size() > 0) {
- quest_updates = true;
- }
- else {
- quest_updates = false;
- }
- MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
- }
- void Client::CheckQuestQueue() {
- MQuestQueue.writelock();
- last_update_time = 0;
- vector<QueuedQuest*>::iterator itr;
- for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
- if(!GetPlayer()->SendQuestStepUpdate((*itr)->quest_id, (*itr)->step, (*itr)->display_quest_helper)) {
- LogWrite(CCLIENT__ERROR, 0, "Client", "Queued Quest ID %u missing for Player %s, cannot send quest step update.", (*itr)->quest_id, GetPlayer()->GetName());
- }
- safe_delete((*itr));
- }
- quest_queue.clear();
- MQuestQueue.releasewritelock();
- }
- void Client::SetStepComplete(int32 quest_id, int32 step) {
- Quest* quest = player->SetStepComplete(quest_id, step);
- if (quest) {
- SendQuestUpdate(quest);
- GetCurrentZone()->SendQuestUpdates(this);
- }
- }
- void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
- Quest* quest = player->AddStepProgress(quest_id, step, progress);
- if (quest) {
- SendQuestUpdate(quest);
- GetCurrentZone()->SendQuestUpdates(this);
- }
- }
- void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
- bool hadUpdates = false;
- vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
- if (quest_updates) {
- for (int32 i = 0; i < quest_updates->size(); i++)
- {
- SendQuestUpdate(quest_updates->at(i));
- hadUpdates = true;
- }
- }
- safe_delete(quest_updates);
- vector<Quest*>* quest_failures = player->CheckQuestsFailures();
- if (quest_failures) {
- for (int32 i = 0; i < quest_failures->size(); i++)
- {
- SendQuestFailure(quest_failures->at(i));
- hadUpdates = true;
- }
- }
- safe_delete(quest_failures);
- if (hadUpdates)
- GetCurrentZone()->SendAllSpawnsForVisChange(this);
- }
- void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
- vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
- if (quest_updates) {
- for (int32 i = 0; i < quest_updates->size(); i++)
- SendQuestUpdate(quest_updates->at(i));
- GetCurrentZone()->SendQuestUpdates(this);
- }
- safe_delete(quest_updates);
- }
- void Client::CheckPlayerQuestsItemUpdate(Item* item) {
- vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
- if (quest_updates) {
- for (int32 i = 0; i < quest_updates->size(); i++)
- SendQuestUpdate(quest_updates->at(i));
- }
- safe_delete(quest_updates);
- vector<Quest*>* quest_failures = player->CheckQuestsFailures();
- if (quest_failures) {
- for (int32 i = 0; i < quest_failures->size(); i++)
- SendQuestFailure(quest_failures->at(i));
- }
- safe_delete(quest_failures);
- }
- void Client::CheckPlayerQuestsLocationUpdate() {
- vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
- if (quest_updates) {
- for (int32 i = 0; i < quest_updates->size(); i++)
- SendQuestUpdate(quest_updates->at(i));
- }
- safe_delete(quest_updates);
- }
- void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
- vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
- if (quest_updates) {
- for (int32 i = 0; i < quest_updates->size(); i++)
- SendQuestUpdate(quest_updates->at(i));
- }
- safe_delete(quest_updates);
- vector<Quest*>* quest_failures = player->CheckQuestsFailures();
- if (quest_failures) {
- for (int32 i = 0; i < quest_failures->size(); i++)
- SendQuestFailure(quest_failures->at(i));
- }
- safe_delete(quest_failures);
- }
- void Client::AddPendingQuest(Quest* quest, bool forced) {
- if (version <= 283 || forced) { //this client doesn't ask if you want the quest, so auto accept
- MPendingQuestAccept.lock();
- player->pending_quests[quest->GetQuestID()] = quest;
- MPendingQuestAccept.unlock();
- AcceptQuest(quest->GetQuestID());
- }
- else {
- MPendingQuestAccept.lock();
- player->pending_quests[quest->GetQuestID()] = quest;
- MPendingQuestAccept.unlock();
- EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
- //DumpPacket(outapp);
- QueuePacket(outapp);
- }
- }
- void Client::AcceptQuest(int32 quest_id) {
- MPendingQuestAccept.lock_shared();
- if (player->pending_quests.count(quest_id) > 0) {
- Quest* quest = player->pending_quests[quest_id];
- if(quest) {
- MPendingQuestAccept.unlock_shared();
- MPendingQuestAccept.lock();
- player->pending_quests.erase(quest->GetQuestID());
- MPendingQuestAccept.unlock();
- AddPlayerQuest(quest);
- GetCurrentZone()->SendQuestUpdates(this);
- GetPlayer()->UpdateQuestCompleteCount(quest_id);
- return; // already unlocked mutex
- }
- }
- MPendingQuestAccept.unlock_shared();
- }
- void Client::RemovePendingQuest(int32 quest_id) {
- bool send_updates = false;
- MPendingQuestAccept.lock_shared();
-
- if (player->pending_quests.count(quest_id) > 0) {
- Quest* quest = player->pending_quests[quest_id];
- MPendingQuestAccept.unlock_shared();
- MPendingQuestAccept.lock();
- player->pending_quests.erase(quest_id);
- MPendingQuestAccept.unlock();
-
- if(lua_interface) {
- lua_interface->CallQuestFunction(quest, "Declined", GetPlayer());
- lua_interface->SetLuaUserDataStale(quest);
- }
-
- safe_delete(quest);
-
- send_updates = true;
- }
- else {
- MPendingQuestAccept.unlock_shared();
- }
- if(send_updates) {
- GetCurrentZone()->SendQuestUpdates(this);
- }
- }
- void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
- if (!quest || !progress) {
- return;
- }
- map<int32, int32>::iterator itr;
- QuestStep* step = 0;
- for (itr = progress->begin(); itr != progress->end(); itr++) {
- step = quest->GetQuestStep(itr->first);
- if (step && itr->second > 0) {
- step->SetStepProgress(itr->second);
- if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
- lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
- }
- }
- if (lua_interface && step)
- lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
- else if(!step) {
- LogWrite(QUEST__ERROR, 0, "Client", "Missing step for quest %s (ID %u), cannot CallQuestFunction for CurrentStep", quest->GetName(), quest->GetQuestID());
- }
- }
- void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
- bool lockCleared = false;
- GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
- if (player->player_quests.count(quest->GetQuestID()) > 0 && player->player_quests[quest->GetQuestID()]) {
- if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
- quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
- int32 questID = quest->GetQuestID();
- lockCleared = true;
- GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
- RemovePlayerQuest(questID, false, false);
- }
- player->player_quests[quest->GetQuestID()] = quest;
-
- if(!lockCleared)
- GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
-
- quest->SetPlayer(player);
- quest->SetSaveNeeded(true);
-
- current_quest_id = quest->GetQuestID();
- if (send_packets && quest->GetQuestGiver() > 0)
- GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
- if (lua_interface && call_accepted)
- lua_interface->CallQuestFunction(quest, "Accepted", player);
- if (send_packets) {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
- //SendQuestJournal();
- SendQuestJournalUpdate(quest);
- // sent twice to match live
- quest->SetTracked(false);
- QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
- quest->SetTracked(true);
- QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
- GetCurrentZone()->SendAllSpawnsForVisChange(this);
- }
- //This isn't during a load screen, so update spawns with required quests
- if (call_accepted)
- player->SendQuestRequiredSpawns(quest->GetQuestID());
- }
- void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
- if (current_quest_id == id)
- current_quest_id = 0;
- GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
- if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
- if (delete_quest) {
- player->player_quests[id]->SetDeleted(true);
- database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
- }
- int32 quest_giver = player->player_quests[id]->GetQuestGiver();
- GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
- if (send_update && quest_giver > 0)
- GetCurrentZone()->SendSpawnChangesByDBID(quest_giver, this, false, true);
- if (send_update) {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
- SendQuestJournal(false, 0, true);
- }
- player->RemoveQuest(id, delete_quest);
- if (send_update) {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
- SendQuestJournal(false, 0, true);
- GetCurrentZone()->SendAllSpawnsForVisChange(this);
- }
- }
- else {
- // if we don't have any quests to count then release the write lock
- GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
- }
- }
- void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
- if (quest) {
- QuestStep* quest_step = quest->GetQuestStep(step);
- if (quest_step) {
- QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
- quest_step->WasUpdated(false);
- }
- }
- }
- void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
- QueuedQuest* item = new QueuedQuest;
- item->quest_id = quest->GetQuestID();
- item->step = step;
- item->display_quest_helper = display_quest_helper;
- MQuestQueue.writelock();
- quest_queue.push_back(item);
- last_update_time = Timer::GetCurrentTime2();
- MQuestQueue.releasewritelock();
- }
- void Client::SendQuestFailure(Quest* quest) {
- vector<QuestStep*>* failures = quest->GetQuestFailures();
- if (failures) {
- QuestStep* step = 0;
- for (int32 i = 0; i < failures->size(); i++) {
- step = failures->at(i);
- QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
- SendQuestJournal(false, 0, true);
- }
- failures->clear();
- }
- }
- void Client::SendQuestUpdate(Quest* quest) {
- vector<QuestStep*>* updates = quest->GetQuestUpdates();
- if (updates) {
- QuestStep* step = 0;
- bool updated = false;
- for (int32 i = 0; i < updates->size(); i++) {
- step = updates->at(i);
- if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
- {
- lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
- SendQuestUpdateStep(quest, step->GetStepID());
- updated = true;
- }
- if (step->WasUpdated()) {
- // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
- SendQuestJournal(false, 0, true);
- if(!updated)
- QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
- updated = true;
- }
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
- }
- if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
- lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
- SendQuestJournalUpdate(quest, true);
- }
- if (quest->GetCompleted()) {
- if (quest->GetQuestReturnNPC() > 0)
- GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
- if (quest->GetCompletedFlag())
- quest->SetCompletedFlag(false);
- }
- updates->clear();
- }
- }
- void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
- if (!client)
- client = this;
- PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
- if (packet) {
- EQ2Packet* outapp = packet->serialize();
- //DumpPacket(outapp);
- client->QueuePacket(outapp);
- safe_delete(packet);
- }
- }
- void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
- PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
- if (packet) {
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- void Client::ReloadQuests() {
- vector<int32> ids = player->GetQuestIDs();
- Quest* quest = 0;
- for (int32 i = 0; i < ids.size(); i++) {
- quest = master_quest_list.GetQuest(ids[i]);
- if (quest)
- AddPlayerQuest(quest, false);
- else
- RemovePlayerQuest(ids[i]);
- }
- }
- Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
- std::unique_lock lock(MPendingQuestAccept);
- bool found_quest = false;
- vector<int32>::iterator itr;
- int32 questID = 0;
- Quest* quest = nullptr;
- for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end();) {
- questID = *itr;
-
- bool quest_exists = false;
- quest = GetPlayer()->PendingQuestAcceptance(questID, item_id, &quest_exists);
-
- if(!quest_exists) {
- LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, removing quest id from pending_quest_accept.", questID, GetPlayer()->GetName());
- itr = pending_quest_accept.erase(itr);
- quest = nullptr;
- continue;
- }
- else if (quest) {
- pending_quest_accept.erase(itr);
- break;
- }
-
- itr++;
- }
- return quest;
- }
- void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
- int8 num_slots_needed = 0;
- int16 free_slots = player->item_list.GetNumberOfFreeSlots();
- Item* master_item = 0;
- if (item_id > 0) {
- num_slots_needed++;
- master_item = master_item_list.GetItem(item_id);
- }
- int32 totalItems = 0;
- vector<Item*>* items = 0;
- vector<Item*>* tmpItems = 0;
-
- bool isTempState = quest->GetQuestTemporaryState();
-
- if(isTempState)
- {
- tmpItems = quest->GetTmpRewardItems();
- if (tmpItems && tmpItems->size() > 0)
- {
- num_slots_needed += tmpItems->size();
- totalItems += tmpItems->size();
- }
- }
- else
- {
- items = quest->GetRewardItems();
- if (items && items->size() > 0)
- {
- num_slots_needed += items->size();
- totalItems += items->size();
- }
- }
-
- RemoveQueuedQuestReward();
-
- GetPlayer()->SetActiveReward(false);
-
- if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= totalItems)) {
- if (master_item)
- AddItem(item_id);
- if (tmpItems && tmpItems->size() > 0) {
- for (int32 i = 0; i < tmpItems->size(); i++)
- AddItem(new Item(tmpItems->at(i)));
- }
- if (items && items->size() > 0) {
- for (int32 i = 0; i < items->size(); i++)
- AddItem(new Item(items->at(i)));
- }
- EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
- if (outapp)
- QueuePacket(outapp);
- map<int32, sint32>* reward_factions = quest->GetRewardFactions();
- map<int32, sint32>::iterator itr;
- for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
- int32 faction_id = itr->first;
- sint32 amount = itr->second;
- if (amount > 0)
- player->GetFactions()->IncreaseFaction(faction_id, amount);
- else
- player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
- }
-
- if(quest->GetQuestTemporaryState())
- {
- int64 total_coins = quest->GetCoinTmpReward();
- if (total_coins > 0)
- AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
- player->GetInfoStruct()->add_status_points(quest->GetStatusTmpReward());
- }
- else {
- player->GetInfoStruct()->add_status_points(quest->GetStatusPoints());
- }
-
- quest->SetQuestTemporaryState(false);
- player->SetCharSheetChanged(true);
- }
- else {
- GetPlayer()->SetActiveReward(true);
- AddPendingQuestAcceptReward(quest);
- SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
- DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
- }
- }
- void Client::DisplayQuestRewards(Quest* quest, int64 coin, vector<Item*>* rewards, vector<Item*>* selectable_rewards, map<int32, sint32>* factions, const char* header, int32 status_points, const char* text, bool was_displayed) {
- if (coin == 0 && (!rewards || rewards->size() == 0) && (!selectable_rewards || selectable_rewards->size() == 0) && (!factions || factions->size() == 0) && status_points == 0 && text == 0 && (!quest || (quest->GetCoinsReward() == 0 && quest->GetCoinsRewardMax() == 0))) {
- /*if (quest)
- text = quest->GetName();
- else*/
- return;//nothing to give
- }
-
- GetPlayer()->ClearPendingSelectableItemRewards(0, true);
- GetPlayer()->ClearPendingItemRewards();
-
- PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
- if (packet2) {
- int32 source_id = 0;
- if (quest)
- source_id = quest->GetQuestID();
- int64 rewarded_coin = 0;
- if (quest) {
- if (quest->GetCoinsReward() > 0) {
- if (quest->GetCoinsRewardMax() > 0)
- rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
- else
- rewarded_coin = quest->GetCoinsReward();
- }
- quest->SetGeneratedCoin(rewarded_coin);
- }
- if (rewarded_coin > coin)
- coin = rewarded_coin;
- if (!quest && !was_displayed) { //this entire function is either for version <=561 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
- if (coin > 0) {
- player->AddCoins(coin);
- PlaySound("coin_cha_ching");
- }
- }
- packet2->setSubstructDataByName("reward_data", "unknown1", 255);
- packet2->setSubstructDataByName("reward_data", "reward", header);
- packet2->setSubstructDataByName("reward_data", "max_coin", coin);
- if (player->GetGuild() && !was_displayed) {
- if (!quest) { //this entire function is either for version <=561 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
- player->GetInfoStruct()->add_status_points(status_points);
- player->SetCharSheetChanged(true);
- }
- packet2->setSubstructDataByName("reward_data", "status_points", status_points);
- }
- if(text)
- packet2->setSubstructDataByName("reward_data", "text", text);
-
-
- std::vector<Item*> items;
- quest->GetTmpRewardItemsByID(&items);
- if(rewards || items.size() > 0){
- int32 item_count = items.size();
- item_count += rewards ? rewards->size() : 0;
- packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
- int i = 0;
- if(rewards) {
- for (i = 0; i < rewards->size(); i++) {
- Item* item = rewards->at(i);
- if (item) {
- packet2->setArrayDataByName("reward_id", item->details.item_id, i);
- packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
- }
- if(!quest) //this entire function is either for version <=561 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
- player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
- }
- }
-
- for (int j = 0; j < items.size(); j++) {
- Item* item = items.at(j);
- if (item) {
- packet2->setArrayDataByName("reward_id", item->details.item_id, i);
- packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
- }
- if(!quest) //this entire function is either for version <=561 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
- player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
-
- i++;
- }
- }
- if (selectable_rewards) {
- packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
- for (int i = 0; i < selectable_rewards->size(); i++) {
- Item* item = selectable_rewards->at(i);
- if (item) {
- packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
- packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
- if (!quest) //this entire function is either for version <=561 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
- player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
- }
- }
- }
- if (factions) {
- map<int32, sint32>::iterator itr;
- map<Faction*, signed int> factions_map;
- for (itr = factions->begin(); itr != factions->end(); itr++) {
- Faction* faction = master_faction_list.GetFaction(itr->first);
- if (faction)
- factions_map[faction] = itr->second;
- }
- packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
- map<Faction*, signed int>::iterator faction_itr;
- int8 i = 0;
- for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
- packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
- sint32 amount = faction_itr->second;
- packet2->setArrayDataByName("amount", amount, i);
- if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
- if (amount > 0)
- player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
- else
- player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
- }
- i++;
- }
- }
- QueuePacket(packet2->serialize());
- safe_delete(packet2);
- }
- }
- void Client::PopulateQuestRewardItems(vector <Item*>* items, PacketStruct* packet,
- std::string num_rewards_str, std::string reward_id_str, std::string item_str) {
- if(!items || !packet)
- return;
-
- if (items) {
- int32 total_item_count = 0;
- for(int s=0;s<items->size();s++) {
- Item* tmpItem = items->at(s);
- if(tmpItem) {
- if(tmpItem->details.count > 1) {
- total_item_count += tmpItem->details.count;
- }
- else {
- total_item_count += 1;
- }
- }
- }
- packet->setArrayLengthByName(num_rewards_str.c_str(), total_item_count);
- int16 count = 0;
- int16 pos = 0;
- for (int32 i = 0; i < items->size();) {
- packet->setArrayDataByName(reward_id_str.c_str(), items->at(i)->details.item_id, pos);
- if (version < 860)
- packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, -1);
- else if (version < 1193)
- packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos);
- else
- packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, 2);
-
- pos++;
-
- if(count >= items->at(i)->details.count-1) {
- count = 0;
- }
- else if(items->at(i)->details.count > 1) {
- count++;
- continue;
- }
-
- i++;
- }
- }
- }
- void Client::DisplayQuestComplete(Quest* quest, bool tempReward, std::string customDescription, bool was_displayed) {
- if (!quest)
- return;
-
- if (GetVersion() <= 561) {
- DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints(), tempReward ? customDescription.c_str() : quest->GetCompletedDescription(), was_displayed);
- return;
- }
- PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
- if (packet) {
- packet->setDataByName("title", "Quest Reward!");
- packet->setDataByName("name", quest->GetName());
- if(tempReward)
- {
- packet->setDataByName("description", customDescription.c_str());
- }
- else
- packet->setDataByName("description", quest->GetCompletedDescription());
-
- packet->setDataByName("level", quest->GetLevel());
- packet->setDataByName("encounter_level", quest->GetEncounterLevel());
- int8 difficulty = 0;
- if ((string)quest->GetType() == "Tradeskill")
- difficulty = player->GetTSArrowColor(quest->GetLevel());
- else
- difficulty = player->GetArrowColor(quest->GetLevel());
- packet->setDataByName("difficulty", difficulty);
- if(tempReward)
- {
- packet->setDataByName("max_coin", quest->GetCoinTmpReward());
- packet->setDataByName("min_coin", quest->GetCoinTmpReward());
- packet->setDataByName("status_points", quest->GetStatusPoints());
- }
- else
- {
- int64 rewarded_coin = 0;
- if (quest->GetCoinsReward() > 0) {
- if (quest->GetCoinsRewardMax() > 0)
- rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
- else
- rewarded_coin = quest->GetCoinsReward();
- }
- quest->SetGeneratedCoin(rewarded_coin);
- packet->setDataByName("max_coin", rewarded_coin);
- packet->setDataByName("min_coin", rewarded_coin);
- packet->setDataByName("status_points", quest->GetStatusPoints());
- }
- if(tempReward) {
- PopulateQuestRewardItems(quest->GetTmpRewardItems(), packet);
- }
- else
- {
- vector<Item*>* items2 = quest->GetSelectableRewardItems();
- PopulateQuestRewardItems(quest->GetRewardItems(), packet);
- PopulateQuestRewardItems(quest->GetSelectableRewardItems(), packet, std::string("num_select_rewards"),
- std::string("select_reward_id"), std::string("select_item"));
-
- map<int32, sint32>* reward_factions = quest->GetRewardFactions();
- if (reward_factions && reward_factions->size() > 0) {
- packet->setArrayLengthByName("num_factions", reward_factions->size());
- map<int32, sint32>::iterator itr;
- int16 index = 0;
- for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
- int32 faction_id = itr->first;
- sint32 amount = itr->second;
- const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
- if (faction_name) {
- packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
- packet->setArrayDataByName("amount", amount, index);
- }
- index++;
- }
- }
- }
- EQ2Packet* outapp = packet->serialize();
- // DumpPacket(outapp);
- QueuePacket(outapp);
- safe_delete(packet);
- }
- }
- void Client::DisplayRandomizeFeatures(int32 flags) {
- SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
- if (flags > 0) {
- if (flags & RANDOMIZE_GENDER)
- SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
- if (flags & RANDOMIZE_RACE)
- SimpleMessage(CHANNEL_NARRATIVE, "- Race");
- if (flags & RANDOMIZE_MODEL_TYPE)
- SimpleMessage(CHANNEL_NARRATIVE, "- Model");
- if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
- SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
- if (flags & RANDOMIZE_HAIR_TYPE)
- SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
- if (flags & RANDOMIZE_WING_TYPE)
- SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
- if (flags & RANDOMIZE_CHEEK_TYPE)
- SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
- if (flags & RANDOMIZE_CHIN_TYPE)
- SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
- if (flags & RANDOMIZE_EAR_TYPE)
- SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
- if (flags & RANDOMIZE_EYE_BROW_TYPE)
- SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
- if (flags & RANDOMIZE_EYE_TYPE)
- SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
- if (flags & RANDOMIZE_LIP_TYPE)
- SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
- if (flags & RANDOMIZE_NOSE_TYPE)
- SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
- if (flags & RANDOMIZE_EYE_COLOR)
- SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
- if (flags & RANDOMIZE_HAIR_COLOR1)
- SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
- if (flags & RANDOMIZE_HAIR_COLOR2)
- SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
- if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
- SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
- if (flags & RANDOMIZE_HAIR_FACE_COLOR)
- SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
- if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
- SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
- if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
- SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
- if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
- SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
- if (flags & RANDOMIZE_SKIN_COLOR)
- SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
- if (flags & RANDOMIZE_WING_COLOR1)
- SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
- if (flags & RANDOMIZE_WING_COLOR2)
- SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
- }
- else
- {
- SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
- }
- }
- void Client::GiveQuestReward(Quest* quest, bool has_displayed) {
- current_quest_id = 0;
- if(!quest->GetQuestTemporaryState() && !has_displayed)
- {
- quest->IncrementCompleteCount();
- player->AddCompletedQuest(quest);
- }
-
- AddPendingQuestAcceptReward(quest);
-
- DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
- SendQuestJournal();
-
- if(quest->GetQuestTemporaryState()) {
- return;
- }
- if(!has_displayed) {
- if (quest->GetExpReward() > 0) {
- int32 xp = quest->GetExpReward();
- player->AddXP(xp);
- }
- if (quest->GetTSExpReward() > 0) {
- int8 ts_level = player->GetTSLevel();
- int32 xp = quest->GetTSExpReward();
- if (player->AddTSXP(xp)) {
- Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
- if (player->GetTSLevel() != ts_level)
- ChangeTSLevel(ts_level, player->GetTSLevel());
- player->SetCharSheetChanged(true);
- }
- }
- int64 total_coins = quest->GetGeneratedCoin();
- if (total_coins > 0)
- AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
-
- player->RemoveQuest(quest->GetQuestID(), false);
- }
-
- if (quest->GetQuestGiver() > 0)
- GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
-
- if(!has_displayed) {
- RemovePlayerQuest(quest->GetQuestID(), true, false);
- }
- }
- void Client::DisplayConversation(int32 conversation_id, int32 spawn_id, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2, int8 language, int8 can_close) {
- std::unique_lock lock(MConversation);
- PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
- if (packet) {
- packet->setDataByName("conversation_id", conversation_id);
- packet->setDataByName("text", text);
- packet->setDataByName("language", language); // default 0
- packet->setDataByName("enable_blue_ui", 0); // default 0
- packet->setDataByName("can_close", can_close); // default 1
- conversation_map[conversation_id].clear();
- if (conversations) {
- packet->setArrayLengthByName("num_responses", conversations->size());
- for (int32 i = 0; i < conversations->size(); i++) {
- packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
- if (conversations->at(i).function.length() > 0)
- conversation_map[conversation_id][i] = conversations->at(i).function;
- }
- }
- packet->setDataByName("spawn_id", spawn_id);
- if (mp3) {
- packet->setDataByName("voice", mp3);
- packet->setDataByName("key1", key1);
- packet->setDataByName("key2", key2);
- }
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- void Client::DisplayConversation(Item* item, vector<ConversationOption>* conversations, const char* text, int8 type, const char* mp3, int32 key1, int32 key2, int8 language, int8 can_close) {
- if (!item || !text || !conversations || conversations->size() == 0) {
- return;
- }
- int32 conversation_id = GetConversationID(0, item);
- if (conversation_id == 0) {
- next_conversation_id++;
- conversation_id = next_conversation_id;
- }
- MConversation.lock();
- conversation_items[conversation_id] = item;
- MConversation.unlock();
- if (type == 4)
- DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
- else
- DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
- }
- void Client::DisplayConversation(Spawn* src, int8 type, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2, int8 language, int8 can_close) {
- if (!src || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
- return;
- }
- int32 conversation_id = GetConversationID(src, 0);
- if (conversation_id == 0) {
- next_conversation_id++;
- conversation_id = next_conversation_id;
- }
- MConversation.lock();
- conversation_spawns[conversation_id] = src->GetID();
- MConversation.unlock();
- /* Spawns can start two different types of conversations.
- * Type 1: The chat type with bubbles.
- * Type 2: The dialog type with the blue box. */
- if (type == 1)
- DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(src), conversations, text, mp3, key1, key2, language, can_close);
- else if (type == 2)
- DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
- else //if (type == 3)
- DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
- }
- void Client::CloseDialog(int32 conversation_id) {
- std::unique_lock lock(MConversation);
- PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
- if (packet) {
- packet->setDataByName("conversation_id", conversation_id);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- std::map<int32, Item*>::iterator itr;
- while((itr = conversation_items.find(conversation_id)) != conversation_items.end())
- {
- conversation_items.erase(itr);
- }
-
- std::map<int32, int32>::iterator itr2 = conversation_spawns.find(conversation_id);
- while((itr2 = conversation_spawns.find(conversation_id)) != conversation_spawns.end())
- {
- conversation_spawns.erase(itr2);
- }
- }
- int32 Client::GetConversationID(Spawn* spawn, Item* item) {
- std::shared_lock lock(MConversation);
- int32 conversation_id = 0;
- if (spawn) {
- map<int32, int32>::iterator itr;
- for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
- if (itr->second == spawn->GetID()) {
- conversation_id = itr->first;
- break;
- }
- }
- }
- else if (item) {
- map<int32, Item*>::iterator itr;
- for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
- if (itr->second == item) {
- conversation_id = itr->first;
- break;
- }
- }
- }
- return conversation_id;
- }
- Spawn* Client::GetCombineSpawn() {
- return combine_spawn;
- }
- bool Client::ShouldTarget() {
- return should_target;
- }
- void Client::TargetSpawn(Spawn* spawn) {
- should_target = false;
- PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- void Client::CombineSpawns(float radius, Spawn* spawn) {
- combine_spawn = spawn;
- spawn->RemoveSpawnFromGroup(true);
- if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
- SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
- GetCurrentZone()->RepopSpawns(this, combine_spawn);
- should_target = true;
- }
- void Client::AddCombineSpawn(Spawn* spawn) {
- if (combine_spawn && combine_spawn != spawn && spawn) {
- combine_spawn->AddSpawnToGroup(spawn);
- spawn->AddSpawnToGroup(combine_spawn);
- GetCurrentZone()->RepopSpawns(this, combine_spawn);
- }
- else if (spawn)
- combine_spawn = spawn;
- should_target = true;
- }
- void Client::RemoveCombineSpawn(Spawn* spawn) {
- if (combine_spawn && spawn)
- spawn->RemoveSpawnFromGroup();
- if (combine_spawn == spawn)
- combine_spawn->RemoveSpawnFromGroup(true);
- GetCurrentZone()->RepopSpawns(this, combine_spawn);
- if (combine_spawn == spawn)
- combine_spawn = 0;
- }
- void Client::SaveCombineSpawns(const char* name) {
- if (!combine_spawn) {
- return;
- }
- vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
- if (!spawns) {
- return;
- }
- int32 count = spawns->size();
- int32 spawnLocationID = 0;
- if (count == 1)
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
- else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
- Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
- // we remove the spawn inside SaveCombinedSpawnLocation
- //GetCurrentZone()->RemoveSpawn(combine_spawn);
- }
- else
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
- safe_delete(spawns);
- combine_spawn = 0;
- }
- bool Client::AddItem(int32 item_id, int16 quantity, AddItemType type) {
- Item* master_item = master_item_list.GetItem(item_id);
- Item* item = 0;
- if (master_item)
- item = new Item(master_item);
- if (item) {
- if (quantity > 0)
- item->details.count = quantity;
-
- return AddItem(item, nullptr, type);
- }
- else
- Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
- return false;
- }
- bool Client::AddItem(Item* item, bool* item_deleted, AddItemType type) {
- if (!item) {
- return false;
- }
- if (player->AddItem(item, type)) {
- EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
- if (outapp) {
- //DumpPacket(outapp);
- QueuePacket(outapp);
- //resend bag desc with new item name added
- outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
- if (outapp) {
- //DumpPacket(outapp);
- QueuePacket(outapp);
- }
- /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
- DumpPacket(app);
- client->QueuePacket(app);
- */
- }
- CheckPlayerQuestsItemUpdate(item);
- if (item->GetItemScript() && lua_interface)
- lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
- }
- else {
- lua_interface->SetLuaUserDataStale(item);
- // likely lore conflict
- if(item_deleted)
- *item_deleted = true;
- return false;
- }
- return true;
- }
- bool Client::AddItemToBank(int32 item_id, int16 quantity) {
- Item* master_item = master_item_list.GetItem(item_id);
- Item* item = 0;
- if (master_item)
- item = new Item(master_item);
- if (item) {
- if (quantity > 0)
- item->details.count = quantity;
- return AddItemToBank(item);
- }
- else
- Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
- return false;
- }
- bool Client::AddItemToBank(Item* item) {
- if (!item) {
- return false;
- }
- if (player->AddItemToBank(item)) {
- EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
- if (outapp) {
- QueuePacket(outapp);
- //resend bag desc with new item name added
- outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
- if (outapp)
- QueuePacket(outapp);
- /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
- DumpPacket(app);
- client->QueuePacket(app);
- */
- }
- CheckPlayerQuestsItemUpdate(item);
- if (item->GetItemScript() && lua_interface)
- lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
- }
- else {
- lua_interface->SetLuaUserDataStale(item);
- // likely lore conflict
- safe_delete(item);
- return false;
- }
- return true;
- }
- void Client::UnequipItem(int16 index, sint32 bag_id, int8 to_slot, int8 appearance_equip) {
- vector<EQ2Packet*> packets = GetPlayer()->UnequipItem(index, bag_id, to_slot, GetVersion(), appearance_equip);
- EQ2Packet* outapp = 0;
- for(int32 i=0;i<packets.size();i++)
- {
- outapp = packets[i];
- if(outapp)
- QueuePacket(outapp);
- }
- GetPlayer()->UpdateWeapons();
- EQ2Packet* characterSheetPackets = GetPlayer()->GetPlayerInfo()->serialize(GetVersion());
- QueuePacket(characterSheetPackets);
- }
- bool Client::RemoveItem(Item* item, int16 quantity, bool force_override_no_delete) {
- EQ2Packet* outapp;
- bool delete_item = false;
- assert(item);
- if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
- item->details.count -= quantity;
- item->save_needed = true;
- }
- else {
- database.DeleteItem(character_id, item, 0);
- player->GetPlayerItemList()->RemoveItem(item, false);
- delete_item = true;
- }
- if(force_override_no_delete)
- delete_item = false;
-
- if ((outapp = player->SendInventoryUpdate(version))) {
- QueuePacket(outapp);
- if (item->GetItemScript() && lua_interface)
- lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
- if (delete_item)
- {
- PurgeItem(item);
- lua_interface->SetLuaUserDataStale(item);
- safe_delete(item);
- }
- GetPlayer()->CalculateApplyWeight();
- return true;
- }
- return false;
- }
- void Client::SetLuaDebugClient(bool val) {
- if (val)
- lua_debug_timer.Start();
- lua_debug = val;
- if (lua_interface && !val) {
- lua_interface->RemoveDebugClients(this);
- lua_debug_timer.Disable();
- }
- }
- void Client::SetMerchantTransaction(Spawn* spawn) {
- merchant_transaction = spawn;
- }
- Spawn* Client::GetMerchantTransaction() {
- return merchant_transaction;
- }
- void Client::SetMailTransaction(Spawn* spawn) {
- ResetSendMail(spawn ? false : true);
- MMailWindowMutex.lock();
- mail_transaction = spawn;
- MMailWindowMutex.unlock();
- }
- Spawn* Client::GetMailTransaction() {
- return mail_transaction;
- }
- void Client::PlaySound(const char* name) {
- if (name) {
- PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
- if (packet) {
- packet->setMediumStringByName("name", name);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- float Client::CalculateBuyMultiplier(int32 merchant_id) {
- /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
- if(multiplier){
- sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
- float diff_low = faction_val - multiplier->faction_min;
- if(diff_low < 0)
- diff_low*=-1;
- float total_diff = multiplier->faction_max - multiplier->faction_min;
- if(total_diff < 0)
- total_diff*=-1;
- float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
- float total1 = (diff_low/total_diff);
- float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
- return final_buy_multiplier;
- }*/
- return 1;
- }
- float Client::CalculateSellMultiplier(int32 merchant_id) {
- /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
- if(multiplier){
- sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
- float diff_low = faction_val - multiplier->faction_min;
- if(diff_low < 0)
- diff_low*=-1;
- float total_diff = multiplier->faction_max - multiplier->faction_min;
- if(total_diff < 0)
- total_diff*=-1;
- float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
- float total1 = (diff_low/total_diff);
- float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
- return final_sell_multiplier;
- }*/
- return 1;
- }
- void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
- Spawn* spawn = GetMerchantTransaction();
- Guild* guild = GetPlayer()->GetGuild();
- if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY)) &&
- spawn->IsClientInMerchantLevelRange(this)) {
- int32 total_sell_price = 0;
- int32 total_status_sell_price = 0; //for status
- float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
- int32 sell_price = 0;
- int32 status_sell_price = 0; //for status
- Item* master_item = master_item_list.GetItem(item_id);
- Item* item = 0;
- if (unique_id == 0)
- item = player->item_list.GetItemFromID(item_id, quantity);
- else
- item = player->item_list.GetItemFromUniqueID(unique_id);
- if (!item)
- item = player->item_list.GetItemFromID(item_id);
- if (item && master_item) {
- if(item->details.item_locked)
- {
- SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell the item in use.");
- return;
- }
- else if(item->CheckFlag(NO_VALUE))
- {
- SimpleMessage(CHANNEL_COLOR_RED, "This item has no value.");
- return;
- }
- else if (item->IsBag())
- {
- int32 bagitemcount = player->GetPlayerItemList()->GetItemCountInBag(item);
- if (bagitemcount > 0) {
- SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell a bag with items inside it.");
- return;
- }
- }
- int32 sell_price = (int32)(master_item->sell_price * multiplier);
- if (sell_price > item->sell_price)
- sell_price = item->sell_price;
- if (quantity > item->details.count)
- quantity = item->details.count;
- total_sell_price = sell_price * quantity;
- //------------------------------For Selling Status Items
- status_sell_price = (int32)(master_item->sell_status * multiplier);
- if (status_sell_price > item->sell_status)
- status_sell_price = item->sell_status;
- if (quantity > item->details.count)
- quantity = item->details.count;
- total_status_sell_price = status_sell_price * quantity;
- if(total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
- total_status_sell_price = 0;
- player->GetInfoStruct()->add_status_points(total_status_sell_price);
- int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
- if (player->GetGuild() && guild->GetLevel() < guildMaxLevel) {
- guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
- guild->SendGuildMemberList();
- guild->AddEXPCurrent((total_status_sell_price / 10), true);
- }
- if (quantity > 1)
- {
- if(total_status_sell_price)
- Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %i %s to %s for %s and %u Status Points.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str(), status_sell_price);
- else
- Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %i %s to %s for %s.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
- }
- else
- {
- if(total_status_sell_price)
- Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %s to %s for %s and %u Status Points.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str(), status_sell_price);
- else
- Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %s to %s for %s.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
- }
- player->AddCoins(total_sell_price);
- if(!item->no_buy_back && (total_status_sell_price == 0 || (total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))))
- AddBuyBack(unique_id, item_id, quantity, sell_price);
- if (quantity >= item->details.count) {
- database.DeleteItem(GetCharacterID(), item, 0);
- player->item_list.DestroyItem(item->details.index);
- }
- else {
- item->details.count -= quantity;
- item->save_needed = true;
- }
- EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
- if (outapp)
- QueuePacket(outapp);
-
- if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
- SendBuyBackList();
- }
- }
- }
- void Client::BuyBack(int32 item_id, int16 quantity) {
- Spawn* spawn = GetMerchantTransaction();
- if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK)) &&
- spawn->IsClientInMerchantLevelRange(this)) {
- deque<BuyBackItem*>::iterator itr;
- BuyBackItem* buyback = 0;
- BuyBackItem* closest = 0;
- MBuyBack.readlock(__FUNCTION__, __LINE__);
- for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
- buyback = *itr;
- if (buyback->unique_id == item_id) {
- closest = buyback;
- quantity = buyback->quantity;
- break;
- }
- }
- MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
- if (closest) {
- Item* item = 0;
- Item* master_item = master_item_list.GetItem(closest->item_id);
- if (master_item) {
- item = new Item(master_item);
- if (closest->quantity >= quantity)
- item->details.count = quantity;
- else
- item->details.count = closest->quantity;
- }
- bool itemDeleted = false;
- bool itemAdded = false;
- sint64 dispFlags = 0;
- if (item && item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buyback_display_flags", item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
- SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
- else if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
- SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
- else if (player->RemoveCoins(closest->quantity * closest->price)) {
- bool removed = false;
- if (closest->quantity == quantity) {
- MBuyBack.writelock(__FUNCTION__, __LINE__);
- for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
- if (*itr == closest) {
- buy_back_items.erase(itr);
- removed = true;
- break;
- }
- }
- MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
- }
- else {
- closest->quantity -= quantity;
- closest->save_needed = true;
- }
- itemAdded = AddItem(item, &itemDeleted);
-
- if (removed) {
- database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
- safe_delete(closest);
- }
-
- if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
- SendBuyBackList();
- }
- else
- SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
- if(!itemAdded && !itemDeleted) {
- lua_interface->SetLuaUserDataStale(item);
- safe_delete(item);
- }
- }
- }
- }
- void Client::BuyItem(int32 item_id, int16 quantity) {
- // Get the merchant we are buying from
- Spawn* spawn = GetMerchantTransaction();
- // Make sure the spawn has a merchant list
- if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
- int32 total_buy_price = 0;
- float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
- int32 sell_price = 0;
- Item* master_item = master_item_list.GetItem(item_id);
- Item* item = 0;
- int16 total_available = 0;
- vector<MerchantItemInfo>* temp;
- vector<MerchantItemInfo>::iterator itr;
- MerchantItemInfo* ItemInfo = 0;
- temp = world.GetMerchantList(spawn->GetMerchantID());
- for (itr = temp->begin(); itr != temp->end(); itr++) {
- if ((*itr).item_id == item_id) {
- ItemInfo = &(*itr);
- break;
- }
- }
- if (master_item && ItemInfo) {
- if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
- quantity = 1;
- total_available = 0xFFFF;
- sell_price = master_item->sell_price;
- }
- else {
- total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
- sell_price = (int32)(master_item->sell_price * multiplier);
- if (quantity > total_available)
- quantity = total_available;
- }
- sint64 dispFlags = 0;
- if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buy_display_flags", master_item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
- {
- SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
- return;
- }
- if(quantity < 1)
- {
- SimpleMessage(CHANNEL_COLOR_RED, "Merchant does not have item for purchase (quantity < 1).");
- return;
- }
- total_buy_price = sell_price * quantity;
- item = new Item(master_item);
- item->details.count = quantity;
- if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
- SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
- lua_interface->SetLuaUserDataStale(item);
- safe_delete(item);
- }
- else {
- // Price not set in the merchant_inventory table, use the old method
- if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
- if (player->RemoveCoins(total_buy_price)) {
- item->SetMaxSellValue(sell_price);
- if (quantity > 1)
- Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %i %s from %s for%s.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
- else
- Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %s from %s for%s.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
- bool itemDeleted = false;
- AddItem(item, &itemDeleted);
- if(!itemDeleted) {
- CheckPlayerQuestsItemUpdate(item);
- if (item && total_available < 0xFF) {
- world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
- SendBuyMerchantList();
- }
-
- if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
- PlayLotto(total_buy_price, item->details.item_id);
- }
- }
- else {
- Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
- GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
- PlaySound("buy_failed");
- }
- }
- else {
- // Price set in merchant_inventory table
- // Check if the player has enough status, coins and staion cash to buy the item before checking the items
- // TODO: need to add support for station cash
- if (player->GetInfoStruct()->get_status_points() >= (ItemInfo->price_status * quantity) && player->HasCoins(ItemInfo->price_coins * quantity)) {
- // Check items
- int16 item_quantity = 0;
- // Default these to true in case price_item_id or price_item2_id was never set
- bool hasItem1 = true;
- bool hasItem2 = true;
- Item* tempItem1 = 0;
- Item* tempItem2 = 0;
- if (ItemInfo->price_item_id != 0) {
- // Same item for whatever reason lets add the quantities together
- if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
- item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
- else
- item_quantity = ItemInfo->price_item_qty;
- tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
- if (tempItem1) {
- if (tempItem1->details.count < item_quantity)
- hasItem1 = false;
- }
- else {
- hasItem1 = false;
- }
- }
- // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
- // as item1 and we already checked for it so we can skip this check
- if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
- tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
- if (tempItem2) {
- if (tempItem2->details.count < ItemInfo->price_item2_qty)
- hasItem2 = false;
- }
- else {
- hasItem2 = false;
- }
- }
- // if we have every thing then remove the price and give the item
- if (hasItem1 && hasItem2) {
- player->GetInfoStruct()->set_status_points(player->GetInfoStruct()->get_status_points() - (ItemInfo->price_status * quantity));
- // TODO: station cash
- // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
- // so there is no need to send it more then that one time
- if (tempItem1) {
- if (tempItem1->details.count > item_quantity) {
- tempItem1->details.count -= item_quantity;
- tempItem1->save_needed = true;
- }
- else {
- database.DeleteItem(GetCharacterID(), tempItem1, 0);
- player->item_list.DestroyItem(tempItem1->details.index);
- }
- }
- if (tempItem2) {
- if (tempItem2->details.count > ItemInfo->price_item2_qty) {
- tempItem2->details.count -= ItemInfo->price_item2_qty;
- tempItem2->save_needed = true;
- }
- else {
- database.DeleteItem(GetCharacterID(), tempItem2, 0);
- player->item_list.DestroyItem(tempItem2->details.index);
- }
- }
- // 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
- player->RemoveCoins(ItemInfo->price_coins * quantity);
- item->SetMaxSellValue(sell_price);
- if (quantity > 1)
- Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %i %s from %s for%s.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
- else
- Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %s from %s for%s.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
- bool itemDeleted = false;
- AddItem(item, &itemDeleted);
- if(!itemDeleted) {
- CheckPlayerQuestsItemUpdate(item);
- if (item && total_available < 0xFF) {
- world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
- SendBuyMerchantList();
- }
-
- SendSellMerchantList();
- if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
- PlayLotto(total_buy_price, item->details.item_id);
- }
- }
- else {
- Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
- GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
- PlaySound("buy_failed");
- }
- }
- else {
- Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
- GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
- PlaySound("buy_failed");
- }
- }
- }
- }
- }
- }
- void Client::RepairItem(int32 item_id) {
- Spawn* spawn = GetMerchantTransaction();
- if (spawn) {
- Item* item = player->item_list.GetItemFromID(item_id);
- if (!item)
- item = player->GetEquipmentList()->GetItemFromItemID(item_id);
- if (item) {
- if(item->CheckFlag2(NO_REPAIR)) {
- Message(CHANNEL_MERCHANT, "The mender was unable to repair your items.");
- PlaySound("buy_failed");
- }
- else {
- int32 repair_cost = item->CalculateRepairCost();
- if (player->RemoveCoins((int32)repair_cost)) {
- item->generic_info.condition = 100;
- item->save_needed = true;
- QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
- QueuePacket(player->SendInventoryUpdate(GetVersion()));
- QueuePacket(item->serialize(version, false, player));
- Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
- PlaySound("coin_cha_ching");
- if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
- SendRepairList();
- }
- else {
- string popup_text = "You do not have enough coin to repair ";
- string popup_item = item->CreateItemLink(GetVersion()).c_str();
- popup_text.append(popup_item);
- SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
- Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
- PlaySound("buy_failed");
- }
- }
- }
- }
- }
- void Client::RepairAllItems() {
- Spawn* spawn = GetMerchantTransaction();
- if (spawn) {
- vector<Item*>* repairable_items = GetRepairableItems();
- if (repairable_items && repairable_items->size() > 0) {
- vector<Item*>::iterator itr;
- int64 total_cost = 0;
- for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
- total_cost += (*itr)->CalculateRepairCost();
- if (player->RemoveCoins((int32)total_cost)) {
- Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
- for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
- Item* item = *itr;
- if (item) {
- item->generic_info.condition = 100;
- item->save_needed = true;
- QueuePacket(item->serialize(version, false, player));
- Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
- }
- }
- QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
- QueuePacket(player->SendInventoryUpdate(GetVersion()));
- PlaySound("coin_cha_ching");
- if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
- SendRepairList();
- }
- else {
- string popup_text = "You do not have enough coin to repair all of your items. ";
- SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
- SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
- PlaySound("buy_failed");
- }
- }
- safe_delete(repairable_items);
- }
- }
- void Client::SendAchievementsList()
- {
- /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
- map<int32, Achievement *>::iterator itr;
- Achievement *achievement;
- vector<AchievementRequirements *> *requirements = 0;
- vector<AchievementRequirements *>::iterator itr2;
- AchievementRequirements *requirement;
- vector<AchievementRewards *> *rewards = 0;
- vector<AchievementRewards *>::iterator itr3;
- AchievementRewards *reward;
- PacketStruct *packet;
- int16 i = 0;
- int16 j = 0;
- int16 k = 0;
- if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
- return;
- }
- packet->setArrayLengthByName("num_achievements" , achievements->size());
- for (itr = achievements->begin(); itr != achievements->end(); itr++) {
- achievement = itr->second;
- packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
- packet->setArrayDataByName("title", achievement->GetTitle(), i);
- packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
- packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
- packet->setArrayDataByName("category", achievement->GetCategory(), i);
- packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
- packet->setArrayDataByName("icon", achievement->GetIcon(), i);
- packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
- packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
- packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
- packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
- packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
- requirements = achievement->GetRequirements();
- rewards = achievement->GetRewards();
- j = 0;
- k = 0;
- packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
- for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
- requirement = *itr2;
- packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
- packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
- j++;
- }
- packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
- for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
- reward = *itr3;
- packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
- k++;
- }
- i++;
- }
- //packet->PrintPacket();
- EQ2Packet* data = packet->serialize();
- EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
- safe_delete(packet);
- safe_delete(data);
- //DumpPacket(app);
- QueuePacket(app);*/
- QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
- SendAchievementUpdate(true);
- }
- void Client::SendAchievementUpdate(bool first_login) {
- map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
- map<int32, AchievementUpdate*>::iterator itr;
- AchievementUpdate* update;
- vector<AchievementUpdateItems*>* update_items = 0;
- vector<AchievementUpdateItems*>::iterator itr2;
- AchievementUpdateItems* update_item;
- int16 i = 0;
- int16 j = 0;
- PacketStruct* packet;
- if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
- return;
- }
- packet->setDataByName("unknown1", first_login ? 1 : 0);
- packet->setArrayLengthByName("num_achievements", updates->size());
- for (itr = updates->begin(); itr != updates->end(); itr++) {
- update = itr->second;
- packet->setArrayDataByName("achievement_id", update->GetID(), i);
- packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
- update_items = update->GetUpdateItems();
- j = 0;
- packet->setSubArrayLengthByName("num_items", update_items->size(), i);
- for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
- update_item = *itr2;
- packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
- j++;
- }
- i++;
- }
- //packet->PrintPacket();
- EQ2Packet* data = packet->serialize();
- EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
- safe_delete(packet);
- safe_delete(data);
- //DumpPacket(app);
- QueuePacket(app);
- }
- void Client::SendBuyMerchantList(bool sell) {
- Spawn* spawn = GetMerchantTransaction();
- if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
- vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
- if (items) {
- PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
- if (packet) {
- float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
- packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
- packet->setArrayLengthByName("num_items", items->size());
- vector<MerchantItemInfo>::iterator itr;
- sint8 item_difficulty = 0;
- int32 sell_price = 0;
- int i = 0;
- int tmp_level = 0;
- for (itr = items->begin(); itr != items->end(); itr++, i++) {
- MerchantItemInfo ItemInfo = *itr;
- Item* item = master_item_list.GetItem(ItemInfo.item_id);
- if (!item)
- continue;
- packet->setArrayDataByName("item_name", item->name.c_str(), i);
- packet->setArrayDataByName("item_id", item->details.item_id, i);
- packet->setArrayDataByName("stack_size", item->stack_count, i);
- packet->setArrayDataByName("icon", item->details.icon, i);
- if (item->generic_info.adventure_default_level > 0)
- tmp_level = item->generic_info.adventure_default_level;
- else
- tmp_level = item->generic_info.tradeskill_default_level;
- packet->setArrayDataByName("level", tmp_level, i);
- if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
- packet->setArrayDataByName("tier", item->details.tier, i);
- }
- packet->setArrayDataByName("item_id2", item->details.item_id, i);
- item_difficulty = player->GetArrowColor(tmp_level);
- if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
- item_difficulty = ARROW_COLOR_WHITE;
- sint64 overrideValue = 0;
- if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
- item_difficulty = (sint8)overrideValue;
- item_difficulty -= 6;
- if (item_difficulty < 0)
- item_difficulty *= -1;
-
- packet->setArrayDataByName("item_difficulty", item_difficulty, i);
- packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
- packet->setArrayDataByName("unknown5", 255, i);
- packet->setArrayDataByName("stack_size2", item->stack_count, i);
- sint64 dispFlags = 0;
- if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buy_display_flags", item, player, nullptr, &dispFlags))
- packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
-
- std::string overrideValueStr;
- // classic client isn't properly tracking this field, DoF we don't have it identified yet, but no field to cause any issues (can add later if identified)
- if (GetVersion() >= 546 && item->GetItemScript() && lua_interface && lua_interface->RunItemScriptWithReturnString(item->GetItemScript(), "item_description", item, player, &overrideValueStr))
- packet->setArrayDataByName("description", overrideValueStr.c_str(), i);
-
- // If no price set in the merchant_inventory table then use the old method
- if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
- sell_price = (int32)(item->sell_price * multiplier);
- packet->setArrayDataByName("price", sell_price, i);
- }
- else {
- int8 count = 0;
- if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
- count++;
- if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
- count++;
- if (count != 0) {
- packet->setSubArrayLengthByName("num_tokens", count, i);
- int8 index = 0;
- Item* token = 0;
- if (ItemInfo.price_item_id != 0) {
- token = master_item_list.GetItem(ItemInfo.price_item_id);
- if (item) {
- packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
- packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
- packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
- packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
- }
- token = 0;
- index++;
- }
- if (ItemInfo.price_item2_id != 0) {
- token = master_item_list.GetItem(ItemInfo.price_item2_id);
- if (item) {
- packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
- packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
- packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
- packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
- }
- }
- }
- packet->setArrayDataByName("price", ItemInfo.price_coins, i);
- packet->setArrayDataByName("status2", ItemInfo.price_status, i);
- packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
- }
- }
- if (GetVersion() <= 546) {
- //buy is 0 so dont need to set it
- if (sell)
- packet->setDataByName("type", 1);
- }
- else {
- if (sell)
- packet->setDataByName("type", 130);
- else
- packet->setDataByName("type", 2);
- }
- EQ2Packet* outapp = packet->serialize();
- QueuePacket(outapp);
- safe_delete(packet);
- }
- safe_delete(items);
- }
- else {
- // Need to send an empty packet in the event there is no item list, otherwise the
- // last item list sent to the player will show for this merchant
- PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
- if (GetVersion() <= 546) {
- //buy is 0 so dont need to set it
- if (sell)
- packet->setDataByName("type", 1);
- }
- else {
- if (sell)
- packet->setDataByName("type", 130);
- else
- packet->setDataByName("type", 2);
- }
- EQ2Packet* outapp = packet->serialize();
- QueuePacket(outapp);
- safe_delete(packet);
- }
- }
- }
- }
- void Client::SendSellMerchantList(bool sell) {
- Spawn* spawn = GetMerchantTransaction();
- if (!spawn || (spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) || (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
- return;
-
- if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
- map<int32, Item*>* items = player->GetItemList();
- if (items) {
- PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
- if (packet) {
- vector<Item*> sellable_items;
- map<int32, Item*>::iterator test_itr;
- for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
- bool isbagwithitems = false;
- if (test_itr->second && test_itr->second->IsBag() && (test_itr->second->details.num_slots - test_itr->second->details.num_free_slots != test_itr->second->details.num_slots))
- isbagwithitems = true;
-
- if (test_itr->second && !test_itr->second->CheckFlag(NO_VALUE) && (isbagwithitems == false) && (test_itr->second->details.inv_slot_id != -3) && (test_itr->second->details.inv_slot_id != -4))
- sellable_items.push_back(test_itr->second);
- }
- packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
- packet->setArrayLengthByName("num_items", sellable_items.size());
- vector<Item*>::iterator itr;
- Item* item = 0;
- sint8 item_difficulty = 0;
- float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
- int32 sell_price = 0;
- Item* master_item = 0;
- int i = 0;
- int tmp_level = 0;
- for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
- item = *itr;
- master_item = master_item_list.GetItem(item->details.item_id);
- if (master_item)
- sell_price = (int32)(master_item->sell_price * multiplier);
- else
- sell_price = 0;
- if (sell_price > item->sell_price)
- sell_price = item->sell_price;
- packet->setArrayDataByName("item_name", item->name.c_str(), i);
- string thename = item->name;
- packet->setArrayDataByName("price", sell_price, i);
- packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
- int8 dispFlags = 0;
- // only city merchants allow selling for status
- if(item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT))
- {
- packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
- int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
- if (GetPlayer()->GetGuild() && GetPlayer()->GetGuild()->GetLevel() >= guildMaxLevel) {
- dispFlags += DISPLAY_FLAG_NO_GUILD_STATUS;
- }
- }
- if(item->no_buy_back || (item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
- {
- if(GetVersion() < 1188)
- dispFlags += DISPLAY_FLAG_RED_TEXT; // for older clients it isn't "no buy back", you can either have 1 for red text or 255 for 'not for sale' to be checked
- else
- dispFlags += DISPLAY_FLAG_NO_BUYBACK;
- }
- if(item->no_sale)
- dispFlags += DISPLAY_FLAG_NOT_FOR_SALE;
-
- packet->setArrayDataByName("display_flags", dispFlags, i);
- packet->setArrayDataByName("item_id", item->details.item_id, i);
- packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
- packet->setArrayDataByName("stack_size", item->details.count, i);
- packet->setArrayDataByName("icon", item->details.icon, i);
- if (item->generic_info.adventure_default_level > 0)
- tmp_level = item->generic_info.adventure_default_level;
- else
- tmp_level = item->generic_info.tradeskill_default_level;
- packet->setArrayDataByName("level", item->details.recommended_level, i);
-
- if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
- packet->setArrayDataByName("tier", item->details.tier, i);
- }
- packet->setArrayDataByName("item_id2", item->details.item_id, i);
- item_difficulty = player->GetArrowColor(tmp_level);
- if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
- item_difficulty = ARROW_COLOR_WHITE;
-
- sint64 overrideValue = 0;
- if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
- item_difficulty = (sint8)overrideValue;
-
- item_difficulty -= 6;
- if (item_difficulty < 0)
- item_difficulty *= -1;
- packet->setArrayDataByName("item_difficulty", item_difficulty, i);
- if (item->details.count == 1)
- packet->setArrayDataByName("quantity", 0xFFFF, i);
- else
- packet->setArrayDataByName("quantity", item->details.count, i);
- packet->setArrayDataByName("stack_size2", item->details.count, i);
- if (GetVersion() <= 1096)
- packet->setArrayDataByName("description", item->description.c_str(), i);
- }
- if (GetVersion() <= 546) {
- packet->setDataByName("type", 1);
- }
- else {
- if (sell)
- packet->setDataByName("type", 129);
- else
- packet->setDataByName("type", 1);
- }
- packet->setDataByName("unknown8a", 16256, 6);
- packet->setDataByName("unknown8a", 16256, 10);
- //packet->PrintPacket();
- EQ2Packet* outapp = packet->serialize();
- //DumpPacket(outapp);
- QueuePacket(outapp);
- safe_delete(packet);
- }
- safe_delete(items);
- }
- }
- }
- void Client::SendBuyBackList(bool sell) {
- if (GetVersion() <= 546) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
- return;
- Spawn* spawn = GetMerchantTransaction();
- if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
- deque<BuyBackItem*>::iterator itr;
- int i = 0;
- Item* master_item = 0;
- BuyBackItem* buyback = 0;
- PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
- packet->setArrayLengthByName("num_items", buy_back_items.size());
- sint8 item_difficulty = 0;
- MBuyBack.readlock(__FUNCTION__, __LINE__);
- int tmp_level = 0;
- for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
- buyback = *itr;
- master_item = master_item_list.GetItem(buyback->item_id);
- if (master_item) {
- packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
- packet->setArrayDataByName("price", buyback->price, i);
- packet->setArrayDataByName("item_id", master_item->details.item_id, i);
- packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
- packet->setArrayDataByName("stack_size", buyback->quantity, i);
- packet->setArrayDataByName("icon", master_item->details.icon, i);
- if (master_item->generic_info.adventure_default_level > 0)
- tmp_level = master_item->generic_info.adventure_default_level;
- else
- tmp_level = master_item->generic_info.tradeskill_default_level;
- packet->setArrayDataByName("level", tmp_level, i);
- if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
- packet->setArrayDataByName("tier", master_item->details.tier, i);
- }
- packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
- item_difficulty = player->GetArrowColor(tmp_level);
- if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
- item_difficulty = ARROW_COLOR_WHITE;
-
- sint64 overrideValue = 0;
- if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "item_difficulty", master_item, player, nullptr, &overrideValue))
- item_difficulty = (sint8)overrideValue;
- item_difficulty -= 6;
- if (item_difficulty < 0)
- item_difficulty *= -1;
- packet->setArrayDataByName("item_difficulty", item_difficulty, i);
- sint64 dispFlags = 0;
- if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buyback_display_flags", master_item, player, nullptr, &dispFlags))
- packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
-
- if (buyback->quantity == 1)
- packet->setArrayDataByName("quantity", 0xFFFF, i);
- else
- packet->setArrayDataByName("quantity", buyback->quantity, i);
- packet->setArrayDataByName("stack_size2", buyback->quantity, i);
- if (GetVersion() <= 1096)
- packet->setArrayDataByName("description", master_item->description.c_str(), i);
- }
- }
- MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
- if (sell)
- packet->setDataByName("type", 640);
- else
- packet->setDataByName("type", 512);
- EQ2Packet* outapp = packet->serialize();
- // DumpPacket(outapp);
- QueuePacket(outapp);
- safe_delete(packet);
- }
- }
- }
- void Client::SendRepairList() {
- Spawn* spawn = GetMerchantTransaction();
- if (spawn) {
- vector<Item*>* repairable_items = GetRepairableItems();
- PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
- packet->setArrayLengthByName("num_items", repairable_items->size());
- Item* item = 0;
- sint8 item_difficulty = 0;
- int32 i = 0;
- vector<Item*>::iterator itr;
- for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
- item = *itr;
-
- packet->setArrayDataByName("item_name", item->name.c_str(), i);
- packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
- packet->setArrayDataByName("item_id", item->details.item_id, i);
- packet->setArrayDataByName("stack_size", item->details.count, i);
- packet->setArrayDataByName("icon", item->details.icon, i);
-
- /*if (item->generic_info.adventure_default_level > 0)
- tmp_level = item->generic_info.adventure_default_level;
- else
- tmp_level = item->generic_info.tradeskill_default_level;
- packet->setArrayDataByName("level", tmp_level, i);*/
- packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
-
- if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
- packet->setArrayDataByName("tier", item->details.tier, i);
- }
- packet->setArrayDataByName("item_id2", item->details.item_id, i);
- item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
- if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
- item_difficulty = ARROW_COLOR_WHITE;
- item_difficulty -= 6;
- if (item_difficulty < 0)
- item_difficulty *= -1;
- packet->setArrayDataByName("item_difficulty", item_difficulty, i);
- if (item->details.count == 1)
- packet->setArrayDataByName("quantity", 0xFFFF, i);
- else
- packet->setArrayDataByName("quantity", item->details.count, i);
- packet->setArrayDataByName("stack_size2", item->details.count, i);
- if (GetVersion() <= 1096)
- packet->setArrayDataByName("description", item->description.c_str(), i);
- }
- if (GetVersion() <= 546) {
- packet->setDataByName("type", 112);
- }
- else {
- packet->setDataByName("type", 96);
- }
- EQ2Packet* outapp = packet->serialize();
-
- //DumpPacket(outapp);
- QueuePacket(outapp);
-
- /*if (GetVersion() <= 546) {
- packet->setDataByName("type", 16);
- EQ2Packet* outapp2 = packet->serialize();
- QueuePacket(outapp2);
- }*/
-
- safe_delete(packet);
- }
- safe_delete(repairable_items);
- }
- }
- void Client::ShowLottoWindow() {
- Spawn* spawn = GetMerchantTransaction();
- if (spawn) {
- int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
- if (!item_id)
- {
- LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
- SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
- return;
- }
- else if (item_id == 0)
- {
- LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
- return;
- }
- Item* item = master_item_list.GetItem(item_id);
- if (!item) {
- LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
- return;
- }
- LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
- PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
- packet->setArrayLengthByName("num_items", 1);
- packet->setArrayDataByName("item_name", item->name.c_str());
- packet->setArrayDataByName("price", item->sell_price);
- packet->setArrayDataByName("item_id", item->details.item_id);
- packet->setArrayDataByName("stack_size", item->details.count);
- packet->setArrayDataByName("icon", item->details.icon);
- packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
-
- if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
- packet->setArrayDataByName("tier", item->details.tier);
- }
- packet->setArrayDataByName("item_id2", item->details.item_id);
- int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
- if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
- item_difficulty = ARROW_COLOR_WHITE;
- item_difficulty -= 6;
- if (item_difficulty < 0)
- item_difficulty *= -1;
- packet->setArrayDataByName("item_difficulty", item_difficulty);
- //if(item->details.count == 1)
- packet->setArrayDataByName("quantity", 0xFFFF);
- //else
- // packet->setArrayDataByName("quantity", item->details.count);
- packet->setArrayDataByName("stack_size2", item->details.count);
- packet->setArrayDataByName("description", item->description.c_str());
- if (GetVersion() <= 546) {
- packet->setDataByName("type", 128);
- }
- else {
- packet->setDataByName("type", 0x00000102);
- }
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- void Client::PlayLotto(int32 price, int32 ticket_item_id) {
- PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
- if (packet) {
- world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
- int32 rolls[6] = { 0 };
- int32 lottery_digits[6] = { 0 };
- int8 num_matches = 0;
- int64 jackpot = 0;
- Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
- if (!item) {
- return;
- }
- database.DeleteItem(GetCharacterID(), item, 0);
- GetPlayer()->item_list.RemoveItem(item, true);
- QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
- Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
- if (!winning_numbers) {
- winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
- variables.AddVariable(winning_numbers);
- database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
- }
- if (strlen(winning_numbers->GetValue()) != 12) {
- winning_numbers->SetValue("231205182236");
- database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
- }
- try {
- for (int32 i = 0; i < 12; i += 2) {
- char num[4];
- strncpy(num, winning_numbers->GetValue() + i, 2);
- lottery_digits[i / 2] = atoi(num);
- }
- }
- catch (...) {
- LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
- return;
- }
- Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
- if (!jackpot_var) {
- jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
- variables.AddVariable(jackpot_var);
- database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
- }
- try {
- jackpot = atoul(jackpot_var->GetValue());
- if (jackpot < 10000)
- jackpot = 10000;
- }
- catch (...) {
- jackpot = 10000;
- }
- char new_jackpot[128] = { 0 };
- sprintf(new_jackpot, "%llu", jackpot + price);
- jackpot_var->SetValue(new_jackpot);
- database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
- world.PickRandomLottoDigits(rolls);
- packet->setDataByName("roll_digit1", rolls[0]);
- packet->setDataByName("roll_digit2", rolls[1]);
- packet->setDataByName("roll_digit3", rolls[2]);
- packet->setDataByName("roll_digit4", rolls[3]);
- packet->setDataByName("roll_digit5", rolls[4]);
- packet->setDataByName("roll_digit6", rolls[5]);
- packet->setDataByName("lottery_digit1", lottery_digits[0]);
- packet->setDataByName("lottery_digit2", lottery_digits[1]);
- packet->setDataByName("lottery_digit3", lottery_digits[2]);
- packet->setDataByName("lottery_digit4", lottery_digits[3]);
- packet->setDataByName("lottery_digit5", lottery_digits[4]);
- packet->setDataByName("lottery_digit6", lottery_digits[5]);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- for (int32 i = 0; i < 6; i++) {
- for (int32 j = 0; j < 6; j++) {
- if (rolls[i] == lottery_digits[j]) {
- num_matches++;
- break;
- }
- }
- }
- char new_jackpot_str[16];
- memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
- world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
- if (num_matches == 6) {
- world.PickRandomLottoDigits(lottery_digits);
- for (int32 i = 0; i < 12; i += 2)
- sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
- winning_numbers->SetValue(new_jackpot_str);
- jackpot_var->SetValue("10000");
- database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
- database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
- }
- }
- }
- void Client::SendGuildCreateWindow() {
- if (GetVersion() <= 546) {
- SimpleMessage(0, "Not implemented on this client...yet?");
- }
- else {
- Spawn* spawn = GetPlayer()->GetTarget();
- if (spawn) {
- PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
- packet->setArrayLengthByName("num_items", 0);
- packet->setDataByName("type", 0x00008000);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- }
- void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
- BuyBackItem* item = new BuyBackItem;
- item->item_id = item_id;
- item->unique_id = unique_id;
- item->price = price;
- item->quantity = quantity;
- item->save_needed = save_needed;
- MBuyBack.writelock(__FUNCTION__, __LINE__);
- buy_back_items.push_back(item);
- if (buy_back_items.size() > 10) {
- safe_delete(buy_back_items.front());
- buy_back_items.pop_front();
- }
- MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
- }
- deque<BuyBackItem*>* Client::GetBuyBacks() {
- return &buy_back_items;
- }
- vector<Item*>* Client::GetRepairableItems() {
- vector<Item*>* repairable_items = new vector<Item*>;
- vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
- map<int32, Item*>* items = player->GetItemList();
- if (equipped_items && equipped_items->size() > 0) {
- for (int32 i = 0; i < equipped_items->size(); i++) {
- Item* item = equipped_items->at(i);
- if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
- repairable_items->push_back(item);
- }
- }
- if (items && items->size() > 0) {
- map<int32, Item*>::iterator itr;
- for (itr = items->begin(); itr != items->end(); itr++) {
- Item* item = itr->second;
- if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
- repairable_items->push_back(item);
- }
- }
- safe_delete(equipped_items);
- safe_delete(items);
- return repairable_items;
- }
- vector<Item*>* Client::GetItemsByEffectType(ItemEffectType type, ItemEffectType type2) {
- if(type == NO_EFFECT_TYPE)
- return nullptr;
-
- vector<Item*>* return_items = new vector<Item*>;
- vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
- map<int32, Item*>* items = player->GetItemList();
- if (equipped_items && equipped_items->size() > 0) {
- for (int32 i = 0; i < equipped_items->size(); i++) {
- Item* item = equipped_items->at(i);
- if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
- return_items->push_back(item);
- }
- }
- if (items && items->size() > 0) {
- map<int32, Item*>::iterator itr;
- for (itr = items->begin(); itr != items->end(); itr++) {
- Item* item = itr->second;
- if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
- return_items->push_back(item);
- }
- }
- safe_delete(equipped_items);
- safe_delete(items);
- return return_items;
- }
- void Client::SendMailList() {
- int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
- if (kiosk_id > 0) {
- PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
- if (p) {
- MutexMap<int32, Mail*>* mail_list = player->GetMail();
- MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
- int32 i = 0;
- p->setDataByName("kiosk_id", kiosk_id);
- p->setArrayLengthByName("num_messages", (int16)mail_list->size());
- while (itr.Next()) {
- Mail* mail = itr->second;
- p->setArrayDataByName("mail_id", mail->mail_id, i);
- p->setArrayDataByName("player_to_id", mail->player_to_id, i);
- p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
- p->setArrayDataByName("subject", mail->subject.c_str(), i);
- p->setArrayDataByName("already_read", mail->already_read, i);
- if(mail->expire_time)
- p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
- else
- p->setArrayDataByName("mail_deletion", 0, i);
-
- p->setArrayDataByName("mail_type", mail->mail_type, i);
- p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
- p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
- p->setArrayDataByName("coin_copper", mail->coin_copper, i);
- p->setArrayDataByName("coin_silver", mail->coin_silver, i);
- p->setArrayDataByName("coin_gold", mail->coin_gold, i);
- p->setArrayDataByName("coin_plat", mail->coin_plat, i);
- //p->setArrayDataByName("unknown2", 0, i);
- bool successItemAdd = false;
- if(mail->stack || mail->char_item_id)
- {
- Item* item = master_item_list.GetItem(mail->char_item_id);
- if(item)
- {
- item->stack_count = mail->stack > 1 ? mail->stack : 0;
- if (version < 860)
- p->setItemArrayDataByName("item", item, player, i, 0, -1);
- else if (version < 1193)
- p->setItemArrayDataByName("item", item, player, i);
- else
- p->setItemArrayDataByName("item", item, player, i, 0, 2);
-
- successItemAdd = true;
- }
- }
- if(!successItemAdd)
- {
- p->setArrayDataByName("end_tag2", GetItemPacketType(GetVersion()), i);
- p->setArrayDataByName("end_tag3", 0xFF, i);
- }
- i++;
- }
- // GMs send mail for free!
- if (GetAdminStatus() > 0)
- {
- p->setDataByName("postage_cost", 0);
- p->setDataByName("attachment_cost", 0);
- }
- else
- {
- p->setDataByName("postage_cost", 10);
- p->setDataByName("attachment_cost", 50);
- }
- p->setDataByName("unknown3", 0x01F4);
- p->setDataByName("unknown4", 0x01000000);
- EQ2Packet* pack = p->serialize();
- //DumpPacket(pack);
- //p->PrintPacket();
- QueuePacket(pack);
- safe_delete(p);
- }
- }
- else
- SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
- }
- void Client::DisplayMailMessage(int32 mail_id) {
- Mail* mail = player->GetMail(mail_id);
- if (mail) {
- int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
- if (kiosk_id > 0) {
- PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
- if (update) {
- update->setDataByName("action", 0x03);
- update->setDataByName("packettype", GetItemPacketType(GetVersion()));
- update->setDataByName("packetsubtype", 0xFF);
- QueuePacket(update->serialize());
- safe_delete(update);
- }
- PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
- if (packet) {
- packet->setDataByName("kiosk_id", kiosk_id);
- packet->setDataByName("mail_id", mail->mail_id);
- packet->setDataByName("player_to_id", mail->player_to_id);
- packet->setDataByName("player_from", mail->player_from.c_str());
- packet->setDataByName("subject", mail->subject.c_str());
- packet->setDataByName("mail_body", mail->mail_body.c_str());
- packet->setDataByName("unknown1", 1);
- packet->setDataByName("unknown2", 0);
- packet->setDataByName("lock_report_button", 1);
- packet->setDataByName("unknown3", 0xFFFFFFFF);
- packet->setDataByName("unknown3a", 0xFFFFFFFF);
- packet->setDataByName("coin_copper", mail->coin_copper);
- packet->setDataByName("coin_silver", mail->coin_silver);
- packet->setDataByName("coin_gold", mail->coin_gold);
- packet->setDataByName("coin_plat", mail->coin_plat);
- if(mail->stack || mail->char_item_id)
- {
- Item* item = master_item_list.GetItem(mail->char_item_id);
- item->stack_count = mail->stack > 1 ? mail->stack : 0;
- if (version < 860)
- packet->setItemByName("item", item, player, 0, -1);
- else if (version < 1193)
- packet->setItemByName("item", item, player, 0, 0);
- else
- packet->setItemByName("item", item, player, 0, 2);
- }
- else
- {
- packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
- packet->setDataByName("end_tag3", 0xFF);
- }
- mail->already_read = true;
- mail->save_needed = true;
- EQ2Packet* pack = packet->serialize();
- QueuePacket(pack);
- safe_delete(packet);
- // trying to update this causes the window not to open
- //SendMailList();
- }
- }
- else
- SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
- }
- }
- /* 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
- packet back to the client before the mail actually sent. */
- void Client::HandleSentMail(EQApplicationPacket* app) {
- PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
- if (packet) {
- if(packet->LoadPacketData(app->pBuffer, app->size)) {
- string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
- PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
- vector<int32>* ids = 0;
- MMailWindowMutex.lock();
- if (reply_packet) {
- int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
- if (player_to.length() == 0)
- reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
- else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
- reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
- else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
- reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
- else {
- if (GetAdminStatus() > 200 && player_to.compare("<all>") == 0) {
- if (mail_window.char_item_id == 0 && (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat) == 0)
- ids = database.GetAllPlayerIDs();
- else
- SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
- }
- else {
- ids = new vector<int32>;
- ids->push_back(database.GetCharacterID(player_to.c_str()));
- }
- if (ids) {
- for (int32 i = 0; i < ids->size(); i++) {
- int32 player_to_id = ids->at(i);
- if (player_to_id > 0) {
- reply_type = MAIL_SEND_RESULT_SUCCESS;
- Mail* mail = new Mail;
- mail->mail_id = 0;
- mail->player_to_id = player_to_id;
- mail->player_from = string(GetPlayer()->GetName());
- mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
- mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
- mail->already_read = 0;
- mail->mail_type = MAIL_TYPE_REGULAR;
- mail->coin_copper = mail_window.coin_copper;
- mail->coin_silver = mail_window.coin_silver;
- mail->coin_gold = mail_window.coin_gold;
- mail->coin_plat = mail_window.coin_plat;
- mail->char_item_id = mail_window.char_item_id;
- mail->stack = mail_window.stack;
- // GM's send mail for free!
- if (GetAdminStatus() > 0)
- {
- mail->postage_cost = 0;
- mail->attachment_cost = 0;
- }
- else
- {
- mail->postage_cost = 10;
- mail->attachment_cost = 50;
- }
- mail->time_sent = Timer::GetUnixTimeStamp();
- mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
-
- mail->save_needed = false;
- database.SavePlayerMail(mail);
- Client* to_client = zone_list.GetClientByCharID(player_to_id);
- if (to_client) {
- to_client->GetPlayer()->AddMail(mail);
- to_client->SimpleMessage(CHANNEL_NARRATIVE, "You have unread mail in your mailbox.");
- string popup_text = "You have unread mail!";
- to_client->SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
- }
- else {
- // don't need the pointer the client doesn't exist currently
- safe_delete(mail);
- }
- ResetSendMail(false, false);
- }
- else
- reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
- }
- }
- }
- string players_to = "";
- if (ids) {
- for (int32 i = 0; i < ids->size(); i++) {
- if (ids->at(i) != 0)
- players_to.append(database.GetCharacterName(ids->at(i)));
- if (i < (ids->size() - 1))
- players_to.append(", ");
- }
- }
- reply_packet->setDataByName("player_to", players_to.c_str());
- reply_packet->setDataByName("reply_type", reply_type);
- QueuePacket(reply_packet->serialize());
- safe_delete(reply_packet);
- safe_delete(ids);
- }
- MMailWindowMutex.unlock();
- }
- safe_delete(packet);
- }
- }
- void Client::DeleteMail(int32 mail_id, bool from_database) {
- player->DeleteMail(mail_id, from_database);
- }
- bool Client::AddMailItem(Item* item)
- {
- if(item && (item->CheckFlag(LORE) || item->CheckFlag(STACK_LORE))) {
- Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "Lore items cannot be mailed.");
- return false;
- }
-
- bool ret = false;
- if (GetMailTransaction()) {
- MMailWindowMutex.lock();
- if(mail_window.char_item_id == 0)
- {
- mail_window.item = item;
- mail_window.char_item_id = item->details.item_id;
- mail_window.stack = item->details.count;
- ret = true;
- PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
- packet->setDataByName("coin_copper", mail_window.coin_copper);
- packet->setDataByName("coin_silver", mail_window.coin_silver);
- packet->setDataByName("coin_gold", mail_window.coin_gold);
- packet->setDataByName("coin_plat", mail_window.coin_plat);
-
- if(item)
- {
- packet->setDataByName("stack", mail_window.stack);
- item->stack_count = mail_window.stack;
- if (version < 860)
- packet->setItemByName("item", item, player, 0, -1);
- else if (version < 1193)
- packet->setItemByName("item", item, player, 0, 0);
- else
- packet->setItemByName("item", item, player, 0, 2);
- }
- else
- {
- packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
- packet->setDataByName("end_tag3", 0xFF);
- }
- QueuePacket(packet->serialize());
- }
- MMailWindowMutex.unlock();
- }
- return ret;
- }
- bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
- bool ret = false;
- if (GetMailTransaction()) {
- MMailWindowMutex.lock();
- PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
- if (packet) {
- if (copper > 0) {
- if (player->RemoveCoins(copper)) {
- mail_window.coin_copper += copper;
- Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
- ret = true;
- }
- }
- else if (silver > 0) {
- if (player->RemoveCoins(silver * 100)) {
- mail_window.coin_silver += silver;
- Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
- ret = true;
- }
- }
- else if (gold > 0) {
- if (player->RemoveCoins(gold * 10000)) {
- mail_window.coin_gold += gold;
- Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
- ret = true;
- }
- }
- else if (plat > 0) {
- if (player->RemoveCoins(plat * 1000000)) {
- mail_window.coin_plat += plat;
- Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
- ret = true;
- }
- }
- if (ret) {
- packet->setDataByName("coin_copper", mail_window.coin_copper);
- packet->setDataByName("coin_silver", mail_window.coin_silver);
- packet->setDataByName("coin_gold", mail_window.coin_gold);
- packet->setDataByName("coin_plat", mail_window.coin_plat);
- Item* item = master_item_list.GetItem(mail_window.char_item_id);
- if(item)
- {
- packet->setDataByName("stack", mail_window.stack);
- item->stack_count = mail_window.stack;
- if (version < 860)
- packet->setItemByName("item", item, player, 0, -1);
- else if (version < 1193)
- packet->setItemByName("item", item, player, 0, 0);
- else
- packet->setItemByName("item", item, player, 0, 2);
- }
- else
- {
- packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
- packet->setDataByName("end_tag3", 0xFF);
- }
- //packet->PrintPacket();
- QueuePacket(packet->serialize());
- }
- else
- SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
- safe_delete(packet);
- }
- MMailWindowMutex.unlock();
- }
- else
- SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
- return ret;
- }
- bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
- bool ret = false;
- if (GetMailTransaction()) {
- MMailWindowMutex.lock();
- PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
- if (packet) {
- if (copper > 0) {
- player->AddCoins(copper);
- mail_window.coin_copper -= copper;
- Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
- ret = true;
- }
- else if (silver > 0) {
- player->AddCoins(silver * 100);
- mail_window.coin_silver -= silver;
- Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
- ret = true;
- }
- else if (gold > 0) {
- player->AddCoins(gold * 10000);
- mail_window.coin_gold -= gold;
- Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
- ret = true;
- }
- else if (plat > 0) {
- player->AddCoins(plat * 1000000);
- mail_window.coin_plat -= plat;
- Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
- ret = true;
- }
- if (ret) {
- packet->setDataByName("coin_copper", mail_window.coin_copper);
- packet->setDataByName("coin_silver", mail_window.coin_silver);
- packet->setDataByName("coin_gold", mail_window.coin_gold);
- packet->setDataByName("coin_plat", mail_window.coin_plat);
- packet->setDataByName("stack", 0);
- packet->setDataByName("packettype", 0x2BFE);
- packet->setDataByName("packetsubtype", 0xFF);
- packet->setDataByName("unknown2", 0);
- QueuePacket(packet->serialize());
- }
- safe_delete(packet);
- }
- MMailWindowMutex.unlock();
- }
- else
- SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
- return ret;
- }
- void Client::TakeMailAttachments(int32 mail_id) {
- if (GetMailTransaction()) {
- Mail* mail = player->GetMail(mail_id);
- if (mail) {
- int64 amount = 0;
- if (mail->coin_copper > 0) {
- amount += mail->coin_copper;
- mail->coin_copper = 0;
- }
- if (mail->coin_silver > 0) {
- amount += mail->coin_silver * 100;
- mail->coin_silver = 0;
- }
- if (mail->coin_gold > 0) {
- amount += mail->coin_gold * 10000;
- mail->coin_gold = 0;
- }
- if (mail->coin_plat > 0) {
- amount += mail->coin_plat * 1000000;
- mail->coin_plat = 0;
- }
- if (mail->char_item_id > 0) {
- AddItem(mail->char_item_id, mail->stack);
- mail->char_item_id = 0;
- mail->stack = 0;
- }
- /* 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
- the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
- find it in any packet logs.*/
- /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
- if (packet) {
- packet->setDataByName("unknown", 0x03);
- packet->setDataByName("coin_copper", mail->coin_copper);
- packet->setDataByName("coin_silver", mail->coin_silver);
- packet->setDataByName("coin_gold", mail->coin_gold);
- packet->setDataByName("coin_plat", mail->coin_plat);
- packet->setDataByName("stack", 0);
- packet->setDataByName("packettype", 0x2BFE);
- packet->setDataByName("packetsubtype", 0xFF);
- packet->setDataByName("unknown2", 0);
- packet->setDataByName("unknown3", 0x00000001);//0x00000016
- DumpPacket(packet->serialize());
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }*/
- database.SavePlayerMail(mail);
- if (amount > 0)
- player->AddCoins(amount);
- SendMailList();
- }
- }
- else
- SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
- }
- void Client::ResetSendMail(bool cancel, bool needslock) {
- if(cancel && mail_transaction)
- SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
- if(needslock)
- MMailWindowMutex.lock();
- if(cancel)
- player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
- if(!cancel)
- mail_transaction = 0;
- mail_window.coin_copper = 0;
- mail_window.coin_silver = 0;
- mail_window.coin_gold = 0;
- mail_window.coin_plat = 0;
- mail_window.char_item_id = 0;
- mail_window.stack = 0;
- if(mail_window.item){
- if(cancel)
- AddItem(mail_window.item);
- else
- safe_delete(mail_window.item);
- }
- mail_window.item = nullptr;
- if(needslock)
- MMailWindowMutex.unlock();
- }
- bool Client::GateAllowed() {
- ZoneServer* zone = GetCurrentZone();
- if (zone){
- bool cangate = zone->GetCanGate();
- return cangate;
- }
-
- return false;
- }
- bool Client::BindAllowed() {
- ZoneServer* zone = GetCurrentZone();
- if (zone){
- bool canbind = zone->GetCanBind();
- return canbind;
- }
- return false;
- }
- bool Client::Bind() {
- int canbind = BindAllowed();
-
- if(canbind == 0) {
- Message(CHANNEL_MERCHANT, "You cannot bind at this location.");
- return false;
- }
- player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
- player->GetPlayerInfo()->SetBindX(player->GetX());
- player->GetPlayerInfo()->SetBindY(player->GetY());
- player->GetPlayerInfo()->SetBindZ(player->GetZ());
- player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
- Message(CHANNEL_MERCHANT, "Your spirit has been bound to this location.");
- return true;
- }
- bool Client::Gate(bool is_spell) {
- if (player->GetPlayerInfo()->GetBindZoneID() == 0) {
- SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells. You have no bind location set.");
- return false;
- }
- ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
- if (zone) {
- int cangate = GateAllowed();
- if(cangate == 0) {
- SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells in this zone.");
- return false;
- }
- player->SetX(player->GetPlayerInfo()->GetBindZoneX());
- player->SetY(player->GetPlayerInfo()->GetBindZoneY());
- player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
- player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
- Zone(zone, false, is_spell);
- return true;
- }
- return false;
- }
- void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id, bool is_spell) {
- if (!destinations || !spawn) {
- return;
- }
- bool has_map = false;
- if (transport_id > 0)
- has_map = GetCurrentZone()->TransportHasMap(transport_id);
- transport_spawn = spawn;
- vector<TransportDestination*> transport_list;
- vector<TransportDestination*>::iterator itr;
- TransportDestination* destination = 0;
- for (itr = destinations->begin(); itr != destinations->end(); itr++) {
- destination = *itr;
- 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)))
- transport_list.push_back(destination);
- }
- if (transport_list.size() == 0 && destination) {
- if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
- if (destination->type == TRANSPORT_TYPE_FLIGHT)
- SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
- else
- {
- EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
- if (app)
- QueuePacket(app);
- }
- }
- else {
- ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
- // determine if this is an instanced zone that already exists
- ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
- if (instance_zone || new_zone) {
- GetPlayer()->SetX(destination->destination_x);
- GetPlayer()->SetY(destination->destination_y);
- GetPlayer()->SetZ(destination->destination_z);
- GetPlayer()->SetHeading(destination->destination_heading);
- if (instance_zone)
- Zone(instance_zone->GetInstanceID(), false, true, is_spell);
- else
- Zone(new_zone, false, is_spell);
- }
- }
- if (destination->message.length() > 0)
- SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
- }
- else if (transport_list.size() > 0) {
- if (!spawn->IsSoundsDisabled())
- PlaySound("mariner_bell");
- PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
- // Put all the destinations the player can go in a new vector
- vector<TransportDestination*> destinations;
- for (int32 i = 0; i < transport_list.size(); i++) {
- destination = transport_list.at(i);
- // Check min level
- if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
- continue;
- // Check max level
- if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
- continue;
- // Check quest complete
- if (destination->req_quest_complete > 0 && GetPlayer()->HasQuestBeenCompleted(destination->req_quest_complete) == 0)
- continue;
- // Check req quest and step
- if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
- continue;
- // 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
- if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
- packet->setDataByName("current_zone", destination->display_name.c_str());
- packet->setDataByName("current_map_x", destination->map_x);
- packet->setDataByName("current_map_y", destination->map_y);
- }
- else {
- destinations.push_back(destination);
- }
- }
- // Use the new vector to create the packet
- destination = 0;
- packet->setArrayLengthByName("num_destinations", destinations.size());
- for (int32 i = 0; i < destinations.size(); i++) {
- destination = destinations.at(i);
- packet->setArrayDataByName("unique_id", destination->unique_id, i);
- packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
- packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
- packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
- packet->setArrayDataByName("cost", destination->cost, i);
- if (has_map) {
- packet->setArrayDataByName("map_x", destination->map_x, i);
- packet->setArrayDataByName("map_y", destination->map_y, i);
- }
- }
- if (has_map)
- packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
- EQ2Packet* app = packet->serialize();
- //DumpPacket(app);
- if (destinations.size() > 0)
- QueuePacket(app);
- safe_delete(packet);
- }
- }
- }
- void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
- PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
- if (packet) {
- if (packet->LoadPacketData(app->pBuffer, app->size)) {
- Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
- int32 unique_id = packet->getType_int32_ByName("unique_id");
- string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
- int32 cost = packet->getType_int32_ByName("cost");
- vector<TransportDestination*> destinations;
- TransportDestination* destination = 0;
- if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
- GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
- vector<TransportDestination*>::iterator itr;
- for (itr = destinations.begin(); itr != destinations.end(); itr++) {
- if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
- destination = *itr;
- break;
- }
- }
- SetTemporaryTransportID(0);
- if (!destination)
- SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
- else {
- if (cost == 0 || player->RemoveCoins(cost)) {
- if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
- if (destination->type == TRANSPORT_TYPE_FLIGHT)
- SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
- else
- {
- EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
- if (outapp)
- QueuePacket(outapp);
- }
- }
- else {
- GetPlayer()->SetX(destination->destination_x);
- GetPlayer()->SetY(destination->destination_y);
- GetPlayer()->SetZ(destination->destination_z);
- GetPlayer()->SetHeading(destination->destination_heading);
- // Test if where we're going is an Instanced zone
- if (!TryZoneInstance(destination->destination_zone_id, false)) {
- LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
- ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
- Zone(new_zone, false);
- }
- }
- if (destination->message.length() > 0)
- SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
- }
- else
- SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
- }
- }
- safe_delete(packet);
- }
- }
- void Client::SendNewSpells(int8 class_id) {
- if (class_id > 0) {
- vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
- AddSendNewSpells(spells);
- safe_delete(spells);
- }
- }
- void Client::SendNewTSSpells(int8 class_id) {
- if (class_id > 0) {
- vector<Spell*>* spells = master_spell_list.GetSpellListByTradeskillClass(class_id, player->GetLevel(), 1);
- AddSendNewSpells(spells);
- safe_delete(spells);
- }
- }
- void Client::AddSendNewSpells(vector<Spell*>* spells) {
- Spell* spell = 0;
- bool send_updates = false;
- vector<Spell*>::iterator itr;
- for (itr = spells->begin(); itr != spells->end(); itr++) {
- spell = *itr;
- if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
- send_updates = true;
- SendSpellUpdate(spell);
- player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
- player->UnlockSpell(spell);
- }
- }
- if (send_updates) {
- EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
- if (outapp)
- QueuePacket(outapp);
- }
- }
- void Client::SetItemSearch(vector<Item*>* items) {
- if (items) {
- safe_delete(search_items);
- search_items = items;
- }
- }
- vector<Item*>* Client::GetSearchItems() {
- return search_items;
- }
- void Client::SearchStore(int32 page) {
- if (search_items) {
- PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
- if (packet) {
- int32 x = page * 8;
- if (search_items->size() > 8) {
- if ((search_items->size() - x) > 8)
- packet->setArrayLengthByName("num_items", 8);
- else
- packet->setArrayLengthByName("num_items", search_items->size() - x);
- }
- else
- packet->setArrayLengthByName("num_items", search_items->size());
- if (search_items->size() > 0) {
- packet->setArrayLengthByName("num_sellers", 1);
- packet->setArrayDataByName("seller_seller_id", 1);
- packet->setDataByName("per_page", 8);
- packet->setDataByName("num_pages", search_items->size() / 8 + 1);
- packet->setDataByName("page", page);
- Item* item = 0;
- int32 limit = search_items->size() > 8 ? 8 : search_items->size();
- for (int32 i = 0; i < limit; i++, x++) {
- if (x >= search_items->size())
- break;
-
- item = search_items->at(x);
- std::string teststr("test ");
- teststr.append(std::to_string(i));
- packet->setArrayDataByName("string_one", teststr.c_str(), i);
- packet->setArrayDataByName("string_two", "testtwo", i);
- packet->setArrayDataByName("seller_name", "EQ2EMuDev", i);
- packet->setArrayDataByName("item_id", item->details.item_id, i);
- packet->setArrayDataByName("item_id2", item->details.item_id, i);
- packet->setArrayDataByName("icon", item->details.icon, i);
- //packet->setArrayDataByName("unknown2b", i, i);
- packet->setArrayDataByName("item_seller_id", 1, i);
- if (item->stack_count == 0)
- packet->setArrayDataByName("quantity", 1, i);
- else
- packet->setArrayDataByName("quantity", item->stack_count, i);
- packet->setArrayDataByName("stack_size", item->stack_count, i);
-
- packet->setArrayDataByName("sell_price", item->sell_price, i);
- std::string tmpStr("");
- tmpStr.append(item->name.c_str());
- tmpStr.append(" (");
- tmpStr.append(std::to_string(item->details.item_id));
- tmpStr.append(")");
- packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
- packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
- //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
- }
- }
- EQ2Packet* outapp = packet->serialize();
- DumpPacket(outapp);
- QueuePacket(outapp);
- safe_delete(packet);
- }
- }
- }
- void Client::SetReadyForUpdates() {
- if (!ready_for_updates) {
- database.loadCharacterProperties(this);
- SendDefaultGroupOptions();
- }
- ready_for_updates = true;
-
- if(GetVersion() <= 546) {
- SendRecipeList();
- }
- }
- void Client::SetReadyForSpawns(bool val) {
- ready_for_spawns = val;
- if (GetPlayer()->GetActivityStatus() > 0) {
- GetPlayer()->SetActivityStatus(0);
- if (GetPlayer()->GetGroupMemberInfo()) {
- world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
- }
- }
- GetPlayer()->SetActiveReward(false);
- zone_list.CheckFriendZoned(this);
- }
- void Client::SendChatRelationship(int8 type, const char* name) {
- if (!name) {
- return;
- }
- PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
- if (packet) {
- packet->setDataByName("account_id", GetAccountID());
- packet->setDataByName("type", type);
- packet->setArrayLengthByName("num_names", 1);
- packet->setArrayDataByName("name", name);
- if (type == 0) {
- Client* client = zone_list.GetClientByCharName(name);
- if (client) {
- packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
- packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
- }
- }
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- void Client::SendFriendList() {
- PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
- if (packet) {
- packet->setDataByName("account_id", GetAccountID());
- map<string, int8>::iterator itr;
- map<string, int8>* friends = player->GetFriends();
- if (friends && friends->size() > 0) {
- Client* client = 0;
- vector<string> names;
- for (itr = friends->begin(); itr != friends->end(); itr++) {
- if (itr->second == 2)
- continue;
- names.push_back(itr->first);
- }
- packet->setArrayLengthByName("num_names", names.size());
- for (int32 i = 0; i < names.size(); i++) {
- client = zone_list.GetClientByCharName(names[i]);
- packet->setArrayDataByName("name", names[i].c_str(), i);
- if (client) {
- packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
- packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
- }
- }
- }
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- void Client::SendIgnoreList() {
- PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
- if (packet) {
- packet->setDataByName("account_id", GetAccountID());
- packet->setDataByName("type", 2);
- map<string, int8>::iterator itr;
- map<string, int8>* ignored = player->GetIgnoredPlayers();
- if (ignored && ignored->size() > 0) {
- vector<string> names;
- for (itr = ignored->begin(); itr != ignored->end(); itr++) {
- if (itr->second == 2)
- continue;
- names.push_back(itr->first);
- }
- packet->setArrayLengthByName("num_names", names.size());
- for (int32 i = 0; i < names.size(); i++)
- packet->setArrayDataByName("name", names[i].c_str(), i);
- }
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- void Client::AddWaypoint(string name, int8 type) {
- waypoint_id++;
- WaypointInfo info;
- info.id = waypoint_id;
- info.type = type;
- waypoints[name] = info;
- }
- void Client::SendWaypoints() {
- PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
- if (packet) {
- packet->setArrayLengthByName("num_updates", waypoints.size());
- map<string, WaypointInfo>::iterator itr;
- int16 i = 0;
- for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
- packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
- packet->setArrayDataByName("waypoint_category", itr->second.type, i);
- packet->setArrayDataByName("spawn_id", itr->second.id, i);
- i++;
- }
- packet->setDataByName("unknown", 0xFFFFFFFF);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- void Client::SelectWaypoint(int32 id) {
- string found_name = "";
- map<string, WaypointInfo>::iterator itr;
- for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
- if (itr->second.id == id) {
- found_name = itr->first;
- break;
- }
- }
- if (found_name.length() > 0) {
- Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
- ShowPathToTarget(spawn);
- }
- }
- void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
- if (waypoint_name) {
- PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
- if (packet) {
- packet->setArrayLengthByName("num_updates", 1);
- packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
- packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
- packet->setArrayDataByName("spawn_id", spawn_id, 0);
- packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
- packet->setArrayDataByName("spawn_id2", spawn_id, 0);
- packet->setDataByName("unknown", 0xFFFFFFFF);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- void Client::ClearWaypoint() {
- PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
- if (packet) {
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
- if (current_zone->pathing) {
- if (GetPlayer()->GetMap()) {
- if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
- return false;
- if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
- return false;
- auto loc = glm::vec3(x, z, y);
- float new_z = GetPlayer()->FindBestZ(loc, nullptr);
- if (new_z != BEST_Z_INVALID) //this is actually y
- y = new_z;
- }
- bool partial = false;
- bool stuck = false;
- PathfinderOptions opts;
- opts.smooth_path = true;
- opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
- opts.offset = y_offset + 1.0f;
- opts.flags = PathingNotDisabled ^ PathingZoneLine;
- PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
- if (packet) {
- auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
- packet->setArrayLengthByName("num_points", path.size());
- int i = 0;
- for (auto& node : path)
- {
- packet->setArrayDataByName("x", node.pos.x, i);
- packet->setArrayDataByName("y", node.pos.z, i);
- packet->setArrayDataByName("z", node.pos.y, i);
- packet->setDataByName("waypoint_x", x);
- packet->setDataByName("waypoint_y", y);
- packet->setDataByName("waypoint_z", z);
- i++;
- }
- if (i > 0)
- QueuePacket(packet->serialize());
- safe_delete(packet);
- return (i > 0);
- }
- }
- return false;
- }
- bool Client::ShowPathToTarget(Spawn* spawn) {
- if (spawn) {
- return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
- }
- return false;
- }
- void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
- if (waypoint_name) {
- PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
- if (packet) {
- packet->setArrayLengthByName("num_points", 1);
- packet->setArrayDataByName("x", x, 0);
- packet->setArrayDataByName("y", y, 0);
- packet->setArrayDataByName("z", z, 0);
- packet->setDataByName("waypoint_x", x);
- packet->setDataByName("waypoint_y", y);
- packet->setDataByName("waypoint_z", z);
- packet->setDataByName("waypoint_name", waypoint_name);
- packet->setDataByName("unknown", 0);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- void Client::InspectPlayer(Player* player_to_inspect) {
- int source_pvp_alignment = GetPlayer()->GetPVPAlignment();
- int target_pvp_alignment = player_to_inspect->GetPVPAlignment();
- bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
- if(pvp_allowed == true){
- if(source_pvp_alignment != target_pvp_alignment){
- Message(CHANNEL_COLOR_RED, "You can not inspect players of different alignments.");
- return;
- }
- }
-
- if (player_to_inspect && player_to_inspect->GetClient()) {
- PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
- if (packet) {
- packet->setDataByName("unknown", 0);
- packet->setSmallStringByName("name", player_to_inspect->GetName());
- packet->setDataByName("race", player_to_inspect->GetRace());
- packet->setDataByName("gender", player_to_inspect->GetGender());
- packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
- int16 effective_level = player_to_inspect->GetInfoStruct()->get_effective_level() != 0 ? player_to_inspect->GetInfoStruct()->get_effective_level() : player_to_inspect->GetLevel();
- packet->setDataByName("adventure_level_effective", effective_level);
- packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
- packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
- packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
- packet->setDataByName("health", player_to_inspect->GetHP());
- packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
- packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
- packet->setDataByName("power", player_to_inspect->GetPower());
- packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
- packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
- packet->setDataByName("mitigation", player_to_inspect->GetInfoStruct()->get_cur_mitigation());
- packet->setDataByName("unknown1", 0);
- packet->setDataByName("avoidance", player_to_inspect->GetInfoStruct()->get_avoidance_display()*10.0f);
- packet->setDataByName("unknown2", 0);
- packet->setDataByName("mitigation_percentage", 0);
- packet->setDataByName("strength", player_to_inspect->GetStr());
- packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
- packet->setDataByName("stamina", player_to_inspect->GetSta());
- packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
- packet->setDataByName("agility", player_to_inspect->GetAgi());
- packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
- packet->setDataByName("wisdom", player_to_inspect->GetWis());
- packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
- packet->setDataByName("intelligence", player_to_inspect->GetInt());
- packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
- packet->setDataByName("unknown4", 0);
- packet->setDataByName("unknown5", 0);
- packet->setDataByName("unknown6", 0);
- packet->setDataByName("unknown7", 0);
- packet->setDataByName("unknown8", 0);
- packet->setDataByName("unknown9", 0);
- packet->setDataByName("unknown10", 0);
- packet->setDataByName("unknown11", 0);
- packet->setDataByName("unknown12", 0);
- packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
- packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
- packet->setDataByName("heat_resist_percentage", 0);
- packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
- packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
- packet->setDataByName("cold_resist_percentage", 0);
- packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
- packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
- packet->setDataByName("magic_resist_percentage", 0);
- packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
- packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
- packet->setDataByName("mental_resist_percentage", 0);
- packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
- packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
- packet->setDataByName("divine_resist_percentage", 0);
- packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
- packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
- packet->setDataByName("disease_resist_percentage", 0);
- packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
- packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
- packet->setDataByName("poison_resist_percentage", 0);
- packet->setArrayLengthByName("num_chars", 0x01FF);
- string biography = player_to_inspect->GetBiography();
- for (size_t i = 0; i < biography.length(); i++)
- packet->setArrayDataByName("biography_char", biography[i], i);
-
- if(GetVersion() <= 546) {
- for(int32 s=0;s<22;s++) {
- int32 slot = s;
-
- char item_slot_name[64], item_slot_name_appearance[64];
- _snprintf(item_slot_name,64,"slot_%u",slot);
- Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, GetVersion()));
- packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 5, true, true);
- }
- }
- else {
- for(int32 s=0;s<NUM_SLOTS;s++) {
- int32 slot = s*2;
-
- char item_slot_name[64], item_slot_name_appearance[64];
- _snprintf(item_slot_name,64,"slot_%u",slot);
- int32 slot_appearance = (s*2)+1;
- _snprintf(item_slot_name_appearance,64,"slot_%u",slot_appearance);
- Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, player_to_inspect->GetClient()->GetVersion()));
- packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 13, false, true);
- if(s <= EQ2_FEET_SLOT || s == EQ2_RANGE_SLOT || s == EQ2_CLOAK_SLOT) {
- pw = player_to_inspect->GetAppearanceEquipmentList()->GetItem(s);
- packet->setItemByName(item_slot_name_appearance, pw, this->GetPlayer(), 0, 13, false, true);
- }
- else {
- packet->setItemByName(item_slot_name_appearance, nullptr, this->GetPlayer(), 0, 13, false, true);
- }
- }
- }
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
- pending_guild_invite.guild = guild;
- pending_guild_invite.invited_by = invited_by;
- }
- void Client::ShowClaimWindow() {
- PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
- if (packet) {
- int16 loaded = database.CountCharClaimItems(GetCharacterID());
- vector<ClaimItems> claim = database.LoadCharacterClaimItems(GetCharacterID());
- int32 account_age = database.GetAccountAge(GetAccountID());
- //not sure if there is a message or not, but adding this and a return, so if we have nothing do nothing rather than display an empty window.
- if (loaded == 0 || claim.empty()) {
- Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
- return;
- }
- packet->setArrayLengthByName("num_claim_items", loaded);
- int j = 0; //use this to track skipped vet items.
- for (int i = 0; i < claim.size(); i++)
- {
- if (j == claim.size()) {
- Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
- return;
- }
- Item* item = master_item_list.GetItem(claim[i].item_id);
- int16 claimed = 0;
- if (claim[i].curr_claim < claim[i].max_claim) {
- claimed = claim[i].max_claim - claim[i].curr_claim;
- }
- else {
- claimed = 0;
- }
- //dont display vet rewards until they reach the age required
- if (account_age < claim[i].vet_reward_time) {
- j++;
- continue;
- }
- packet->setArrayDataByName("id", i, i);
- packet->setArrayDataByName("not_yet_claimed", 1, i);
- packet->setArrayDataByName("num_remaining", claim[i].curr_claim, i);
- packet->setArrayDataByName("one_per_character", claim[i].one_per_char, i);
- packet->setArrayDataByName("claimed_on_this_char", 0, i);
- packet->setArrayDataByName("item_name", item->name.c_str(), i);
- packet->setArrayDataByName("text", "If you ever see this text, let a developer know!", i); //I've not seen this!
- //packet->setArrayDataByName("category", "Scott's Shit", i); //devn00b: not using so commenting out, leaving in case we ever do implement categories.
- packet->setArrayDataByName("icon", item->details.icon, i);
- packet->setArrayDataByName("item_id", item->details.item_id, i);
- j++;
- }
- }
- packet->setDataByName("unknown3", 1);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- void Client::ShowGuildSearchWindow() {
- PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
- if (packet) {
- MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
- MutexMap<int32, Guild*>::iterator itr = guilds->begin();
- packet->setArrayLengthByName("num_guilds", guilds->size());
- int32 i = 0;
- while (itr.Next()) {
- Guild* guild = itr.second;
- packet->setArrayDataByName("guild_id", guild->GetID(), i);
- packet->setArrayDataByName("guild_name", guild->GetName(), i);
- packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
- packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
- packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
- packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
- packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
- packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
- packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
- packet->setArrayDataByName("unknown7", 0x02, i);
- packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
- i++;
- }
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- void Client::ShowDressingRoom(Item* item, sint32 crc) {
- PacketStruct* packet;
- vector<int8>* slot_data;
- vector<int8>::iterator itr;
- int32 slots = 0;
- assert(item);
- if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
- return;
- }
- slot_data = &item->slot_data;
- for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
- if (version >= 1188)
- slots = *itr;
- else
- slots += (int8)pow(2.0, *itr);
- }
- packet->setDataByName("slot", slots);
- packet->setDataByName("appearance_id", item->generic_info.appearance_id);
- if (slots == 2) {
- packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
- packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
- }
- else {
- packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
- packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
- }
- packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
- if (slots == 4) {
- packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
- packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
- packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
- }
- else if (slots == 7) {
- packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
- packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
- packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
- }
- else {
- packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
- packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
- packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
- }
- packet->setDataByName("icon", item->details.icon);
- packet->setDataByName("item_id", item->details.item_id);
- packet->setDataByName("item_crc", crc);
- packet->setDataByName("unknown2", 0xFFFFFFFF);
- packet->setDataByName("unknown4", 0xFFFFFFFF);
- packet->setDataByName("unknown5", 0xFF, 9);
- packet->setDataByName("unknown5", 0xFF, 10);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- void Client::SendCollectionList() {
- map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
- map<int32, Collection*>::iterator itr;
- vector<struct CollectionItem*>* collection_items;
- Collection* collection;
- struct CollectionItem* collection_item;
- PacketStruct* packet = 0;
- int16 i = 0, j;
- if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
- return;
- packet->setArrayLengthByName("num_collections", collections->size());
- for (itr = collections->begin(); itr != collections->end(); itr++) {
- collection = itr->second;
- collection_items = collection->GetCollectionItems();
- packet->setArrayDataByName("unknown", 1, i);
- packet->setArrayDataByName("collection_name", collection->GetName(), i);
- packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
- packet->setArrayDataByName("completed", collection->GetCompleted(), i);
- packet->setArrayDataByName("collection_id", collection->GetID(), i);
- packet->setArrayDataByName("level", collection->GetLevel(), i);
- packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
- packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
- for (j = 0; j < collection_items->size(); j++) {
- collection_item = collection_items->at(j);
- Item* item = master_item_list.GetItem(collection_item->item);
- if (item) {
- packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
- if (version < 955)
- packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
- else
- packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
- }
- packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
- }
- i++;
- }
- packet->setDataByName("new_collection_flag", 1);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- bool Client::SendCollectionsForItem(Item* item) {
- map<int32, Collection*> collections_to_send;
- map<int32, Collection*>* collections;
- map<int32, Collection*>::iterator itr;
- vector<struct CollectionItem*>* collection_items;
- Collection* collection;
- struct CollectionItem* collection_item;
- PacketStruct* packet;
- int16 i;
- assert(item);
- /* get any collections required by this item that the player already has */
- collections = player->GetCollectionList()->GetCollections();
- for (itr = collections->begin(); itr != collections->end(); itr++) {
- collection = itr->second;
- if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
- LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
- collections_to_send[collection->GetID()] = collection;
- }
- }
- /* get any collections required by this item that the player does not have and send it to the client */
- collections = master_collection_list.GetCollections();
- for (itr = collections->begin(); itr != collections->end(); itr++) {
- collection = itr->second;
- if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
- if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
- return false;
- }
- packet->setArrayLengthByName("num_collections", 1);
- packet->setArrayDataByName("unknown", 1, 0);
- packet->setArrayDataByName("collection_name", collection->GetName(), 0);
- packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
- packet->setArrayDataByName("completed", 0, 0);
- packet->setArrayDataByName("collection_id", collection->GetID(), 0);
- packet->setArrayDataByName("level", collection->GetLevel(), 0);
- packet->setArrayDataByName("ready_to_turn_in", 0, 0);
- packet->setArrayDataByName("unknown3", 0x28, 0);
- collection_items = collection->GetCollectionItems();
- packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
- for (i = 0; i < collection_items->size(); i++) {
- collection_item = collection_items->at(i);
- Item* item2 = master_item_list.GetItem(collection_item->item);
- if (item2) {
- packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
- if (version < 955)
- packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
- else
- packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
- packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
- }
- }
- packet->setDataByName("new_collection_flag", 0);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
- collections_to_send[collection->GetID()] = collection;
- }
- }
- /* send the client a list of collections that should be filtered for this item */
- if (collections_to_send.size() > 0) {
- if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
- return false;
- }
- i = 0;
- packet->setArrayLengthByName("num_filters", collections_to_send.size());
- for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
- collection = itr->second;
- packet->setArrayDataByName("collection_id", collection->GetID(), i);
- packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
- i++;
- }
- packet->setDataByName("item_icon", item->details.icon);
- packet->setDataByName("item_name", item->name.c_str());
- packet->setDataByName("item_id", item->details.item_id);
- packet->setDataByName("unknown3", player->GetCollectionList()->Size());
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- return collections_to_send.size() > 0;
- }
- void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
- Collection* collection;
- struct CollectionItem* collection_item;
- PacketStruct* packet;
- char tmp[200] = { 0 };
- assert(item);
- /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
- if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
- /* get the item struct that represents the item for this collection */
- if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
- SendCollectionList();
- LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
- return;
- }
- /* sanity check */
- if (collection_item->found) {
- SendCollectionList();
- 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());
- return;
- }
- }
- else if ((collection = master_collection_list.GetCollection(collection_id))) {
- collection = new Collection(collection);
- /* get the item struct that represents the item for this collection */
- if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
- SendCollectionList();
- LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
- safe_delete(collection);
- return;
- }
- /* add the new collection to the player's collection list */
- if (!player->GetCollectionList()->AddCollection(collection)) {
- SendCollectionList();
- LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
- safe_delete(collection);
- return;
- }
- }
- else {
- LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
- return;
- }
- collection_item->found = 1;
- collection->SetSaveNeeded(true);
- if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
- SendCollectionList();
- LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
- return;
- }
- packet->setDataByName("collection_id", collection_id);
- packet->setDataByName("collection_item_num", collection_item->index);
- packet->setDataByName("add", 1);
- QueuePacket(packet->serialize());
- Item* item2 = master_item_list.GetItem(collection_item->item);
- if (item2) {
- Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
- sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
- SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
- }
- safe_delete(packet);
- RemoveItem(item, 1);
- SendCollectionList();
- }
- void Client::DisplayCollectionComplete(Collection* collection) {
- vector<struct CollectionRewardItem*>* reward_items;
- vector<struct CollectionRewardItem*>* selectable_reward_items;
- struct CollectionRewardItem* reward_item;
- PacketStruct* packet;
- int32 i;
- assert(collection);
-
- reward_items = collection->GetRewardItems();
- selectable_reward_items = collection->GetSelectableRewardItems();
- if (GetVersion() <= 546) {
- int32 source_id = collection->GetID();
- PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
- if (packet2) {
- packet2->setSubstructDataByName("reward_data", "unknown1", 255);
- packet2->setSubstructDataByName("reward_data", "reward", "Quest Reward!");
- packet2->setSubstructDataByName("reward_data", "max_coin", collection->GetRewardCoin());
- packet2->setSubstructDataByName("reward_data", "exp_bonus", collection->GetRewardXP());
-
- if(reward_items){
- int32 item_count = reward_items->size();
- packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
- i = 0;
- if(reward_items) {
- for (i = 0; i < reward_items->size(); i++) {
- Item* item = reward_items->at(i)->item;
- if (item) {
- packet2->setArrayDataByName("reward_id", item->details.item_id, i);
- packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
- }
- }
- }
- }
- if (selectable_reward_items) {
- packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_reward_items->size());
- for (i = 0; i < selectable_reward_items->size(); i++) {
- Item* item = selectable_reward_items->at(i)->item;
- if (item) {
- packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
- packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
- }
- }
- }
- }
- EQ2Packet* app = packet2->serialize();
- QueuePacket(app);
- safe_delete(packet2);
- return;
- }
-
- if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
- return;
- }
-
- packet->setDataByName("title", "Quest Reward!");
- packet->setDataByName("name", collection->GetName());
- packet->setDataByName("description", collection->GetCategory());
- packet->setDataByName("level", collection->GetLevel());
- packet->setDataByName("max_coin", collection->GetRewardCoin());
- packet->setDataByName("min_coin", collection->GetRewardCoin());
- //packet->setDataByName("status_points", quest->GetStatusPoints());
- packet->setArrayLengthByName("num_rewards", reward_items->size());
- for (i = 0; i < reward_items->size(); i++) {
- reward_item = reward_items->at(i);
- if(!reward_item->item)
- {
- LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
- Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
- continue;
- }
- packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
- if (version < 860)
- packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
- else if (version < 1193)
- packet->setItemArrayDataByName("item", reward_item->item, player, i);
- else
- packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
- }
- packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
- for (i = 0; i < selectable_reward_items->size(); i++) {
- reward_item = selectable_reward_items->at(i);
- if(!reward_item->item)
- {
- LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
- Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
- continue;
- }
- packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
- if (version < 860)
- packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
- else if (version < 1193)
- packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
- else
- packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
- }
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- void Client::HandInCollections() {
- map<int32, Collection*>* collections;
- map<int32, Collection*>::iterator itr;
- Collection* collection;
- /* only show 1 collection reward dialog at a time */
- if (player->GetPendingCollectionReward()) {
- return;
- }
- collections = player->GetCollectionList()->GetCollections();
- /* 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
- for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
- for (itr = collections->begin(); itr != collections->end(); itr++) {
- collection = itr->second;
- if (collection->GetIsReadyToTurnIn()) {
- player->SetPendingCollectionReward(collection);
- MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
- QuestRewardData* data = new QuestRewardData;
- data->quest_id = 0;
- data->is_temporary = false;
- data->description = std::string("");
- data->is_collection = true;
- data->has_displayed = false;
- data->tmp_coin = 0;
- data->tmp_status = 0;
- data->db_saved = false;
- data->db_index = 0;
- quest_pending_reward.push_back(data);
- MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
- quest_updates = true;
- break;
- }
- }
- if(quest_updates) {
- SaveQuestRewardData(true);
- }
- }
- void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
- vector<struct CollectionRewardItem*>* reward_items;
- vector<struct CollectionRewardItem*>::iterator itr;
- struct CollectionRewardItem* reward_item;
- int16 num_slots_needed;
- int16 num_slots;
- assert(collection);
- reward_items = collection->GetRewardItems();
- num_slots_needed = (int16)reward_items->size();
- if (selectable_item_id > 0)
- num_slots_needed++;
- num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
- if (num_slots < num_slots_needed) {
- SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
- DisplayCollectionComplete(collection);
- return;
- }
- /* add manditory items */
- for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
- reward_item = *itr;
- AddItem(reward_item->item->details.item_id, reward_item->quantity);
- }
- /* find and add the selectable item if there's one */
- if (selectable_item_id > 0) {
- reward_items = collection->GetSelectableRewardItems();
- for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
- reward_item = *itr;
- if (reward_item->item->details.item_id == selectable_item_id) {
- AddItem(reward_item->item->details.item_id, reward_item->quantity);
- break;
- }
- }
- }
- if (collection->GetRewardXP() > 0) {
- player->AddXP((int32)collection->GetRewardXP());
- }
- if (collection->GetRewardCoin() > 0) {
- player->AddCoins(collection->GetRewardCoin());
- Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
- }
- collection->SetCompleted(true);
- //update achievements for completeing collection here
- collection->SetSaveNeeded(true);
- SendCollectionList();
- /* reset the pending collection reward and check for my collections that the player needs to hand in */
- player->SetPendingCollectionReward(0);
-
- RemoveQueuedQuestReward();
-
- GetPlayer()->SetActiveReward(false);
-
- HandInCollections();
- GetPlayer()->GetZone()->SendSubSpawnUpdates(SUBSPAWN_TYPES::COLLECTOR);
- }
- void Client::SendRecipeList() {
- if(GetRecipeListSent()) {
- return;
- }
-
- PacketStruct* packet = 0;
- map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
- map<int32, Recipe*>::iterator itr;
- int16 i = 0;
- Recipe* recipe;
-
- if(version <= 546) {
- PacketStruct* packet = 0;
- if (!(packet = configReader.getStruct("WS_UpdateRecipeBook", GetVersion()))) {
- return;
- }
- packet->setArrayLengthByName("recipe_count", recipes->size());
- for (itr = recipes->begin(); itr != recipes->end(); itr++) {
- recipe = itr->second;
- int32 recipe_id = recipe->GetID();
- packet->setArrayDataByName("recipe_id", recipe_id, i);
- packet->setArrayDataByName("recipe_data_crc", GetRecipeCRC(recipe), i);
- packet->setArrayDataByName("unknown", 0x7005BE3, i); //0x7005BE3
- i++;
- }
- //packet->PrintPacket();
- EQ2Packet* ret = packet->serializeCountPacket(GetVersion(), 0, nullptr, nullptr);
- QueuePacket(ret);
- safe_delete(packet);
- SetRecipeListSent(true);
- return;
- }
- else if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
- return;
- }
- int8 level = player->GetTSLevel();
- int index = 0;
- for (itr = recipes->begin(); itr != recipes->end(); itr++) {
- recipe = itr->second;
- auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
- if (res != devices.end())
- index = res - devices.begin();
- else
- devices.push_back(recipe->GetDevice());
- }
- packet->setDataByName("command_type", 0);
- packet->setArrayLengthByName("num_recipes", recipes->size());
- int stringsize = 0;
- for (itr = recipes->begin(); itr != recipes->end(); itr++) {
- recipe = itr->second;
- int32 myid = recipe->GetID();
- int8 rlevel = recipe->GetLevel();
- int8 even = level - level * .05 + .5;
- int8 easymin = level - level * .25 + .5;
- int8 veasymin = level - level * .35 + .5;
- if (rlevel > level )
- packet->setArrayDataByName("tier", 4, i);
- else if ((rlevel <= level) & (rlevel >= even))
- packet->setArrayDataByName("tier", 3, i);
- else if ((rlevel <= even) & (rlevel >= easymin))
- packet->setArrayDataByName("tier", 2, i);
- else if ((rlevel <= easymin) & (rlevel >= veasymin))
- packet->setArrayDataByName("tier", 1, i);
- else if ((rlevel <= veasymin) & (rlevel >= 0))
- packet->setArrayDataByName("tier", 0, i);
- if (rlevel == 2)
- int xxx = 1;
- packet->setArrayDataByName("recipe_id", myid, i);
- packet->setArrayDataByName("level", recipe->GetLevel(), i);
- packet->setArrayDataByName("unknown1", recipe->GetLevel(), i);
- packet->setArrayDataByName("icon", recipe->GetIcon(), i);
- packet->setArrayDataByName("classes", recipe->GetClasses(), i);
- packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
- packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
-
- auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
- if (recipe_device != devices.end())
- packet->setArrayDataByName("device_type", recipe_device - devices.begin(), i);
- else
- {//TODO error should never get here
- }
- packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
- packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
- packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
- packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
- i++;
- }
- //packet->PrintPacket();
- EQ2Packet* pack = packet->serialize();
- QueuePacket(pack);
- safe_delete(packet);
- SetRecipeListSent(true);
- }
- void Client::ShowRecipeBook() {
- PacketStruct* packet = 0;
- Spawn* target = 0;
- int index = 0;
- if (!(target = player->GetTarget())) {
- SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
- return;
- }
- if (!target->IsObject()) {
- return;
- }
- if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
- return;
- }
- packet->setDataByName("device", target->GetName());
- packet->setDataByName("unknown1", 1);
- auto res = std::find(devices.begin(), devices.end(), target->GetName());
- if (res != devices.end()){
- index = res - devices.begin();
- int32 deviceID = 0;
- deviceID |= 1UL << index;
- //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
- packet->setDataByName("unknown2", devices.size());
- packet->setDataByName("unknown3", deviceID);
- }
- else
- packet->setDataByName("unknown2", devices.size());
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- void Client::SendTitleUpdate() {
- // must call release read lock before leaving function on GetPlayerTitles
- vector<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
- vector<Title*>::iterator itr;
- Title* title;
- sint32 i = 0;
- sint32 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
- sint32 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
- PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
- if (packet) {
- packet->setArrayLengthByName("num_titles", titles->size());
- for (itr = titles->begin(); itr != titles->end(); itr++) {
- title = *itr;
- packet->setArrayDataByName("title", title->GetName(), i);
- packet->setArrayDataByName("prefix", title->GetPrefix(), i);
- i++;
- }
- packet->setDataByName("current_prefix", prefix_index);
- packet->setDataByName("current_suffix", suffix_index);
- LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
- #if EQDEBUG >= 9
- packet->PrintPacket();
- #endif
- QueuePacket(packet->serialize());
- safe_delete(packet);
- SendUpdateTitles(prefix_index, suffix_index);
- }
- player->GetPlayerTitles()->ReleaseReadLock();
- }
- void Client::SendUpdateTitles(sint32 prefix, sint32 suffix) {
- Title* suffix_title = 0;
- Title* prefix_title = 0;
- if (suffix != -1) {
- suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
- if(suffix_title)
- strcpy(player->appearance.suffix_title, suffix_title->GetName());
- }
- else
- memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
- if (prefix != -1) {
- prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
- if(prefix_title)
- strcpy(player->appearance.prefix_title, prefix_title->GetName());
- }
- else
- memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
- current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
- }
- void Client::SendLanguagesUpdate(int32 id, bool setlang) {
- list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
- list<Language*>::iterator itr;
- Language* language;
- int32 i = 0;
- if(setlang==1){
- GetPlayer()->SetCurrentLanguage(id);
- }
- PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
- if (packet) {
- packet->setArrayLengthByName("num_languages", languages->size());
- for (itr = languages->begin(); itr != languages->end(); itr++) {
- language = *itr;
- packet->setArrayDataByName("language_id", language->GetID(), i);
- i++;
- }
- packet->setDataByName("current_language", id);
- LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
- #if EQDEBUG >= 9
- packet->PrintPacket();
- #endif
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
- PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
- if (packet) {
- if (pet_name)
- packet->setDataByName("pet_name", pet_name);
- if (player->GetInfoStruct()->get_pet_behavior() & 1)
- packet->setDataByName("protect_master", 1);
- if (player->GetInfoStruct()->get_pet_behavior() & 2)
- packet->setDataByName("protect_self", 1);
- if (player->GetInfoStruct()->get_pet_movement() == 2)
- packet->setDataByName("stay_follow_toggle", 1);
- packet->setDataByName("pet_type", type);
- QueuePacket(packet->serialize());
- }
- safe_delete(packet);
- }
- bool Client::IsCrafting() {
- return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
- }
- void Client::SendBiography() {
- PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
- if (packet) {
- char biography[512];
- if(player->GetInfoStruct()->get_biography().size() < 1)
- {
- safe_delete(packet);
- return;
- }
- else
- {
- int16 size = player->GetInfoStruct()->get_biography().size();
- if(size>511)
- size = 511;
-
- strncpy(biography, player->GetInfoStruct()->get_biography().c_str(), player->GetInfoStruct()->get_biography().size());
- biography[player->GetInfoStruct()->get_biography().size()] = '\0';
- }
- packet->setDataByName("biography", biography);
- QueuePacket(packet->serialize());
- }
- safe_delete(packet);
- }
- PendingResurrection* Client::GetCurrentRez() {
- return ¤t_rez;
- }
- Mutex* Client::GetResurrectMutex() {
- return &m_resurrect;
- }
- void Client::SendResurrectionWindow() {
- Spawn* caster = current_rez.caster;
- if (!caster || !player)
- return;
- PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
- if (!packet)
- return;
- char* tmp = new char[512];
- sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
- packet->setMediumStringByName("text", tmp);
- packet->setMediumStringByName("accept_text", "Yes");
- packet->setMediumStringByName("cancel_text", "No");
- sprintf(tmp, "accept_resurrection %u", player->GetID());
- packet->setMediumStringByName("accept_command", tmp);
- sprintf(tmp, "decline_resurrection %u", player->GetID());
- packet->setMediumStringByName("cancel_command", tmp);
- packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- safe_delete_array(tmp);
- }
- void Client::AcceptResurrection() {
- Spawn* caster = current_rez.caster;
- if (!player || !caster)
- return;
- if (player->Alive())
- return;
- if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
- SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
- SendResurrectionWindow();
- return;
- }
- player->GetZone()->ResurrectSpawn(player, this);
- current_rez.should_delete = true;
- }
- void Client::SetPendingLastName(string last_name) {
- pending_last_name = new string;
- pending_last_name->assign(last_name);
- }
- string* Client::GetPendingLastName() {
- return pending_last_name;
- }
- void Client::RemovePendingLastName() {
- safe_delete(pending_last_name);
- }
- void Client::SendLastNameConfirmation() {
- if (!pending_last_name)
- return;
- PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
- if (packet) {
- char* text = new char[128];
- sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
- packet->setDataByName("text", text);
- packet->setDataByName("accept_text", "Yes");
- packet->setDataByName("accept_command", "confirmedlastname");
- packet->setDataByName("cancel_text", "No");
- packet->setDataByName("max_length", 50);
- packet->setDataByName("unknown4", 1);
- packet->setDataByName("unknown5", 1);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- safe_delete_array(text);
- }
- }
- void Client::AddQuestTimer(int32 quest_id) {
- MQuestTimers.writelock(__FUNCTION__, __LINE__);
- quest_timers.push_back(quest_id);
- MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
- }
- void Client::RemoveQuestTimer(int32 quest_id) {
- MQuestTimers.writelock(__FUNCTION__, __LINE__);
- vector<int32>::iterator itr;
- for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
- if ((*itr) == quest_id) {
- quest_timers.erase(itr);
- break;
- }
- }
- MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
- }
- void Client::SavePlayerImages() {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
- // Save the paperdoll image if the server allows it
- if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
- database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
- if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
- // Save the head shot if the server allows it
- if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
- database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
- // Send the head shot to the login server
- if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
- int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
- ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
- memset(packet->pBuffer, 0, size);
- CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
- pic->account_id = GetAccountID();
- pic->char_id = GetCharacterID();
- pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
- memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
- loginserver.SendPacket(packet);
- safe_delete(packet);
- }
- }
- safe_delete_array(incoming_paperdoll.image_bytes);
- incoming_paperdoll.current_size_bytes = 0;
- }
- void Client::EndAutoMount() {
- PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
- if (packet) {
- packet->setDataByName("parameter1", 128);
- packet->setDataByName("parameter2", 64);
- packet->setDataByName("value", 1);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
- if (packet) {
- packet->setDataByName("parameter3", 4);
- packet->setDataByName("parameter5", 2);
- packet->setDataByName("value", 0);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- on_auto_mount = false;
- player->SetMount(((Player*)player)->GetTempMount());
- EQ2_Color mount_color = player->GetTempMountColor();
- EQ2_Color saddle_color = player->GetTempMountSaddleColor();
- player->SetMountColor(&mount_color);
- player->SetMountSaddleColor(&saddle_color);
- player->SetTempMount(0);
- }
- bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
- const char* spawn_script = spawn->GetSpawnScript();
- bool should_use_spawn = true;
- if (spawn_script) {
- lua_State* state = lua_interface->GetSpawnScript(spawn_script);
- if (state) {
- Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
- if (state_mutex)
- state_mutex->writelock(__FUNCTION__, __LINE__);
- lua_getglobal(state, "can_use_command");
- if (lua_isfunction(state, -1)) {
- lua_interface->SetSpawnValue(state, spawn);
- lua_interface->SetSpawnValue(state, GetPlayer());
- lua_interface->SetStringValue(state, command ? command : "");
- if (lua_pcall(state, 3, 1, 0) == 0) {
- should_use_spawn = lua_interface->GetBooleanValue(state, 1);
- }
- }
- lua_interface->ResetFunctionStack(state);
- if (state_mutex)
- state_mutex->releasewritelock(__FUNCTION__, __LINE__);
- }
- }
- return should_use_spawn;
- }
- bool Client::IsCurrentTransmuteID(int32 req_id) {
- return req_id == transmuteID;
- }
- void Client::SetTransmuteID(int32 trans_id) {
- transmuteID = trans_id;
- }
- int32 Client::GetTransmuteID() {
- return transmuteID;
- }
- bool Client::HandleNewLogin(int32 account_id, int32 access_code)
- {
- printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
- ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
- if (zar)
- {
- int32 charID = database.GetCharacterID(zar->GetCharacterName());
- if (database.IsActiveQuery(charID))
- {
- delayedLogin = true;
- delayedAccountID = account_id;
- delayedAccessKey = access_code;
- delayTimer.Start(500);
- 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);
- return true;
- }
- delayedLogin = false;
- delayTimer.Disable();
- firstlogin = zar->isFirstLogin();
- SetReadyForSpawns(false);
- ready_for_updates = false;
- 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);
- Client* client = zone_list.GetClientByCharName(zar->GetCharacterName());
- if (client || database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
- GetPlayer()->CalculateOfflineDebtRecovery(GetLastSavedTimeStamp());
- GetPlayer()->vis_changed = false;
- GetPlayer()->info_changed = false;
-
- bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
- if (pvp_allowed)
- this->GetPlayer()->SetAttackable(1);
- MDeletePlayer.writelock(__FUNCTION__, __LINE__);
- if (client) {
- if (client->getConnection())
- client->getConnection()->SendDisconnect(true);
-
- bool restore_ld_success = false;
- if (client->GetCurrentZone() && !client->IsZoning()) {
- //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
- if (client->GetVersion() == version) {
- client->DisableSave();
- client->ReplaceGroupClient(this);
- Player* current_player = GetPlayer();
- SetPlayer(client->GetPlayer());
- GetPlayer()->SetClient(this);
- GetPlayer()->SetReturningFromLD(true);
-
- SetCharacterID(client->GetCharacterID());
- SetAccountID(client->GetAccountID());
- SetAdminStatus(client->GetAdminStatus());
- SetCurrentZone(GetPlayer()->GetZone());
- client->SetPlayer(current_player);
- GetPlayer()->ResetSavedSpawns();
- restore_ld_success = true;
-
- char tmpldname[128];
- snprintf(tmpldname, 128, "%s Linkdead",GetPlayer()->GetName());
- client->GetPlayer()->SetName(tmpldname, false);
- }
- ZoneServer* tmpZone = client->GetCurrentZone();
- tmpZone->RemoveClientImmediately(client);
- }
- if(!restore_ld_success && !database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
- LogWrite(ZONE__ERROR, 0, "Zone", "Error reloading LD character and loading DB character: %s", player->GetName());
- ClientPacketFunctions::SendLoginDenied(this);
- Disconnect();
- return false;
- }
- }
- MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
- if (!GetCurrentZone()) {
- LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
- ClientPacketFunctions::SendLoginDenied(this);
- Disconnect();
- return false;
- }
- else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
- getConnection()->SetClientVersion(version);
- GetCurrentZone()->SetSpawnStructs(this);
- connected_to_zone = true;
- client_list.Remove(this); //remove from master client list
- GetCurrentZone()->AddClient(this); //add to zones client list
- zone_list.AddClientToMap(player->GetName(), this);
- // this initiates additional DB loading and client offloading within the Zone the player resides, need the client already added in zone and to the map above.
- if(GetCurrentZone()->IsLoading()) {
- new_client_login = NewLoginState::LOGIN_DELAYED;
- }
- else {
- new_client_login = NewLoginState::LOGIN_ALLOWED;
- }
- const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
- if (zone_script && lua_interface)
- lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
- }
- else {
- LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
- version = 0;
- ClientPacketFunctions::SendLoginDenied(this);
- Disconnect();
- return false;
- }
- }
- else {
- LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
- ClientPacketFunctions::SendLoginDenied(this);
- Disconnect();
- return false;
- }
- zone_auth.RemoveAuth(zar);
- }
- else
- {
- LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
- Disconnect();
- return false;
- }
- return true;
- }
- void Client::SendSpawnChanges(set<Spawn*>& spawns) {
- if (!IsReadyForUpdates())
- return;
- map<int32, SpawnData> info_changes;
- map<int32, SpawnData> pos_changes;
- map<int32, SpawnData> vis_changes;
- map<int32, SpawnData> empty_changes;
- int32 info_size = 0;
- int32 pos_size = 0;
- int32 vis_size = 0;
- int count = 0;
- for (const auto& spawn : spawns) {
- int16 index = GetPlayer()->GetIndexForSpawn(spawn);
- if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()))
- continue;
- int16 tmp_info_size = 0;
- int16 tmp_pos_size = 0;
- int16 tmp_vis_size = 0;
- if (spawn->vis_changed)
- {
- auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
- if (vis_change) {
- SpawnData data;
- data.spawn = spawn;
- data.data = vis_change;
- data.size = tmp_vis_size;
- map<int32, SpawnData> tmp_vis_changes;
- tmp_vis_changes[index] = data;
- map<int32, SpawnData> tmp_info_changes;
- map<int32, SpawnData> tmp_pos_changes;
- if (spawn->info_changed) {
- auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
- if (info_change) {
- SpawnData data;
- data.spawn = spawn;
- data.data = info_change;
- data.size = tmp_info_size;
- tmp_info_changes[index] = data;
- }
- }
- if (spawn->position_changed) {
- auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
- if (pos_change) {
- SpawnData data;
- data.spawn = spawn;
- data.data = pos_change;
- data.size = tmp_pos_size;
- tmp_pos_changes[index] = data;
- }
- }
- MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
-
- for (auto& kv : tmp_info_changes) {
- safe_delete_array(kv.second.data);
- }
- for (auto& kv : tmp_pos_changes) {
- safe_delete_array(kv.second.data);
- }
- for (auto& kv : tmp_vis_changes) {
- safe_delete_array(kv.second.data);
- }
- continue;
- }
- }
- if (spawn->info_changed) {
- auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
- if (info_change) {
- SpawnData data;
- data.spawn = spawn;
- data.data = info_change;
- data.size = tmp_info_size;
- info_size += tmp_info_size;
- info_changes[index] = data;
- }
- count++;
- }
- if (spawn->position_changed) {
- auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
- if (pos_change) {
- SpawnData data;
- data.spawn = spawn;
- data.data = pos_change;
- data.size = tmp_pos_size;
- pos_size += tmp_pos_size;
- pos_changes[index] = data;
- }
- count++;
- }
- if (spawn->vis_changed) {
- auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
- if (vis_change) {
- SpawnData data;
- data.spawn = spawn;
- data.data = vis_change;
- data.size = tmp_vis_size;
- vis_size += tmp_vis_size;
- vis_changes[index] = data;
- }
- count++;
- }
- }
- if (info_size == 0 && pos_size == 0 && vis_size == 0) {
- return;
- }
- MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
- for (auto& kv : info_changes) {
- safe_delete_array(kv.second.data);
- }
- for (auto& kv : pos_changes) {
- safe_delete_array(kv.second.data);
- }
- for (auto& kv : vis_changes) {
- safe_delete_array(kv.second.data);
- }
- }
- 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)
- {
- static const int8 oversized = 255;
- int16 opcode_val = 0;
-
- if (EQOpcodeManager.count(GetOpcodeVersion(version)) != 0) {
- opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
- }
- int32 size = info_size + pos_size + vis_size + 8;
- if (version > 283) //version 283 and below uses an overload for size, not always 4 bytes
- size += 3;
- size += CheckOverLoadSize(info_size);
- size += CheckOverLoadSize(pos_size);
- size += CheckOverLoadSize(vis_size);
- if (version <= 283 && size >= 255) {//1 byte to 3 for overloaded val
- size += 2;
- }
- uchar* tmp = new uchar[size];
- uchar* ptr = tmp;
- memset(tmp, 0, size);
- if (version <= 283) {
- if (size >= 255) {
- size -= 3;
- memcpy(ptr, &oversized, sizeof(int8));
- ptr += sizeof(int8);
- memcpy(ptr, &size, sizeof(int16));
- ptr += sizeof(int16);
- size += 3;
- }
- else {
- size -= 1;
- memcpy(ptr, &size, sizeof(int8));
- ptr += sizeof(int8);
- size += 1;
- }
- }
- else {
- size -= 4;
- memcpy(ptr, &size, sizeof(int32));
- ptr += sizeof(int32);
- size += 4;
- }
- memcpy(ptr, &oversized, sizeof(int8));
- ptr += sizeof(int8);
- memcpy(ptr, &opcode_val, sizeof(int16));
- ptr += sizeof(int16);
- int32 current_time = Timer::GetCurrentTime2();
- memcpy(ptr, ¤t_time, sizeof(int32));
- ptr += sizeof(int32);
- ptr += DoOverLoad(info_size, ptr);
- for (const auto& kv : info_changes) {
- auto info = kv.second;
- memcpy(ptr, info.data, info.size);
- ptr += info.size;
- }
- ptr += DoOverLoad(pos_size, ptr);
- for (const auto& kv : pos_changes) {
- auto pos = kv.second;
- memcpy(ptr, pos.data, pos.size);
- ptr += pos.size;
- }
- ptr += DoOverLoad(vis_size, ptr);
- for (const auto& kv : vis_changes) {
- auto vis = kv.second;
- memcpy(ptr, vis.data, vis.size);
- ptr += vis.size;
- }
- EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
- if (packet) {
- /*char blah[64];
- snprintf(blah, 64, "Sending %i", current_time);
- SimpleMessage(4, blah);*/
- QueuePacket(packet);
- }
- delete[] tmp;
- }
- void Client::SendHailCommand(Spawn* spawn)
- {
- // hardcoded 'hail' entity commands
- switch (spawn->secondary_command_list_id)
- {
- case 9:
- case 1262:
- case 1265:
- case 1267:
- {
- EQ2_16BitString* command = new EQ2_16BitString();
- command->data = "";
- command->size = 0;
- commands.Process(COMMAND_HAIL, command, this, spawn);
- safe_delete(command);
- break;
- }
- }
- }
- void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
- {
- if (GetPlayer()->WasSentSpawn(spawn->GetID())) {
- PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
- packet->setMediumStringByName("command_name", command);
- packet->setDataByName("distance", distance);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
- {
- if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
- return false;
- if (command == "house_spawn_examine")
- {
- uint32 itemID = spawn->GetPickupItemID();
- if (itemID)
- {
- Item* item = master_item_list.GetItem(itemID);
- if (item)
- {
- EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
- //DumpPacket(app);
- QueuePacket(app);
- }
- }
- return true;
- }
- return false;
- }
- bool Client::PopulateHouseSpawn(PacketStruct* place_object)
- {
- if (GetTempPlacementSpawn())
- {
- Spawn* tmp = GetTempPlacementSpawn();
- int32 spawn_group_id = database.GetNextSpawnLocation();
- tmp->SetSpawnLocationID(spawn_group_id);
- float newHeading = place_object->getType_float_ByName("heading") + 180;
- int32 spawnDBID = 0;
- if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
- {
- spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
- tmp->SetDatabaseID(spawnDBID);
- }
- else
- {
- spawnDBID = database.FindHouseInstanceSpawn(tmp);
- if (spawnDBID)
- {
- GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
- tmp->SetDatabaseID(spawnDBID);
- }
- }
- tmp->SetX(place_object->getType_float_ByName("x"));
- tmp->SetY(place_object->getType_float_ByName("y"));
- tmp->SetZ(place_object->getType_float_ByName("z"));
- tmp->SetHeading(newHeading);
- tmp->SetSpawnOrigX(tmp->GetX());
- tmp->SetSpawnOrigY(tmp->GetY());
- tmp->SetSpawnOrigZ(tmp->GetZ());
- tmp->SetSpawnOrigHeading(tmp->GetHeading());
-
- database.SaveSpawnInfo(tmp);
- database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
- if (!spawnDBID)
- {
- GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
- // we need to copy as to not delete the ZoneServer object_list entry this on house item pickup
- GetCurrentZone()->AddObject(tmp->GetDatabaseID(), ((Object*)tmp)->Copy());
- }
- return true;
- }
- return false;
- }
- bool Client::PopulateHouseSpawnFinalize()
- {
- if (GetTempPlacementSpawn())
- {
- Spawn* tmp = GetTempPlacementSpawn();
- GetCurrentZone()->AddSpawn(tmp);
- GetCurrentZone()->SendSpawnChanges(tmp, this);
- SetTempPlacementSpawn(nullptr);
- int32 uniqueID = GetPlacementUniqueItemID();
- Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
- tmp->SetPickupItemID(uniqueItem->details.item_id);
- tmp->SetPickupUniqueItemID(uniqueID);
- if (uniqueItem)
- {
- if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
- {
- Query query;
- 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);
- }
- if(uniqueItem->GetItemScript() &&
- lua_interface->RunItemScript(uniqueItem->GetItemScript(), "placed", uniqueItem, GetPlayer(), tmp))
- {
- uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
- }
-
- if(uniqueItem) {
- database.DeleteItem(GetCharacterID(), uniqueItem, 0);
- GetPlayer()->item_list.RemoveItem(uniqueItem, true);
- QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
- }
-
- SetPlacementUniqueItemID(0);
- }
- return true;
- }
- return false;
- }
- void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
- {
- PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
- packet->setDataByName("placement_mode", placementMode);
- packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
- packet->setDataByName("model_type", spawn->GetModelType());
- packet->setDataByName("unknown", 1); //size
- packet->setDataByName("unknown2", 1); //size 2
- packet->setDataByName("unknown2", .5, 1); //size 3
- packet->setDataByName("unknown2", 3, 2);
- packet->setDataByName("unknown2", unknown2_3, 3);
- packet->setDataByName("max_distance", 500);
- packet->setDataByName("CoEunknown", 0xFFFFFFFF);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
- {
- SetPendingFlightPath(path_id);
- ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
- ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
- ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
- PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
- if (packet) {
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- if (mount_id)
- ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
- }
- void Client::SendShowBook(Spawn* sender, string title, int8 language, int8 num_pages, ...)
- {
- if (!sender)
- {
- LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
- return;
- }
- PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
- if (!packet) {
- LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
- return;
- }
- packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
- packet->setDataByName("book_title", title.c_str());
- packet->setDataByName("book_type", "simple");
- packet->setDataByName("unknown2", 1);
- if(language > 0 && !GetPlayer()->HasLanguage(language))
- packet->setDataByName("language", language);
-
- if (GetVersion() > 546)
- packet->setDataByName("unknown5", 1, 4);
- packet->setArrayLengthByName("num_pages", num_pages);
- va_list args;
- va_start(args, num_pages);
- std::string endString("");
- for (int8 p = 0; p < num_pages; p++)
- {
- std::string page = va_arg(args, string);
- switch (GetVersion())
- {
- // release client
- case 283:
- {
- endString.append(page);
- break;
- }
- // DoF trial
- case 546:
- {
- if (p == 0)
- packet->setDataByName("cover_page", page.c_str());
- else
- packet->setArrayDataByName("page_text", page.c_str(), p - 1);
- break;
- }
- // all other clients
- default:
- {
- packet->setArrayDataByName("page_text", page.c_str(), p);
- break;
- }
- }
- }
- if (GetVersion() == 283)
- {
- packet->setDataByName("page_text", endString.c_str());
- }
- va_end(args);
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- void Client::SendShowBook(Spawn* sender, string title, int8 language, vector<Item::BookPage*> pages)
- {
- if (!sender)
- {
- LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
- return;
- }
- PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
- if (!packet) {
- LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
- return;
- }
- packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
- packet->setDataByName("book_title", title.c_str());
- packet->setDataByName("book_type", "simple");
- packet->setDataByName("unknown2", 1);
-
- if(language > 0 && !GetPlayer()->HasLanguage(language))
- packet->setDataByName("language", language);
- if (GetVersion() > 546)
- packet->setDataByName("unknown5", 1, 4);
- packet->setArrayLengthByName("num_pages", pages.size());
- std::string endString("");
- for (int8 p = 0; p < pages.size(); p++)
- {
- Item::BookPage* page = pages[p];
- std::string pageText = string(page->page_text.data);
- switch (GetVersion())
- {
- // release client
- case 283:
- {
- endString.append(pageText);
- break;
- }
- // DoF trial
- case 546:
- {
- if (p == 0)
- packet->setDataByName("cover_page", pageText.c_str());
- else
- packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
- break;
- }
- // all other clients
- default:
- {
- int8 valign = int8(page->valign);
- int8 halign = int8(page->halign);
- packet->setArrayDataByName("page_text", pageText.c_str(), p);
- packet->setArrayDataByName("page_text_valign", valign, p);
- packet->setArrayDataByName("page_text_halign", halign, p);
- break;
- }
- }
- }
- if (GetVersion() == 283)
- {
- packet->setDataByName("page_text", endString.c_str());
- }
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- void Client::ReplaceGroupClient(Client* new_client)
- {
- if (this->GetPlayer()->GetGroupMemberInfo())
- {
- world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
- PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
- if(group)
- {
- group->MGroupMembers.writelock();
- rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
- this->GetPlayer()->GetGroupMemberInfo()->client = new_client;
- this->GetPlayer()->GetGroupMemberInfo()->member = GetPlayer();
- group->MGroupMembers.releasewritelock();
- }
- else
- {
- this->GetPlayer()->GetGroupMemberInfo()->client = 0;
- this->GetPlayer()->GetGroupMemberInfo()->member = 0;
- this->GetPlayer()->SetGroupMemberInfo(0);
- }
- world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
- }
- }
- void Client::TempRemoveGroup()
- {
- if (this->GetPlayer()->GetGroupMemberInfo())
- {
- world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
- PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
- if(group)
- {
- group->MGroupMembers.writelock();
- rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
- this->GetPlayer()->GetGroupMemberInfo()->client = 0;
- this->GetPlayer()->GetGroupMemberInfo()->member = 0;
- this->GetPlayer()->SetGroupMemberInfo(0);
- group->MGroupMembers.releasewritelock();
- group->RemoveClientReference(this);
- }
- else
- {
- this->GetPlayer()->GetGroupMemberInfo()->client = 0;
- this->GetPlayer()->GetGroupMemberInfo()->member = 0;
- this->GetPlayer()->SetGroupMemberInfo(0);
- }
- world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
- }
- }
- void Client::CreateMail(int32 charID, std::string fromName, std::string subjectName, std::string mailBody,
- int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
- {
- Mail mail;
- mail.mail_id = 0;
- mail.already_read = 0;
- mail.postage_cost = 0;
- mail.attachment_cost = 0;
- mail.save_needed = 1;
- //uhh...mail has std::strings so
- //memset(&mail,0,sizeof(Mail));
- mail.player_to_id = charID;
- mail.player_from = fromName;
- mail.subject = subjectName;
- mail.mail_body = mailBody;
- mail.mail_type = mailType;
- mail.coin_copper = copper;
- mail.coin_silver = silver;
- mail.coin_gold = gold;
- mail.coin_plat = platinum;
- mail.char_item_id = item_id;
- mail.stack = stack_size;
- mail.time_sent = time_sent;
- mail.expire_time = expire_time;
- database.SavePlayerMail(&mail);
- }
- void Client::CreateAndUpdateMail(std::string fromName, std::string subjectName, std::string mailBody,
- int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
- {
- Mail* mail = new Mail();
- mail->player_to_id = GetCharacterID();
- mail->player_from = fromName;
- mail->subject = subjectName;
- mail->mail_body = mailBody;
- mail->mail_type = mailType;
- mail->coin_copper = copper;
- mail->coin_silver = silver;
- mail->coin_gold = gold;
- mail->coin_plat = platinum;
- mail->char_item_id = item_id;
- mail->stack = stack_size;
- mail->time_sent = time_sent;
- mail->expire_time = expire_time;
- mail->postage_cost = 0;
- mail->save_needed = 1;
- mail->already_read = 0;
- database.SavePlayerMail(mail);
- GetPlayer()->AddMail(mail);
- }
- void Client::SendEquipOrInvUpdateBySlot(int8 slot)
- {
- if(slot < NUM_SLOTS)
- {
- EQ2Packet* app = GetPlayer()->GetEquipmentList()->serialize(GetVersion(), GetPlayer());
- if (app)
- QueuePacket(app);
- }
- else
- {
- EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
- if (outapp)
- QueuePacket(outapp);
- }
- }
- void Client::QueueStateCommand(int32 spawn_player_id, int32 state)
- {
- if(spawn_player_id < 1)
- return;
- MQueueStateCmds.writelock();
- queued_state_commands.insert(make_pair(spawn_player_id, state));
- MQueueStateCmds.releasewritelock();
- }
- void Client::ProcessStateCommands()
- {
- if(!IsReadyForUpdates())
- return;
- MQueueStateCmds.writelock();
- map<int32, int32>::iterator itr = queued_state_commands.begin();
- for(; itr != queued_state_commands.end(); itr++)
- ClientPacketFunctions::SendStateCommand(this, itr->first, itr->second);
- queued_state_commands.clear();
- MQueueStateCmds.releasewritelock();
- }
- void Client::PurgeItem(Item* item)
- {
- std::unique_lock lock(MConversation);
- map<int32, Item*>::iterator itr;
- for(itr = conversation_items.begin(); itr != conversation_items.end(); itr++)
- {
- if ( itr->second == item )
- {
- conversation_items.erase(itr);
- break;
- }
- }
- }
- void Client::ConsumeFoodDrink(Item* item, int32 slot)
- {
- if(GetPlayer()->StopSaveSpellEffects())
- return;
- if(item) {
- LogWrite(MISC__INFO, 1, "Command", "ItemID: %u, ItemName: %s ItemCount: %i ", item->details.item_id, item->name.c_str(), item->details.count);
- if(item->GetItemScript() && lua_interface){
- lua_interface->RunItemScript(item->GetItemScript(), "cast", item, GetPlayer());
- if (slot == 22)
- Message(CHANNEL_NARRATIVE, "You eat a %s.", item->name.c_str());
- else
- Message(CHANNEL_NARRATIVE, "You drink a %s.", item->name.c_str());
- }
- if (item->details.count > 1) {
- item->details.count -= 1;
- item->save_needed = true;
- }
- else {
- database.DeleteItem(GetPlayer()->GetCharacterID(), item, "EQUIPPED");
- GetPlayer()->GetEquipmentList()->RemoveItem(slot, true);
-
- }
- GetPlayer()->SetCharSheetChanged(true);
- QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
- }
- }
- void Client::AwardCoins(int64 total_coins, std::string reason)
- {
- if (total_coins > 0) {
- player->AddCoins(total_coins);
- PlaySound("coin_cha_ching");
- char tmp[64] = { 0 };
- string message = "You receive ";
- int32 val = 0;
- if (total_coins >= 1000000) {
- val = total_coins / 1000000;
- total_coins -= 1000000 * val;
- sprintf(tmp, "%u Platinum ", val);
- message.append(tmp);
- memset(tmp, 0, 64);
- }
- if (total_coins >= 10000) {
- val = total_coins / 10000;
- total_coins -= 10000 * val;
- sprintf(tmp, "%u Gold ", val);
- message.append(tmp);
- memset(tmp, 0, 64);
- }
- if (total_coins >= 100) {
- val = total_coins / 100;
- total_coins -= 100 * val;
- sprintf(tmp, "%u Silver ", val);
- message.append(tmp);
- memset(tmp, 0, 64);
- }
- if (total_coins > 0) {
- sprintf(tmp, "%u Copper ", (int32)total_coins);
- message.append(tmp);
- }
- message.append(reason);
- int8 type = CHANNEL_LOOT;
- SimpleMessage(type, message.c_str());
- }
- }
- void Client::TriggerSpellSave()
- {
- int32 interval = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateWaitInterval)->GetInt32();
- // default to not have some bogus value in the rule
- if(interval < 1)
- interval = 100;
-
- MSaveSpellStateMutex.lock();
- if(!save_spell_state_timer.Enabled())
- {
- save_spell_state_time_bucket = 0;
- save_spell_state_timer.Start(interval, true);
- }
- else
- {
- int32 elapsed_time = save_spell_state_timer.GetElapsedTime();
- save_spell_state_time_bucket += elapsed_time;
- int32 save_wait_cap = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateCap)->GetInt32();
-
- // default to not have some bogus value in the rule
- if(save_wait_cap < interval)
- save_wait_cap = interval+1;
-
- if(save_spell_state_time_bucket >= save_wait_cap)
- {
- save_spell_state_timer.Trigger();
- }
- }
- MSaveSpellStateMutex.unlock();
- }
- void Client::UpdateSentSpellList() {
- MSpellDetails.readlock(__FUNCTION__, __LINE__);
- std::map<int32, int32>::iterator itr;
- for(itr = sent_spell_details.begin(); itr != sent_spell_details.end(); itr++) {
- Spell* spell = master_spell_list.GetSpell(itr->first, itr->second);
- EQ2Packet* app = spell->SerializeSpell(this, false, false);
- QueuePacket(app);
- }
- MSpellDetails.releasereadlock(__FUNCTION__, __LINE__);
- }
- void Client::SetTempPlacementSpawn(Spawn* tmp) {
- tempPlacementSpawn = tmp;
- hasSentTempPlacementSpawn = false;
- if(tempPlacementSpawn)
- temp_placement_timer.Start();
- else
- temp_placement_timer.Disable();
- }
- void Client::SetPlayer(Player* new_player) {
- if (player && player != new_player)
- zone_list.RemoveClientFromMap(player->GetName(), this);
- player = new_player;
- player->SetClient(this);
- }
- bool Client::UseItem(Item* item, Spawn* target) {
- if (item && item->GetItemScript()) {
- int16 item_index = item->details.index;
- if(!item->CheckFlag2(INDESTRUCTABLE) && item->generic_info.condition == 0) {
- SimpleMessage(CHANNEL_COLOR_RED, "This item is broken and must be repaired at a mender before it can be used");
- }
- else if (item->CheckFlag(EVIL_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_EVIL) {
- Message(0, "%s requires an evil race.", item->name.c_str());
- }
- else if (item->CheckFlag(GOOD_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_GOOD) {
- Message(0, "%s requires a good race.", item->name.c_str());
- }
- else if (item->generic_info.max_charges == 0 || item->generic_info.max_charges == 0xFFFF) {
- lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target);
- return true;
- }
- else {
- if (item->details.count > 0) {
- std::string itemName = string(item->name);
- int32 item_id = item->details.item_id;
- sint64 flags = 0;
- if(lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target, &flags) && flags >= 0)
- {
- //reobtain item make sure it wasn't removed
- item = player->item_list.GetItemFromIndex(item_index);
- if(!item) {
- LogWrite(PLAYER__WARNING, 0, "Command", "%s: Item %s (%i) was used, however after the item looks to be removed.", GetPlayer()->GetName(), itemName.c_str(), item_id);
- return true;
- }
- else if(!item->generic_info.display_charges && item->generic_info.max_charges == 1) {
- Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
- RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
- return true;
- }
- else
- {
- item->details.count--; // charges
- item->save_needed = true;
- QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
- if(!item->details.count) {
- Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
- RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
- }
- return true;
- }
- }
- else {
- LogWrite(PLAYER__WARNING, 0, "Command", "%s: Item %s (%i) was used, after it returned %i, bypassing any removal/update of items.", GetPlayer()->GetName(), itemName.c_str(), item_id, flags);
- return true;
- }
- }
- else
- {
- //reobtain item make sure it wasn't removed
- item = player->item_list.GetItemFromIndex(item_index);
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Item is out of charges.");
- if(item) {
- LogWrite(PLAYER__ERROR, 0, "Command", "%s: Item %s (%i) attempted to be used, however details.count is 0.", GetPlayer()->GetName(), item->name.c_str(), item->details.item_id);
- }
- }
- }
- }
- return false;
- }
- void Client::SendPlayFlavor(Spawn* spawn, int8 language, VoiceOverStruct* non_garble,
- VoiceOverStruct* garble, bool success, bool garble_success) {
- VoiceOverStruct* resStruct = nullptr;
-
- if(language == 0 || GetPlayer()->HasLanguage(language)) {
- if(success) {
- resStruct = non_garble;
- }
- }
- else if(garble_success) {
- resStruct = garble;
- }
-
- if(resStruct) {
- GetPlayer()->GetZone()->PlayFlavor(this, spawn, resStruct->mp3_string.c_str(), resStruct->text_string.c_str(), resStruct->emote_string.c_str(), resStruct->key1, resStruct->key2, language);
- }
- }
- void Client::SaveQuestRewardData(bool force_refresh) {
- Query query;
- if(force_refresh) {
- query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_rewards where char_id = %u",
- GetCharacterID());
-
- query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_temporary_rewards where char_id = %u",
- GetCharacterID());
- }
- vector<QuestRewardData*>::iterator itr;
- vector<QuestRewardData*> tmp_quest_rewards;
- MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
- int index = 0;
- for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
- int32 questID = (*itr)->quest_id;
- if(!(*itr)->db_saved || force_refresh) {
- query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_rewards (char_id, indexed, quest_id, is_temporary, is_collection, has_displayed, tmp_coin, tmp_status, description) values(%u, %u, %u, %u, %u, %u, %llu, %u, '%s')",
- GetCharacterID(), index, questID, (*itr)->is_temporary, (*itr)->is_collection, (*itr)->has_displayed, (*itr)->tmp_coin, (*itr)->tmp_status, database.getSafeEscapeString((*itr)->description.c_str()).c_str());
- (*itr)->db_saved = true;
- (*itr)->db_index = index;
- if(questID && (*itr)->is_temporary) {
- std::vector<Item*> items;
- GetPlayer()->GetQuestTemporaryRewards(questID, &items);
- if(!force_refresh && items.size() > 0) {
- query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "delete from character_quest_temporary_rewards where char_id = %u and quest_id = %u",
- GetCharacterID(), questID);
- }
- for(int i=0;i<items.size();i++) {
- query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_temporary_rewards (char_id, quest_id, item_id, count) values(%u, %u, %u, %u)",
- GetCharacterID(), questID, items[i]->details.item_id, items[i]->details.count);
- }
- }
- }
- index++;
- }
- MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
- }
- void Client::UpdateCharacterRewardData(QuestRewardData* data) {
-
- if(!data)
- return;
- if(data->db_saved) {
- Query query;
- query.AddQueryAsync(GetCharacterID(), &database, Q_INSERT, "update character_quest_rewards set is_temporary = %u, is_collection = %u, has_displayed = %u, tmp_coin = %llu, tmp_status = %u, description = '%s' where char_id=%u and indexed=%u and quest_id=%u",
- data->is_temporary, data->is_collection, data->has_displayed, data->tmp_coin, data->tmp_status, database.getSafeEscapeString(data->description.c_str()).c_str(), GetCharacterID(), data->db_index, data->quest_id);
- }
- }
- void Client::AddRecipeToPlayerPack(Recipe* recipe, PacketStruct* packet, int16* i) {
-
-
- int index = 0;
- if(recipe == nullptr)
- return;
-
- PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
- if (prl->GetRecipe(recipe->GetID())) {
- delete recipe;
- return;
- }
- auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
- if (res != devices.end())
- index = res - devices.begin();
- else
- devices.push_back(recipe->GetDevice());
- prl->AddRecipe(recipe);
- database.SavePlayerRecipe(GetPlayer(), recipe->GetID());
- Message(CHANNEL_NARRATIVE, "Recipe: \"%s\" put in recipe book.", recipe->GetName());
- if (packet && GetRecipeListSent()) {
- packet->setArrayDataByName("id", recipe->GetID(), *i);
- packet->setArrayDataByName("tier", recipe->GetTier(), *i);
- packet->setArrayDataByName("level", recipe->GetLevel(), *i);
- packet->setArrayDataByName("icon", recipe->GetIcon(), *i);
- packet->setArrayDataByName("classes", recipe->GetClasses(), *i);
- //packet->setArrayDataByName("skill", recipe->GetSkill(), *i);
- packet->setArrayDataByName("technique", recipe->GetTechnique(), *i);
- packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), *i);
- auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
- if (recipe_device != devices.end())
- packet->setArrayDataByName("device_type", recipe_device - devices.begin(), *i);
- else
- {//TODO error should never get here
- }
- packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), *i);
- packet->setArrayDataByName("recipe_name", recipe->GetName(), *i);
- packet->setArrayDataByName("recipe_book", recipe->GetBook(), *i);
- packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), *i);
- if(i) {
- (*i)++;
- }
- }
- }
- bool Client::SetPlayerPOVGhost(Spawn* spawn) {
- if(!spawn) {
- pov_ghost_spawn_id = 0;
- SendCharPOVGhost();
- return true;
- }
-
- int32 ghost_id = player->GetIDWithPlayerSpawn(spawn);
- if(ghost_id) {
- pov_ghost_spawn_id = spawn->GetID();
- SendCharPOVGhost();
- return true;
- }
-
- return false;
- }
- void Client::HandleDialogSelectMsg(int32 conversation_id, int32 response_index) {
- std::string conversation = "";
- bool conv_established = false;
- MConversation.lock_shared();
- if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
- conversation = std::string(conversation_map[conversation_id][response_index].c_str());
- conv_established = true;
- }
-
- int32 spawn_id = conversation_spawns[conversation_id];
-
- Item* item = conversation_items[conversation_id];
- MConversation.unlock_shared();
-
- if (GetCurrentZone()) {
- Spawn* spawn = nullptr;
- if(spawn_id) {
- spawn = GetCurrentZone()->GetSpawnByID(spawn_id);
- }
-
- if (conv_established) {
- if (spawn) {
- if(conversation == "CloseItemConversation") {
- LogWrite(LUA__ERROR, 0, "LUA", "CloseItemConversation is an invalid function call for this conversation with spawn id %u", spawn_id);
- }
- else {
- GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation.c_str());
- }
- }
- else if (item && lua_interface && item->GetItemScript())
- lua_interface->RunItemScript(item->GetItemScript(), conversation.c_str(), item, player);
- else
- CloseDialog(conversation_id);
- }
- else
- CloseDialog(conversation_id);
- }
- }
- bool Client::SetPetName(const char* petName) {
- int8 result = database.CheckNameFilter(petName,4,31);
- if (result == BADNAMELENGTH_REPLY) {
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Name length is invalid, must be greater then 3 characters and less then 31.");
- return false;
- }
- else if (result == NAMEINVALID_REPLY) {
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is invalid, can only contain letters.");
- return false;
- }
- else if (result == NAMETAKEN_REPLY) {
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is already taken, please choose another.");
- return false;
- }
- else if (result == NAMEFILTER_REPLY) {
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Name failed the filter check.");
- return false;
- }
- else if (result == UNKNOWNERROR_REPLY) {
- SimpleMessage(CHANNEL_COLOR_YELLOW, "Unknown error while checking the name.");
- return false;
- }
- GetPlayer()->GetInfoStruct()->set_pet_name(petName);
- return true;
- }
- bool Client::CheckConsumptionAllowed(int16 slot, bool send_message) {
- switch(slot) {
- case EQ2_FOOD_SLOT: {
- if(GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_FOOD)) {
- if(send_message) {
- Message(CHANNEL_NARRATIVE, "If you ate anymore you would explode!");
- }
- return false;
- }
- break;
- }
- case EQ2_DRINK_SLOT: {
- if (GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_DRINK))
- {
- if(send_message) {
- Message(CHANNEL_NARRATIVE, "If you drank anymore you would explode!");
- }
- return false;
- }
- break;
- }
- default: {
- return false;
- break;
- }
- }
-
- return true;
- }
- void Client::StartLinkdeadTimer() {
- if(!linkdead_timer) {
- int32 LD_Timer = rule_manager.GetGlobalRule(R_World, LinkDeadTimer)->GetInt32();
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Starting linkdead timer for %s (timer %u seconds)", GetPlayer()->GetName(), (LD_Timer/1000));
- linkdead_timer = new Timer(LD_Timer);
- linkdead_timer->Enable();
-
- if(GetPlayer()->GetGroupMemberInfo()) {
- LogWrite(CCLIENT__DEBUG, 0, "Client", "Telling player %s group they are disconnecting", GetPlayer()->GetName());
- world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has gone Linkdead.", GetPlayer()->GetName());
- }
- }
- }
- bool Client::IsLinkdeadTimerEnabled() {
- if(linkdead_timer) {
- return linkdead_timer->Enabled();
- }
-
- return false;
- }
- void Client::SendNewAdventureSpells() {
- SendNewSpells(player->GetAdventureClass());
- int8 base_class = classes.GetBaseClass(player->GetAdventureClass());
- int secondary_class = classes.GetSecondaryBaseClass(player->GetAdventureClass());
- if(base_class != player->GetAdventureClass()) {
- SendNewSpells(base_class);
- }
- if(secondary_class != player->GetAdventureClass() && secondary_class != base_class) {
- SendNewSpells(secondary_class);
- }
- }
- void Client::SendNewTradeskillSpells() {
- SendNewTSSpells(player->GetTradeskillClass());
- int8 secondary_class = classes.GetSecondaryTSBaseClass(player->GetTradeskillClass());
- if(secondary_class != player->GetTradeskillClass()) {
- SendNewTSSpells(secondary_class);
- }
- }
- bool Client::AddRecipeBookToPlayer(int32 recipe_book_id, Item* item) {
- Recipe* master_recipe = master_recipebook_list.GetRecipeBooks(recipe_book_id);
-
- if(master_recipe) {
- Recipe* recipe_book = new Recipe(master_recipe);
- // if valid recipe book and the player doesn't have it
- if (recipe_book && recipe_book->GetLevel() > GetPlayer()->GetTSLevel()) {
- if(item) {
- Message(CHANNEL_NARRATIVE, "Your tradeskill level is not high enough to scribe this book.");
- }
- safe_delete(recipe_book);
- }
- else if(recipe_book && item && !recipe_book->CanUseRecipeByClass(item, GetPlayer()->GetTradeskillClass())) {
- if(item) {
- Message(CHANNEL_NARRATIVE, "Your tradeskill class cannot use this recipe.");
- }
- safe_delete(recipe_book);
- }
- else if (recipe_book && (!item || !(GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)))){
- LogWrite(PLAYER__DEBUG, 0, "Recipe", "Valid recipe book that the player doesn't have");
- // Add recipe book to the players list
- if(!GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)) {
- GetPlayer()->GetRecipeBookList()->AddRecipeBook(recipe_book);
- }
- std::vector<Recipe*> recipes;
- // Get a list of all recipes this book contains
- if (item && item->recipebook_info) {
- //Backup I guess if the recipe book is empty for whatever reason?
- for (auto& itr : item->recipebook_info->recipes) {
- Recipe* r = master_recipe_list.GetRecipeByCRC(itr); //GetRecipeByName(itr.c_str());
- if (r) {
- recipes.push_back(r);
- }
- }
- LogWrite(PLAYER__DEBUG, 0, "Recipe", "%i recipes found for %s book", recipes.size(), recipe_book->GetBookName());
- }
- else {
- LogWrite(PLAYER__ERROR, 0, "Recipe", "no recipes found for %s book", recipe_book->GetBookName());
- }
-
- //Filter out duplicate recipes the player already has
- for (auto itr = recipes.begin(); itr != recipes.end();) {
- Recipe* recipe = *itr;
- if (GetPlayer()->GetRecipeList()->GetRecipe(recipe->GetID())) {
- itr = recipes.erase(itr);
- }
- else itr++;
- }
- int16 i = 0;
- // Create the packet to send to update the players recipe list
- PacketStruct* packet = 0;
- if (!recipes.empty() && GetRecipeListSent()) {
- packet = configReader.getStruct("WS_RecipeList", GetVersion());
- if (packet) {
- packet->setArrayLengthByName("num_recipes", recipes.size());
- }
- }
- for (int32 r = 0; r < recipes.size(); r++) {
- Recipe* recipe = recipes[r];
- if (recipe) {
- Recipe* player_recipe = new Recipe(recipe);
- AddRecipeToPlayerPack(player_recipe, packet, &i);
- }
- }
- LogWrite(TRADESKILL__DEBUG, 0, "Recipe", "Done adding recipes");
- database.SavePlayerRecipeBook(GetPlayer(), recipe_book->GetBookID());
- if(item) {
- database.DeleteItem(GetCharacterID(), item, 0);
- GetPlayer()->item_list.RemoveItem(item, true);
- }
- QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
- SetRecipeListSent(false);
- SendRecipeList();
- safe_delete(packet);
- return true;
- }
- else {
- if (recipe_book && item) {
- Message(CHANNEL_NARRATIVE, "You have already learned all you can from this item.");
- }
- safe_delete(recipe_book);
- }
- }
- else {
- LogWrite(PLAYER__ERROR, 0, "Player", "%u recipe book id does not exist. Cannot AddRecipeToPlayer.", recipe_book_id);
- }
- return false;
- }
- bool Client::RemoveRecipeFromPlayer(int32 recipe_id) {
- PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
-
- PacketStruct* packet = configReader.getStruct("WS_RecipeList", version);
- Recipe* recipe = prl->GetRecipe(recipe_id);
- int8 level = player->GetTSLevel();
- if(packet && recipe) {
- packet->setDataByName("command_type", 1);
- packet->setArrayLengthByName("num_recipes", 1);
- int32 myid = recipe->GetID();
- int8 rlevel = recipe->GetLevel();
- int8 even = level - level * .05 + .5;
- int8 easymin = level - level * .25 + .5;
- int8 veasymin = level - level * .35 + .5;
- if (rlevel > level )
- packet->setArrayDataByName("tier", 4, 0);
- else if ((rlevel <= level) & (rlevel >= even))
- packet->setArrayDataByName("tier", 3, 0);
- else if ((rlevel <= even) & (rlevel >= easymin))
- packet->setArrayDataByName("tier", 2, 0);
- else if ((rlevel <= easymin) & (rlevel >= veasymin))
- packet->setArrayDataByName("tier", 1, 0);
- else if ((rlevel <= veasymin) & (rlevel >= 0))
- packet->setArrayDataByName("tier", 0, 0);
- if (rlevel == 2)
- int xxx = 1;
- packet->setArrayDataByName("recipe_id", myid, 0);
- packet->setArrayDataByName("level", recipe->GetLevel(), 0);
- packet->setArrayDataByName("unknown1", recipe->GetLevel(), 0);
- packet->setArrayDataByName("icon", recipe->GetIcon(), 0);
- packet->setArrayDataByName("classes", recipe->GetClasses(), 0);
- packet->setArrayDataByName("technique", recipe->GetTechnique(), 0);
- packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), 0);
-
- auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
- if (recipe_device != devices.end())
- packet->setArrayDataByName("device_type", recipe_device - devices.begin(), 0);
- else
- {//TODO error should never get here
- }
- packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), 0);
- packet->setArrayDataByName("recipe_name", recipe->GetName(), 0);
- packet->setArrayDataByName("recipe_book", recipe->GetBook(), 0);
- packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), 0);
- QueuePacket(packet->serialize());
- }
- safe_delete(packet);
-
- bool res = prl->RemoveRecipe(recipe_id);
- if(res) {
- Query query;
- query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "DELETE FROM character_recipes where char_id=%u and recipe_id=%u", GetCharacterID(), recipe_id);
- }
- return res;
- }
- void Client::SaveSpells() {
- MSaveSpellStateMutex.lock();
- player->SaveSpellEffects();
- player->SetSaveSpellEffects(true);
- MSaveSpellStateMutex.unlock();
- }
- void Client::SendReplaceWidget(int32 widget_id, bool delete_widget, float x, float y, float z, int32 grid_id) {
- Widget* new_spawn = new Widget();
- new_spawn->SetWidgetID(widget_id);
- new_spawn->SetLocation(grid_id);
- new_spawn->SetWidgetX(x);
- new_spawn->SetWidgetY(y);
- new_spawn->SetWidgetZ(z);
- new_spawn->SetX(x);
- new_spawn->SetY(y);
- new_spawn->SetZ(z);
- EQ2Packet* ret = new_spawn->serialize(GetPlayer(), GetVersion());
- QueuePacket(ret);
-
- // we have to delete spawn* references anyway, we don't keep this widget live in the spawn list
- GetPlayer()->RemoveSpawn(new_spawn, delete_widget);
-
- safe_delete(new_spawn);
- }
- void Client::ProcessZoneIgnoreWidgets() {
- GetPlayer()->MIgnoredWidgets.lock_shared();
- std::map<int32, bool>::iterator itr;
- for(itr = GetPlayer()->ignored_widgets.begin(); itr != GetPlayer()->ignored_widgets.end(); itr++) {
- SendReplaceWidget(itr->first, true);
- }
- GetPlayer()->MIgnoredWidgets.unlock_shared();
- }
- void Client::PopulateRecipeData(Recipe* recipe, PacketStruct* packet, int i) {
- if(!recipe || !packet)
- return;
-
- int8 level = player->GetTSLevel();
- int32 myid = recipe->GetID();
- int8 rlevel = recipe->GetLevel();
- int8 even = level - level * .05 + .5;
- int8 easymin = level - level * .25 + .5;
- int8 veasymin = level - level * .35 + .5;
- if (rlevel > level )
- packet->setArrayDataByName("tier", 4, i);
- else if ((rlevel <= level) & (rlevel >= even))
- packet->setArrayDataByName("tier", 3, i);
- else if ((rlevel <= even) & (rlevel >= easymin))
- packet->setArrayDataByName("tier", 2, i);
- else if ((rlevel <= easymin) & (rlevel >= veasymin))
- packet->setArrayDataByName("tier", 1, i);
- else if ((rlevel <= veasymin) & (rlevel >= 0))
- packet->setArrayDataByName("tier", 0, i);
- if (rlevel == 2)
- int xxx = 1;
- packet->setArrayDataByName("recipe_id", myid, i);
- packet->setArrayDataByName("level", recipe->GetLevel(), i);
- packet->setArrayDataByName("icon", recipe->GetIcon(), i);
- packet->setArrayDataByName("classes", recipe->GetClasses(), i);
- packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
- packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
- packet->setArrayDataByName("device", recipe->GetDevice(), i);
- packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
- packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
- packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
- packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
-
- packet->setArrayDataByName("book_volume", 0x01, i);
- packet->setArrayDataByName("device_id", 0x01, i);
- }
- int32 Client::GetRecipeCRC(Recipe* recipe) {
-
- PacketStruct* packet = 0;
- if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
- return 0;
- }
- packet->setArrayLengthByName("num_recipes", 1);
-
- PopulateRecipeData(recipe, packet);
-
- string* generic_string_data = packet->serializeString();
- int32 size = generic_string_data->length();
-
- if(size < 5)
- return 0;
-
- uchar* out_data = new uchar[size+1];
- uchar* out_ptr = out_data;
- memcpy(out_ptr, (uchar*)generic_string_data->c_str()+4, generic_string_data->length()-4);
- uint32 out_crc = GenerateCRCRecipe(0, (void*)out_ptr, size-4);
- safe_delete(packet);
- safe_delete_array(out_data);
-
- return out_crc;
- }
- void Client::SendRecipeDetails(vector<int32>* recipes) {
- if(!recipes || recipes->size() == 0)
- return;
-
- PacketStruct* packet = 0;
- if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
- return;
- }
- int32 recipe_size = player->GetRecipeList()->Size();
- packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
- int16 i = 0;
- int32 count = 0;
- vector<int32>::iterator recipe_itr;
- for(recipe_itr = recipes->begin(); recipe_itr != recipes->end(); recipe_itr++) {
- Recipe* recipe = player->GetRecipeList()->GetRecipe(*recipe_itr);
- if(!recipe) {
- continue;
- }
- else if(i > 99) {
- QueuePacket(packet->serialize());
- safe_delete(packet);
- packet = configReader.getStruct("WS_RecipeDetailList", GetVersion());
- recipe_size -= i;
- packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
- i = 0;
- }
- count++;
- PopulateRecipeData(recipe, packet, i);
- i++;
- }
-
- //packet->PrintPacket();
-
- QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- ZoneServer* Client::GetHouseZoneServer(int32 spawn_id, int64 house_id) {
- PlayerHouse* ph = nullptr;
- HouseZone* hz = nullptr;
- if(spawn_id) {
- Spawn* houseWidget = GetPlayer()->GetSpawnByIndex(spawn_id);
- if(houseWidget && houseWidget->IsWidget() && ((Widget*)houseWidget)->GetHouseID()) {
- hz = world.GetHouseZone(((Widget*)houseWidget)->GetHouseID());
- if (hz) {
- ph = world.GetPlayerHouseByHouseID(GetPlayer()->GetCharacterID(), hz->id);
- } else {
- Message(CHANNEL_COLOR_YELLOW, "HouseWidget spawn index %u house zone could not be found.", spawn_id);
- }
- }
- }
-
- if(!ph && house_id) {
- ph = world.GetPlayerHouseByUniqueID(house_id);
- if (ph) {
- hz = world.GetHouseZone(ph->house_id);
- }
- }
-
- if (ph && hz) {
- ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id, false, true);
- return house;
- }
-
- return nullptr;
- }
- void Client::SendHearCast(Spawn* caster, Spawn* target, int32 spell_visual, int16 cast_time) {
- PacketStruct* packet = configReader.getStruct("WS_HearCastSpell", GetVersion());
- if (packet) {
- int32 caster_id = GetPlayer()->GetIDWithPlayerSpawn(caster);
- int32 target_id = GetPlayer()->GetIDWithPlayerSpawn(target);
-
- packet->setDataByName("spawn_id", caster_id);
- packet->setArrayLengthByName("num_targets", 1);
- packet->setArrayDataByName("target", target_id);
- packet->setDataByName("num_targets", 1);
- int32 visual = GetSpellVisualOverride(spell_visual);
-
- packet->setDataByName("spell_visual", visual); //result
- packet->setDataByName("cast_time", cast_time*.01f); //delay
- packet->setDataByName("spell_id", 1);
- packet->setDataByName("spell_level", 1);
- packet->setDataByName("spell_tier", 1);
- EQ2Packet* outapp = packet->serialize();
-
- DumpPacket(outapp);
- QueuePacket(outapp);
- safe_delete(packet);
- }
- }
- int32 Client::GetSpellVisualOverride(int32 spell_visual) {
- int32 visual = spell_visual;
- if(GetVersion() <= 546) { // spell's spell_visual field is based on newer clients, DoF has to convert
- Emote* spellVisualEmote = visual_states.FindSpellVisualByID(visual, 60085);
- if(spellVisualEmote != nullptr && spellVisualEmote->GetMessageString().size() > 0) {
- spellVisualEmote = visual_states.FindSpellVisual(spellVisualEmote->GetMessageString(), GetVersion());
- if(spellVisualEmote) {
- visual = (int32)spellVisualEmote->GetVisualState();
- }
- }
- }
-
- return visual;
- }
|